casa  5.7.0-16
 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>
34 
35 namespace casacore { //# NAMESPACE CASACORE - BEGIN
36 
37 //# Forward Declarations
38 template<class T> class Vector;
39 
40 
41 // <summary>
42 // Templated base class for virtual scalar column
43 // </summary>
44 
45 // <use visibility=local>
46 
47 // <reviewed reviewer="Gareth Hunt" date="94Nov17" tests="">
48 // </reviewed>
49 
50 // <prerequisite>
51 //# Classes you should understand before using this one.
52 // <li> DataManagerColumn
53 // <li> VirtualColumnEngine
54 // </prerequisite>
55 
56 // <etymology>
57 // VirtualScalarColumn handles a virtual column containing a scalar.
58 // </etymology>
59 
60 // <synopsis>
61 // VirtualScalarColumn is the abstract base class to handle a scalar column
62 // for a virtual column engine.
63 // It is derived from DataManagerColumn and reimplements some
64 // virtual functions to make life easier for the derived classes.
65 // It does the following:
66 // <ul>
67 // <li>
68 // It implements the dataType function, so it is not needed to implement
69 // that in derived classes.
70 // <li>
71 // It has a default implementation of False for function isWritable.
72 // Thus by default virtual scalar columns are not writable, which will
73 // often be the case. Only if a virtual scalar column can be writable,
74 // it has to be implemented in the derived class.
75 // <li>
76 // Declare a get/put function with the template parameter as its argument.
77 // The virtual functions get/putBoolV, etc. (defined in DataManagerColumn)
78 // are by default implemented using this (templated) get/put function.
79 // This allows for the default implementation of get/putBlock and
80 // makes life easier for the implementor of a derived class.
81 // However, the disadvantage of this is an extra virtual function call.
82 // (E.g. for a Bool value the first one is getBoolV and the second
83 // one get(T&), where T is Bool). If efficiency is really necessary,
84 // getBoolV, etc. should also be implemented in the derived class.
85 // <li>
86 // In DataManagerColumn the functions get/putBlockV and get/putColumnV
87 // are defined, which have a void* data argument. This is necessary
88 // to handle arbitrary data types in the non-templated base class
89 // DataManagerColumn.
90 // In this templated VirtualScalarColumn class, virtual functions
91 // get/putBlock and get/putColumn have been defined. They cast
92 // the void* data argument to T&, so in a derived class no care has
93 // to be taken for that cast.
94 // Furthermore a default implementation of them has been made.
95 // <ul>
96 // <li> getBlock gets one value using function get.
97 // <li> putBlock puts one value at the time using function put.
98 // <li> getColumn uses function getBlock.
99 // <li> putColumn uses function putBlock.
100 // </ul>
101 // If efficiency is an issue, these functions should be implemented
102 // in the derived class.
103 // </ul>
104 // </synopsis>
105 
106 // <motivation>
107 // This class reimplements some virtual functions implemented by
108 // DataManagerColumn and types the data argument. In that way they are
109 // easier to implement in derived classes. Furthermore they allow
110 // default implementations.
111 // </motivation>
112 
113 // <templating arg=T>
114 // <li> default constructor
115 // <li> copy constructor
116 // <li> assignment operator
117 // <li> <src>static String dataTypeId(); // unique name of the class</src>
118 // </templating>
119 
120 // <todo asof="$DATE:$">
121 //# A List of bugs, limitations, extensions or planned refinements.
122 // </todo>
123 
124 
125 template<class T>
127 {
128 public:
129 
130  // Create a column.
132  {;}
133 
134  // Frees up the storage.
135  virtual ~VirtualScalarColumn();
136 
137  // Return the data type of the column.
138  int dataType() const;
139 
140  // Return the data type Id of the column.
141  String dataTypeId() const;
142 
143  // By default no data can be put in a virtual column.
144  virtual Bool isWritable() const;
145 
146  // Get the scalar value in the given row.
147  virtual void get (uInt rownr, T& data) = 0;
148 
149  // Put the scalar value into the given row.
150  // The default implementation throws an exception.
151  virtual void put (uInt rownr, const T& data);
152 
153 protected:
154  // The class can handle a get/putScalarColumn.
155  Bool canAccessScalarColumn (Bool& reask) const;
156 
157  // Get all scalar values in the column.
158  // The argument dataPtr is in fact a Vector<T>*, but a void*
159  // is needed to be generic.
160  // The vector pointed to by dataPtr has to have the correct length
161  // (which is guaranteed by the ScalarColumn getColumn function).
162  virtual void getScalarColumn (Vector<T>& data);
163 
164  // Put all scalar values in the column.
165  // The argument dataPtr is in fact a const Vector<T>*, but a const void*
166  // is needed to be generic.
167  // The vector pointed to by dataPtr has to have the correct length
168  // (which is guaranteed by the ScalarColumn putColumn function).
169  virtual void putScalarColumn (const Vector<T>& data);
170 
171  // Get scalars from the given row on with a maximum of nrmax values.
172  // It returns the actual number of values got.
173  // This can be used to get an entire column of scalars or to get
174  // a part of a column (for a cache for example).
175  // The argument dataPtr is in fact a T*, but a void*
176  // is needed to be generic. It must have length nrmax.
177  virtual uInt getBlock (uInt rownr, uInt nrmax, T* dataPtr);
178 
179  // Put nrmax scalars from the given row on.
180  // It returns the actual number of values put.
181  // This can be used to put an entire column of scalars or to put
182  // a part of a column (for a cache for example).
183  // The argument dataPtr is in fact a const T*, but a const void*
184  // is needed to be generic. It must have length nrmax.
185  virtual void putBlock (uInt rownr, uInt nrmax, const T* dataPtr);
186 
187 
188 private:
189  // Implement the virtual functions defined in DataManagerColumn.
190  // Get the scalar value in the given row.
191  // <group>
192  void getBoolV (uInt rownr, Bool* dataPtr);
193  void getuCharV (uInt rownr, uChar* dataPtr);
194  void getShortV (uInt rownr, Short* dataPtr);
195  void getuShortV (uInt rownr, uShort* dataPtr);
196  void getIntV (uInt rownr, Int* dataPtr);
197  void getuIntV (uInt rownr, uInt* dataPtr);
198  void getInt64V (uInt rownr, Int64* dataPtr);
199  void getfloatV (uInt rownr, float* dataPtr);
200  void getdoubleV (uInt rownr, double* dataPtr);
201  void getComplexV (uInt rownr, Complex* dataPtr);
202  void getDComplexV (uInt rownr, DComplex* dataPtr);
203  void getStringV (uInt rownr, String* dataPtr);
204  // This function is the get for all non-standard data types.
205  void getOtherV (uInt 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  void putBoolV (uInt rownr, const Bool* dataPtr);
212  void putuCharV (uInt rownr, const uChar* dataPtr);
213  void putShortV (uInt rownr, const Short* dataPtr);
214  void putuShortV (uInt rownr, const uShort* dataPtr);
215  void putIntV (uInt rownr, const Int* dataPtr);
216  void putuIntV (uInt rownr, const uInt* dataPtr);
217  void putInt64V (uInt rownr, const Int64* dataPtr);
218  void putfloatV (uInt rownr, const float* dataPtr);
219  void putdoubleV (uInt rownr, const double* dataPtr);
220  void putComplexV (uInt rownr, const Complex* dataPtr);
221  void putDComplexV (uInt rownr, const DComplex* dataPtr);
222  void putStringV (uInt rownr, const String* dataPtr);
223  // This function is the put for all non-standard data types.
224  void putOtherV (uInt rownr, const void* dataPtr);
225  // </group>
226 
227  // Implement the virtual functions defined in DataManagerColumn.
228  // Get all scalar values in the column.
229  void getScalarColumnV (void* dataPtr);
230 
231  // Implement the virtual functions defined in DataManagerColumn.
232  // Put all scalar values in the column.
233  void putScalarColumnV (const void* dataPtr);
234 
235  // Implement the virtual functions defined in DataManagerColumn.
236  // Get scalars from the given row on with a maximum of nrmax values.
237  uInt getBlockV (uInt rownr, uInt nrmax, void* dataPtr);
238 
239  // Implement the virtual functions defined in DataManagerColumn.
240  // Put nrmax scalars from the given row on.
241  void putBlockV (uInt rownr, uInt nrmax, const void* dataPtr);
242 
243 private:
244  // The object cannot be copied.
246 
247  // The object cannot be assigned to.
249 };
250 
251 
252 
253 // <summary>
254 // Global functions to get or put data of a virtual column
255 // </summary>
256 // <synopsis>
257 // </synopsis>
258 // <group name=getVirtualScalarColumn>
259 template<class T>
260 inline void getVirtualScalarColumn (VirtualScalarColumn<T>* col,
261  uInt rownr, T* dataPtr)
262  { col->get (rownr, *dataPtr); }
263 inline void getVirtualScalarColumn (DataManagerColumn* col,
264  uInt, void*)
265  { col->throwGet(); }
266 
267 template<class T>
269  uInt rownr, const T* dataPtr)
270  { col->put (rownr, *dataPtr); }
272  uInt, const void*)
273  { col->throwPut(); }
274 // </group>
275 
276 
277 
278 } //# NAMESPACE CASACORE - END
279 
280 #ifndef CASACORE_NO_AUTO_TEMPLATES
281 #include <casacore/tables/DataMan/VirtScaCol.tcc>
282 #endif //# CASACORE_NO_AUTO_TEMPLATES
283 #endif
void putInt64V(uInt rownr, const Int64 *dataPtr)
void putOtherV(uInt rownr, const void *dataPtr)
This function is the put for all non-standard data types.
A 1-D Specialization of the Array class.
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
void putuIntV(uInt rownr, const uInt *dataPtr)
int Int
Definition: aipstype.h:50
void putIntV(uInt rownr, const Int *dataPtr)
std::vector< double > Vector
Definition: ds9context.h:24
virtual uInt getBlock(uInt rownr, uInt nrmax, T *dataPtr)
Get scalars from the given row on with a maximum of nrmax values.
uInt getBlockV(uInt rownr, uInt nrmax, void *dataPtr)
Implement the virtual functions defined in DataManagerColumn.
void putVirtualScalarColumn(VirtualScalarColumn< T > *col, uInt rownr, const T *dataPtr)
Definition: VirtScaCol.h:268
void getuShortV(uInt rownr, uShort *dataPtr)
void putdoubleV(uInt rownr, const double *dataPtr)
Abstract base class for a column in a data manager.
Definition: DataManager.h:611
void putShortV(uInt rownr, const Short *dataPtr)
void getScalarColumnV(void *dataPtr)
Implement the virtual functions defined in DataManagerColumn.
unsigned char uChar
Definition: aipstype.h:47
virtual ~VirtualScalarColumn()
Frees up the storage.
void getOtherV(uInt rownr, void *dataPtr)
This function is the get for all non-standard data types.
Templated base class for virtual scalar column.
Definition: VirtScaCol.h:126
void throwPut() const
Throw an &quot;invalid operation&quot; exception for the default implementation of put.
VirtualScalarColumn< T > & operator=(const VirtualScalarColumn< T > &)
The object cannot be assigned to.
void putuCharV(uInt rownr, const uChar *dataPtr)
void getDComplexV(uInt rownr, DComplex *dataPtr)
short Short
Definition: aipstype.h:48
void putScalarColumnV(const void *dataPtr)
Implement the virtual functions defined in DataManagerColumn.
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
Definition: PlotData.h:48
void getInt64V(uInt rownr, Int64 *dataPtr)
void getIntV(uInt rownr, Int *dataPtr)
virtual Bool isWritable() const
By default no data can be put in a virtual column.
String dataTypeId() const
Return the data type Id of the column.
void putBoolV(uInt rownr, const Bool *dataPtr)
Implement the virtual functions defined in DataManagerColumn.
void getuCharV(uInt rownr, uChar *dataPtr)
int dataType() const
Return the data type of the column.
void getBoolV(uInt rownr, Bool *dataPtr)
Implement the virtual functions defined in DataManagerColumn.
void putBlockV(uInt rownr, uInt nrmax, const void *dataPtr)
Implement the virtual functions defined in DataManagerColumn.
void getStringV(uInt rownr, String *dataPtr)
void getComplexV(uInt rownr, Complex *dataPtr)
void putComplexV(uInt rownr, const Complex *dataPtr)
void putfloatV(uInt rownr, const float *dataPtr)
void getuIntV(uInt rownr, uInt *dataPtr)
void putDComplexV(uInt rownr, const DComplex *dataPtr)
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
void getShortV(uInt rownr, Short *dataPtr)
void throwGet() const
Throw an &quot;invalid operation&quot; exception for the default implementation of get.
void putuShortV(uInt rownr, const uShort *dataPtr)
void putStringV(uInt rownr, const String *dataPtr)
Bool canAccessScalarColumn(Bool &reask) const
The class can handle a get/putScalarColumn.
void getfloatV(uInt rownr, float *dataPtr)
VirtualScalarColumn()
Create a column.
Definition: VirtScaCol.h:131
virtual void getScalarColumn(Vector< T > &data)
Get all scalar values in the column.
virtual void putBlock(uInt rownr, uInt nrmax, const T *dataPtr)
Put nrmax scalars from the given row on.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
void getdoubleV(uInt rownr, double *dataPtr)
void putVirtualScalarColumn(DataManagerColumn *col, uInt, const void *)
Definition: VirtScaCol.h:271
virtual void put(uInt rownr, const T &data)
Put the scalar value into the given row.
virtual void putScalarColumn(const Vector< T > &data)
Put all scalar values in the column.
unsigned int uInt
Definition: aipstype.h:51
virtual void get(uInt rownr, T &data)=0
Get the scalar value in the given row.
unsigned short uShort
Definition: aipstype.h:49
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42