An ArraySampledFunctional allows an Array
The Array that is passed to the constructor is copied by this class but
because Arrays themselves use reference symantics, the actual data is not
copied but referenced. This means that modifying the data in the original
array will correspondingly modify the data accessed by this class.
Similarly the Array that is returned for each Slice is a reference to the
actual data so that modifying this array really modifies the original
data. This is not recommended as the operator() function is not supposed
to be used to get a modifiable portion of the data.
The standard copy constructor and assignment operator
Define the functions for the SampledFunction interface
An alternate version of the sampling function which is more effecient
because it does not need to create as many temporary objects or copy the
Array data.
Example
Constructing and using ArraySampledFunctionals
Array<Float> a(IPosition(4,4,3,20,1)); // Create an array
... Fill the array any way you like ...
ArraySampledFunctional<Array<Float> >fa(a);
for(uInt i = 0; i < 20; i++)
cout << "f(" << i << ") = " << fa(i) << endl;
// Each 'slice' is a 4 by 3 Matrix
Motivation
I needed a SampledFunctional which could return Arrays of arbitrary (but
fixed) size for each index. This could be done using a
ScalarSampledFunctional<Array<T> > but is ineffecient as each
element is stored as a separate Array. This class is a more efficient way
to solve this problem.
Template Type Argument Requirements (T)
The template type MUST be an Array of some arbitrary type. This is
because this class will return a slice of this Array. The Array template
type cannot be subsumed into the class definition because the definition
of the inherited operator() function means that the return type must be
the template type
Thrown Exceptions
Exceptions are not thrown directly by this class.
To Do
Member Description
ArraySampledFunctional()
These constructors copy the array that is passed to them. But because
arrays use reference symantics the data is not copied. The default
constructor is basically useless, as there is no way to add the data
once the class has been constructed.
ArraySampledFunctional(const T & data)
ArraySampledFunctional(ArraySampledFunctional<T> & other)
ArraySampledFunctional<T> & operator=(ArraySampledFunctional<T> &other)
virtual T operator()(const uInt & index) const
virtual uInt nelements() const
virtual ~ArraySampledFunctional()
const T operator()(const uInt & index)