casacore
Loading...
Searching...
No Matches
VACEngine.h
Go to the documentation of this file.
1// # VACEngine.h: Base virtual column for an array 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_VACENGINE_H
27#define TABLES_VACENGINE_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/DataMan/VirtColEng.h>
32#include <casacore/tables/DataMan/VirtArrCol.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// <summary>
37// Base virtual column for an array 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> VirtualArrayColumn
49// </prerequisite>
50
51// <etymology>
52// VACEngine stands for Virtual Array Column Engine, i.e. a class
53// handling a virtual table column containing array values.
54// </etymology>
55
56// <synopsis>
57// VACEngine 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// VACEngine 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 AVACEngine 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>VACEngine</src>, where VAC
75// stands for Virtual Array Column (e.g. <src>AVACEngine</src> for class A).
76// In this way the default data manager name supplied by the class and by
77// class ArrayColumnDesc can be used.
78// </synopsis>
79
80// <example>
81// This example shows the implementation of an engine class AVACEngine,
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 AVACEngine functions are shown inline, but they
91// should be implemented out-of-line in a separate .cc file.
92// <srcblock>
93// //# AVACEngine.h: Example virtual column engine to handle data type A
94//
95// #if !defined(AIPS_AVACENGINE_H)
96// #define AIPS_AVACENGINE_H
97//
98// //# Includes
99// #include <casacore/tables/DataMan/VACEngine.h>
100// #include <casacore/tables/Tables/ArrayColumn.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 AVACEngine : public VACEngine<A>
130// {
131// public:
132//
133// // The default constructor is required for reconstruction of the
134// // engine when a table is read back.
135// AVACEngine() = default;
136//
137// // Construct the engine for the given source column and storing
138// // the result in the given target columns for the data members
139// // x and y of class A.
140// AVACEngine (const String& sourceColumnName,
141// const String& xTargetColumnName,
142// const String& yTargetColumnname)
143// : VACEngine<A> (sourceColumnName),
144// xTargetName_p (xTargetColumnName),
145// yTargetName_p (yTargetColumnName)
146// {}
147//
148// // Destructor is only needed if something has to be destructed.
149// ~AVACEngine() = override
150// {}
151//
152// // Assignment is not needed and therefore forbidden.
153// AVACEngine& operator= (const AVACEngine&) = delete;
154//
155// // Clone the object.
156// virtual DataManager* clone() const
157// {
158// DataManager* dmPtr = new AVACEngine (sourceColumnName(),
159// xTargetName_p, yTargetName_p);
160// return dmPtr;
161// }
162//
163// // Store the target column names in the source column keywords.
164// virtual void create (rownr_t)
165// {
166// TableColumn src (table(), sourceColumnName());
167// src.keywordSet().keysString()("_xTargetName") = xTargetName_p;
168// src.keywordSet().keysString()("_yTargetName") = yTargetName_p;
169// }
170//
171// // Prepare the engine by allocating column objects
172// // for the target columns.
173// virtual void prepare()
174// {
175// TableColumn src (table(), sourceColumnName());
176// xTargetName_p = src.keywordSet().asString ("_xTargetName");
177// yTargetName_p = src.keywordSet().asString ("_yTargetName");
178// rocolx.attach (table(), xTargetName_p);
179// rocoly.attach (table(), yTargetName_p);
180// if (table().isWritable()) {
181// colx.attach (table(), xTargetName_p);
182// coly.attach (table(), yTargetName_p);
183// }
184// }
185//
186// // Get the data from a row.
187// virtual void get (rownr_t rownr, A& value)
188// {
189// rocolx.get (rownr, value.x());
190// rocoly.get (rownr, value.y());
191// }
192//
193// // Put the data in a row.
194// virtual void put (rownr_t rownr, const A& value)
195// {
196// colx.put (rownr, value.x());
197// coly.put (rownr, value.y());
198// }
199//
200// // Register the class name and the static makeObject "constructor".
201// // This will make the engine known to the table system.
202// static void registerClass()
203// {
204// DataManager::registerCtor ("AVACEngine", makeObject);
205// }
206//
207// private:
208// // Copy constructor is only used by clone().
209// // (so it is made private).
210// AVACEngine (const AVACEngine&)
211// : VACEngine<A> (that),
212// xTargetName_p (that.xTargetName_p),
213// yTargetName_p (that.yTargetName_p)
214// {}
215//
216//
217// // The target column names.
218// String xTargetName_p;
219// String yTargetName_p;
220// // Objects for the target columns.
221// ArrayColumn<Int> colx; // used by put
222// ArrayColumn<Int> rocolx; // used by get
223// ArrayColumn<float> coly; // used by put
224// ArrayColumn<float> rocoly; // used by get
225//
226// public:
227// // Define the "constructor" to construct this engine when a
228// // table is read back.
229// // This "constructor" has to be registered by the user of the engine.
230// // Function registerClass() is doing that.
231// static DataManager* makeObject (const String& dataManagerType)
232// {
233// DataManager* dmPtr = new AVACEngine();
234// return dmPtr;
235// }
236// };
237//
238// #endif
239// </srcblock>
240//
241// User code using this engine to create a new table could look like:
242// <srcblock>
243// // Register the engine.
244// // This is not needed if the engine is registered as part
245// // of the general DataManager::registerAllCtor function.
246// AVACEngine::registerClass();
247// // Create the table description.
248// TableDesc td;
249// td.addColumn (ArrayColumnDesc<A>("source"));
250// td.addColumn (ArrayColumnDesc<Int>("xTarget"));
251// td.addColumn (ArrayColumnDesc<Int>("yTarget"));
252// SetupNewTable setup ("table.name", td, Table::New);
253// // Define the engine for column "source".
254// AVACEngine engine ("source", "xTarget", "yTarget");
255// Table tab (setup, 10);
256// // Put data into column "source".
257// ArrayColumn<A> col (tab, "source");
258// for (uInt i=0; i<10; i++) {
259// col.put (i, someA); // writes indirectly xTarget and yTarget
260// }
261// </srcblock>
262// </example>
263//
264// <motivation>
265// This class makes it easier for the user to implement the engine.
266// It supplies several default functions.
267// </motivation>
268
269// <templating arg=T>
270// <li> Default constructor T();
271// <li> Copy constructor T(const T&);
272// <li> Assignment operator T& operator= (const T&);
273// <li> comparison operator int operator== (const T&) const;
274// <li> comparison operator int operator< (const T&) const;
275// <li> identification <src>static String dataTypeId();</src>
276// This should return the (unique) name of the class, thus
277// when T is templated in its turn, the name should contain the
278// template argument name.
279// </templating>
280
281template <class T>
283 // # Make members of parent class known.
284 public:
286
287 public:
288 // The default constructor is required for reconstruction of the
289 // engine when a table is read back.
290 // It is also used to construct an engine, which does not check
291 // the source column name.
292 VACEngine() = default;
293
294 // Construct an engine to handle a column with an arbitrary data type.
295 // Later it will check if the source column name is correct.
297
298 // Destructor.
299 virtual ~VACEngine() = default;
300
301 // Assignment is not needed and therefore forbidden.
303
304 // Return the data manager type name.
305 // This defaults to the data type ID followed by VACEngine
306 // (meaning Virtual Array Column Engine).
308
309 // Get the name of the source column.
310 const String& sourceColumnName() const { return sourceName_p; }
311
312 protected:
313 // Copy constructor is only used by clone().
314 // (so it is made protected).
316
317 private:
318 // The column is in principle writable.
319 // This does not mean it is actually writable, because that
320 // depends on the fact if the table is writable.
322
323 // Create the column object for the array column in this engine.
324 // It will check if the given column name matches the source
325 // column name. This assures that the engine is bound to the
326 // correct column.
328 const String& dataTypeID);
330 const String& dataTypeID);
331
332 // # Now define the data members.
333 String sourceName_p; // # source column name
334};
335
336} // namespace casacore
337
338#ifndef CASACORE_NO_AUTO_TEMPLATES
339#include <casacore/tables/DataMan/VACEngine.tcc>
340#endif // # CASACORE_NO_AUTO_TEMPLATES
341#endif
const String & columnName() const
Get rhe column name.
String: the storage and methods of handling collections of characters.
Definition String.h:355
DataManagerColumn * makeDirArrColumn(const String &columnName, int dataType, const String &dataTypeID)
Create the column object for the array column in this engine.
Bool isWritable() const
The column is in principle writable.
const String & sourceColumnName() const
Get the name of the source column.
Definition VACEngine.h:310
VACEngine(const String &sourceColumnName)
Construct an engine to handle a column with an arbitrary data type.
DataManagerColumn * makeIndArrColumn(const String &columnName, int dataType, const String &dataTypeID)
Create an indirect array column.
VACEngine(const VACEngine< T > &)
Copy constructor is only used by clone().
virtual ~VACEngine()=default
Destructor.
String dataManagerType() const
Return the data manager type name.
VACEngine< T > & operator=(const VACEngine< T > &)=delete
Assignment is not needed and therefore forbidden.
VACEngine()=default
The default constructor is required for reconstruction of the engine when a table is read back.
virtual int dataType() const
Return the data type of the column.
virtual String dataTypeId() const
Return the data type Id of the column.
VirtualArrayColumn()
Create a column.
Definition VirtArrCol.h:173
VirtualColumnEngine()
Create the object.
Definition VirtColEng.h:110
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