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