casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TSMShape.h
Go to the documentation of this file.
1 //# TSMShape.h: Expanded IPosition for shapes
2 //# Copyright (C) 1994,1995,1996,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 //# $Id$
27 
28 #ifndef TABLES_TSMSHAPE_H
29 #define TABLES_TSMSHAPE_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
34 
35 namespace casacore { //# NAMESPACE CASACORE - BEGIN
36 
37 //# Forward Declarations
38 
39 
40 // <summary>
41 // Expanded IPosition for shapes.
42 // </summary>
43 
44 // <use visibility=local>
45 
46 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
47 // </reviewed>
48 
49 // <prerequisite>
50 //# Classes you should understand before using this one.
51 // <li> <linkto class=IPosition>IPosition</linkto>
52 // </prerequisite>
53 
54 // <etymology>
55 // TSMShape handles the shapes for the Tiled Storage Manager.
56 // </etymology>
57 
58 // <synopsis>
59 // TSMShape is an extension of class
60 // <linkto class=IPosition>IPosition</linkto>
61 // to handle shapes.
62 // It contains some precalculated values to speed up the calculation
63 // of an array offset from an array index (and vice-versa).
64 // </synopsis>
65 
66 // <motivation>
67 // The Tiled Hypercube Storage Manager is heavily using array shapes
68 // and determining offsets from array indices. This class makes these
69 // calculations more efficient.
70 // </motivation>
71 
72 // <todo asof="$DATE:$">
73 // <li> Integrate in a class like LatticeLayout.
74 // </todo>
75 
76 
77 class TSMShape
78 {
79 public:
80  // A zero-length TSMShape.
81  TSMShape();
82 
83  // Construct from a shape and precalculate some values.
84  TSMShape (const IPosition& shape);
85 
86  // Copy constructor (copy semantics).
87  TSMShape (const TSMShape& that);
88 
89  // Assignment (copy semantics).
90  // "this" and "that" must either be conformant (same size)
91  // or "this" must be 0-length, in which case it will
92  // resize itself to be the same length as "that".
93  TSMShape& operator= (const TSMShape& that);
94 
95  ~TSMShape();
96 
97  // Index into the TSMShape. Indices are zero-based. If the preprocessor
98  // symbol AIPS_ARRAY_INDEX_CHECK is defined, "index" will be
99  // checked to ensure it is not out of bounds. If this check fails, an
100  // AipsError will be thrown.
101  Int operator() (uInt index) const;
102 
103  // The number of elements in this TSMShape. Since TSMShape
104  // objects use zero-based indexing, the maximum available index is
105  // nelements() - 1.
106  uInt nelements() const;
107 
108  // conform returns true if nelements() == other.nelements().
109  Bool conform (const TSMShape& other) const;
110 
111  // Calculate the offset for a given position.
112  // <group>
113  size_t offset (const IPosition& position) const;
114  size_t offset (const IPosition& position, const IPosition& origin) const;
115  // </group>
116 
117  // Calculate the position for a given offset.
118  // <group>
119  IPosition position (size_t offset) const;
120  IPosition position (size_t offset, const IPosition& origin) const;
121  // </group>
122 
123  // Calculate the increments when stepping through an array in
124  // a linear way. This can be used to update the array offset
125  // without recalculating it after each step.
126  // For example:
127  // <srcblock>
128  // template<class T>
129  // Array<T> someFunc (const Array<T>& array,
130  // const IPosition& subArrayShape,
131  // const IPosition& subArrayStart) const
132  // {
133  // TSMShape TSM (array.shape());
134  // IPosition offsetIncr = TSM.offsetIncrement (subArrayShape);
135  // Array<T> subArray(subArrayShape);
136  // Bool deleteMain;
137  // const T* mainData = array.getStorage (deleteMain);
138  // mainData += TSM.offset (subArrayStart)
139  // Bool deleteSub;
140  // T* subData = subArray.getStorage (deleteSub);
141  // for (uInt i=0; i<subArrayShape(2); i++) {
142  // for (uInt j=0; j<subArrayShape(1); j++) {
143  // for (uInt k=0; k<subArrayShape(0); k++) {
144  // *subData++ = *mainData++;
145  // }
146  // mainData += offsetIncr(1);
147  // }
148  // mainData += offSetIncr(2);
149  // }
150  // }
151  // </srcblock>
152  // <group>
153  IPosition offsetIncrement (const IPosition& subShape) const;
154  IPosition offsetIncrement (const IPosition& subShape,
155  const IPosition& stride) const;
156  // </group>
157 
158 private:
160  uInt size_p; //# Not necessary, but done for speedup
161 };
162 
163 
164 inline uInt TSMShape::nelements() const
165 {
166  return size_p;
167 }
168 
169 inline Int TSMShape::operator()(uInt index) const
170 {
171  return data_p(index);
172 }
173 
174 inline Bool TSMShape::conform (const TSMShape& other) const
175 {
176  return data_p.conform (other.data_p);
177 }
178 
179 
180 
181 } //# NAMESPACE CASACORE - END
182 
183 #endif
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
Int operator()(uInt index) const
Index into the TSMShape.
Definition: TSMShape.h:169
int Int
Definition: aipstype.h:50
Bool conform(const IPosition &other) const
conform returns true if nelements() == other.nelements().
Definition: IPosition.h:612
size_t offset(const IPosition &position) const
Calculate the offset for a given position.
uInt nelements() const
The number of elements in this TSMShape.
Definition: TSMShape.h:164
TSMShape & operator=(const TSMShape &that)
Assignment (copy semantics).
TSMShape()
A zero-length TSMShape.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
IPosition data_p
Definition: TSMShape.h:159
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape...
Definition: ExprNode.h:1944
virtual Origin origin() const =0
ABSTRACT METHODS //.
IPosition position(size_t offset) const
Calculate the position for a given offset.
Expanded IPosition for shapes.
Definition: TSMShape.h:77
IPosition offsetIncrement(const IPosition &subShape) const
Calculate the increments when stepping through an array in a linear way.
Bool conform(const TSMShape &other) const
conform returns true if nelements() == other.nelements().
Definition: TSMShape.h:174
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42