casacore
Loading...
Searching...
No Matches
BaseColumn.h
Go to the documentation of this file.
1// # BaseColumn.h: Abstract base class for a table column
2// # Copyright (C) 1994,1995,1996,1997,1998
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: casa-feedback@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#ifndef TABLES_BASECOLUMN_H
27#define TABLES_BASECOLUMN_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/Tables/ColumnDesc.h>
32#include <casacore/casa/Utilities/Compare.h>
33#include <casacore/casa/BasicSL/Complex.h>
34#include <casacore/casa/Arrays/ArrayFwd.h>
35#include <memory>
36
37namespace casacore { // # NAMESPACE CASACORE - BEGIN
38
39// # Forward Declarations
40class ArrayBase;
41class BaseColumnDesc;
42class ColumnCache;
43class TableRecord;
44class RefRows;
45class IPosition;
46class Slicer;
47class Sort;
48
49// <summary>
50// Abstract base class for a table column
51// </summary>
52
53// <use visibility=local>
54
55// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
56// </reviewed>
57
58// <prerequisite>
59// # Classes you should understand before using this one.
60// <li> ColumnDesc
61// <li> Table
62// </prerequisite>
63
64// <etymology>
65// This is the (abstract) base class to access a column in a table.
66// </etymology>
67
68// <synopsis>
69// This class is the base class for the derived column classes.
70// It is a private class in the sense that the user cannot get
71// access to it. All user access to a column is done via the
72// classes TableColumn, ScalarColumn and ArrayColumn. They call
73// the corresponding functions in this class and its derived classes.
74// </synopsis>
75
76// <motivation>
77// This class serves a the base for the more specialized column classes
78// like FilledScalarColumn and RefColumn. It defines many virtual
79// functions, which are implemented in the derived classes.
80// Some of these functions are purely virtual, some have a default
81// implementation throwing an "invalid operation" exception. In that
82// way those latter functions only have to be implemented in the
83// classes which handle those cases.
84// <note role=tip> The class RefColumn is in fact implemented in terms of
85// this class. Almost every function in RefColumn calls the corresponding
86// function in BaseColumn with the correct row number.
87// </note>
88// </motivation>
89
90// <todo asof="$DATE:$">
91// # A List of bugs, limitations, extensions or planned refinements.
92// </todo>
93
95 public:
96 // Construct it using the given column description.
98
99 virtual ~BaseColumn();
100
101 // Test if the column is writable.
102 virtual Bool isWritable() const = 0;
103
104 // Test if the column is stored (otherwise it is virtual).
105 virtual Bool isStored() const = 0;
106
107 // Get access to the column keyword set.
108 // <group>
109 virtual TableRecord& rwKeywordSet() = 0;
110 virtual TableRecord& keywordSet() = 0;
111 // </group>
112
113 // Get const access to the column description.
114 const ColumnDesc& columnDesc() const;
115
116 // Get nr of rows in the column.
117 virtual rownr_t nrow() const = 0;
118
119 // Test if the given cell contains a defined value.
120 virtual Bool isDefined(rownr_t rownr) const = 0;
121
122 // Set the shape of the array in the given row.
123 virtual void setShape(rownr_t rownr, const IPosition& shape);
124
125 // Set the shape and tile shape of the array in the given row.
126 virtual void setShape(rownr_t rownr, const IPosition& shape, const IPosition& tileShape);
127
128 // Get the global #dimensions of an array (ie. for all rows).
129 virtual uInt ndimColumn() const;
130
131 // Get the global shape of an array (ie. for all rows).
132 virtual IPosition shapeColumn() const;
133
134 // Get the #dimensions of an array in a particular cell.
135 virtual uInt ndim(rownr_t rownr) const;
136
137 // Get the shape of an array in a particular cell.
138 virtual IPosition shape(rownr_t rownr) const;
139
140 // Get the tile shape of an array in a particular cell.
141 virtual IPosition tileShape(rownr_t rownr) const;
142
143 // Ask the data manager if the shape of an existing array can be changed.
144 // Default is no.
145 virtual Bool canChangeShape() const;
146
147 // Initialize the rows from startRow till endRow (inclusive)
148 // with the default value defined in the column description.
149 virtual void initialize(rownr_t startRownr, rownr_t endRownr) = 0;
150
151 // Get a scalar value from a particular cell.
152 virtual void get(rownr_t rownr, void* dataPtr) const;
153
154 // Get an array from a particular cell.
155 virtual void getArray(rownr_t rownr, ArrayBase& dataPtr) const;
156
157 // Get a slice of an N-dimensional array in a particular cell.
158 virtual void getSlice(rownr_t rownr, const Slicer&, ArrayBase& dataPtr) const;
159
160 // Get the vector of all scalar values in a column.
161 virtual void getScalarColumn(ArrayBase& dataPtr) const;
162
163 // Get the array of all array values in a column.
164 // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
165 // The arrays in the column have to have the same shape in all cells.
166 virtual void getArrayColumn(ArrayBase& dataPtr) const;
167
168 // Get subsections from all arrays in the column.
169 // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
170 // The arrays in the column have to have the same shape in all cells.
171 virtual void getColumnSlice(const Slicer&, ArrayBase& dataPtr) const;
172
173 // Get the vector of some scalar values in a column.
174 virtual void getScalarColumnCells(const RefRows& rownrs, ArrayBase& dataPtr) const;
175
176 // Get the array of some array values in a column.
177 // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
178 // The arrays in the column have to have the same shape in all cells.
179 virtual void getArrayColumnCells(const RefRows& rownrs, ArrayBase& dataPtr) const;
180
181 // Get subsections from some arrays in the column.
182 // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
183 // The arrays in the column have to have the same shape in all cells.
184 virtual void getColumnSliceCells(const RefRows& rownrs, const Slicer&, ArrayBase& dataPtr) const;
185
186 // Put the scalar value in a particular cell.
187 virtual void put(rownr_t rownr, const void* dataPtr);
188
189 // Put the array value in a particular cell.
190 virtual void putArray(rownr_t rownr, const ArrayBase& dataPtr);
191
192 // Put a slice of an N-dimensional array in a particular cell.
193 virtual void putSlice(rownr_t rownr, const Slicer&, const ArrayBase& dataPtr);
194
195 // Put the vector of all scalar values in the column.
196 virtual void putScalarColumn(const ArrayBase& dataPtr);
197
198 // Put the array of all array values in the column.
199 // If the column contains n-dim arrays, the source array is (n+1)-dim.
200 // The arrays in the column have to have the same shape in all cells.
201 virtual void putArrayColumn(const ArrayBase& dataPtr);
202
203 // Put into subsections of all table arrays in the column.
204 // If the column contains n-dim arrays, the source array is (n+1)-dim.
205 // The arrays in the column have to have the same shape in all cells.
206 virtual void putColumnSlice(const Slicer&, const ArrayBase& dataPtr);
207
208 // Get the vector of some scalar values in a column.
209 virtual void putScalarColumnCells(const RefRows& rownrs, const ArrayBase& dataPtr);
210
211 // Get the array of some array values in a column.
212 // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
213 // The arrays in the column have to have the same shape in all cells.
214 virtual void putArrayColumnCells(const RefRows& rownrs, const ArrayBase& dataPtr);
215
216 // Put subsections of some arrays in the column.
217 // If the column contains n-dim arrays, the source array is (n+1)-dim.
218 // The arrays in the column have to have the same shape in all cells.
219 virtual void putColumnSliceCells(const RefRows& rownrs, const Slicer&, const ArrayBase& dataPtr);
220
221 // Get the value from the row and convert it to the required type.
222 // This can only be used for scalar columns with a standard data type.
223 // Note that an unsigned integer cannot be converted to a signed integer
224 // with the same length. So only Int64 can handle all integer values.
225 // <group>
226 void getScalar(rownr_t rownr, Bool& value) const;
227 void getScalar(rownr_t rownr, uChar& value) const;
228 void getScalar(rownr_t rownr, Short& value) const;
229 void getScalar(rownr_t rownr, uShort& value) const;
230 void getScalar(rownr_t rownr, Int& value) const;
231 void getScalar(rownr_t rownr, uInt& value) const;
232 void getScalar(rownr_t rownr, Int64& value) const;
233 void getScalar(rownr_t rownr, float& value) const;
234 void getScalar(rownr_t rownr, double& value) const;
235 void getScalar(rownr_t rownr, Complex& value) const;
236 void getScalar(rownr_t rownr, DComplex& value) const;
237 void getScalar(rownr_t rownr, String& value) const;
238 void getScalar(rownr_t rownr, TableRecord& value) const;
239 // </group>
240
241 // Get a scalar for the other data types.
242 // The given data type id must match the data type id of this column.
243 void getScalar(rownr_t rownr, void* value, const String& dataTypeId) const;
244
245 // Put the value into the row and convert it from the given type.
246 // This can only be used for scalar columns with a standard data type.
247 // <group>
248 void putScalar(rownr_t rownr, const Bool& value);
249 void putScalar(rownr_t rownr, const uChar& value);
250 void putScalar(rownr_t rownr, const Short& value);
251 void putScalar(rownr_t rownr, const uShort& value);
252 void putScalar(rownr_t rownr, const Int& value);
253 void putScalar(rownr_t rownr, const uInt& value);
254 void putScalar(rownr_t rownr, const Int64& value);
255 void putScalar(rownr_t rownr, const float& value);
256 void putScalar(rownr_t rownr, const double& value);
257 void putScalar(rownr_t rownr, const Complex& value);
258 void putScalar(rownr_t rownr, const DComplex& value);
259 void putScalar(rownr_t rownr, const String& value);
260 void putScalar(rownr_t rownr, const Char* value) { putScalar(rownr, String(value)); }
261 void putScalar(rownr_t rownr, const TableRecord& value);
262 // </group>
263
264 // Get a pointer to the underlying column cache.
265 virtual ColumnCache& columnCache() = 0;
266
267 // Set the maximum cache size (in bytes) to be used by a storage manager.
268 virtual void setMaximumCacheSize(uInt nbytes) = 0;
269
270 // Add this column and its data to the Sort object.
271 // It may allocate some storage on the heap, which will be saved
272 // in the argument dataSave.
273 // The function freeSortKey must be called to free this storage.
274 // <group>
275 virtual void makeSortKey(Sort&, std::shared_ptr<BaseCompare>& cmpObj, Int order,
276 std::shared_ptr<ArrayBase>& dataSave);
277 // Do it only for the given row numbers.
278 virtual void makeRefSortKey(Sort&, std::shared_ptr<BaseCompare>& cmpObj, Int order,
279 const Vector<rownr_t>& rownrs, std::shared_ptr<ArrayBase>& dataSave);
280 // </group>
281
282 // Allocate value buffers for the table iterator.
283 // Also get a comparison object if undefined.
284 // The function freeIterBuf must be called to free the buffers.
285 virtual void allocIterBuf(void*& lastVal, void*& curVal, std::shared_ptr<BaseCompare>& cmpObj);
286
287 // Free the value buffers allocated by allocIterBuf.
288 virtual void freeIterBuf(void*& lastVal, void*& curVal);
289
290 protected:
291 // Throw exceptions for invalid scalar get or put.
292 // <group>
293 void throwGetScalar() const;
294 void throwPutScalar() const;
295 void throwGetType(const String& type) const;
296 void throwPutType(const String& type) const;
297 // </group>
298
299 // # Data members
301
302 private:
303 // # This ColumnDesc object is created to be able to return
304 // # a const ColumnDesc& by function columnDesc().
306};
307
308} // namespace casacore
309
310#endif
Non-templated base class for templated Array class.
Definition ArrayBase.h:69
virtual IPosition tileShape(rownr_t rownr) const
Get the tile shape of an array in a particular cell.
void putScalar(rownr_t rownr, const Char *value)
Definition BaseColumn.h:260
virtual rownr_t nrow() const =0
Get nr of rows in the column.
virtual void putScalarColumn(const ArrayBase &dataPtr)
Put the vector of all scalar values in the column.
virtual void setShape(rownr_t rownr, const IPosition &shape, const IPosition &tileShape)
Set the shape and tile shape of the array in the given row.
void putScalar(rownr_t rownr, const Short &value)
void getScalar(rownr_t rownr, Int &value) const
void putScalar(rownr_t rownr, const double &value)
virtual void getArray(rownr_t rownr, ArrayBase &dataPtr) const
Get an array from a particular cell.
void getScalar(rownr_t rownr, void *value, const String &dataTypeId) const
Get a scalar for the other data types.
virtual void getScalarColumn(ArrayBase &dataPtr) const
Get the vector of all scalar values in a column.
void getScalar(rownr_t rownr, Short &value) const
virtual void getArrayColumnCells(const RefRows &rownrs, ArrayBase &dataPtr) const
Get the array of some array values in a column.
void getScalar(rownr_t rownr, DComplex &value) const
virtual void putColumnSlice(const Slicer &, const ArrayBase &dataPtr)
Put into subsections of all table arrays in the column.
void getScalar(rownr_t rownr, String &value) const
virtual void setMaximumCacheSize(uInt nbytes)=0
Set the maximum cache size (in bytes) to be used by a storage manager.
virtual void getArrayColumn(ArrayBase &dataPtr) const
Get the array of all array values in a column.
virtual void get(rownr_t rownr, void *dataPtr) const
Get a scalar value from a particular cell.
void putScalar(rownr_t rownr, const uChar &value)
virtual void getSlice(rownr_t rownr, const Slicer &, ArrayBase &dataPtr) const
Get a slice of an N-dimensional array in a particular cell.
virtual void makeSortKey(Sort &, std::shared_ptr< BaseCompare > &cmpObj, Int order, std::shared_ptr< ArrayBase > &dataSave)
Add this column and its data to the Sort object.
void putScalar(rownr_t rownr, const Int64 &value)
void getScalar(rownr_t rownr, Bool &value) const
Get the value from the row and convert it to the required type.
void getScalar(rownr_t rownr, uInt &value) const
virtual void getScalarColumnCells(const RefRows &rownrs, ArrayBase &dataPtr) const
Get the vector of some scalar values in a column.
void getScalar(rownr_t rownr, double &value) const
virtual void putColumnSliceCells(const RefRows &rownrs, const Slicer &, const ArrayBase &dataPtr)
Put subsections of some arrays in the column.
virtual Bool isDefined(rownr_t rownr) const =0
Test if the given cell contains a defined value.
virtual uInt ndim(rownr_t rownr) const
Get the #dimensions of an array in a particular cell.
virtual IPosition shapeColumn() const
Get the global shape of an array (ie.
virtual IPosition shape(rownr_t rownr) const
Get the shape of an array in a particular cell.
void getScalar(rownr_t rownr, Int64 &value) const
const BaseColumnDesc * colDescPtr_p
Definition BaseColumn.h:300
void getScalar(rownr_t rownr, float &value) const
virtual void makeRefSortKey(Sort &, std::shared_ptr< BaseCompare > &cmpObj, Int order, const Vector< rownr_t > &rownrs, std::shared_ptr< ArrayBase > &dataSave)
Do it only for the given row numbers.
virtual ColumnCache & columnCache()=0
Get a pointer to the underlying column cache.
void putScalar(rownr_t rownr, const Int &value)
virtual uInt ndimColumn() const
Get the global #dimensions of an array (ie.
BaseColumn(const BaseColumnDesc *)
Construct it using the given column description.
virtual void putArray(rownr_t rownr, const ArrayBase &dataPtr)
Put the array value in a particular cell.
void putScalar(rownr_t rownr, const float &value)
virtual TableRecord & rwKeywordSet()=0
Get access to the column keyword set.
virtual Bool isStored() const =0
Test if the column is stored (otherwise it is virtual).
virtual void setShape(rownr_t rownr, const IPosition &shape)
Set the shape of the array in the given row.
virtual void getColumnSlice(const Slicer &, ArrayBase &dataPtr) const
Get subsections from all arrays in the column.
virtual void putArrayColumn(const ArrayBase &dataPtr)
Put the array of all array values in the column.
void putScalar(rownr_t rownr, const uShort &value)
virtual void initialize(rownr_t startRownr, rownr_t endRownr)=0
Initialize the rows from startRow till endRow (inclusive) with the default value defined in the colum...
virtual void allocIterBuf(void *&lastVal, void *&curVal, std::shared_ptr< BaseCompare > &cmpObj)
Allocate value buffers for the table iterator.
void getScalar(rownr_t rownr, Complex &value) const
void getScalar(rownr_t rownr, uChar &value) const
void throwPutScalar() const
virtual TableRecord & keywordSet()=0
void getScalar(rownr_t rownr, uShort &value) const
virtual Bool isWritable() const =0
Test if the column is writable.
void throwGetScalar() const
Throw exceptions for invalid scalar get or put.
void putScalar(rownr_t rownr, const Complex &value)
virtual Bool canChangeShape() const
Ask the data manager if the shape of an existing array can be changed.
virtual void putArrayColumnCells(const RefRows &rownrs, const ArrayBase &dataPtr)
Get the array of some array values in a column.
void putScalar(rownr_t rownr, const uInt &value)
virtual void put(rownr_t rownr, const void *dataPtr)
Put the scalar value in a particular cell.
void throwPutType(const String &type) const
void putScalar(rownr_t rownr, const Bool &value)
Put the value into the row and convert it from the given type.
void putScalar(rownr_t rownr, const TableRecord &value)
void putScalar(rownr_t rownr, const DComplex &value)
const ColumnDesc & columnDesc() const
Get const access to the column description.
void getScalar(rownr_t rownr, TableRecord &value) const
virtual void putScalarColumnCells(const RefRows &rownrs, const ArrayBase &dataPtr)
Get the vector of some scalar values in a column.
void throwGetType(const String &type) const
virtual void freeIterBuf(void *&lastVal, void *&curVal)
Free the value buffers allocated by allocIterBuf.
virtual void putSlice(rownr_t rownr, const Slicer &, const ArrayBase &dataPtr)
Put a slice of an N-dimensional array in a particular cell.
void putScalar(rownr_t rownr, const String &value)
virtual void getColumnSliceCells(const RefRows &rownrs, const Slicer &, ArrayBase &dataPtr) const
Get subsections from some arrays in the column.
Sort on one or more keys, ascending and/or descending.
Definition Sort.h:239
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned char uChar
Definition aipstype.h:45
short Short
Definition aipstype.h:46
unsigned int uInt
Definition aipstype.h:49
unsigned short uShort
Definition aipstype.h:47
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size).
Definition aipsxtype.h:36
uInt order() const
What is the order of the polynomial, i.e.
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44
char Char
Definition aipstype.h:44