casacore
Loading...
Searching...
No Matches
VSCEngine.h
Go to the documentation of this file.
1// # VSCEngine.h: Base virtual column for a scalar column with any type
2// # Copyright (C) 1994,1995,1996,1999,2000
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_VSCENGINE_H
27#define TABLES_VSCENGINE_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/DataMan/VirtColEng.h>
32#include <casacore/tables/DataMan/VirtScaCol.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// <summary>
37// Base virtual column for a scalar column with any type
38// </summary>
39
40// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
41// </reviewed>
42
43// <use visibility=export>
44
45// <prerequisite>
46// # Classes you should understand before using this one.
47// <li> VirtualColumnEngine
48// <li> VirtualScalarColumn
49// </prerequisite>
50
51// <etymology>
52// VSCEngine stands for Virtual Scalar Column Engine, i.e. a class
53// handling a virtual table column containing scalar values.
54// </etymology>
55
56// <synopsis>
57// VSCEngine is a base virtual column engine to handle a column
58// with an arbitrary type.
59// Data of columns with standard data types can directly be stored
60// in a Table using a storage manager, but data of column with non-standard
61// types have to be stored in another way.
62// The way to do this is to split the object with the non-standard
63// type into its individual elements, which are subsequently put into the
64// appropriate columns.
65//
66// A virtual column engine has to be implemented for each non-standard
67// data type, which has to be stored in a table. This engine has to get
68// and put the individual parts the object.
69// VSCEngine is the base class for such engines, so the actual
70// engine quite simple to implement. The example shows the implementation
71// of an engine AVSCEngine handling a data type A.
72//
73// In principle the name of the engine class is free, but it is strongly
74// recommended to use the name <src><dataTypeId>VSCEngine</src>, where VSC
75// stands for Virtual Scalar Column (e.g. <src>AVSCEngine</src> for class A).
76// In this way the default data manager name supplied by the class and by
77// class ScalarColumnDesc can be used.
78// </synopsis>
79
80// <example>
81// This example shows the implementation of an engine class AVSCEngine,
82// which stores the data of a class A.
83// The data objects A are stored in a column called the source column.
84// The user has to associate two target columns with it. The engine stores
85// the data parts x and y in the target columns.
86// The names of the target columns are stored as keywords in the source
87// column. In this way the engine can reconstruct itself when the table
88// is read back.
89//
90// In the example all AVSCEngine functions are shown inline, but they
91// should be implemented out-of-line in a separate .cc file.
92// <srcblock>
93// //# AVSCEngine.h: Example virtual column engine to handle data type A
94//
95// #if !defined(AIPS_AVSCENGINE_H)
96// #define AIPS_AVSCENGINE_H
97//
98// //# Includes
99// #include <casacore/tables/DataMan/VSCEngine.h>
100// #include <casacore/tables/Tables/ScalarColumn.h>
101//
102// // Define the class A.
103// class A
104// {
105// public:
106// A(): x_p(0), y_p(0) {}
107// A(Int x, float y) : x_p(x), y_p(y) {}
108// A(const A& that): x_p(that.x_p), y_p(that.y_p) {}
109// static String dataTypeId()
110// { return "A"; }
111// Int x() const
112// { return x_p; }
113// float y() const
114// { return y_p; }
115// Int& x()
116// { return x_p; }
117// float& y()
118// { return y_p; }
119// int operator== (const A& that) const
120// { return x_p==that.x_p && y_p==that.y_p; }
121// int operator< (const A& that) const
122// { return x_p<that.x_p || (x_p==that.x_p && y_p<that.y_p); }
123// private:
124// Int x_p;
125// float y_p;
126// };
127//
128// // Now define the engine to handle objects of type A.
129// class AVSCEngine : public VSCEngine<A>
130// {
131// public:
132//
133// // The default constructor is required for reconstruction of the
134// // engine when a table is read back.
135// AVSCEngine()
136// {}
137//
138// // Construct the engine for the given source column and storing
139// // the result in the given target columns for the data members
140// // x and y of class A.
141// AVSCEngine (const String& sourceColumnName,
142// const String& xTargetColumnName,
143// const String& yTargetColumnname)
144// : VSCEngine<A> (sourceColumnName),
145// xTargetName_p (xTargetColumnName),
146// yTargetName_p (yTargetColumnName)
147// {}
148//
149// // Destructor is mandatory.
150// virtual ~AVSCEngine()
151// {}
152//
153// // Assignment is not needed and therefore forbidden.
154// AVSCEngine& operator= (const AVSCEngine&) = delete;
155//
156// // Clone the object.
157// virtual DataManager* clone() const
158// {
159// DataManager* dmPtr = new AVSCEngine (sourceColumnName(),
160// xTargetName_p, yTargetName_p);
161// return dmPtr;
162// }
163//
164// // Store the target column names in the source column keywords.
165// virtual void create (rownr_t)
166// {
167// TableColumn src (table(), sourceColumnName());
168// src.keywordSet().keysString()("_xTargetName") = xTargetName_p;
169// src.keywordSet().keysString()("_yTargetName") = yTargetName_p;
170// }
171//
172// // Prepare the engine by allocating column objects
173// // for the target columns.
174// virtual void prepare()
175// {
176// TableColumn src (table(), sourceColumnName());
177// xTargetName_p = src.keywordSet().asString ("_xTargetName");
178// yTargetName_p = src.keywordSet().asString ("_yTargetName");
179// rocolx.attach (table(), xTargetName_p);
180// rocoly.attach (table(), yTargetName_p);
181// if (table().isWritable()) {
182// colx.attach (table(), xTargetName_p);
183// coly.attach (table(), yTargetName_p);
184// }
185// }
186//
187// // Get the data from a row.
188// virtual void get (rownr_t rownr, A& value)
189// {
190// rocolx.get (rownr, value.x());
191// rocoly.get (rownr, value.y());
192// }
193//
194// // Put the data in a row.
195// virtual void put (rownr_t rownr, const A& value)
196// {
197// colx.put (rownr, value.x());
198// coly.put (rownr, value.y());
199// }
200//
201// // Register the class name and the static makeObject "constructor".
202// // This will make the engine known to the table system.
203// static void registerClass()
204// {
205// DataManager::registerCtor ("AVSCEngine", makeObject);
206// }
207//
208// private:
209// // Copy constructor is only used by clone().
210// // (so it is made private).
211// AVSCEngine (const AVSCEngine&)
212// : VSCEngine<A> (that),
213// xTargetName_p (that.xTargetName_p),
214// yTargetName_p (that.yTargetName_p)
215// {}
216//
217//
218// // The target column names.
219// String xTargetName_p;
220// String yTargetName_p;
221// // Objects for the target columns.
222// ScalarColumn<Int> colx; // used by put
223// ScalarColumn<Int> rocolx; // used by get
224// ScalarColumn<float> coly; // used by put
225// ScalarColumn<float> rocoly; // used by get
226//
227// public:
228// // Define the "constructor" to construct this engine when a
229// // table is read back.
230// // This "constructor" has to be registered by the user of the engine.
231// // Function registerClass() is doing that.
232// static DataManager* makeObject (const String& dataManagerType)
233// {
234// DataManager* dmPtr = new AVSCEngine();
235// return dmPtr;
236// }
237// };
238//
239// #endif
240// </srcblock>
241//
242// User code using this engine to create a new table could look like:
243// <srcblock>
244// // Register the engine.
245// // This is not needed if the engine is registered as part
246// // of the general DataManager::registerAllCtor function.
247// AVSCEngine::registerClass();
248// // Create the table description.
249// TableDesc td;
250// td.addColumn (ScalarColumnDesc<A>("source"));
251// td.addColumn (ScalarColumnDesc<Int>("xTarget"));
252// td.addColumn (ScalarColumnDesc<Int>("yTarget"));
253// SetupNewTable setup ("table.name", td, Table::New);
254// // Define the engine for column "source".
255// AVSCEngine engine ("source", "xTarget", "yTarget");
256// Table tab (setup, 10);
257// // Put data into column "source".
258// ScalarColumn<A> col (tab, "source");
259// for (uInt i=0; i<10; i++) {
260// col.put (i, someA); // writes indirectly xTarget and yTarget
261// }
262// </srcblock>
263// </example>
264//
265// <motivation>
266// This class makes it easier for the user to implement the engine.
267// It supplies several default functions.
268// </motivation>
269
270// <templating arg=T>
271// <li> Default constructor T();
272// <li> Copy constructor T(const T&);
273// <li> Assignment operator T& operator= (const T&);
274// <li> comparison operator int operator== (const T&) const;
275// <li> comparison operator int operator< (const T&) const;
276// <li> identification <src>static String dataTypeId();</src>
277// This should return the (unique) name of the class, thus
278// when T is templated in its turn, the name should contain the
279// template argument name.
280// </templating>
281
282template <class T>
284 // # Make members of parent class known.
285 public:
287
288 public:
289 // The default constructor is required for reconstruction of the
290 // engine when a table is read back.
291 // It is also used to construct an engine, which does not check
292 // the source column name.
294
295 // Construct an engine to handle a column with an arbitrary data type.
296 // Later it will check if the source column name is correct.
298
299 // Destructor is mandatory.
301
302 // Assignment is not needed and therefore forbidden.
304
305 // Return the data manager type name.
306 // This defaults to the data type ID followed by VSCEngine
307 // (meaning Virtual Scalar Column Engine).
309
310 // Get the name of the source column.
311 const String& sourceColumnName() const { return sourceName_p; }
312
313 protected:
314 // Copy constructor is only used by clone().
315 // (so it is made protected).
317
318 private:
319 // The column is in principle writable.
320 // This does not mean it is actually writable, because that
321 // depends on the fact if the table is writable.
323
324 // Create the column object for the scalar column in this engine.
325 // It will check if the given column name matches the source
326 // column name. This assures that the engine is bound to the
327 // correct column.
329 const String& dataTypeID);
330
331 // # Now define the data members.
332 String sourceName_p; // # source column name
333};
334
335} // namespace casacore
336
337#ifndef CASACORE_NO_AUTO_TEMPLATES
338#include <casacore/tables/DataMan/VSCEngine.tcc>
339#endif // # CASACORE_NO_AUTO_TEMPLATES
340#endif
const String & columnName() const
Get rhe column name.
String: the storage and methods of handling collections of characters.
Definition String.h:355
VSCEngine(const VSCEngine< T > &)
Copy constructor is only used by clone().
DataManagerColumn * makeScalarColumn(const String &columnName, int dataType, const String &dataTypeID)
Create the column object for the scalar column in this engine.
VSCEngine< T > & operator=(const VSCEngine< T > &)=delete
Assignment is not needed and therefore forbidden.
String dataManagerType() const
Return the data manager type name.
Bool isWritable() const
The column is in principle writable.
VSCEngine()
The default constructor is required for reconstruction of the engine when a table is read back.
const String & sourceColumnName() const
Get the name of the source column.
Definition VSCEngine.h:311
VSCEngine(const String &sourceColumnName)
Construct an engine to handle a column with an arbitrary data type.
~VSCEngine()
Destructor is mandatory.
VirtualColumnEngine()
Create the object.
Definition VirtColEng.h:110
String dataTypeId() const override
Return the data type Id of the column.
int dataType() const override
Return the data type of the column.
VirtualScalarColumn()
Create a column.
Definition VirtScaCol.h:152
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40