casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ArraySampledFunctional.h
Go to the documentation of this file.
00001 //# ArraySampledFunctional:
00002 //# Copyright (C) 1996,1997,1999
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: ArraySampledFunctional.h 20229 2008-01-29 15:19:06Z gervandiepen $
00028 
00029 #ifndef SCIMATH_ARRAYSAMPLEDFUNCTIONAL_H
00030 #define SCIMATH_ARRAYSAMPLEDFUNCTIONAL_H
00031 
00032 #include <casa/aips.h>
00033 #include <scimath/Functionals/SampledFunctional.h>
00034 #include <casa/Arrays/Array.h>
00035 #include <casa/Arrays/IPosition.h>
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 // <summary> Index into an array using the longest axis </summary>
00040 
00041 // <use visibility=export>
00042 
00043 // <reviewed reviewer="wyoung" date="1996/10/19" tests="tSampledFunctional.cc">
00044 // </reviewed>
00045 
00046 // <prerequisite>
00047 //   <li> SampledFunctional
00048 //   <li> Array
00049 // </prerequisite>
00050 
00051 // <etymology>
00052 // A SampledFunctional is an interface that allows random access to a fixed
00053 // size data set. An ArraySampledFunctional allows you to access slices of
00054 // an an Array<T> object. 
00055 // </etymology>
00056 
00057 // <synopsis> 
00058 //
00059 // An ArraySampledFunctional allows an Array<T> object to be sliced up with
00060 // each sample being one slice of the original Array. The slices are always
00061 // the same size and the indexing is always done along the last
00062 // non-degenerate dimension. For example a(4,3,20,1) is interpreted as a
00063 // SampledFunctional with 20 elements, each one being a 4 by 3 matrix.
00064 //
00065 // The Array that is passed to the constructor is copied by this class but
00066 // because Arrays themselves use reference symantics, the actual data is not
00067 // copied but referenced. This means that modifying the data in the original
00068 // array will correspondingly modify the data accessed by this class. 
00069 //
00070 // Similarly the Array that is returned for each Slice is a reference to the
00071 // actual data so that modifying this array really modifies the original
00072 // data. This is not recommended as the operator() function is not supposed
00073 // to be used to get a modifiable portion of the data.
00074 //   </synopsis>
00075 
00076 // <example>
00077 // Constructing and using ArraySampledFunctionals
00078 // <srcblock> 
00079 // Array<Float> a(IPosition(4,4,3,20,1)); // Create an array
00080 // ... Fill the array any way you like ... 
00081 // ArraySampledFunctional<Array<Float> >fa(a);
00082 // for(uInt i = 0; i < 20; i++)
00083 //  cout << "f(" << i << ") = " << fa(i) << endl;
00084 // // Each 'slice' is a 4 by 3 Matrix
00085 // </srcblock>
00086 // </example>
00087 
00088 // <motivation>
00089 // I needed a SampledFunctional which could return Arrays of arbitrary (but
00090 // fixed) size for each index. This could be done using a <src>
00091 // ScalarSampledFunctional<Array<T> > </src> but is ineffecient as each
00092 // element is stored as a separate Array. This class is a more efficient way
00093 // to solve this problem.
00094 // </motivation>
00095 
00096 // <templating arg=T>
00097 // <li> The template type MUST be an Array of some arbitrary type. This is
00098 // because this class will return a slice of this Array. The Array template
00099 // type cannot be subsumed into the class definition because the definition
00100 // of the inherited operator() function means that the return type must be
00101 // the template type
00102 // </templating>
00103 
00104 // <thrown>
00105 // <li> Exceptions are not thrown directly by this class.
00106 // </thrown>
00107 
00108 // <todo asof="1996/10/19">
00109 //   <li> Nothing I can think of.
00110 // </todo>
00111 
00112 template<class T> class ArraySampledFunctional
00113   :public SampledFunctional<T>
00114 {
00115 public:
00116   // These constructors copy the array that is passed to them. But because
00117   // arrays use reference symantics the data is not copied. The default
00118   // constructor is basically useless, as there is no way to add the data
00119   // once the class has been constructed.  
00120   // <group>
00121   ArraySampledFunctional();
00122   ArraySampledFunctional(const T & data);
00123   // </group>
00124 
00125   // The standard copy constructor and assignment operator
00126   // <group>
00127   ArraySampledFunctional(ArraySampledFunctional<T> & other);
00128   ArraySampledFunctional<T> & operator=(ArraySampledFunctional<T> &other);
00129   // </group>
00130 
00131   // Define the functions for the SampledFunction interface
00132   // <group>
00133   virtual T operator()(const uInt & index) const;
00134   virtual uInt nelements() const;
00135   virtual ~ArraySampledFunctional();
00136   // </group>
00137 
00138   // An alternate version of the sampling function which is more effecient
00139   // because it does not need to create as many temporary objects or copy the
00140   // Array data.
00141   // <group>
00142   const T operator()(const uInt & index);
00143   // </group>
00144 
00145 private:
00146   T theRefData;
00147   IPosition theEnd;
00148   uInt theLastAxis;
00149   uInt theNelements;
00150 };
00151 
00152 
00153 } //# NAMESPACE CASA - END
00154 
00155 #ifndef CASACORE_NO_AUTO_TEMPLATES
00156 #include <scimath/Functionals/ArraySampledFunctional.tcc>
00157 #endif //# CASACORE_NO_AUTO_TEMPLATES
00158 #endif