casacore
Loading...
Searching...
No Matches
ColumnDesc.h
Go to the documentation of this file.
1//# ColumnDesc.h: an envelope class for column descriptions in tables
2//# Copyright (C) 1994,1995,1996,1997,1998,1999,2000,2001,2016
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_COLUMNDESC_H
27#define TABLES_COLUMNDESC_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/tables/Tables/BaseColDesc.h>
33#include <casacore/casa/BasicSL/String.h>
34#include <casacore/casa/Arrays/IPosition.h>
35
36#include <map>
37#include <mutex>
38
39namespace casacore { //# NAMESPACE CASACORE - BEGIN
40
41// <summary>
42// Envelope class for the description of a table column
43// </summary>
44
45// <use visibility=export>
46
47// <reviewed reviewer="Paul Shannon" date="1994/08/11" tests="none">
48// </reviewed>
49
50// <prerequisite>
51// <li> Tables module (see especially Tables.h, the module header file)
52// <li> Envelope/Letter class design (see J. Coplien, Advanced C++)
53// </prerequisite>
54
55// <synopsis>
56// Class ColumnDesc is an envelope for the letter class BaseColDesc
57// and its derivations like
58// <linkto class="ScalarColumnDesc:description">ScalarColumnDesc</linkto>,
59// <linkto class="ScalarRecordColumnDesc:description">
60// ScalarRecordColumnDesc</linkto>.
61// <linkto class="ArrayColumnDesc:description">ArrayColumnDesc</linkto>, and
62// <linkto class="SubTableDesc:description">SubTableDesc</linkto>.
63// ColumnDesc is meant to examine or slightly modify already existing
64// column descriptions.
65// It allows the retrieval of attributes like name, data type, etc..
66// For non-const ColumnDesc objects it is possible to modify the
67// attributes comment and keyword set.
68//
69// Since there are several types of columns, the class ColumnDesc
70// cannot handle all details of those column types. Therefore,
71// to create a column description, an instance of the specialized
72// classes ArrayColumnDesc<T>, etc. has to be constructed.
73// In there column type dependent things like array shape and
74// default value can be defined.
75//
76// This class also enumerates the possible options which can be used
77// when defining a column via classes like ScalarColumnDesc<T>.
78// These options are:
79// <dl>
80// <dt> FixedShape
81// <dd>
82// This is only useful for columns containing arrays and tables.
83// FixedShape means that the shape of the array or table must
84// be the same in each cell of the column.
85// If not given, the array or table shape may vary.
86// Option Direct forces FixedShape.
87// <dt> Direct
88// <dd>
89// This is only useful for columns containing arrays and tables.
90// Direct means that the data is directly stored in the table.
91// Direct forces option FixedShape.
92// If not given, the array or table is indirect, which implies
93// that the data will be stored in a separate file.
94// <dt> Undefined
95// <dd>
96// Undefined is only useful for scalars. If not given, all possible
97// values of the scalar have a meaning. If given, a value equal to
98// the default value in the column description is an undefined value.
99// The function TableColumn::isDefined will return False for such
100// values.
101// </dl>
102// </synopsis>
103
104// <example>
105// <srcblock>
106// TableDesc tableDesc("theTableDesc", TableDesc::New);
107// // Add a float scalar column.
108// tableDesc.addColumn (ScalarColumnDesc<float> ("NAME");
109// // Get the description of a column and change the comments.
110// // In order to change the comments, a reference must be used
111// // (because the ColumnDesc copy constructor and assign have copy
112// // semantics).
113// ColumnDesc& myColDesc = tableDesc.columnDesc ("aName");
114// myColDesc.comment() += "some more comments";
115// </srcblock>
116// </example>
117
118// <motivation>
119// When getting the description of an arbitrary column, a pointer to
120// that description is needed to allow proper execution of virtual
121// functions.
122// An envelope class is needed to hide this from the user.
123// </motivation>
124
125// <todo asof="$DATE:$">
126//# A List of bugs, limitations, extensions or planned refinements.
127// </todo>
128
129
131{
132friend class ColumnDescSet;
133friend class ColumnSet;
134friend class BaseColumn;
135
136public:
137
138 // Enumerate the possible column options.
139 // They can be combined by adding (logical or-ing) them.
140 enum Option {
141 // direct table or array
143 // undefined values are possible
145 // fixed array/table shape
146 FixedShape=4
147 };
148
149 // Construct from a column description.
150 // This constructor is merely for the purpose of the automatic
151 // conversion of an object like ScalarColumnDesc<T> to
152 // ColumnDesc when adding a column to the table description
153 // using the function TableDesc::addColumn.
155
156 // Copy constructor (copy semantics).
157 ColumnDesc (const ColumnDesc& that);
158
159 // Default constructor (needed for ColumnDescSet).
161 : colPtr_p(0),
163 {}
164
166
167 // Assignment (copy semantics).
169
170 // Comparison.
171 // Two descriptions are equal when their data types, value types
172 // (scalar, array or table) and possible dimensionalities are equal.
173 // <group>
176 // </group>
177
178 // Get access to the set of keywords.
179 // <group>
182 const TableRecord& keywordSet() const
183 { return colPtr_p->keywordSet(); }
184 // </group>
185
186 // Get the name of the column.
187 //# Maybe it can be inlined.
188 const String& name() const;
189
190 // Get the data type of the column.
191 // This always returns the type of a scalar, even when the column
192 // contains arrays.
193 DataType dataType() const
194 { return colPtr_p->dataType(); }
195
196 // Get the true data type of the column.
197 // Unlike dataType, it returns an array data type (e.g. TpArrayInt)
198 // when the column contains arrays.
199 DataType trueDataType() const;
200
201 // Get the type id for non-standard data types (i.e. for TpOther).
202 // For standard data types the returned string is empty.
203 const String& dataTypeId() const
204 { return colPtr_p->dataTypeId(); }
205
206 // Get the type name of the default data manager.
207 const String& dataManagerType() const
208 { return colPtr_p->dataManagerType(); }
209
210 // Get the type name of the default data manager
211 // (allowing it to be changed).
214
215 // Get the data manager group.
217 { return colPtr_p->dataManagerGroup(); }
218
219 // Get the data manager group.
220 // (allowing it to be changed).
223
224 // If <src>always==True</src> they are always set, otherwise only if empty.
227
228 // Get comment string.
229 const String& comment() const
230 { return colPtr_p->comment(); }
231
232 // Get comment string (allowing it to be changed).
234 { return colPtr_p->comment(); }
235
236 // Get the options. The possible options are defined by the enum Option.
237 // E.g.
238 // <srcblock>
239 // const ColumnDesc& coldesc = tableDesc.getColumn ("column_name");
240 // if (coldesc.option() & ColumnDesc::Direct == ColumnDesc::Direct) {
241 // // the column has the Direct flag set
242 // }
243 // </srcblock>
244 int options() const
245 { return colPtr_p->options(); }
246
247 // Check if the column is defined with a fixed shape.
248 // This is always true for scalars. For arrays it is true when
249 // the FixedShape flag was set when the column was defined.
251
252 // Test if column is a scalar.
254 { return colPtr_p->isScalar(); }
255 // Test if column is an array.
256 Bool isArray() const
257 { return colPtr_p->isArray(); }
258 // Test if column is a table.
259 Bool isTable() const
260 { return colPtr_p->isTable(); }
261
262 // Get the number of dimensions.
263 Int ndim() const
264 { return colPtr_p->ndim(); }
265
266 // Get the predefined shape.
267 // If not defined, a zero shape will be returned.
268 const IPosition& shape() const
269 { return colPtr_p->shape(); }
270
271 // Set the number of dimensions.
272 // This is only allowed for arrays.
273 // <src>ndim</src> can be zero to clear the number of dimensions
274 // and the shape.
275 // Otherwise it can only be used if the dimensionality has not been
276 // defined yet.
278 { colPtr_p->setNdim (ndim); }
279
280 // Set the predefined shape.
281 // This is only allowed for arrays, for which the shape
282 // has not been defined yet.
283 // If the dimensionality has already been defined, it must match.
284 // It will set the option <src>FixedShape</src> if not set yet.
285 // <br> The first version leaves the <src>Direct</src> option as is.
286 // The second version sets the <src>Direct</src> option as given.
287 // <group>
289 { colPtr_p->setShape (shape); }
290 void setShape (const IPosition& shape, Bool directOption)
291 { colPtr_p->setShape (shape, directOption); }
292 // </group>
293
294 // Set the options to the given value.
295 // Option <src>ColumnDesc::Direct</src> forces <src>FixedShape</src>.
296 // If <src>FixedShape</src> is not given (implicitly or explicitly),
297 // the column can have no shape, so its shape is cleared.
300
301 // Get the maximum value length.
303 { return colPtr_p->maxLength(); }
304
305 // Set the maximum value length.
306 // So far, this is only possible for columns containing String values.
307 // An exception is thrown if the column data type is not TpString.
308 // Some storage managers support fixed length strings and can store
309 // them more efficiently than variable length strings.
312
313 // Get table description (in case column contains subtables).
314 // <group>
315 const TableDesc* tableDesc() const
316 { return colPtr_p->tableDesc(); }
318 { return colPtr_p->tableDesc(); }
319 // </group>
320
321 // Show the column on cout.
322 void show() const;
323
324 // Show the column.
325 void show (ostream& os) const;
326
327 // Write into AipsIO.
328 friend AipsIO& operator<< (AipsIO& ios, const ColumnDesc& cd);
329
330 // Read from AipsIO.
332
333 // Show on ostream.
334 friend ostream& operator<< (ostream& ios, const ColumnDesc& cd);
335
336 // Set the name of the column.
337 void setName (const String& name)
338 { colPtr_p->setName(name); }
339
340 // Create a RefColumn column object out of this column description.
342 { return colPtr_p->makeRefColumn (rtp, bcp); }
343
344 // Create a ConcatColumn column object out of this column description.
347
348
349 // Define the type of a XXColumnDesc construction function.
350 typedef BaseColumnDesc* ColumnDescCtor (const String& className);
351
352 // Get a construction function for a XXColumnDesc object (thread-safe).
354
355 // Register a "XXColumnDesc" constructor (thread-safe).
356 static void registerCtor (const String& name, ColumnDescCtor* func);
357
358private:
359 // A mutex for additions to the constructor map.
360 static std::mutex theirMutex;
361
362 // Define a map which maps the name of the various XXColumnDesc
363 // classes to a static function constructing them.
364 // This is used when reading a column description back; it in fact
365 // determines the exact column type and is an easier thing to do
366 // than an enormous switch statement.
367 // The map is filled with the main XXColumnDesc construction functions
368 // by the function registerColumnDesc upon the first call of
369 // <src>ColumnDesc::getFile</src>.
370 static std::map<String, ColumnDescCtor*>& getRegisterMap();
371
372 // Register the main data managers.
373 static std::map<String, ColumnDescCtor*> initRegisterMap();
374
375 // Construct from a pointer (for class BaseColumn).
377
378 // Check if a column can be handled by ColumnDescSet.
379 // It is called before the column gets actually added, etc..
380 // <group>
381 // Check if the column can be added to the table description.
382 // It is implemented for a virtual column to check if the columns
383 // it uses really exist.
384 void checkAdd (const ColumnDescSet& cds) const
385 { colPtr_p->checkAdd (cds); }
386 // Check when a column gets renamed in a table description.
387 // It is not used.
388 void checkRename (const ColumnDescSet& cds, const String& newName) const
389 { colPtr_p->checkRename (cds, newName); }
390 // </group>
391
392 // Take action after a column has been handled by ColumnDescSet.
393 // It is called after the column has been actually added, etc..
394 // This gives, for instance, the virtual column class the opportunity
395 // to update the virtual column list.
396 // <group>
398 { colPtr_p->handleAdd (cds); }
399 void handleRename (ColumnDescSet& cds, const String& oldName)
400 { colPtr_p->handleRename (cds, oldName); }
402 { colPtr_p->handleRemove (cds); }
403 // </group>
404
405 // This function allows each column to act upon a rename of another column.
406 // If the old name is used internally, the column can update itself.
407 // It is called after handleRename has been called.
408 void renameAction (const String& newName, const String& oldName)
409 { colPtr_p->renameAction (newName, oldName); }
410
411 // Create a PlainColumn column object out of this column description.
413 { return colPtr_p->makeColumn (csp); }
414
415 // Store the object in AipsIO.
416 void putFile (AipsIO& ios, const TableAttr&) const;
417
418 // Get the object from AipsIO.
419 void getFile (AipsIO&, const TableAttr&);
420
421
422protected:
424 Bool allocated_p; //# False = not allocated -> do not delete
425};
426
427
428} //# NAMESPACE CASACORE - END
429
430#endif
void setMaxLength(uInt maxLength)
Set the maximum value length.
void setNdim(uInt ndim)
Set the number of dimensions.
virtual void checkAdd(const ColumnDescSet &cds) const
Check if a column can be handled by ColumnDescSet.
const String & dataManagerGroup() const
Get the data manager group.
const TableRecord & keywordSet() const
virtual void handleRemove(ColumnDescSet &cds)
virtual void handleRename(ColumnDescSet &cds, const String &oldName)
const IPosition & shape() const
Get the predefined shape.
void setDefaultDataManager(Bool always)
Set the data manager type and group to the default.
Int options() const
Get the options.
TableRecord & rwKeywordSet()
Get access to the set of keywords.
const String & comment() const
Get comment string.
uInt maxLength() const
Get the maximum value length.
Bool isScalar() const
Test if column is scalar, array or table.
virtual void handleAdd(ColumnDescSet &cds)
Take action after a column has been handled by ColumnDescSet.
void setName(const String &name)
Set the name of the column (for a rename).
virtual PlainColumn * makeColumn(ColumnSet *) const =0
Make a PlainColumn object out of the description.
virtual void checkRename(const ColumnDescSet &cds, const String &newName) const
const String & dataTypeId() const
Get the type id for non-standard data types (i.e.
void setOptions(Int options)
Set the options to the given value.
virtual ConcatColumn * makeConcatColumn(ConcatTable *) const
Make a ConcatColumn object out of the description.
RefColumn * makeRefColumn(RefTable *, BaseColumn *) const
Make a RefColumn object out of the description.
void setShape(const IPosition &shape)
Set the predefined shape.
Int ndim() const
Get the number of dimensions.
const TableDesc * tableDesc() const
Get table description (in case column contains subtables).
virtual void renameAction(const String &newName, const String &oldName)
This function allows each column to act upon a rename of another column.
DataType dataType() const
Get the data type of the column.
const String & dataManagerType() const
Get the type name of the default data manager.
String & comment()
Get comment string (allowing it to be changed).
Definition ColumnDesc.h:233
RefColumn * makeRefColumn(RefTable *rtp, BaseColumn *bcp) const
Create a RefColumn column object out of this column description.
Definition ColumnDesc.h:341
void setName(const String &name)
Set the name of the column.
Definition ColumnDesc.h:337
const String & name() const
Get the name of the column.
DataType trueDataType() const
Get the true data type of the column.
DataType dataType() const
Get the data type of the column.
Definition ColumnDesc.h:193
static std::map< String, ColumnDescCtor * > & getRegisterMap()
Define a map which maps the name of the various XXColumnDesc classes to a static function constructin...
friend AipsIO & operator<<(AipsIO &ios, const ColumnDesc &cd)
Write into AipsIO.
Bool operator==(const ColumnDesc &) const
Comparison.
Bool isFixedShape() const
Check if the column is defined with a fixed shape.
ColumnDesc()
Default constructor (needed for ColumnDescSet).
Definition ColumnDesc.h:160
const IPosition & shape() const
Get the predefined shape.
Definition ColumnDesc.h:268
void checkRename(const ColumnDescSet &cds, const String &newName) const
Check when a column gets renamed in a table description.
Definition ColumnDesc.h:388
void setShape(const IPosition &shape)
Set the predefined shape.
Definition ColumnDesc.h:288
static void registerCtor(const String &name, ColumnDescCtor *func)
Register a "XXColumnDesc" constructor (thread-safe).
BaseColumnDesc * colPtr_p
Definition ColumnDesc.h:423
const String & dataManagerType() const
Get the type name of the default data manager.
Definition ColumnDesc.h:207
void handleRemove(ColumnDescSet &cds)
Definition ColumnDesc.h:401
static std::map< String, ColumnDescCtor * > initRegisterMap()
Register the main data managers.
void getFile(AipsIO &, const TableAttr &)
Get the object from AipsIO.
Bool operator!=(const ColumnDesc &) const
const String & comment() const
Get comment string.
Definition ColumnDesc.h:229
ColumnDesc(const BaseColumnDesc &)
Construct from a column description.
ColumnDesc(BaseColumnDesc *)
Construct from a pointer (for class BaseColumn).
void setShape(const IPosition &shape, Bool directOption)
Definition ColumnDesc.h:290
void setOptions(int options)
Set the options to the given value.
Definition ColumnDesc.h:298
String & dataManagerType()
Get the type name of the default data manager (allowing it to be changed).
Definition ColumnDesc.h:212
void setDefaultDataManager(Bool always=True)
If always==True they are always set, otherwise only if empty.
Definition ColumnDesc.h:225
void show() const
Show the column on cout.
ColumnDesc & operator=(const ColumnDesc &that)
Assignment (copy semantics).
void setNdim(uInt ndim)
Set the number of dimensions.
Definition ColumnDesc.h:277
void handleAdd(ColumnDescSet &cds)
Take action after a column has been handled by ColumnDescSet.
Definition ColumnDesc.h:397
String & dataManagerGroup()
Get the data manager group.
Definition ColumnDesc.h:221
PlainColumn * makeColumn(ColumnSet *csp) const
Create a PlainColumn column object out of this column description.
Definition ColumnDesc.h:412
Option
Enumerate the possible column options.
Definition ColumnDesc.h:140
@ Direct
direct table or array
Definition ColumnDesc.h:142
@ FixedShape
fixed array/table shape
Definition ColumnDesc.h:146
@ Undefined
undefined values are possible
Definition ColumnDesc.h:144
const TableRecord & keywordSet() const
Definition ColumnDesc.h:182
void setMaxLength(uInt maxLength)
Set the maximum value length.
Definition ColumnDesc.h:310
TableRecord & rwKeywordSet()
Get access to the set of keywords.
Definition ColumnDesc.h:180
TableDesc * tableDesc()
Definition ColumnDesc.h:317
void handleRename(ColumnDescSet &cds, const String &oldName)
Definition ColumnDesc.h:399
BaseColumnDesc * ColumnDescCtor(const String &className)
Define the type of a XXColumnDesc construction function.
Definition ColumnDesc.h:350
ConcatColumn * makeConcatColumn(ConcatTable *rtp) const
Create a ConcatColumn column object out of this column description.
Definition ColumnDesc.h:345
static ColumnDescCtor * getCtor(const String &name)
Get a construction function for a XXColumnDesc object (thread-safe).
int options() const
Get the options.
Definition ColumnDesc.h:244
void renameAction(const String &newName, const String &oldName)
This function allows each column to act upon a rename of another column.
Definition ColumnDesc.h:408
void putFile(AipsIO &ios, const TableAttr &) const
Store the object in AipsIO.
ColumnDesc(const ColumnDesc &that)
Copy constructor (copy semantics).
void checkAdd(const ColumnDescSet &cds) const
Check if a column can be handled by ColumnDescSet.
Definition ColumnDesc.h:384
Bool isArray() const
Test if column is an array.
Definition ColumnDesc.h:256
static std::mutex theirMutex
A mutex for additions to the constructor map.
Definition ColumnDesc.h:360
const String & dataTypeId() const
Get the type id for non-standard data types (i.e.
Definition ColumnDesc.h:203
uInt maxLength() const
Get the maximum value length.
Definition ColumnDesc.h:302
Int ndim() const
Get the number of dimensions.
Definition ColumnDesc.h:263
Bool isTable() const
Test if column is a table.
Definition ColumnDesc.h:259
friend AipsIO & operator>>(AipsIO &ios, ColumnDesc &cd)
Read from AipsIO.
Bool isScalar() const
Test if column is a scalar.
Definition ColumnDesc.h:253
void show(ostream &os) const
Show the column.
const TableDesc * tableDesc() const
Get table description (in case column contains subtables).
Definition ColumnDesc.h:315
const String & dataManagerGroup() const
Get the data manager group.
Definition ColumnDesc.h:216
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
unsigned int uInt
Definition aipstype.h:49
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41