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
27#ifndef CASA_VALUEHOLDERREP_H
28#define CASA_VALUEHOLDERREP_H
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/casa/Arrays/ArrayFwd.h>
33#include <casacore/casa/Utilities/DataType.h>
34#include <iosfwd>
35
36namespace casacore { //# NAMESPACE CASACORE - BEGIN
37
38//# Forward Declarations
39class AipsIO;
40class Record;
41class RecordFieldId;
42
43
44// <summary>
45// A holder for a value of any basic type.
46// </summary>
47
48// <use visibility=local>
49// <reviewed reviewer="" date="" tests="tValueHolder">
50// </reviewed>
51
52// <synopsis>
53// Class ValueHolderRep is the letter class for the envelope class ValueHolder.
54// See <linkto class=ValueHolder>that class</linkto> for more information.
55// </synopsis>
56
57// <motivation>
58// Copying ValueHolders should be as cheap as possible, so a counted
59// referenced letter class is used.
60// </motivation>
61
63{
64public:
65 // Create the object for the given value.
66 // <group>
76 explicit ValueHolderRep (const Complex& value);
77 explicit ValueHolderRep (const DComplex& value);
78 explicit ValueHolderRep (const Char* value);
79 explicit ValueHolderRep (const String& value);
80 explicit ValueHolderRep (const Array<Bool>& value);
84 explicit ValueHolderRep (const Array<Int>& value);
85 explicit ValueHolderRep (const Array<uInt>& value);
92 explicit ValueHolderRep (const Record& value);
93 // </group>
94
95 // Create an empty N-dim array.
97
98 // Destructor.
100
101 // Forbid copy ctor and assignment.
102 //# There is no fundamental reason to forbid them, but it saves
103 //# implementation work as long as they are not needed.
104 // <group>
107 // </group>
108
109
110 // Get the data type (as defined in DataType.h).
111 DataType dataType() const;
112
113 // Get the value.
114 // If possible, it converts the data as needed.
115 // <group>
116 Bool asBool () const;
117 uChar asuChar () const;
118 Short asShort () const;
119 uShort asuShort () const;
120 Int asInt () const;
121 uInt asuInt () const;
122 Int64 asInt64 () const;
123 Float asFloat () const;
124 Double asDouble () const;
125 Complex asComplex () const;
126 DComplex asDComplex() const;
127 const String& asString () const;
128 const Array<Bool> asArrayBool () const;
132 const Array<Int> asArrayInt () const;
133 const Array<uInt> asArrayuInt () const;
140 const Record& asRecord () const;
141 // </group>
142
143 // Put the value as a field in a record.
144 void toRecord (Record&, const RecordFieldId&) const;
145
146 // Construct the object from the value in a record.
147 static ValueHolderRep* fromRecord (const Record& rec, const RecordFieldId&);
148
149 // Write the ValueHolderRep to an output stream.
150 // Arrays are written as normal arrays using ArrayIO.h.
151 std::ostream& write (std::ostream& os) const;
152
153 // Compare two ValueHolder objects.
154 // They must have the same data type.
155 bool operator< (const ValueHolderRep& right) const;
156 /*
157 bool operator== (const ValueHolderRep& right) const;
158 bool near (const ValueHolderRep& right, tolerance=1e-5) const;
159 bool nearAbs (const ValueHolderRep& right, double tolerance=1e-5) const;
160 */
161
162private:
164 DataType itsType;
165 union {
170 void* itsPtr;
171 };
172};
173
174
175inline DataType ValueHolderRep::dataType() const
176{
177 return itsType;
178}
179
180
181} //# NAMESPACE CASACORE - END
182
183#endif
String: the storage and methods of handling collections of characters.
Definition String.h:223
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)
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
this file contains all the compiler specific defines
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
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
double Double
Definition aipstype.h:53
char Char
Definition aipstype.h:44