casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
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.
102  TableRecordRep();
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.
111  TableRecordRep (const TableRecordRep& other);
112 
113  // Copy all the data over.
115 
116  // Delete all data.
117  ~TableRecordRep();
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.
185  Bool areTablesMultiUsed() const;
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
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
void mergeField(const TableRecordRep &other, Int whichFieldFromOther, RecordInterface::DuplicatesFlag)
Merge a field from another record into this record.
int Int
Definition: aipstype.h:50
RecordType
Define the flag telling if a Record has a fixed or variable structure.
void getRecord(AipsIO &os, Int &recordType, const TableAttr &)
Get the description and data of the Record.
void getData(AipsIO &os, uInt version, const TableAttr &)
Read the data of a record.
TableRecordRep()
Create a record with no fields.
Main interface class to a read/write table.
Definition: Table.h:153
AipsIO is the object persistency mechanism of Casacore.
Definition: AipsIO.h:168
void defineDataField(Int whichField, DataType type, const void *value)
Define a value for the given field.
const RecordDesc & description() const
Describes the current structure of this Record.
void getTableKeySet(AipsIO &os, uInt version, const TableAttr &, uInt type)
Get a KeywordSet object as a TableRecord.
virtual void removeFieldFromDesc(Int whichField)
Remove a field from the description.
The representation of a Record.
Definition: RecordRep.h:100
void copy_other(const TableRecordRep &other)
Utility function to avoid code duplication in the public member functions.
virtual casacore::String type() const
Implements RegionShape::type.
Definition: RegionShapes.h:548
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
const String & comment(Int whichField) const
Get the comment for this field.
Definition: RecordDesc.h:348
virtual Int fieldNumber(const String &name) const
Get the field number for a given name.
void renameField(const String &newName, Int whichField)
Rename the given field.
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 copyData(const TableRecordRep &other)
Copy all data of the TableRecord.
Description of the fields in a record object.
Definition: RecordDesc.h:105
DuplicatesFlag
Define the Duplicates flag for the function merge in the various record classes.
The representation of a TableRecord.
void putData(AipsIO &os, const TableAttr &) const
Put the data of a record.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
void merge(const TableRecordRep &other, RecordInterface::DuplicatesFlag)
Merge all fields from the other record into this record.
void closeTable(Int whichField) const
Close the table in the given field.
Bool areTablesMultiUsed() const
Are subtables used in other processes.
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape...
Definition: ExprNode.h:1944
A hierarchical collection of named fields of various types.
Definition: TableRecord.h:182
~TableRecordRep()
Delete all data.
void renameTables(const String &newParentName, const String &oldParentName)
Rename the subtables with a path containing the old parent table name.
void setComment(Int whichField, const String &comment)
Set the comment for this field.
void setComment(Int whichField, const String &comment)
Set the comment for this field.
Definition: RecordDesc.h:353
void closeTables() const
Close all open tables.
void flushTables(Bool fsync) const
Flush all open subtables.
void print(std::ostream &, Int maxNrValues=25, const String &indent="") const
Print a record.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
RecordDesc desc_p
Holds the description.
void reopenRW()
Reopen possible tables in keywords as read/write.
virtual void addFieldToDesc(const String &name, DataType type, const IPosition &shape, Bool fixedShape)
Add a field to the description.
const String & comment(Int whichField) const
Get the comment for this field.
Some attributes of a table.
Definition: TableAttr.h:77
void addField(const String &name, const TableRecord &value, RecordInterface::RecordType type)
Add a field with the given name and value to the record.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
unsigned int uInt
Definition: aipstype.h:51
virtual void removeData(Int whichField, void *ptr, void *vecptr)
Remove a data field.
void putRecord(AipsIO &os, Int recordType, const TableAttr &) const
Put the description and data of the Record.
void restructure(const RecordDesc &newDescription, Bool recursive)
Change the structure of this Record to contain the fields in newDescription.
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42
Bool conform(const TableRecordRep &other) const
Returns True if this and other have the same RecordDesc, other than different names for the fields...