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 
39 namespace casacore { //# NAMESPACE CASACORE - BEGIN
40 
41 //# Forward Declarations
42 class BaseColumnDesc;
43 class ColumnCache;
44 class TableRecord;
45 class RefRows;
46 class IPosition;
47 class Slicer;
48 class Sort;
49 template<class T> class Array;
50 template<class T> class Vector;
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.
103  BaseColumn (const BaseColumnDesc*);
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 uInt nrow() const = 0;
124 
125  // Test if the given cell contains a defined value.
126  virtual Bool isDefined (uInt rownr) const = 0;
127 
128  // Set the shape of the array in the given row.
129  virtual void setShape (uInt rownr, const IPosition& shape);
130 
131  // Set the shape and tile shape of the array in the given row.
132  virtual void setShape (uInt 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 (uInt rownr) const;
143 
144  // Get the shape of an array in a particular cell.
145  virtual IPosition shape (uInt rownr) const;
146 
147  // Get the tile shape of an array in a particular cell.
148  virtual IPosition tileShape (uInt 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  // Ask if the data manager can handle a scalar column.
155  // Default is never.
156  virtual Bool canAccessScalarColumn (Bool& reask) const;
157 
158  // Ask if the data manager can handle an array column.
159  // Default is never.
160  virtual Bool canAccessArrayColumn (Bool& reask) const;
161 
162  // Ask if the data manager can handle a collection of cells in a
163  // scalar column. Default is never.
164  virtual Bool canAccessScalarColumnCells (Bool& reask) const;
165 
166  // Ask if the data manager can handle a collection of cells in an
167  // array column. Default is never.
168  virtual Bool canAccessArrayColumnCells (Bool& reask) const;
169 
170  // Ask if the data manager can handle a cell slice.
171  // Default is never.
172  virtual Bool canAccessSlice (Bool& reask) const;
173 
174  // Ask if the data manager can handle a column slice.
175  // Default is never.
176  virtual Bool canAccessColumnSlice (Bool& reask) const;
177 
178  // Initialize the rows from startRow till endRow (inclusive)
179  // with the default value defined in the column description.
180  virtual void initialize (uInt startRownr, uInt endRownr) = 0;
181 
182  // Get the value from a particular cell.
183  // This can be a scalar or an array.
184  virtual void get (uInt rownr, void* dataPtr) const = 0;
185 
186  // Get a slice of an N-dimensional array in a particular cell.
187  virtual void getSlice (uInt rownr, const Slicer&, void* dataPtr) const;
188 
189  // Get the vector of all scalar values in a column.
190  virtual void getScalarColumn (void* dataPtr) const;
191 
192  // Get the array of all array values in a column.
193  // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
194  // The arrays in the column have to have the same shape in all cells.
195  virtual void getArrayColumn (void* dataPtr) const;
196 
197  // Get subsections from all arrays in the column.
198  // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
199  // The arrays in the column have to have the same shape in all cells.
200  virtual void getColumnSlice (const Slicer&, void* dataPtr) const;
201 
202  // Get the vector of some scalar values in a column.
203  virtual void getScalarColumnCells (const RefRows& rownrs,
204  void* dataPtr) const;
205 
206  // Get the array of some array values in a column.
207  // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
208  // The arrays in the column have to have the same shape in all cells.
209  virtual void getArrayColumnCells (const RefRows& rownrs,
210  void* dataPtr) const;
211 
212  // Get subsections from some arrays in the column.
213  // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
214  // The arrays in the column have to have the same shape in all cells.
215  virtual void getColumnSliceCells (const RefRows& rownrs,
216  const Slicer&, void* dataPtr) const;
217 
218  // Put the value in a particular cell.
219  // This can be a scalar or an array.
220  virtual void put (uInt rownr, const void* dataPtr) = 0;
221 
222  // Put a slice of an N-dimensional array in a particular cell.
223  virtual void putSlice (uInt rownr, const Slicer&, const void* dataPtr);
224 
225  // Put the vector of all scalar values in the column.
226  virtual void putScalarColumn (const void* dataPtr);
227 
228  // Put the array of all array values 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 putArrayColumn (const void* dataPtr);
232 
233  // Put into subsections of all table arrays in the column.
234  // If the column contains n-dim arrays, the source array is (n+1)-dim.
235  // The arrays in the column have to have the same shape in all cells.
236  virtual void putColumnSlice (const Slicer&, const void* dataPtr);
237 
238  // Get the vector of some scalar values in a column.
239  virtual void putScalarColumnCells (const RefRows& rownrs,
240  const void* dataPtr);
241 
242  // Get the array of some array values in a column.
243  // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
244  // The arrays in the column have to have the same shape in all cells.
245  virtual void putArrayColumnCells (const RefRows& rownrs,
246  const void* dataPtr);
247 
248  // Put subsections of some arrays in the column.
249  // If the column contains n-dim arrays, the source array is (n+1)-dim.
250  // The arrays in the column have to have the same shape in all cells.
251  virtual void putColumnSliceCells (const RefRows& rownrs,
252  const Slicer&, const void* dataPtr);
253 
254  // Get the value from the row and convert it to the required type.
255  // This can only be used for scalar columns with a standard data type.
256  // Note that an unsigned integer cannot be converted to a signed integer
257  // with the same length. So only Int64 can handle all integer values.
258  // <group>
259  void getScalar (uInt rownr, Bool& value) const;
260  void getScalar (uInt rownr, uChar& value) const;
261  void getScalar (uInt rownr, Short& value) const;
262  void getScalar (uInt rownr, uShort& value) const;
263  void getScalar (uInt rownr, Int& value) const;
264  void getScalar (uInt rownr, uInt& value) const;
265  void getScalar (uInt rownr, Int64& value) const;
266  void getScalar (uInt rownr, float& value) const;
267  void getScalar (uInt rownr, double& value) const;
268  void getScalar (uInt rownr, Complex& value) const;
269  void getScalar (uInt rownr, DComplex& value) const;
270  void getScalar (uInt rownr, String& value) const;
271  void getScalar (uInt rownr, TableRecord& value) const;
272  // </group>
273 
274  // Get a scalar for the other data types.
275  // The given data type id must match the data type id of this column.
276  void getScalar (uInt rownr, void* value, const String& dataTypeId) const;
277 
278  // Put the value into the row and convert it from the given type.
279  // This can only be used for scalar columns with a standard data type.
280  // <group>
281  void putScalar (uInt rownr, const Bool& value);
282  void putScalar (uInt rownr, const uChar& value);
283  void putScalar (uInt rownr, const Short& value);
284  void putScalar (uInt rownr, const uShort& value);
285  void putScalar (uInt rownr, const Int& value);
286  void putScalar (uInt rownr, const uInt& value);
287  void putScalar (uInt rownr, const Int64& value);
288  void putScalar (uInt rownr, const float& value);
289  void putScalar (uInt rownr, const double& value);
290  void putScalar (uInt rownr, const Complex& value);
291  void putScalar (uInt rownr, const DComplex& value);
292  void putScalar (uInt rownr, const String& value);
293  void putScalar (uInt rownr, const Char* value)
294  { putScalar (rownr, String(value)); }
295  void putScalar (uInt rownr, const TableRecord& value);
296  // </group>
297 
298  // Get a pointer to the underlying column cache.
299  virtual ColumnCache& columnCache() = 0;
300 
301  // Set the maximum cache size (in bytes) to be used by a storage manager.
302  virtual void setMaximumCacheSize (uInt nbytes) = 0;
303 
304  // Add this column and its data to the Sort object.
305  // It may allocate some storage on the heap, which will be saved
306  // in the argument dataSave.
307  // The function freeSortKey must be called to free this storage.
308  // <group>
309  virtual void makeSortKey (Sort&, CountedPtr<BaseCompare>& cmpObj,
310  Int order, const void*& dataSave);
311  // Do it only for the given row numbers.
312  virtual void makeRefSortKey (Sort&, CountedPtr<BaseCompare>& cmpObj,
313  Int order, const Vector<uInt>& rownrs,
314  const void*& dataSave);
315  // </group>
316 
317  // Free storage on the heap allocated by makeSortkey().
318  // The pointer will be set to zero.
319  virtual void freeSortKey (const void*& dataSave);
320 
321  // Allocate value buffers for the table iterator.
322  // Also get a comparison object if undefined.
323  // The function freeIterBuf must be called to free the buffers.
324  virtual void allocIterBuf (void*& lastVal, void*& curVal,
325  CountedPtr<BaseCompare>& cmpObj);
326 
327  // Free the value buffers allocated by allocIterBuf.
328  virtual void freeIterBuf (void*& lastVal, void*& curVal);
329 
330 protected:
331  // Throw exceptions for invalid scalar get or put.
332  // <group>
333  void throwGetScalar() const;
334  void throwPutScalar() const;
335  void throwGetType (const String& type) const;
336  void throwPutType (const String& type) const;
337  // </group>
338 
339  //# Data members
341 
342 private:
343  //# This ColumnDesc object is created to be able to return
344  //# a const ColumnDesc& by function columnDesc().
346 };
347 
348 
349 
350 
351 } //# NAMESPACE CASACORE - END
352 
353 #endif
casacore::BaseColumn::throwGetType
void throwGetType(const String &type) const
casacore::Slicer
Specify which elements to extract from an n-dimensional array.
Definition: Slicer.h:289
casacore::BaseColumn::nrow
virtual uInt nrow() const =0
Get nr of rows in the column.
casacore::IPosition
A Vector of integers, for indexing into Array<T> objects.
Definition: IPosition.h:119
casacore::BaseColumn::allocIterBuf
virtual void allocIterBuf(void *&lastVal, void *&curVal, CountedPtr< BaseCompare > &cmpObj)
Allocate value buffers for the table iterator.
casacore::BaseColumn::makeSortKey
virtual void makeSortKey(Sort &, CountedPtr< BaseCompare > &cmpObj, Int order, const void *&dataSave)
Add this column and its data to the Sort object.
casacore::BaseColumn::isWritable
virtual Bool isWritable() const =0
Test if the column is writable.
casacore::BaseColumn::put
virtual void put(uInt rownr, const void *dataPtr)=0
Put the value in a particular cell.
casacore::BaseColumn::getScalarColumnCells
virtual void getScalarColumnCells(const RefRows &rownrs, void *dataPtr) const
Get the vector of some scalar values in a column.
casacore::BaseColumn::ndim
virtual uInt ndim(uInt rownr) const
Get the #dimensions of an array in a particular cell.
Complexfwd_global_functions_Complexfwd::casacore::DComplex
std::complex< Double > DComplex
Definition: Complexfwd.h:50
casacore::TableRecord
A hierarchical collection of named fields of various types.
Definition: TableRecord.h:182
casacore::CountedPtr
Referenced counted pointer for constant data.
Definition: CountedPtr.h:80
casacore::BaseColumn::canAccessScalarColumnCells
virtual Bool canAccessScalarColumnCells(Bool &reask) const
Ask if the data manager can handle a collection of cells in a scalar column.
casacore::uChar
unsigned char uChar
Definition: aipstype.h:47
casacore::BaseColumn::columnCache
virtual ColumnCache & columnCache()=0
Get a pointer to the underlying column cache.
casacore::BaseColumn::putScalarColumn
virtual void putScalarColumn(const void *dataPtr)
Put the vector of all scalar values in the column.
casacore::BaseColumn::shapeColumn
virtual IPosition shapeColumn() const
Get the global shape of an array (ie.
casacore::BaseColumn::freeSortKey
virtual void freeSortKey(const void *&dataSave)
Free storage on the heap allocated by makeSortkey().
casacore::BaseColumn::setMaximumCacheSize
virtual void setMaximumCacheSize(uInt nbytes)=0
Set the maximum cache size (in bytes) to be used by a storage manager.
casacore::BaseColumn::BaseColumn
BaseColumn(const BaseColumnDesc *)
Construct it using the given column description.
casacore::BaseColumn::getArrayColumnCells
virtual void getArrayColumnCells(const RefRows &rownrs, void *dataPtr) const
Get the array of some array values in a column.
casacore::BaseColumn::initialize
virtual void initialize(uInt startRownr, uInt endRownr)=0
Initialize the rows from startRow till endRow (inclusive) with the default value defined in the colum...
casacore::BaseColumn::putColumnSliceCells
virtual void putColumnSliceCells(const RefRows &rownrs, const Slicer &, const void *dataPtr)
Put subsections of some arrays in the column.
casacore::BaseColumn::tileShape
virtual IPosition tileShape(uInt rownr) const
Get the tile shape of an array in a particular cell.
casacore::BaseColumn::getScalar
void getScalar(uInt rownr, Bool &value) const
Get the value from the row and convert it to the required type.
casacore::BaseColumn::putSlice
virtual void putSlice(uInt rownr, const Slicer &, const void *dataPtr)
Put a slice of an N-dimensional array in a particular cell.
casacore::BaseColumn::canAccessArrayColumn
virtual Bool canAccessArrayColumn(Bool &reask) const
Ask if the data manager can handle an array column.
casacore::value
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
casacore::uShort
unsigned short uShort
Definition: aipstype.h:49
casacore::RefRows
Class holding the row numbers in a RefTable.
Definition: RefRows.h:85
casacore::BaseColumn
Abstract base class for a table column.
Definition: BaseColumn.h:98
casacore::BaseColumn::canAccessColumnSlice
virtual Bool canAccessColumnSlice(Bool &reask) const
Ask if the data manager can handle a column slice.
casacore::BaseColumn::getScalarColumn
virtual void getScalarColumn(void *dataPtr) const
Get the vector of all scalar values in a column.
casacore::uInt
unsigned int uInt
Definition: aipstype.h:51
casacore::BaseColumn::getColumnSlice
virtual void getColumnSlice(const Slicer &, void *dataPtr) const
Get subsections from all arrays in the column.
casacore::BaseColumn::colDescPtr_p
const BaseColumnDesc * colDescPtr_p
Definition: BaseColumn.h:340
casacore::BaseColumn::canChangeShape
virtual Bool canChangeShape() const
Ask the data manager if the shape of an existing array can be changed.
casacore::BaseColumn::throwPutScalar
void throwPutScalar() const
casacore::BaseColumn::getSlice
virtual void getSlice(uInt rownr, const Slicer &, void *dataPtr) const
Get a slice of an N-dimensional array in a particular cell.
casacore::BaseColumn::putScalar
void putScalar(uInt rownr, const Bool &value)
Put the value into the row and convert it from the given type.
casacore::BaseColumn::canAccessSlice
virtual Bool canAccessSlice(Bool &reask) const
Ask if the data manager can handle a cell slice.
casacore::BaseColumnDesc
An abstract base class for table column descriptions.
Definition: BaseColDesc.h:107
casacore::BaseColumn::makeRefSortKey
virtual void makeRefSortKey(Sort &, CountedPtr< BaseCompare > &cmpObj, Int order, const Vector< uInt > &rownrs, const void *&dataSave)
Do it only for the given row numbers.
casacore::Int
int Int
Definition: aipstype.h:50
casacore
this file contains all the compiler specific defines
Definition: mainpage.dox:28
casacore::BaseColumn::freeIterBuf
virtual void freeIterBuf(void *&lastVal, void *&curVal)
Free the value buffers allocated by allocIterBuf.
casacore::BaseColumn::getArrayColumn
virtual void getArrayColumn(void *dataPtr) const
Get the array of all array values in a column.
casacore::BaseColumn::putColumnSlice
virtual void putColumnSlice(const Slicer &, const void *dataPtr)
Put into subsections of all table arrays in the column.
casacore::Sort
Sort on one or more keys, ascending and/or descending.
Definition: Sort.h:248
casacore::BaseColumn::shape
virtual IPosition shape(uInt rownr) const
Get the shape of an array in a particular cell.
casacore::BaseColumn::canAccessArrayColumnCells
virtual Bool canAccessArrayColumnCells(Bool &reask) const
Ask if the data manager can handle a collection of cells in an array column.
casacore::BaseColumn::throwGetScalar
void throwGetScalar() const
Throw exceptions for invalid scalar get or put.
casacore::ColumnCache
A caching object for a table column.
Definition: ColumnCache.h:83
casacore::Int64
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
casacore::BaseColumn::rwKeywordSet
virtual TableRecord & rwKeywordSet()=0
Get access to the column keyword set.
casacore::BaseColumn::colDesc_p
ColumnDesc colDesc_p
Definition: BaseColumn.h:345
casacore::BaseColumn::canAccessScalarColumn
virtual Bool canAccessScalarColumn(Bool &reask) const
Ask if the data manager can handle a scalar column.
casacore::BaseColumn::getColumnSliceCells
virtual void getColumnSliceCells(const RefRows &rownrs, const Slicer &, void *dataPtr) const
Get subsections from some arrays in the column.
casacore::BaseColumn::get
virtual void get(uInt rownr, void *dataPtr) const =0
Get the value from a particular cell.
casacore::String
String: the storage and methods of handling collections of characters.
Definition: String.h:223
casacore::BaseColumn::setShape
virtual void setShape(uInt rownr, const IPosition &shape)
Set the shape of the array in the given row.
casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Complexfwd_global_functions_Complexfwd::casacore::Complex
std::complex< Float > Complex
Definition: Complexfwd.h:49
casacore::BaseColumn::putArrayColumnCells
virtual void putArrayColumnCells(const RefRows &rownrs, const void *dataPtr)
Get the array of some array values in a column.
casacore::BaseColumn::putScalarColumnCells
virtual void putScalarColumnCells(const RefRows &rownrs, const void *dataPtr)
Get the vector of some scalar values in a column.
casacore::Short
short Short
Definition: aipstype.h:48
casacore::BaseColumn::isDefined
virtual Bool isDefined(uInt rownr) const =0
Test if the given cell contains a defined value.
casacore::Vector< uInt >
casacore::BaseColumn::putScalar
void putScalar(uInt rownr, const Char *value)
Definition: BaseColumn.h:293
casacore::BaseColumn::throwPutType
void throwPutType(const String &type) const
casacore::BaseColumn::keywordSet
virtual TableRecord & keywordSet()=0
casacore::BaseColumn::putArrayColumn
virtual void putArrayColumn(const void *dataPtr)
Put the array of all array values in the column.
casacore::BaseColumn::ndimColumn
virtual uInt ndimColumn() const
Get the global #dimensions of an array (ie.
casacore::BaseColumn::~BaseColumn
virtual ~BaseColumn()
casacore::Char
char Char
Definition: aipstype.h:46
casacore::ColumnDesc
Envelope class for the description of a table column.
Definition: ColumnDesc.h:131
casacore::BaseColumn::columnDesc
const ColumnDesc & columnDesc() const
Get const access to the column description.
casacore::BaseColumn::isStored
virtual Bool isStored() const =0
Test if the column is stored (otherwise it is virtual).