casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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: 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 CASA_VALUEHOLDERREP_H
31 #define CASA_VALUEHOLDERREP_H
32 
33 //# Includes
34 #include <casacore/casa/aips.h>
36 #include <iosfwd>
37 
38 namespace casacore { //# NAMESPACE CASACORE - BEGIN
39 
40 //# Forward Declarations
41 class AipsIO;
42 template<class T> class Array;
43 class Record;
44 class RecordFieldId;
45 
46 
47 // <summary>
48 // A holder for a value of any basic type.
49 // </summary>
50 
51 // <use visibility=local>
52 // <reviewed reviewer="" date="" tests="tValueHolder">
53 // </reviewed>
54 
55 // <synopsis>
56 // Class ValueHolderRep is the letter class for the envelope class ValueHolder.
57 // See <linkto class=ValueHolder>that class</linkto> for more information.
58 // </synopsis>
59 
60 // <motivation>
61 // Copying ValueHolders should be as cheap as possible, so a counted
62 // referenced letter class is used.
63 // </motivation>
64 
66 {
67 public:
68  // Create the object for the given value.
69  // <group>
70  explicit ValueHolderRep (Bool value);
71  explicit ValueHolderRep (uChar value);
72  explicit ValueHolderRep (Short value);
73  explicit ValueHolderRep (uShort value);
74  explicit ValueHolderRep (Int value);
75  explicit ValueHolderRep (uInt value);
76  explicit ValueHolderRep (Int64 value);
77  explicit ValueHolderRep (Float value);
78  explicit ValueHolderRep (Double value);
79  explicit ValueHolderRep (const Complex& value);
80  explicit ValueHolderRep (const DComplex& value);
81  explicit ValueHolderRep (const Char* value);
82  explicit ValueHolderRep (const String& value);
83  explicit ValueHolderRep (const Array<Bool>& value);
84  explicit ValueHolderRep (const Array<uChar>& value);
85  explicit ValueHolderRep (const Array<Short>& value);
86  explicit ValueHolderRep (const Array<uShort>& value);
87  explicit ValueHolderRep (const Array<Int>& value);
88  explicit ValueHolderRep (const Array<uInt>& value);
89  explicit ValueHolderRep (const Array<Int64>& value);
90  explicit ValueHolderRep (const Array<Float>& value);
91  explicit ValueHolderRep (const Array<Double>& value);
92  explicit ValueHolderRep (const Array<Complex>& value);
93  explicit ValueHolderRep (const Array<DComplex>& value);
94  explicit ValueHolderRep (const Array<String>& value);
95  explicit ValueHolderRep (const Record& value);
96  // </group>
97 
98  // Create an empty N-dim array.
99  ValueHolderRep (uInt ndim, Bool dummy);
100 
101  // Destructor.
102  ~ValueHolderRep();
103 
104  // Get the data type (as defined in DataType.h).
105  DataType dataType() const;
106 
107  // Get the value.
108  // If possible, it converts the data as needed.
109  // <group>
110  Bool asBool () const;
111  uChar asuChar () const;
112  Short asShort () const;
113  uShort asuShort () const;
114  Int asInt () const;
115  uInt asuInt () const;
116  Int64 asInt64 () const;
117  Float asFloat () const;
118  Double asDouble () const;
119  Complex asComplex () const;
120  DComplex asDComplex() const;
121  const String& asString () const;
122  const Array<Bool> asArrayBool () const;
123  const Array<uChar> asArrayuChar () const;
124  const Array<Short> asArrayShort () const;
125  const Array<uShort> asArrayuShort () const;
126  const Array<Int> asArrayInt () const;
127  const Array<uInt> asArrayuInt () const;
128  const Array<Int64> asArrayInt64 () const;
129  const Array<Float> asArrayFloat () const;
130  const Array<Double> asArrayDouble () const;
131  const Array<Complex> asArrayComplex () const;
132  const Array<DComplex> asArrayDComplex() const;
133  const Array<String> asArrayString () const;
134  const Record& asRecord () const;
135  // </group>
136 
137  // Put the value as a field in a record.
138  void toRecord (Record&, const RecordFieldId&) const;
139 
140  // Construct the object from the value in a record.
141  static ValueHolderRep* fromRecord (const Record& rec, const RecordFieldId&);
142 
143  // Write the ValueHolderRep to an output stream.
144  // Arrays are written as normal arrays using ArrayIO.h.
145  std::ostream& write (std::ostream& os) const;
146 
147  // Compare two ValueHolder objects.
148  // They must have the same data type.
149  bool operator< (const ValueHolderRep& right) const;
150  /*
151  bool operator== (const ValueHolderRep& right) const;
152  bool near (const ValueHolderRep& right, tolerance=1e-5) const;
153  bool nearAbs (const ValueHolderRep& right, double tolerance=1e-5) const;
154  */
155 
156 private:
157  // Forbid copy ctor and assignment.
158  //# There is no fundamental reason to forbid them, but it saves
159  //# implementation work as long as they are not needed.
160  // <group>
163  // </group>
164 
165 
167  DataType itsType;
168  union {
173  void* itsPtr;
174  };
175 };
176 
177 
178 inline DataType ValueHolderRep::dataType() const
179 {
180  return itsType;
181 }
182 
183 
184 } //# NAMESPACE CASACORE - END
185 
186 #endif
Int64 asInt64() const
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
int Int
Definition: aipstype.h:50
uShort asuShort() const
static ValueHolderRep * fromRecord(const Record &rec, const RecordFieldId &)
Construct the object from the value in a record.
DataType dataType() const
Get the data type (as defined in DataType.h).
const Array< Bool > asArrayBool() const
const Array< uChar > asArrayuChar() const
uChar asuChar() const
unsigned char uChar
Definition: aipstype.h:47
Double asDouble() const
const Array< Short > asArrayShort() const
const Array< uInt > asArrayuInt() const
char Char
Definition: aipstype.h:46
~ValueHolderRep()
Destructor.
Bool asBool() const
Get the value.
A holder for a value of any basic type.
const Array< Int > asArrayInt() const
short Short
Definition: aipstype.h:48
const Array< uShort > asArrayuShort() const
const Array< Complex > asArrayComplex() const
bool operator<(const ValueHolderRep &right) const
Compare two ValueHolder objects.
The identification of a record field.
Definition: RecordFieldId.h:91
const Record & asRecord() const
ValueHolderRep & operator=(const ValueHolderRep &)
double Double
Definition: aipstype.h:55
const String & asString() const
LatticeExprNode ndim(const LatticeExprNode &expr)
1-argument function to get the dimensionality of a lattice.
DComplex asDComplex() const
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
std::ostream & write(std::ostream &os) const
Write the ValueHolderRep to an output stream.
float Float
Definition: aipstype.h:54
Complex asComplex() const
ValueHolderRep(Bool value)
Create the object for the given value.
Short asShort() const
const Array< String > asArrayString() const
const Array< Int64 > asArrayInt64() const
String: the storage and methods of handling collections of characters.
Definition: String.h:223
const Array< Float > asArrayFloat() const
const Array< DComplex > asArrayDComplex() const
Float asFloat() const
void toRecord(Record &, const RecordFieldId &) const
Put the value as a field in a record.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
unsigned int uInt
Definition: aipstype.h:51
const Array< Double > asArrayDouble() const
unsigned short uShort
Definition: aipstype.h:49
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42