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
119
121{
122public:
123 // Create a column.
126
128
129 // By default no data can be put in a virtual column.
130 virtual Bool isWritable() const;
131
132protected:
133 // The array access functions throw an exception.
134 // <group>
135 virtual void getArrayV (rownr_t rownr, ArrayBase& dataPtr);
136 virtual void putArrayV (rownr_t rownr, const ArrayBase& data);
137 virtual void getArrayColumnV (ArrayBase& data);
138 virtual void putArrayColumnV (const ArrayBase& data);
139 virtual void getArrayColumnCellsV (const RefRows& rownrs,
140 ArrayBase& data);
141 virtual void putArrayColumnCellsV (const RefRows& rownrs,
142 const ArrayBase& data);
143 virtual void getSliceV (rownr_t rownr, const Slicer& slicer, ArrayBase& data);
144 virtual void putSliceV (rownr_t rownr, const Slicer& slicer,
145 const ArrayBase& data);
146 virtual void getColumnSliceV (const Slicer& slicer, ArrayBase& data);
147 virtual void putColumnSliceV (const Slicer& slicer, const ArrayBase& data);
148 virtual void getColumnSliceCellsV (const RefRows& rownrs,
149 const Slicer& slicer, ArrayBase& data);
150 virtual void putColumnSliceCellsV (const RefRows& rownrs,
151 const Slicer& slicer,
152 const ArrayBase& data);
153 // </group>
154};
155
156
157template<class T>
159{
160public:
161
162 // Create a column.
165
166 // Frees up the storage.
168
169 // The object cannot be copied.
171
172 // The object cannot be assigned to.
174
175 // Return the data type of the column.
176 virtual int dataType() const;
177
178 // Return the data type Id of the column.
179 virtual String dataTypeId() const;
180
181 // Let a derived class get the scalar value in the given row.
182 virtual void get (rownr_t rownr, T& data) = 0;
183
184 // Let a derived class put the scalar value into the given row.
185 // The default implementation throws an exception.
186 virtual void put (rownr_t rownr, const T& data);
187
188private:
189 // Implement the virtual functions defined in DataManagerColumn.
190 // Get the scalar value in the given row.
191 // <group>
192 virtual void getBool (rownr_t rownr, Bool* dataPtr);
193 virtual void getuChar (rownr_t rownr, uChar* dataPtr);
194 virtual void getShort (rownr_t rownr, Short* dataPtr);
195 virtual void getuShort (rownr_t rownr, uShort* dataPtr);
196 virtual void getInt (rownr_t rownr, Int* dataPtr);
197 virtual void getuInt (rownr_t rownr, uInt* dataPtr);
198 virtual void getInt64 (rownr_t rownr, Int64* dataPtr);
199 virtual void getfloat (rownr_t rownr, float* dataPtr);
200 virtual void getdouble (rownr_t rownr, double* dataPtr);
201 virtual void getComplex (rownr_t rownr, Complex* dataPtr);
202 virtual void getDComplex (rownr_t rownr, DComplex* dataPtr);
203 virtual void getString (rownr_t rownr, String* dataPtr);
204 // This function is the get for all non-standard data types.
205 virtual void getOther (rownr_t rownr, void* dataPtr);
206 // </group>
207
208 // Implement the virtual functions defined in DataManagerColumn.
209 // Put the scalar value into the given row.
210 // <group>
211 virtual void putBool (rownr_t rownr, const Bool* dataPtr);
212 virtual void putuChar (rownr_t rownr, const uChar* dataPtr);
213 virtual void putShort (rownr_t rownr, const Short* dataPtr);
214 virtual void putuShort (rownr_t rownr, const uShort* dataPtr);
215 virtual void putInt (rownr_t rownr, const Int* dataPtr);
216 virtual void putuInt (rownr_t rownr, const uInt* dataPtr);
217 virtual void putInt64 (rownr_t rownr, const Int64* dataPtr);
218 virtual void putfloat (rownr_t rownr, const float* dataPtr);
219 virtual void putdouble (rownr_t rownr, const double* dataPtr);
220 virtual void putComplex (rownr_t rownr, const Complex* dataPtr);
221 virtual void putDComplex (rownr_t rownr, const DComplex* dataPtr);
222 virtual void putString (rownr_t rownr, const String* dataPtr);
223 // This function is the put for all non-standard data types.
224 virtual void putOther (rownr_t rownr, const void* dataPtr);
225 // </group>
226
227 // Get all scalar values in the column.
228 // The default implementation loops over the rows.
229 virtual void getScalarColumnV (ArrayBase& dataPtr);
230
231 // Put all scalar values in the column.
232 // The default implementation loops over the rows.
233 virtual void putScalarColumnV (const ArrayBase& dataPtr);
234
235 // Get some scalar values in the column.
236 // The default implementation loops over the rows.
237 virtual void getScalarColumnCellsV (const RefRows& rownrs,
238 ArrayBase& dataPtr);
239
240 // Put some scalar values in the column.
241 // The default implementation loops over the rows.
242 virtual void putScalarColumnCellsV (const RefRows& rownrs,
243 const ArrayBase& dataPtr);
244};
245
246
247
248// <summary>
249// Global functions to get or put data of a virtual column
250// </summary>
251// <synopsis>
252// </synopsis>
253// <group name=get_putVirtualScalar>
254template<class T>
255inline void getVirtualScalar (VirtualScalarColumn<T>* col,
256 uInt rownr, T* dataPtr)
257 { col->get (rownr, *dataPtr); }
258inline void getVirtualScalar (DataManagerColumn* col,
259 uInt, void*)
260 { col->throwGet(); }
261
262template<class T>
264 uInt rownr, const T* dataPtr)
265 { col->put (rownr, *dataPtr); }
267 uInt, const void*)
268 { col->throwPut(); }
269// </group>
270
271
272
273} //# NAMESPACE CASACORE - END
274
275#ifndef CASACORE_NO_AUTO_TEMPLATES
276#include <casacore/tables/DataMan/VirtScaCol.tcc>
277#endif //# CASACORE_NO_AUTO_TEMPLATES
278#endif
Non-templated base class for templated Array class.
Definition ArrayBase.h:71
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.
String: the storage and methods of handling collections of characters.
Definition String.h:223
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:124
virtual void putuChar(rownr_t rownr, const uChar *dataPtr)
virtual void getScalarColumnCellsV(const RefRows &rownrs, ArrayBase &dataPtr)
Get some scalar values in the column.
virtual void getString(rownr_t rownr, String *dataPtr)
virtual void putuInt(rownr_t rownr, const uInt *dataPtr)
virtual void putString(rownr_t rownr, const String *dataPtr)
VirtualScalarColumn< T > & operator=(const VirtualScalarColumn< T > &)=delete
The object cannot be assigned to.
virtual void getfloat(rownr_t rownr, float *dataPtr)
virtual void getInt64(rownr_t rownr, Int64 *dataPtr)
virtual void putfloat(rownr_t rownr, const float *dataPtr)
virtual void putShort(rownr_t rownr, const Short *dataPtr)
virtual void getuChar(rownr_t rownr, uChar *dataPtr)
virtual void putuShort(rownr_t rownr, const uShort *dataPtr)
virtual void putInt64(rownr_t rownr, const Int64 *dataPtr)
virtual void putComplex(rownr_t rownr, const Complex *dataPtr)
virtual void getShort(rownr_t rownr, Short *dataPtr)
VirtualScalarColumn(const VirtualScalarColumn< T > &)=delete
The object cannot be copied.
virtual void putdouble(rownr_t rownr, const double *dataPtr)
virtual void getBool(rownr_t rownr, Bool *dataPtr)
Implement the virtual functions defined in DataManagerColumn.
virtual String dataTypeId() const
Return the data type Id of the column.
virtual void getScalarColumnV(ArrayBase &dataPtr)
Get all scalar values in the column.
virtual void getInt(rownr_t rownr, Int *dataPtr)
virtual void putDComplex(rownr_t rownr, const DComplex *dataPtr)
virtual void getComplex(rownr_t rownr, Complex *dataPtr)
virtual void putBool(rownr_t rownr, const Bool *dataPtr)
Implement the virtual functions defined in DataManagerColumn.
virtual void getDComplex(rownr_t rownr, DComplex *dataPtr)
virtual void get(rownr_t rownr, T &data)=0
Let a derived class get the scalar value in the given row.
virtual void getdouble(rownr_t rownr, double *dataPtr)
virtual void putScalarColumnV(const ArrayBase &dataPtr)
Put all scalar values in the column.
virtual void getuShort(rownr_t rownr, uShort *dataPtr)
virtual void putOther(rownr_t rownr, const void *dataPtr)
This function is the put for all non-standard data types.
virtual void getOther(rownr_t rownr, void *dataPtr)
This function is the get for all non-standard data types.
virtual void putScalarColumnCellsV(const RefRows &rownrs, const ArrayBase &dataPtr)
Put some scalar values in the column.
virtual void getuInt(rownr_t rownr, uInt *dataPtr)
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.
virtual void putInt(rownr_t rownr, const Int *dataPtr)
virtual int dataType() const
Return the data type of the column.
VirtualScalarColumn()
Create a column.
Definition VirtScaCol.h:163
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
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:254
void putVirtualScalar(VirtualScalarColumn< T > *col, uInt rownr, const T *dataPtr)
Definition VirtScaCol.h:263
void getVirtualScalar(VirtualScalarColumn< T > *col, uInt rownr, T *dataPtr)
Definition VirtScaCol.h:256
void getVirtualScalar(DataManagerColumn *col, uInt, void *)
Definition VirtScaCol.h:259
void putVirtualScalar(DataManagerColumn *col, uInt, const void *)
Definition VirtScaCol.h:266