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