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