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