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