casacore
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>
33#include <casacore/casa/Arrays/IPosition.h>
34
35namespace 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
78{
79public:
80 // A zero-length TSMShape.
82
83 // Construct from a shape and precalculate some values.
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".
94
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;
155 const IPosition& stride) const;
156 // </group>
157
158private:
160 uInt size_p; //# Not necessary, but done for speedup
161};
162
163
165{
166 return size_p;
167}
168
169inline Int TSMShape::operator()(uInt index) const
170{
171 return data_p(index);
172}
173
174inline 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
bool conform(const IPosition &other) const
conform returns true if nelements() == other.nelements().
Definition: IPosition.h:636
TSMShape(const TSMShape &that)
Copy constructor (copy semantics).
size_t offset(const IPosition &position, const IPosition &origin) const
size_t offset(const IPosition &position) const
Calculate the offset for a given position.
TSMShape()
A zero-length TSMShape.
IPosition offsetIncrement(const IPosition &subShape) const
Calculate the increments when stepping through an array in a linear way.
IPosition position(size_t offset, const IPosition &origin) const
TSMShape & operator=(const TSMShape &that)
Assignment (copy semantics).
uInt nelements() const
The number of elements in this TSMShape.
Definition: TSMShape.h:164
IPosition data_p
Definition: TSMShape.h:159
IPosition position(size_t offset) const
Calculate the position for a given offset.
IPosition offsetIncrement(const IPosition &subShape, const IPosition &stride) const
TSMShape(const IPosition &shape)
Construct from a shape and precalculate some values.
Bool conform(const TSMShape &other) const
conform returns true if nelements() == other.nelements().
Definition: TSMShape.h:174
Int operator()(uInt index) const
Index into the TSMShape.
Definition: TSMShape.h:169
this file contains all the compiler specific defines
Definition: mainpage.dox:28
unsigned int uInt
Definition: aipstype.h:51
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape.
Definition: ExprNode.h:1987
int Int
Definition: aipstype.h:50
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42