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