casacore
Loading...
Searching...
No Matches
ValueHolderRep.h
Go to the documentation of this file.
1// # ValueHolderRep.h: A holder object for the standard CASACORE data
2// # Copyright (C) 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#ifndef CASA_VALUEHOLDERREP_H
27#define CASA_VALUEHOLDERREP_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/ArrayFwd.h>
32#include <casacore/casa/Utilities/DataType.h>
33#include <iosfwd>
34
35namespace casacore { // # NAMESPACE CASACORE - BEGIN
36
37// # Forward Declarations
38class AipsIO;
39class Record;
40class RecordFieldId;
41
42// <summary>
43// A holder for a value of any basic type.
44// </summary>
45
46// <use visibility=local>
47// <reviewed reviewer="" date="" tests="tValueHolder">
48// </reviewed>
49
50// <synopsis>
51// Class ValueHolderRep is the letter class for the envelope class ValueHolder.
52// See <linkto class=ValueHolder>that class</linkto> for more information.
53// </synopsis>
54
55// <motivation>
56// Copying ValueHolders should be as cheap as possible, so a counted
57// referenced letter class is used.
58// </motivation>
59
61 public:
62 // Create the object for the given value.
63 // <group>
73 explicit ValueHolderRep(const Complex& value);
74 explicit ValueHolderRep(const DComplex& value);
75 explicit ValueHolderRep(const Char* value);
76 explicit ValueHolderRep(const String& value);
89 explicit ValueHolderRep(const Record& value);
90 // </group>
91
92 // Create an empty N-dim array.
94
95 // Destructor.
97
98 // Forbid copy ctor and assignment.
99 // # There is no fundamental reason to forbid them, but it saves
100 // # implementation work as long as they are not needed.
101 // <group>
104 // </group>
105
106 // Get the data type (as defined in DataType.h).
107 DataType dataType() const;
108
109 // Get the value.
110 // If possible, it converts the data as needed.
111 // <group>
112 Bool asBool() const;
113 uChar asuChar() const;
114 Short asShort() const;
116 Int asInt() const;
117 uInt asuInt() const;
118 Int64 asInt64() const;
119 Float asFloat() const;
121 Complex asComplex() const;
122 DComplex asDComplex() const;
123 const String& asString() const;
128 const Array<Int> asArrayInt() const;
136 const Record& asRecord() const;
137 // </group>
138
139 // Put the value as a field in a record.
140 void toRecord(Record&, const RecordFieldId&) const;
141
142 // Construct the object from the value in a record.
143 static ValueHolderRep* fromRecord(const Record& rec, const RecordFieldId&);
144
145 // Write the ValueHolderRep to an output stream.
146 // Arrays are written as normal arrays using ArrayIO.h.
147 std::ostream& write(std::ostream& os) const;
148
149 // Compare two ValueHolder objects.
150 // They must have the same data type.
151 bool operator<(const ValueHolderRep& right) const;
152 /*
153 bool operator== (const ValueHolderRep& right) const;
154 bool near (const ValueHolderRep& right, tolerance=1e-5) const;
155 bool nearAbs (const ValueHolderRep& right, double tolerance=1e-5) const;
156 */
157
158 private:
160 DataType itsType;
161 union {
166 void* itsPtr;
167 };
168};
169
170inline DataType ValueHolderRep::dataType() const { return itsType; }
171
172} // namespace casacore
173
174#endif
String: the storage and methods of handling collections of characters.
Definition String.h:355
static ValueHolderRep * fromRecord(const Record &rec, const RecordFieldId &)
Construct the object from the value in a record.
uShort asuShort() const
Double asDouble() const
std::ostream & write(std::ostream &os) const
Write the ValueHolderRep to an output stream.
ValueHolderRep(const Array< Int > &value)
const Array< String > asArrayString() const
ValueHolderRep(Int64 value)
ValueHolderRep(const Array< Short > &value)
ValueHolderRep & operator=(const ValueHolderRep &)=delete
ValueHolderRep(const ValueHolderRep &)=delete
Forbid copy ctor and assignment.
ValueHolderRep(const Array< uInt > &value)
ValueHolderRep(const Array< Bool > &value)
ValueHolderRep(const DComplex &value)
Bool asBool() const
Get the value.
const Record & asRecord() const
ValueHolderRep(const Array< DComplex > &value)
ValueHolderRep(Bool value)
Create the object for the given value.
ValueHolderRep(uShort value)
ValueHolderRep(const Array< String > &value)
Complex asComplex() const
ValueHolderRep(const Complex &value)
bool operator<(const ValueHolderRep &right) const
Compare two ValueHolder objects.
ValueHolderRep(const Array< Int64 > &value)
void toRecord(Record &, const RecordFieldId &) const
Put the value as a field in a record.
ValueHolderRep(const Array< Complex > &value)
ValueHolderRep(uInt ndim, Bool dummy)
Create an empty N-dim array.
ValueHolderRep(const Char *value)
const Array< Double > asArrayDouble() const
ValueHolderRep(const Record &value)
const Array< DComplex > asArrayDComplex() const
ValueHolderRep(Short value)
ValueHolderRep(const Array< Float > &value)
ValueHolderRep(uChar value)
const Array< Int64 > asArrayInt64() const
ValueHolderRep(const String &value)
ValueHolderRep(Float value)
const Array< Short > asArrayShort() const
const Array< uChar > asArrayuChar() const
const Array< Bool > asArrayBool() const
ValueHolderRep(const Array< Double > &value)
ValueHolderRep(const Array< uChar > &value)
DataType dataType() const
Get the data type (as defined in DataType.h).
ValueHolderRep(Double value)
ValueHolderRep(const Array< uShort > &value)
DComplex asDComplex() const
const Array< uShort > asArrayuShort() const
~ValueHolderRep()
Destructor.
const Array< Complex > asArrayComplex() const
const Array< uInt > asArrayuInt() const
const Array< Int > asArrayInt() const
const String & asString() const
const Array< Float > asArrayFloat() const
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned char uChar
Definition aipstype.h:45
LatticeExprNode ndim(const LatticeExprNode &expr)
1-argument function to get the dimensionality of a lattice.
short Short
Definition aipstype.h:46
unsigned int uInt
Definition aipstype.h:49
unsigned short uShort
Definition aipstype.h:47
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size).
Definition aipsxtype.h:36
float Float
Definition aipstype.h:52
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
double Double
Definition aipstype.h:53
char Char
Definition aipstype.h:44