casa
$Rev:20696$
|
00001 //# ScalarSampledFunctional.h: 00002 //# Copyright (C) 1996 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# 00027 //# $Id: ScalarSampledFunctional.h 20299 2008-04-03 05:56:44Z gervandiepen $ 00028 00029 #ifndef SCIMATH_SCALARSAMPLEDFUNCTIONAL_H 00030 #define SCIMATH_SCALARSAMPLEDFUNCTIONAL_H 00031 00032 #include <casa/aips.h> 00033 #include <scimath/Functionals/SampledFunctional.h> 00034 #include <casa/Arrays/Vector.h> 00035 00036 namespace casa { //# NAMESPACE CASA - BEGIN 00037 00038 template<class T> class Block; 00039 00040 // <summary> A unified interface for indexing into Vectors or Blocks </summary> 00041 00042 // <use visibility=export> 00043 00044 // <reviewed reviewer="wyoung" date="1996/10/18" tests="tSampledFunctional.cc"> 00045 00046 // <prerequisite> 00047 // <li> <linkto class="SampledFunctional">SampledFunctional</linkto> 00048 // <li> <linkto class="Vector">Vector</linkto> 00049 // <li> <linkto class="Block">Block</linkto> 00050 // </prerequisite> 00051 00052 // <etymology> 00053 // A SampledFunctional is an interface that allows random access to a fixed 00054 // size data set. I originally conceived this class as being used to access 00055 // scalar values (Int's Float's etc.) stored in Vectors, using the 00056 // SampledFunctional interface. It became generalised to incorporate Blocks 00057 // and I now realise that a better name might be MemorySampledFunctional, to 00058 // highlight that the data is stored in memory (and not on disk). 00059 // </etymology> 00060 00061 // <synopsis> 00062 // This derived class allows allows a Block<T> or Vector<T> object to be 00063 // accessed through the SampledFunctional<T> interface. The principle 00064 // advantage of this is that it unifies the different indexing operators 00065 // (ie. [] for Blocks and () for Vectors). The disadvantage is that it hides 00066 // just about all the other functionality of Vectors and Blocks. If all you 00067 // are interested in is random access to various elements of these objects 00068 // then this class is a suitable abstraction. 00069 00070 // Reference semantics are used (ie. the class does not make a copy of the 00071 // data but refers to the original data) whenever possible. It is not 00072 // possible to use reference semantics (so a physical copy of the data is 00073 // made), in the following cases: 00074 // <ul> 00075 // <li> When constructing the class from a Block<T> 00076 // <li> When constructing the class from a const Vector<T> 00077 // </ul> 00078 // Reference semantics are always used for the copy constructor and 00079 // assignment operators when the ScalarSampledFunctional is 00080 // non-const. Otherwise copy semantics are used. 00081 00082 // When reference semantics are used you need to be aware that modifying the 00083 // contents of the original Vector will modify the data used by this class. 00084 00085 // This class is always more efficient if reference semantics are used, so 00086 // avoid using const arguments unless you really need to. 00087 00088 // </synopsis> 00089 00090 // <example> 00091 // Constructing and using ScalarSampledFunctional's 00092 // <srcblock> 00093 // Block<Float> b(10); // Create a block of ten elements 00094 // // ... Fill the block any way you like ... 00095 // ScalarSampledFunctional<Float> fb(b); 00096 // for(uInt i = 0; i < 10; i++) 00097 // cout << "f(" << i << ") = " << fb(i) << endl; 00098 // </srcblock> 00099 // </example> 00100 00101 // <motivation> 00102 // The SampledFunctional is a useful interface. But it needs some concrete 00103 // classes to back it up. This is the first one that was written. 00104 // </motivation> 00105 00106 // <templating arg=Range> 00107 // <li> Very few assumptions are made on the templating type. So this class 00108 // should work for a wide variety of templates types. 00109 // </templating> 00110 00111 // <thrown> 00112 // <li> Exceptions are not thrown directly by this class. 00113 // </thrown> 00114 00115 // <todo asof="1996/10/28"> 00116 // <li> Nothing I can think of 00117 // </todo> 00118 00119 template<class T> class ScalarSampledFunctional 00120 :public SampledFunctional<T> 00121 { 00122 public: 00123 // See the description above to determine whether a copy or a reference is 00124 // made to the original data. 00125 // <group> 00126 ScalarSampledFunctional(); 00127 ScalarSampledFunctional(Vector<T> & data); 00128 ScalarSampledFunctional(const Vector<T> & data); 00129 ScalarSampledFunctional(const Block<T> & data); 00130 // </group> 00131 00132 // The standard copy constructor and assignment operator. These functions 00133 // use reference semantics when the ScalarSampledFunctional is 00134 // non-const, and copy semantics otherwise. 00135 // <group> 00136 ScalarSampledFunctional(ScalarSampledFunctional<T> & other); 00137 ScalarSampledFunctional(const ScalarSampledFunctional<T> & other); 00138 ScalarSampledFunctional<T> & operator=(ScalarSampledFunctional<T> &other); 00139 ScalarSampledFunctional<T> & operator=(const ScalarSampledFunctional<T> &other); 00140 // </group> 00141 00142 // Define the functions for the SampledFunctional interface 00143 // <group> 00144 virtual T operator()(const uInt &index) const; 00145 virtual uInt nelements() const; 00146 virtual ~ScalarSampledFunctional(); 00147 // </group> 00148 00149 private: 00150 Vector<T> refData; 00151 }; 00152 00153 00154 } //# NAMESPACE CASA - END 00155 00156 #ifndef CASACORE_NO_AUTO_TEMPLATES 00157 #include <scimath/Functionals/ScalarSampledFunctional.tcc> 00158 #endif //# CASACORE_NO_AUTO_TEMPLATES 00159 #endif 00160 00161