casacore
Loading...
Searching...
No Matches
RecordRep.h
Go to the documentation of this file.
1//# RecordRep.h: The representation of a Record
2//# Copyright (C) 1996,1997,2000,2001,2005
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 CASA_RECORDREP_H
28#define CASA_RECORDREP_H
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/casa/Containers/Block.h>
33#include <casacore/casa/Containers/RecordDesc.h>
34#include <casacore/casa/Containers/RecordInterface.h>
35
36namespace casacore { //# NAMESPACE CASACORE - BEGIN
37
38//# Forward Declarations
39class AipsIO;
40class IPosition;
41class String;
42
43
44// <summary>
45// The representation of a Record
46// </summary>
47
48// <use visibility=local>
49// <reviewed reviewer="Mark Wieringa" date="1996/04/15" tests="tRecord">
50// </reviewed>
51
52// <prerequisite>
53// <li> <linkto class="Record">Record</linkto>.
54// </prerequisite>
55//
56// <etymology>
57// RecordRep is the REPresentation of a Record.
58// </etymology>
59//
60// <synopsis>
61// RecordRep is the actual implementation of a Record 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 RecordRep does not know anything about RecordFieldPtr
75// objects pointing to its data. Only its mother class Record
76// knows about them and handles all cases where the RecordFieldPtr's
77// have to be notified.
78// </synopsis>
79//
80// <example>
81// RecordRep mirrors all functions in Record.
82// </example>
83//
84// <motivation>
85// Having a separate RecordRep class makes copy-on-write possible.
86// It also allows derivation of other RecordRep classes (like TableRecordRep),
87// while their mother classes are not derived from each other.
88// </motivation>
89//
90// <todo asof="1996/03/12">
91// <li> An implementation where arrays are stored as T*'s would cut down on
92// instantiations (the Arrayness would come back through the creation
93// of the <src>RecordFieldPtr<Array<T> ></src>).
94// </todo>
95
96
98{
99public:
100 // Create a record with no fields.
102
103 // Create a record with the given description. If it is not possible to
104 // create all fields (for example, if a field of an unsupported type is
105 // requested), an exception is thrown.
106 // All fields are checked by the field checking function (if defined).
108
109 // Create a copy of other using copy semantics.
110 RecordRep (const RecordRep& other);
111
112 // Copy all the data over.
114
115 // Delete all data.
116 virtual ~RecordRep();
117
118 // Get the comment for this field.
119 const String& comment (Int whichField) const;
120
121 // Set the comment for this field.
122 void setComment (Int whichField, const String& comment);
123
124 // Describes the current structure of this Record.
125 const RecordDesc& description() const;
126
127 // Change the structure of this Record to contain the fields in
128 // newDescription. After calling restructure, <src>description() ==
129 // newDescription</src>.
130 void restructure (const RecordDesc& newDescription, Bool recursive);
131
132 // Returns True if this and other have the same RecordDesc, other
133 // than different names for the fields. That is, the number, type and the
134 // order of the fields must be identical (recursively for fixed
135 // structured sub-Records in this).
136 // <note role=caution>
137 // <src>thisRecord.conform(thatRecord) == True</src> does not imply
138 // <br><src>thatRecord.conform(thisRecord) == True</src>, because
139 // a variable record in one conforms a fixed record in that, but
140 // not vice-versa.
141 // </note>
142 Bool conform (const RecordRep& other) const;
143
144 // Copy all data of the Record.
145 void copyData (const RecordRep& other);
146
147 // Copy a data field.
148 // This can only handle scalars and arrays.
149 void copyDataField (DataType type, Int whichField, const void* that) const;
150
151 // Remove a field from the record.
152 void removeField (Int whichField);
153
154 // Rename the given field.
155 void renameField (const String& newName, Int whichField);
156
157 // Add a field with the given name and value to the record.
158 // The data type of the field is determined by the data type of the value.
159 // For arrays it is possible to define if the shape is fixed.
160 // <group>
161 void addDataField (const String& name, DataType type,
162 const IPosition& shape, Bool fixedShape,
163 const void* data);
164 void addField (const String& name, const Record& value,
166 // </group>
167
168 // Define a value for the given field.
169 // Array conformance rules will not be applied for variable shaped arrays.
170 // When the field and value data type mismatch, type promotion
171 // of scalars will be done if possible. If not possible, an exception
172 // is thrown.
173 void defineDataField (Int whichField, DataType type, const void* value);
174
175 // Put the description and data of the Record.
176 // It also puts the fixedFlag attribute (of the mother object).
177 void putRecord (AipsIO& os, int recordType) const;
178
179 // Get the description and data of the Record.
180 // It also gets the fixedFlag attribute (of the mother object).
181 void getRecord (AipsIO& os, Int& recordType);
182
183 // Put the data of a record.
184 // This is used to write a subrecord, whose description has
185 // already been written.
186 void putData (AipsIO& os) const;
187
188 // Read the data of a record.
189 // This is used to read a subrecord, whose description has
190 // already been read.
191 void getData (AipsIO& os, uInt version);
192
193 // Used by the RecordFieldPtr classes to attach in a type-safe way to the
194 // correct field.
195 // <group>
196 void* get_pointer (Int whichField, DataType type) const;
197 void* get_pointer (Int whichField, DataType type,
198 const String& recordType) const;
199 // </group>
200
201 // Merge a field from another record into this record.
202 void mergeField (const RecordRep& other, Int whichFieldFromOther,
204
205 // Merge all fields from the other record into this record.
207
208 // Print a record.
209 // Print the contents of the record.
210 // Only the first <src>maxNrValues</src> of an array will be printed.
211 // A value < 0 means the entire array.
212 void print (std::ostream&,
213 Int maxNrValues = 25,
214 const String& indent="") const;
215
216protected:
217 // Utility functions to avoid code duplication in the public member
218 // functions.
219 // <group>
220 void delete_myself (uInt nfields);
221 void copy_other (const RecordRep& other);
222 // </group>
223
224 // Get the field number for a given name.
225 virtual Int fieldNumber (const String& name) const;
226
227 // Add the data pointer to the data block.
228 // The block is extended when needed.
229 void addDataPtr (void* ptr);
230
231 // Remove a data pointer add the given index.
232 void removeDataPtr (Int index);
233
234 // Check if the shape of the data array matches the shape of a
235 // fixed-shaped array in the description.
236 void checkShape (DataType type, const IPosition& shape,
237 const void* value, const String& fieldName);
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 // Create a data field for the given type and shape.
250 // This can only handle scalars and arrays.
251 void* createDataField (DataType type, const IPosition& shape);
252
253 // Delete a data field.
254 // This can only handle scalars and arrays.
255 void deleteDataField (DataType type, void* ptr, void* vecptr);
256
257 // Copy a data field.
258 // This can only handle scalars and arrays.
259 void copyDataField (DataType type, void* ptr, const void* that) const;
260
261 // Print a data field.
262 // This can only handle scalars and arrays.
263 void printDataField (std::ostream& os, DataType type,
264 const String& indent, Int maxNrValues,
265 const void* ptr) const;
266
267 // Put a data field.
268 // This can only handle scalars and arrays.
269 void putDataField (AipsIO& os, DataType type, const void* ptr) const;
270
271 // Get a data field.
272 // This can only handle scalars and arrays.
273 void getDataField (AipsIO& os, DataType type, void* ptr);
274
275 // Make an array for a scalar data field.
276 // It shares the data, so a change in the data is reflected in the array.
277 // It is used to be able to access a scalar as an 1D array.
278 void makeDataVec (Int whichField, DataType type);
279
280 // Get a Scalar/ArrayKeywordSet object as a Record.
281 // (type 0 = ScalarKeywordSet; type 1 = ArrayKeywordSet).
282 void getKeySet (AipsIO& os, uInt version, uInt type);
283
284 // Get the description of a keyword set as a RecordDesc.
285 void getKeyDesc (AipsIO& os, RecordDesc& desc);
286
287 // Get the scalar values of a keyword set.
289
290 // Get the array values of a keyword set.
292
293
294 // Holds the structure of this Record.
296 // Pointers to data values.
298 // Pointers to a vector of a scalar (to access a scalar as an array).
300 // #Entries used in data_p.
302};
303
304
306{
307 return desc_p;
308}
309
310inline const String& RecordRep::comment (Int whichField) const
311{
312 return desc_p.comment (whichField);
313}
314
315inline void RecordRep::setComment (Int whichField, const String& comment)
316{
317 desc_p.setComment (whichField, comment);
318}
319
320inline void RecordRep::renameField (const String& newName, Int whichField)
321{
322 desc_p.renameField (newName, whichField);
323}
324
325
326
327} //# NAMESPACE CASACORE - END
328
329#endif
simple 1-D array
Definition Block.h:198
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.
void merge(const RecordRep &other, RecordInterface::DuplicatesFlag)
Merge all fields from the other record into this record.
Block< void * > datavec_p
Pointers to a vector of a scalar (to access a scalar as an array).
Definition RecordRep.h:299
void getRecord(AipsIO &os, Int &recordType)
Get the description and data of the Record.
void delete_myself(uInt nfields)
Utility functions to avoid code duplication in the public member functions.
void deleteDataField(DataType type, void *ptr, void *vecptr)
Delete a data field.
void copyDataField(DataType type, void *ptr, const void *that) const
Copy a data field.
void renameField(const String &newName, Int whichField)
Rename the given field.
Definition RecordRep.h:320
void printDataField(std::ostream &os, DataType type, const String &indent, Int maxNrValues, const void *ptr) const
Print a data field.
void copyDataField(DataType type, Int whichField, const void *that) const
Copy a data field.
Bool conform(const RecordRep &other) const
Returns True if this and other have the same RecordDesc, other than different names for the fields.
virtual ~RecordRep()
Delete all data.
void addField(const String &name, const Record &value, RecordInterface::RecordType type)
void print(std::ostream &, Int maxNrValues=25, const String &indent="") const
Print a record.
void defineDataField(Int whichField, DataType type, const void *value)
Define a value for the given field.
RecordRep & operator=(const RecordRep &other)
Copy all the data over.
void putDataField(AipsIO &os, DataType type, const void *ptr) const
Put a data field.
void removeDataPtr(Int index)
Remove a data pointer add the given index.
void getDataField(AipsIO &os, DataType type, void *ptr)
Get a data field.
void mergeField(const RecordRep &other, Int whichFieldFromOther, RecordInterface::DuplicatesFlag)
Merge a field from another record into this record.
const RecordDesc & description() const
Describes the current structure of this Record.
Definition RecordRep.h:305
void getScalarKeys(AipsIO &os)
Get the scalar values of a keyword set.
void removeField(Int whichField)
Remove a field from the record.
RecordRep()
Create a record with no fields.
void getArrayKeys(AipsIO &os)
Get the array values of a keyword set.
void checkShape(DataType type, const IPosition &shape, const void *value, const String &fieldName)
Check if the shape of the data array matches the shape of a fixed-shaped array in the description.
void makeDataVec(Int whichField, DataType type)
Make an array for a scalar data field.
void copy_other(const RecordRep &other)
virtual void removeFieldFromDesc(Int whichField)
Remove a field from the description.
void * get_pointer(Int whichField, DataType type, const String &recordType) const
void * get_pointer(Int whichField, DataType type) const
Used by the RecordFieldPtr classes to attach in a type-safe way to the correct field.
const String & comment(Int whichField) const
Get the comment for this field.
Definition RecordRep.h:310
void getData(AipsIO &os, uInt version)
Read the data of a record.
RecordRep(const RecordRep &other)
Create a copy of other using copy semantics.
void copyData(const RecordRep &other)
Copy all data of the Record.
void restructure(const RecordDesc &newDescription, Bool recursive)
Change the structure of this Record to contain the fields in newDescription.
virtual Int fieldNumber(const String &name) const
Get the field number for a given name.
void getKeyDesc(AipsIO &os, RecordDesc &desc)
Get the description of a keyword set as a RecordDesc.
void putRecord(AipsIO &os, int recordType) const
Put the description and data of the Record.
Block< void * > data_p
Pointers to data values.
Definition RecordRep.h:297
void setComment(Int whichField, const String &comment)
Set the comment for this field.
Definition RecordRep.h:315
RecordDesc desc_p
Holds the structure of this Record.
Definition RecordRep.h:295
void addDataPtr(void *ptr)
Add the data pointer to the data block.
void addDataField(const String &name, DataType type, const IPosition &shape, Bool fixedShape, const void *data)
Add a field with the given name and value to the record.
uInt nused_p
#Entries used in data_p.
Definition RecordRep.h:301
void getKeySet(AipsIO &os, uInt version, uInt type)
Get a Scalar/ArrayKeywordSet object as a Record.
virtual void addFieldToDesc(const String &name, DataType type, const IPosition &shape, Bool fixedShape)
Add a field to the description.
void * createDataField(DataType type, const IPosition &shape)
Create a data field for the given type and shape.
virtual void removeData(Int whichField, void *ptr, void *vecptr)
Remove a data field.
void putData(AipsIO &os) const
Put the data of a record.
RecordRep(const RecordDesc &description)
Create a record with the given description.
String: the storage and methods of handling collections of characters.
Definition String.h:223
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.