casacore
Loading...
Searching...
No Matches
VirtScaCol.h
Go to the documentation of this file.
1// # VirtScaCol.h: Templated base class for virtual scalar column
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: 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_VIRTSCACOL_H
27#define TABLES_VIRTSCACOL_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/ArrayFwd.h>
32#include <casacore/tables/DataMan/DataManager.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// <summary>
37// Templated base class for virtual scalar column
38// </summary>
39
40// <use visibility=local>
41
42// <reviewed reviewer="Gareth Hunt" date="94Nov17" tests="">
43// </reviewed>
44
45// <prerequisite>
46// # Classes you should understand before using this one.
47// <li> DataManagerColumn
48// <li> VirtualColumnEngine
49// </prerequisite>
50
51// <etymology>
52// VirtualScalarColumn handles a virtual column containing a scalar.
53// </etymology>
54
55// <synopsis>
56// VirtualScalarColumn is the abstract base class to handle a scalar column
57// for a virtual column engine.
58// It is derived from DataManagerColumn and reimplements some
59// virtual functions to make life easier for the derived classes.
60// It does the following:
61// <ul>
62// <li>
63// It implements the dataType function, so it is not needed to implement
64// that in derived classes.
65// <li>
66// It has a default implementation of False for function isWritable.
67// Thus by default virtual scalar columns are not writable, which will
68// often be the case. Only if a virtual scalar column can be writable,
69// it has to be implemented in the derived class.
70// <li>
71// Declare a get/put function with the template parameter as its argument.
72// The virtual functions get/putBoolV, etc. (defined in DataManagerColumn)
73// are by default implemented using this (templated) get/put function.
74// This allows for the default implementation of get/putBlock and
75// makes life easier for the implementor of a derived class.
76// However, the disadvantage of this is an extra virtual function call.
77// (E.g. for a Bool value the first one is getBoolV and the second
78// one get(T&), where T is Bool). If efficiency is really necessary,
79// getBoolV, etc. should also be implemented in the derived class.
80// <li>
81// In DataManagerColumn the functions get/putBlockV and get/putColumnV
82// are defined, which have a void* data argument. This is necessary
83// to handle arbitrary data types in the non-templated base class
84// DataManagerColumn.
85// In this templated VirtualScalarColumn class, virtual functions
86// get/putBlock and get/putColumn have been defined. They cast
87// the void* data argument to T&, so in a derived class no care has
88// to be taken for that cast.
89// Furthermore a default implementation of them has been made.
90// <ul>
91// <li> getBlock gets one value using function get.
92// <li> putBlock puts one value at the time using function put.
93// <li> getColumn uses function getBlock.
94// <li> putColumn uses function putBlock.
95// </ul>
96// If efficiency is an issue, these functions should be implemented
97// in the derived class.
98// </ul>
99// </synopsis>
100
101// <motivation>
102// This class reimplements some virtual functions implemented by
103// DataManagerColumn and types the data argument. In that way they are
104// easier to implement in derived classes. Furthermore they allow
105// default implementations.
106// </motivation>
107
108// <templating arg=T>
109// <li> default constructor
110// <li> copy constructor
111// <li> assignment operator
112// <li> <src>static String dataTypeId(); // unique name of the class</src>
113// </templating>
114
115// <todo asof="$DATE:$">
116// # A List of bugs, limitations, extensions or planned refinements.
117// </todo>
118
120 public:
121 // Create a column.
123
125
126 // By default no data can be put in a virtual column.
127 virtual Bool isWritable() const;
128
129 protected:
130 // The array access functions throw an exception.
131 // <group>
132 virtual void getArrayV(rownr_t rownr, ArrayBase& dataPtr);
133 virtual void putArrayV(rownr_t rownr, const ArrayBase& data);
134 virtual void getArrayColumnV(ArrayBase& data);
135 virtual void putArrayColumnV(const ArrayBase& data);
136 virtual void getArrayColumnCellsV(const RefRows& rownrs, ArrayBase& data);
137 virtual void putArrayColumnCellsV(const RefRows& rownrs, const ArrayBase& data);
138 virtual void getSliceV(rownr_t rownr, const Slicer& slicer, ArrayBase& data);
139 virtual void putSliceV(rownr_t rownr, const Slicer& slicer, const ArrayBase& data);
140 virtual void getColumnSliceV(const Slicer& slicer, ArrayBase& data);
141 virtual void putColumnSliceV(const Slicer& slicer, const ArrayBase& data);
142 virtual void getColumnSliceCellsV(const RefRows& rownrs, const Slicer& slicer, ArrayBase& data);
143 virtual void putColumnSliceCellsV(const RefRows& rownrs, const Slicer& slicer,
144 const ArrayBase& data);
145 // </group>
146};
147
148template <class T>
150 public:
151 // Create a column.
153
154 // Frees up the storage.
156
157 // The object cannot be copied.
159
160 // The object cannot be assigned to.
162
163 // Return the data type of the column.
164 int dataType() const override;
165
166 // Return the data type Id of the column.
167 String dataTypeId() const override;
168
169 // Let a derived class get the scalar value in the given row.
170 virtual void get(rownr_t rownr, T& data) = 0;
171
172 // Let a derived class put the scalar value into the given row.
173 // The default implementation throws an exception.
174 virtual void put(rownr_t rownr, const T& data);
175
176 private:
177 // Implement the virtual functions defined in DataManagerColumn.
178 // Get the scalar value in the given row.
179 // <group>
180 void getBool(rownr_t rownr, Bool* dataPtr) override { getVirtualScalar(this, rownr, dataPtr); }
181 void getuChar(rownr_t rownr, uChar* dataPtr) override { getVirtualScalar(this, rownr, dataPtr); }
182 void getShort(rownr_t rownr, Short* dataPtr) override { getVirtualScalar(this, rownr, dataPtr); }
183 void getuShort(rownr_t rownr, uShort* dataPtr) override {
184 getVirtualScalar(this, rownr, dataPtr);
185 }
186 void getInt(rownr_t rownr, Int* dataPtr) override { getVirtualScalar(this, rownr, dataPtr); }
187 void getuInt(rownr_t rownr, uInt* dataPtr) override { getVirtualScalar(this, rownr, dataPtr); }
188 void getInt64(rownr_t rownr, Int64* dataPtr) override { getVirtualScalar(this, rownr, dataPtr); }
189 void getfloat(rownr_t rownr, float* dataPtr) override { getVirtualScalar(this, rownr, dataPtr); }
190 void getdouble(rownr_t rownr, double* dataPtr) override {
191 getVirtualScalar(this, rownr, dataPtr);
192 }
193 void getComplex(rownr_t rownr, Complex* dataPtr) override {
194 getVirtualScalar(this, rownr, dataPtr);
195 }
196 void getDComplex(rownr_t rownr, DComplex* dataPtr) override {
197 getVirtualScalar(this, rownr, dataPtr);
198 }
199 void getString(rownr_t rownr, String* dataPtr) override {
200 getVirtualScalar(this, rownr, dataPtr);
201 }
202 // This function is the get for all non-standard data types.
203 void getOther(rownr_t rownr, void* dataPtr) override;
204 // </group>
205
206 // Implement the virtual functions defined in DataManagerColumn.
207 // Put the scalar value into the given row.
208 // <group>
209 void putBool(rownr_t rownr, const Bool* dataPtr) override {
210 putVirtualScalar(this, rownr, dataPtr);
211 }
212 void putuChar(rownr_t rownr, const uChar* dataPtr) override {
213 putVirtualScalar(this, rownr, dataPtr);
214 }
215 void putShort(rownr_t rownr, const Short* dataPtr) override {
216 putVirtualScalar(this, rownr, dataPtr);
217 }
218 void putuShort(rownr_t rownr, const uShort* dataPtr) override {
219 putVirtualScalar(this, rownr, dataPtr);
220 }
221 void putInt(rownr_t rownr, const Int* dataPtr) override {
222 putVirtualScalar(this, rownr, dataPtr);
223 }
224 void putuInt(rownr_t rownr, const uInt* dataPtr) override {
225 putVirtualScalar(this, rownr, dataPtr);
226 }
227 void putInt64(rownr_t rownr, const Int64* dataPtr) override {
228 putVirtualScalar(this, rownr, dataPtr);
229 }
230 void putfloat(rownr_t rownr, const float* dataPtr) override {
231 putVirtualScalar(this, rownr, dataPtr);
232 }
233 void putdouble(rownr_t rownr, const double* dataPtr) override {
234 putVirtualScalar(this, rownr, dataPtr);
235 }
236 void putComplex(rownr_t rownr, const Complex* dataPtr) override {
237 putVirtualScalar(this, rownr, dataPtr);
238 }
239 void putDComplex(rownr_t rownr, const DComplex* dataPtr) override {
240 putVirtualScalar(this, rownr, dataPtr);
241 }
242 void putString(rownr_t rownr, const String* dataPtr) override {
243 putVirtualScalar(this, rownr, dataPtr);
244 }
245 // This function is the put for all non-standard data types.
246 void putOther(rownr_t rownr, const void* dataPtr) override;
247 // </group>
248
249 // Get all scalar values in the column.
250 // The default implementation loops over the rows.
251 void getScalarColumnV(ArrayBase& dataPtr) override;
252
253 // Put all scalar values in the column.
254 // The default implementation loops over the rows.
255 void putScalarColumnV(const ArrayBase& dataPtr) override;
256
257 // Get some scalar values in the column.
258 // The default implementation loops over the rows.
259 void getScalarColumnCellsV(const RefRows& rownrs, ArrayBase& dataPtr) override;
260
261 // Put some scalar values in the column.
262 // The default implementation loops over the rows.
263 void putScalarColumnCellsV(const RefRows& rownrs, const ArrayBase& dataPtr) override;
264};
265
266// <summary>
267// Global functions to get or put data of a virtual column
268// </summary>
269// <synopsis>
270// </synopsis>
271// <group name=get_putVirtualScalar>
272template <class T>
273inline void getVirtualScalar(VirtualScalarColumn<T>* col, uInt rownr, T* dataPtr) {
274 col->get(rownr, *dataPtr);
275}
276inline void getVirtualScalar(DataManagerColumn* col, uInt, void*) { col->throwGet(); }
278template <class T>
279inline void putVirtualScalar(VirtualScalarColumn<T>* col, uInt rownr, const T* dataPtr) {
280 col->put(rownr, *dataPtr);
281}
282inline void putVirtualScalar(DataManagerColumn* col, uInt, const void*) { col->throwPut(); }
283// </group>
284
285} // namespace casacore
286
287#ifndef CASACORE_NO_AUTO_TEMPLATES
288#include <casacore/tables/DataMan/VirtScaCol.tcc>
289#endif // # CASACORE_NO_AUTO_TEMPLATES
290#endif
Non-templated base class for templated Array class.
Definition ArrayBase.h:69
void throwGet() const
Throw an "invalid operation" exception for the default implementation of get.
void throwPut() const
Throw an "invalid operation" exception for the default implementation of put.
DataManagerColumn()
Create a column.
String: the storage and methods of handling collections of characters.
Definition String.h:355
virtual void putColumnSliceV(const Slicer &slicer, const ArrayBase &data)
Put into a section of all arrays in the column.
virtual void getArrayColumnV(ArrayBase &data)
Get all array values in the column.
virtual void putArrayColumnCellsV(const RefRows &rownrs, const ArrayBase &data)
Put some array values in the column.
virtual void getSliceV(rownr_t rownr, const Slicer &slicer, ArrayBase &data)
Get a section of the array in the given row.
virtual Bool isWritable() const
By default no data can be put in a virtual column.
virtual void putArrayColumnV(const ArrayBase &data)
Put all array values in the column.
virtual void getColumnSliceCellsV(const RefRows &rownrs, const Slicer &slicer, ArrayBase &data)
Get a section of some arrays in the column.
virtual void putArrayV(rownr_t rownr, const ArrayBase &data)
Put the array value into the given row.
virtual void putColumnSliceCellsV(const RefRows &rownrs, const Slicer &slicer, const ArrayBase &data)
Put into a section of some arrays in the column.
virtual void getArrayV(rownr_t rownr, ArrayBase &dataPtr)
The array access functions throw an exception.
virtual void getColumnSliceV(const Slicer &slicer, ArrayBase &data)
Get a section of all arrays in the column.
virtual void putSliceV(rownr_t rownr, const Slicer &slicer, const ArrayBase &data)
Put into a section of the array in the given row.
virtual void getArrayColumnCellsV(const RefRows &rownrs, ArrayBase &data)
Get some array values in the column.
VirtualScalarColumnBase()
Create a column.
Definition VirtScaCol.h:122
void getDComplex(rownr_t rownr, DComplex *dataPtr) override
Definition VirtScaCol.h:196
void getBool(rownr_t rownr, Bool *dataPtr) override
Implement the virtual functions defined in DataManagerColumn.
Definition VirtScaCol.h:180
void getuChar(rownr_t rownr, uChar *dataPtr) override
Definition VirtScaCol.h:181
void putScalarColumnCellsV(const RefRows &rownrs, const ArrayBase &dataPtr) override
Put some scalar values in the column.
void putOther(rownr_t rownr, const void *dataPtr) override
This function is the put for all non-standard data types.
void putScalarColumnV(const ArrayBase &dataPtr) override
Put all scalar values in the column.
VirtualScalarColumn< T > & operator=(const VirtualScalarColumn< T > &)=delete
The object cannot be assigned to.
void putuShort(rownr_t rownr, const uShort *dataPtr) override
Definition VirtScaCol.h:218
void getComplex(rownr_t rownr, Complex *dataPtr) override
Definition VirtScaCol.h:193
void putInt64(rownr_t rownr, const Int64 *dataPtr) override
Definition VirtScaCol.h:227
void putfloat(rownr_t rownr, const float *dataPtr) override
Definition VirtScaCol.h:230
String dataTypeId() const override
Return the data type Id of the column.
void putComplex(rownr_t rownr, const Complex *dataPtr) override
Definition VirtScaCol.h:236
void getScalarColumnV(ArrayBase &dataPtr) override
Get all scalar values in the column.
VirtualScalarColumn(const VirtualScalarColumn< T > &)=delete
The object cannot be copied.
void getuInt(rownr_t rownr, uInt *dataPtr) override
Definition VirtScaCol.h:187
void getInt64(rownr_t rownr, Int64 *dataPtr) override
Definition VirtScaCol.h:188
void getScalarColumnCellsV(const RefRows &rownrs, ArrayBase &dataPtr) override
Get some scalar values in the column.
void getOther(rownr_t rownr, void *dataPtr) override
This function is the get for all non-standard data types.
void putInt(rownr_t rownr, const Int *dataPtr) override
Definition VirtScaCol.h:221
void getString(rownr_t rownr, String *dataPtr) override
Definition VirtScaCol.h:199
void getShort(rownr_t rownr, Short *dataPtr) override
Definition VirtScaCol.h:182
void putuInt(rownr_t rownr, const uInt *dataPtr) override
Definition VirtScaCol.h:224
void putShort(rownr_t rownr, const Short *dataPtr) override
Definition VirtScaCol.h:215
void getdouble(rownr_t rownr, double *dataPtr) override
Definition VirtScaCol.h:190
virtual void get(rownr_t rownr, T &data)=0
Let a derived class get the scalar value in the given row.
void putdouble(rownr_t rownr, const double *dataPtr) override
Definition VirtScaCol.h:233
void putString(rownr_t rownr, const String *dataPtr) override
Definition VirtScaCol.h:242
void putDComplex(rownr_t rownr, const DComplex *dataPtr) override
Definition VirtScaCol.h:239
void getfloat(rownr_t rownr, float *dataPtr) override
Definition VirtScaCol.h:189
void putuChar(rownr_t rownr, const uChar *dataPtr) override
Definition VirtScaCol.h:212
void getInt(rownr_t rownr, Int *dataPtr) override
Definition VirtScaCol.h:186
void putBool(rownr_t rownr, const Bool *dataPtr) override
Implement the virtual functions defined in DataManagerColumn.
Definition VirtScaCol.h:209
int dataType() const override
Return the data type of the column.
void getuShort(rownr_t rownr, uShort *dataPtr) override
Definition VirtScaCol.h:183
virtual void put(rownr_t rownr, const T &data)
Let a derived class put the scalar value into the given row.
virtual ~VirtualScalarColumn()
Frees up the storage.
VirtualScalarColumn()
Create a column.
Definition VirtScaCol.h:152
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
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44
Global functions to get or put data of a virtual column.
Definition VirtScaCol.h:272
void putVirtualScalar(VirtualScalarColumn< T > *col, uInt rownr, const T *dataPtr)
Definition VirtScaCol.h:279
void getVirtualScalar(VirtualScalarColumn< T > *col, uInt rownr, T *dataPtr)
Definition VirtScaCol.h:274
void getVirtualScalar(DataManagerColumn *col, uInt, void *)
Definition VirtScaCol.h:277
void putVirtualScalar(DataManagerColumn *col, uInt, const void *)
Definition VirtScaCol.h:282