casacore
Loading...
Searching...
No Matches
ArraySampledFunctional.h
Go to the documentation of this file.
1//# ArraySampledFunctional:
2//# Copyright (C) 1996,1997,1999
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: aips2-request@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25//#
26//#
27//# $Id$
28
29#ifndef SCIMATH_ARRAYSAMPLEDFUNCTIONAL_H
30#define SCIMATH_ARRAYSAMPLEDFUNCTIONAL_H
31
32#include <casacore/casa/aips.h>
33#include <casacore/scimath/Functionals/SampledFunctional.h>
34#include <casacore/casa/Arrays/Array.h>
35#include <casacore/casa/Arrays/IPosition.h>
36
37namespace casacore { //# NAMESPACE CASACORE - BEGIN
38
39// <summary> Index into an array using the longest axis </summary>
40
41// <use visibility=export>
42
43// <reviewed reviewer="wyoung" date="1996/10/19" tests="tSampledFunctional.cc">
44// </reviewed>
45
46// <prerequisite>
47// <li> SampledFunctional
48// <li> Array
49// </prerequisite>
50
51// <etymology>
52// A SampledFunctional is an interface that allows random access to a fixed
53// size data set. An ArraySampledFunctional allows you to access slices of
54// an an Array<T> object.
55// </etymology>
56
57// <synopsis>
58//
59// An ArraySampledFunctional allows an Array<T> object to be sliced up with
60// each sample being one slice of the original Array. The slices are always
61// the same size and the indexing is always done along the last
62// non-degenerate dimension. For example a(4,3,20,1) is interpreted as a
63// SampledFunctional with 20 elements, each one being a 4 by 3 matrix.
64//
65// The Array that is passed to the constructor is copied by this class but
66// because Arrays themselves use reference symantics, the actual data is not
67// copied but referenced. This means that modifying the data in the original
68// array will correspondingly modify the data accessed by this class.
69//
70// Similarly the Array that is returned for each Slice is a reference to the
71// actual data so that modifying this array really modifies the original
72// data. This is not recommended as the operator() function is not supposed
73// to be used to get a modifiable portion of the data.
74// </synopsis>
75
76// <example>
77// Constructing and using ArraySampledFunctionals
78// <srcblock>
79// Array<Float> a(IPosition(4,4,3,20,1)); // Create an array
80// ... Fill the array any way you like ...
81// ArraySampledFunctional<Array<Float> >fa(a);
82// for(uInt i = 0; i < 20; i++)
83// cout << "f(" << i << ") = " << fa(i) << endl;
84// // Each 'slice' is a 4 by 3 Matrix
85// </srcblock>
86// </example>
87
88// <motivation>
89// I needed a SampledFunctional which could return Arrays of arbitrary (but
90// fixed) size for each index. This could be done using a <src>
91// ScalarSampledFunctional<Array<T> > </src> but is ineffecient as each
92// element is stored as a separate Array. This class is a more efficient way
93// to solve this problem.
94// </motivation>
95
96// <templating arg=T>
97// <li> The template type MUST be an Array of some arbitrary type. This is
98// because this class will return a slice of this Array. The Array template
99// type cannot be subsumed into the class definition because the definition
100// of the inherited operator() function means that the return type must be
101// the template type
102// </templating>
103
104// <thrown>
105// <li> Exceptions are not thrown directly by this class.
106// </thrown>
107
108// <todo asof="1996/10/19">
109// <li> Nothing I can think of.
110// </todo>
111
112template<class T> class ArraySampledFunctional
113 :public SampledFunctional<T>
114{
115public:
116 // These constructors copy the array that is passed to them. But because
117 // arrays use reference symantics the data is not copied. The default
118 // constructor is basically useless, as there is no way to add the data
119 // once the class has been constructed.
120 // <group>
122 ArraySampledFunctional(const T & data);
123 // </group>
124
125 // The standard copy constructor and assignment operator
126 // <group>
129 // </group>
130
131 // Define the functions for the SampledFunction interface
132 // <group>
133 virtual T operator()(const uInt & index) const;
134 virtual uInt nelements() const;
136 // </group>
137
138 // An alternate version of the sampling function which is more effecient
139 // because it does not need to create as many temporary objects or copy the
140 // Array data.
141 // <group>
142 const T operator()(const uInt & index);
143 // </group>
144
145private:
150};
151
152
153} //# NAMESPACE CASACORE - END
154
155#ifndef CASACORE_NO_AUTO_TEMPLATES
156#include <casacore/scimath/Functionals/ArraySampledFunctional.tcc>
157#endif //# CASACORE_NO_AUTO_TEMPLATES
158#endif
ArraySampledFunctional()
These constructors copy the array that is passed to them.
ArraySampledFunctional(ArraySampledFunctional< T > &other)
The standard copy constructor and assignment operator.
virtual uInt nelements() const
Return the total size of the data set.
const T operator()(const uInt &index)
An alternate version of the sampling function which is more effecient because it does not need to cre...
virtual T operator()(const uInt &index) const
Define the functions for the SampledFunction interface.
ArraySampledFunctional< T > & operator=(ArraySampledFunctional< T > &other)
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:51