casacore
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>
35 #include <casacore/casa/Arrays/ArrayFwd.h>
36 #include <casacore/casa/Utilities/DataType.h>
37 #include <iosfwd>
38 
39 namespace casacore { //# NAMESPACE CASACORE - BEGIN
40 
41 //# Forward Declarations
42 class AipsIO;
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>
74  explicit ValueHolderRep (Int 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);
94  explicit ValueHolderRep (const Array<String>& value);
95  explicit ValueHolderRep (const Record& value);
96  // </group>
97 
98  // Create an empty N-dim array.
100 
101  // Destructor.
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;
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;
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
String: the storage and methods of handling collections of characters.
Definition: String.h:225
uShort asuShort() const
Double asDouble() const
const Array< Int > asArrayInt() const
ValueHolderRep(const Array< Int > &value)
ValueHolderRep(Int64 value)
ValueHolderRep(const Array< Short > &value)
ValueHolderRep(const Array< uInt > &value)
ValueHolderRep & operator=(const ValueHolderRep &)
const Array< uInt > asArrayuInt() const
ValueHolderRep(const Array< Bool > &value)
const Array< Complex > asArrayComplex() const
const Array< Short > asArrayShort() const
ValueHolderRep(const DComplex &value)
Bool asBool() const
Get the value.
const String & asString() 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
const Array< String > asArrayString() 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< Float > asArrayFloat() const
ValueHolderRep(const Record &value)
const Array< uShort > asArrayuShort() const
const Array< DComplex > asArrayDComplex() const
const Array< Bool > asArrayBool() const
ValueHolderRep(Short value)
ValueHolderRep(const ValueHolderRep &)
Forbid copy ctor and assignment.
const Record & asRecord() const
const Array< Double > asArrayDouble() const
ValueHolderRep(const Array< Float > &value)
ValueHolderRep(uChar value)
ValueHolderRep(const String &value)
ValueHolderRep(Float value)
const Array< uChar > asArrayuChar() const
ValueHolderRep(const Array< Double > &value)
const Array< Int64 > asArrayInt64() const
ValueHolderRep(const Array< uChar > &value)
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).
std::ostream & write(std::ostream &os) const
Write the ValueHolderRep to an output stream.
ValueHolderRep(Double value)
ValueHolderRep(const Array< uShort > &value)
DComplex asDComplex() const
~ValueHolderRep()
Destructor.
this file contains all the compiler specific defines
Definition: mainpage.dox:28
unsigned char uChar
Definition: aipstype.h:47
LatticeExprNode ndim(const LatticeExprNode &expr)
1-argument function to get the dimensionality of a lattice.
short Short
Definition: aipstype.h:48
unsigned int uInt
Definition: aipstype.h:51
unsigned short uShort
Definition: aipstype.h:49
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
float Float
Definition: aipstype.h:54
int Int
Definition: aipstype.h:50
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
double Double
Definition: aipstype.h:55
char Char
Definition: aipstype.h:46