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