casacore
Loading...
Searching...
No Matches
TableRecordRep.h
Go to the documentation of this file.
1//# TableRecordRep.h: The representation of a TableRecord
2//# Copyright (C) 1996,1997,2000,2001
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
27#ifndef TABLES_TABLERECORDREP_H
28#define TABLES_TABLERECORDREP_H
29
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Containers/RecordRep.h>
32
33namespace casacore { //# NAMESPACE CASACORE - BEGIN
34
35//# Forward Declarations
36class TableRecord;
37class TableAttr;
38
39
40// <summary>
41// The representation of a TableRecord
42// </summary>
43
44// <use visibility=local>
45// <reviewed reviewer="Mark Wieringa" date="1996/04/15" tests="tTableRecord">
46// </reviewed>
47
48// <prerequisite>
49// <li> <linkto class="TableRecord">TableRecord</linkto>.
50// <li> <linkto class="RecordRep">RecordRep</linkto>.
51// </prerequisite>
52//
53// <etymology>
54// TableRecordRep is the REPresentation of a TableRecord.
55// </etymology>
56//
57// <synopsis>
58// TableRecordRep is the actual implementation of a TableRecord object.
59// It contains the description and the data. The data is stored as
60// a collection of void* pointers to the actual data. By storing
61// it in this indirect way, it is easier to extend the data block.
62// It also means that RecordFieldPtr objects always have the correct
63// pointer and do not need to be adjusted when the data block is extended.
64// <p>
65// Despite the fact that the data pointers have type void*, the
66// functions are completely type safe. This is done by passing the
67// type around using the DataType enumeration. The downpart is that
68// only types from that enumeration are supported (but that is also
69// required by the RecordDesc mechanics).
70// <p>
71// Note that TableRecordRep does not know anything about RecordFieldPtr
72// objects pointing to its data. Only its mother class TableRecord
73// knows about them and handles all cases where the RecordFieldPtr's
74// have to be notified.
75// <p>
76// Fields containing tables are not directly handled using class Table.
77// Instead the class <linkto class=TableKeyword>TableKeyword</linkto>
78// is used to map a table name to a table and to take care of
79// opening a table on demand.
80// </synopsis>
81//
82// <example>
83// TableRecordRep mirrors all functions in TableRecord.
84// </example>
85//
86// <motivation>
87// Having a separate TableRecordRep class makes copy-on-write possible.
88// It also allows derivation from RecordRep.
89// </motivation>
90//
91//# <todo asof="1995/08/22">
92//# </todo>
93
94
96{
97public:
98 // Create a record with no fields.
100
101 // Create a record with the given description. If it is not possible to
102 // create all fields (for example, if a field of an unsupported type is
103 // requested), an exception is thrown.
104 // All fields are checked by the field checking function (if defined).
106
107 // Create a copy of other using copy semantics.
109
110 // Copy all the data over.
112
113 // Delete all data.
115
116 // Get the comment for this field.
117 const String& comment (Int whichField) const;
118
119 // Set the comment for this field.
120 void setComment (Int whichField, const String& comment);
121
122 // Describes the current structure of this Record.
123 const RecordDesc& description() const;
124
125 // Change the structure of this Record to contain the fields in
126 // newDescription. After calling restructure, <src>description() ==
127 // newDescription</src>.
128 void restructure (const RecordDesc& newDescription, Bool recursive);
129
130 // Returns True if this and other have the same RecordDesc, other
131 // than different names for the fields. That is, the number, type and the
132 // order of the fields must be identical (recursively for fixed
133 // structured sub-Records in this).
134 // <note role=caution>
135 // <src>thisRecord.conform(thatRecord) == True</src> does not imply
136 // <br><src>thatRecord.conform(thisRecord) == True</src>, because
137 // a variable record in one conforms a fixed record in that, but
138 // not vice-versa.
139 // </note>
140 Bool conform (const TableRecordRep& other) const;
141
142 // Rename the given field.
143 void renameField (const String& newName, Int whichField);
144
145 // Copy all data of the TableRecord.
146 void copyData (const TableRecordRep& other);
147
148 // Add a field with the given name and value to the record.
149 // The data type of the field is determined by the data type of the value.
150 // <group>
151 void addField (const String& name, const TableRecord& value,
153 void addField (const String& name, const Table& value,
155 // </group>
156
157 // Define a value for the given field.
158 // Array conformance rules will not be applied for variable shaped arrays.
159 // When the field and value data type mismatch, type promotion
160 // of scalars will be done if possible. If not possible, an exception
161 // is thrown.
162 void defineDataField (Int whichField, DataType type, const void* value);
163
164 // Close the table in the given field.
165 // When accessed again, it will be opened automatically.
166 // This can be useful to save memory usage.
167 void closeTable (Int whichField) const;
168
169 // Close all open tables.
170 // When accessed again, it will be opened automatically.
171 // This can be useful to save memory usage.
172 void closeTables() const;
173
174 // Flush all open subtables.
175 void flushTables (Bool fsync) const;
176
177 // Rename the subtables with a path containing the old parent table name.
178 void renameTables (const String& newParentName,
179 const String& oldParentName);
180
181 // Are subtables used in other processes.
183
184 // Put the description and data of the Record.
185 // It also puts the fixedFlag attribute (of the mother object).
186 void putRecord (AipsIO& os, Int recordType, const TableAttr&) const;
187
188 // Get the description and data of the Record.
189 // It also gets the fixedFlag attribute (of the mother object).
190 void getRecord (AipsIO& os, Int& recordType, const TableAttr&);
191
192 // Put the data of a record.
193 // This is used to write a subrecord, whose description has
194 // already been written.
195 void putData (AipsIO& os, const TableAttr&) const;
196
197 // Read the data of a record.
198 // This is used to read a subrecord, whose description has
199 // already been read.
200 void getData (AipsIO& os, uInt version, const TableAttr&);
201
202 // Reopen possible tables in keywords as read/write.
203 // Tables are not reopened if they are not writable.
204 void reopenRW();
205
206 // Used by the RecordFieldPtr classes to attach in a type-safe way to the
207 // correct field.
208 // <group>
209 void* get_pointer (Int whichField, DataType type) const;
210 void* get_pointer (Int whichField, DataType type,
211 const String& recordType) const;
212 // </group>
213
214 // Merge a field from another record into this record.
215 void mergeField (const TableRecordRep& other, Int whichFieldFromOther,
217
218 // Merge all fields from the other record into this record.
219 void merge (const TableRecordRep& other,
221
222 // Print a record.
223 // Print the contents of the record.
224 // Only the first <src>maxNrValues</src> of an array will be printed.
225 // A value < 0 means the entire array.
226 void print (std::ostream&,
227 Int maxNrValues = 25,
228 const String& indent="") const;
229
230
231protected:
232 // Utility function to avoid code duplication in the public member
233 // functions.
234 void copy_other (const TableRecordRep& other);
235
236 // Get the field number for a given name.
237 virtual Int fieldNumber (const String& name) const;
238
239 // Add a field to the description.
240 virtual void addFieldToDesc (const String& name, DataType type,
241 const IPosition& shape, Bool fixedShape);
242
243 // Remove a data field.
244 virtual void removeData (Int whichField, void* ptr, void* vecptr);
245
246 // Remove a field from the description.
247 virtual void removeFieldFromDesc (Int whichField);
248
249 // Get a KeywordSet object as a TableRecord.
250 // (type: 0=ScalarKeywordSet, 1=ArrayKeywordSet, 2=TableKeywordSet)
251 void getTableKeySet (AipsIO& os, uInt version, const TableAttr&,
252 uInt type);
253
254
255 // Holds the description.
256 //# Although we could use the RecordDesc object from RecordRep,
257 //# it is better to use an own RecordDesc object in case a dedicated
258 //# TableRecordDesc is needed in the future. In this way it
259 //# is sure that inherited functions do not use the RecordDesc object
260 //# in RecordRep.
262};
263
264
265inline const String& TableRecordRep::comment (Int whichField) const
266{
267 return desc_p.comment (whichField);
268}
269
270inline void TableRecordRep::setComment (Int whichField, const String& comment)
271{
272 desc_p.setComment (whichField, comment);
273}
274
276{
277 return desc_p;
278}
279
280inline void TableRecordRep::renameField (const String& newName, Int whichField)
281{
282 desc_p.renameField (newName, whichField);
283}
284
285
286
287
288} //# NAMESPACE CASACORE - END
289
290#endif
void renameField(const String &newName, Int whichField)
Rename the given field.
Definition RecordDesc.h:379
const String & comment(Int whichField) const
Get the comment for this field.
Definition RecordDesc.h:345
void setComment(Int whichField, const String &comment)
Set the comment for this field.
Definition RecordDesc.h:350
RecordType
Define the flag telling if a Record has a fixed or variable structure.
DuplicatesFlag
Define the Duplicates flag for the function merge in the various record classes.
String: the storage and methods of handling collections of characters.
Definition String.h:223
void copy_other(const TableRecordRep &other)
Utility function to avoid code duplication in the public member functions.
virtual void removeData(Int whichField, void *ptr, void *vecptr)
Remove a data field.
void getRecord(AipsIO &os, Int &recordType, const TableAttr &)
Get the description and data of the Record.
void print(std::ostream &, Int maxNrValues=25, const String &indent="") const
Print a record.
void merge(const TableRecordRep &other, RecordInterface::DuplicatesFlag)
Merge all fields from the other record into this record.
void closeTables() const
Close all open tables.
const RecordDesc & description() const
Describes the current structure of this Record.
void setComment(Int whichField, const String &comment)
Set the comment for this field.
void reopenRW()
Reopen possible tables in keywords as read/write.
TableRecordRep()
Create a record with no fields.
Bool areTablesMultiUsed() const
Are subtables used in other processes.
void putRecord(AipsIO &os, Int recordType, const TableAttr &) const
Put the description and data of the Record.
virtual Int fieldNumber(const String &name) const
Get the field number for a given name.
void restructure(const RecordDesc &newDescription, Bool recursive)
Change the structure of this Record to contain the fields in newDescription.
void getData(AipsIO &os, uInt version, const TableAttr &)
Read the data of a record.
void putData(AipsIO &os, const TableAttr &) const
Put the data of a record.
void renameTables(const String &newParentName, const String &oldParentName)
Rename the subtables with a path containing the old parent table name.
Bool conform(const TableRecordRep &other) const
Returns True if this and other have the same RecordDesc, other than different names for the fields.
TableRecordRep(const TableRecordRep &other)
Create a copy of other using copy semantics.
~TableRecordRep()
Delete all data.
void mergeField(const TableRecordRep &other, Int whichFieldFromOther, RecordInterface::DuplicatesFlag)
Merge a field from another record into this record.
void flushTables(Bool fsync) const
Flush all open subtables.
RecordDesc desc_p
Holds the description.
void * get_pointer(Int whichField, DataType type, const String &recordType) const
TableRecordRep(const RecordDesc &description)
Create a record with the given description.
void getTableKeySet(AipsIO &os, uInt version, const TableAttr &, uInt type)
Get a KeywordSet object as a TableRecord.
void defineDataField(Int whichField, DataType type, const void *value)
Define a value for the given field.
void renameField(const String &newName, Int whichField)
Rename the given field.
void closeTable(Int whichField) const
Close the table in the given field.
void addField(const String &name, const TableRecord &value, RecordInterface::RecordType type)
Add a field with the given name and value to the record.
const String & comment(Int whichField) const
Get the comment for this field.
TableRecordRep & operator=(const TableRecordRep &other)
Copy all the data over.
void * get_pointer(Int whichField, DataType type) const
Used by the RecordFieldPtr classes to attach in a type-safe way to the correct field.
virtual void removeFieldFromDesc(Int whichField)
Remove a field from the description.
virtual void addFieldToDesc(const String &name, DataType type, const IPosition &shape, Bool fixedShape)
Add a field to the description.
void copyData(const TableRecordRep &other)
Copy all data of the TableRecord.
void addField(const String &name, const Table &value, RecordInterface::RecordType type)
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape.
Definition ExprNode.h:1991
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.