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
34
35namespace casacore { //# NAMESPACE CASACORE - BEGIN
36
37// <summary>
38// Base virtual column for an array 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> VirtualArrayColumn
50// </prerequisite>
51
52// <etymology>
53// VACEngine stands for Virtual Array Column Engine, i.e. a class
54// handling a virtual table column containing array values.
55// </etymology>
56
57// <synopsis>
58// VACEngine 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// VACEngine 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 AVACEngine 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>VACEngine</src>, where VAC
76// stands for Virtual Array Column (e.g. <src>AVACEngine</src> for class A).
77// In this way the default data manager name supplied by the class and by
78// class ArrayColumnDesc can be used.
79// </synopsis>
80
81// <example>
82// This example shows the implementation of an engine class AVACEngine,
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 AVACEngine functions are shown inline, but they
92// should be implemented out-of-line in a separate .cc file.
93// <srcblock>
94// //# AVACEngine.h: Example virtual column engine to handle data type A
95//
96// #if !defined(AIPS_AVACENGINE_H)
97// #define AIPS_AVACENGINE_H
98//
99// //# Includes
100// #include <casacore/tables/DataMan/VACEngine.h>
101// #include <casacore/tables/Tables/ArrayColumn.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 AVACEngine : public VACEngine<A>
131// {
132// public:
133//
134// // The default constructor is required for reconstruction of the
135// // engine when a table is read back.
136// AVACEngine() = default;
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// AVACEngine (const String& sourceColumnName,
142// const String& xTargetColumnName,
143// const String& yTargetColumnname)
144// : VACEngine<A> (sourceColumnName),
145// xTargetName_p (xTargetColumnName),
146// yTargetName_p (yTargetColumnName)
147// {}
148//
149// // Destructor is only needed if something has to be destructed.
150// ~AVACEngine() = override
151// {}
152//
153// // Assignment is not needed and therefore forbidden.
154// AVACEngine& operator= (const AVACEngine&) = delete;
155//
156// // Clone the object.
157// virtual DataManager* clone() const
158// {
159// DataManager* dmPtr = new AVACEngine (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 ("AVACEngine", makeObject);
206// }
207//
208// private:
209// // Copy constructor is only used by clone().
210// // (so it is made private).
211// AVACEngine (const AVACEngine&)
212// : VACEngine<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// ArrayColumn<Int> colx; // used by put
223// ArrayColumn<Int> rocolx; // used by get
224// ArrayColumn<float> coly; // used by put
225// ArrayColumn<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 AVACEngine();
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// AVACEngine::registerClass();
248// // Create the table description.
249// TableDesc td;
250// td.addColumn (ArrayColumnDesc<A>("source"));
251// td.addColumn (ArrayColumnDesc<Int>("xTarget"));
252// td.addColumn (ArrayColumnDesc<Int>("yTarget"));
253// SetupNewTable setup ("table.name", td, Table::New);
254// // Define the engine for column "source".
255// AVACEngine engine ("source", "xTarget", "yTarget");
256// Table tab (setup, 10);
257// // Put data into column "source".
258// ArrayColumn<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
282
283template<class T>
285 public VirtualArrayColumn<T>
286{
287 //# Make members of parent class known.
288public:
290
291public:
292 // The default constructor is required for reconstruction of the
293 // engine when a table is read back.
294 // It is also used to construct an engine, which does not check
295 // the source column name.
296 VACEngine() = default;
297
298 // Construct an engine to handle a column with an arbitrary data type.
299 // Later it will check if the source column name is correct.
301
302 // Destructor.
303 virtual ~VACEngine() = default;
304
305 // Assignment is not needed and therefore forbidden.
307
308 // Return the data manager type name.
309 // This defaults to the data type ID followed by VACEngine
310 // (meaning Virtual Array Column Engine).
312
313 // Get the name of the source column.
315 { return sourceName_p; }
316
317protected:
318 // Copy constructor is only used by clone().
319 // (so it is made protected).
321
322private:
323 // The column is in principle writable.
324 // This does not mean it is actually writable, because that
325 // depends on the fact if the table is writable.
327
328 // Create the column object for the array column in this engine.
329 // It will check if the given column name matches the source
330 // column name. This assures that the engine is bound to the
331 // correct column.
333 int dataType,
334 const String& dataTypeID);
336 int dataType,
337 const String& dataTypeID);
338
339
340 //# Now define the data members.
341 String sourceName_p; //# source column name
342};
343
344
345
346} //# NAMESPACE CASACORE - END
347
348#ifndef CASACORE_NO_AUTO_TEMPLATES
349#include <casacore/tables/DataMan/VACEngine.tcc>
350#endif //# CASACORE_NO_AUTO_TEMPLATES
351#endif
const String & columnName() const
Get rhe column name.
String: the storage and methods of handling collections of characters.
Definition String.h:223
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:314
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:181
VirtualColumnEngine()
Create the object.
Definition VirtColEng.h:114
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