Loading...
Searching...
No Matches
ValueHolder.h
Go to the documentation of this file.
//# ValueHolder.h: A holder object for the standard Casacore data types
//# Copyright (C) 2005
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: casa-feedback@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
#ifndef CASA_VALUEHOLDER_H
#define CASA_VALUEHOLDER_H
//# Includes
#include <casacore/casa/aips.h>
#include <casacore/casa/Containers/ValueHolderRep.h>
#include <casacore/casa/Arrays/Array.h>
#include <memory>
namespace casacore { //# NAMESPACE CASACORE - BEGIN
// <summary>
// A holder for a value of any basic Casacore data type.
// </summary>
// <use visibility=export>
// <reviewed reviewer="" date="" tests="tValueHolder">
// </reviewed>
// <synopsis>
// Class ValueHolder is meant to be used for holding a single Casacore value.
// The value can be scalar or an array of any basic type (including complex
// and string). Also a Record value is possible.
// In this way varying typed data (e.g. the result of getCell in the table DO)
// can be packed in a strongly typed variable.
// <br>All unsigned integer type values are kept as signed 32-bit integers
// because scripting languages usually only support those types.
//
// ValueHolder is an envelope class that holds a counted-referenced letter
// object <linkto class=ValueHolderRep>ValueHolderRep</linkto>.
// </synopsis>
// <motivation>
// This class comes handy in passing arbitrary values from a DO to
// its environment.
// </motivation>
class ValueHolder
{
public:
// Construct a null object.
ValueHolder()
{}
// Create the object for the given value.
// <group>
explicit ValueHolder (Bool value);
explicit ValueHolder (uChar value);
explicit ValueHolder (Short value);
explicit ValueHolder (uShort value);
explicit ValueHolder (Int value);
explicit ValueHolder (uInt value);
explicit ValueHolder (Int64 value);
explicit ValueHolder (Float value);
explicit ValueHolder (Double value);
explicit ValueHolder (const Complex& value);
explicit ValueHolder (const DComplex& value);
explicit ValueHolder (const Char* value);
explicit ValueHolder (const String& value);
explicit ValueHolder (const Array<Bool>& value);
explicit ValueHolder (const Array<uChar>& value);
explicit ValueHolder (const Array<Short>& value);
explicit ValueHolder (const Array<uShort>& value);
explicit ValueHolder (const Array<Int>& value);
explicit ValueHolder (const Array<uInt>& value);
explicit ValueHolder (const Array<Int64>& value);
explicit ValueHolder (const Array<Float>& value);
explicit ValueHolder (const Array<Double>& value);
explicit ValueHolder (const Array<Complex>& value);
explicit ValueHolder (const Array<DComplex>& value);
explicit ValueHolder (const Array<String>& value);
explicit ValueHolder (const Record& value);
// </group>
// Create an empty N-dim array (gets type TpOther).
ValueHolder (uInt ndim, Bool dummy);
// Create a ValueHolder from a ValueHolderRep.
// It takes over the pointer and deletes it in the destructor.
explicit ValueHolder (ValueHolderRep* rep)
: itsRep (rep)
{}
// Copy constructor (reference semantics).
ValueHolder (const ValueHolder&);
// Destructor.
~ValueHolder()
{}
// Assignment (reference semantics).
ValueHolder& operator= (const ValueHolder&);
// Is this a null object?
Bool isNull() const
{ return !itsRep; }
// Get the data type (as defined in DataType.h).
// Note that TpOther is returned for an empty untyped array.
DataType dataType() const;
// Get the value.
// If possible, it converts the data as needed.
// <group>
Bool asBool () const;
uChar asuChar () const;
Short asShort () const;
uShort asuShort () const;
Int asInt () const;
uInt asuInt () const;
Int64 asInt64 () const;
Float asFloat () const;
Double asDouble () const;
Complex asComplex () const;
DComplex asDComplex() const;
const String& asString () const;
const Array<Bool> asArrayBool () const;
const Array<uChar> asArrayuChar () const;
const Array<Short> asArrayShort () const;
const Array<uShort> asArrayuShort () const;
const Array<Int> asArrayInt () const;
const Array<uInt> asArrayuInt () const;
const Array<Int64> asArrayInt64 () const;
const Array<Float> asArrayFloat () const;
const Array<Double> asArrayDouble () const;
const Array<Complex> asArrayComplex () const;
const Array<DComplex> asArrayDComplex() const;
const Array<String> asArrayString () const;
const Record& asRecord () const;
// </group>
// Get the data in a way useful for templates.
// If possible, it converts the the data as needed.
// <group>
void getValue (Bool& value) const { value = asBool(); }
void getValue (uChar& value) const { value = asuChar(); }
void getValue (Short& value) const { value = asShort(); }
void getValue (uShort& value) const { value = asuShort(); }
void getValue (Int& value) const { value = asInt(); }
void getValue (uInt& value) const { value = asuInt(); }
void getValue (Int64& value) const { value = asInt64(); }
void getValue (Float& value) const { value = asFloat(); }
void getValue (Double& value) const { value = asDouble(); }
void getValue (Complex& value) const { value = asComplex(); }
void getValue (DComplex& value) const { value = asDComplex(); }
void getValue (String& value) const { value = asString(); }
void getValue (Array<Bool>& value) const
{ value.reference(asArrayBool()); }
void getValue (Array<uChar>& value) const
{ value.reference(asArrayuChar()); }
void getValue (Array<Short>& value) const
{ value.reference(asArrayShort()); }
void getValue (Array<uShort>& value) const
{ value.reference(asArrayuShort()); }
void getValue (Array<Int>& value) const
{ value.reference(asArrayInt()); }
void getValue (Array<uInt>& value) const
{ value.reference(asArrayuInt()); }
void getValue (Array<Int64>& value) const
{ value.reference(asArrayInt64()); }
void getValue (Array<Float>& value) const
{ value.reference(asArrayFloat()); }
void getValue (Array<Double>& value) const
{ value.reference(asArrayDouble()); }
void getValue (Array<Complex>& value) const
{ value.reference(asArrayComplex()); }
void getValue (Array<DComplex>& value) const
{ value.reference(asArrayDComplex()); }
void getValue (Array<String>& value) const
{ value.reference(asArrayString()); }
// </group>
// Put the value as a field in a record.
void toRecord (Record&, const RecordFieldId&) const;
// Construct the object from the value in a record.
static ValueHolder fromRecord (const Record&, const RecordFieldId&);
// Compare two ValueHolder objects.
// They must have the same data type.
bool operator< (const ValueHolder& right) const
{ return itsRep->operator< (*right.itsRep); }
// Write the ValueHolder to an output stream.
// Arrays are written as normal arrays using ArrayIO.h.
friend std::ostream& operator<< (std::ostream& os, const ValueHolder& vh)
{ return vh.itsRep->write (os); }
private:
std::shared_ptr<ValueHolderRep> itsRep;
};
inline DataType ValueHolder::dataType() const
{ return itsRep->dataType(); }
inline void ValueHolder::toRecord (Record& rec, const RecordFieldId& id) const
{ return itsRep->toRecord (rec, id); }
inline ValueHolder ValueHolder::fromRecord (const Record& rec,
const RecordFieldId& id)
{ return ValueHolder (ValueHolderRep::fromRecord (rec, id)); }
inline Bool ValueHolder::asBool() const
{ return itsRep->asBool(); }
inline uChar ValueHolder::asuChar() const
{ return itsRep->asuChar(); }
inline Short ValueHolder::asShort() const
{ return itsRep->asShort(); }
inline uShort ValueHolder::asuShort() const
{ return itsRep->asuShort(); }
inline Int ValueHolder::asInt() const
{ return itsRep->asInt(); }
inline uInt ValueHolder::asuInt() const
{ return itsRep->asuInt(); }
inline Int64 ValueHolder::asInt64() const
{ return itsRep->asInt64(); }
inline Float ValueHolder::asFloat() const
{ return itsRep->asFloat(); }
inline Double ValueHolder::asDouble() const
{ return itsRep->asDouble(); }
inline Complex ValueHolder::asComplex() const
{ return itsRep->asComplex(); }
inline DComplex ValueHolder::asDComplex() const
{ return itsRep->asDComplex(); }
inline const String& ValueHolder::asString() const
{ return itsRep->asString(); }
inline const Array<Bool> ValueHolder::asArrayBool() const
{ return itsRep->asArrayBool(); }
inline const Array<uChar> ValueHolder::asArrayuChar() const
{ return itsRep->asArrayuChar(); }
inline const Array<Short> ValueHolder::asArrayShort() const
{ return itsRep->asArrayShort(); }
inline const Array<uShort> ValueHolder::asArrayuShort() const
{ return itsRep->asArrayuShort(); }
inline const Array<Int> ValueHolder::asArrayInt() const
{ return itsRep->asArrayInt(); }
inline const Array<uInt> ValueHolder::asArrayuInt() const
{ return itsRep->asArrayuInt(); }
inline const Array<Int64> ValueHolder::asArrayInt64() const
{ return itsRep->asArrayInt64(); }
inline const Array<Float> ValueHolder::asArrayFloat() const
{ return itsRep->asArrayFloat(); }
inline const Array<Double> ValueHolder::asArrayDouble() const
{ return itsRep->asArrayDouble(); }
inline const Array<Complex> ValueHolder::asArrayComplex() const
{ return itsRep->asArrayComplex(); }
inline const Array<DComplex> ValueHolder::asArrayDComplex() const
{ return itsRep->asArrayDComplex(); }
inline const Array<String> ValueHolder::asArrayString() const
{ return itsRep->asArrayString(); }
inline const Record& ValueHolder::asRecord() const
{ return itsRep->asRecord(); }
} //# NAMESPACE CASACORE - END
#endif
casacore::Array
Definition Array.h:155
casacore::RecordFieldId
Definition RecordFieldId.h:89
casacore::String
String: the storage and methods of handling collections of characters.
Definition String.h:223
casacore::ValueHolderRep
Definition ValueHolderRep.h:63
casacore::ValueHolderRep::fromRecord
static ValueHolderRep * fromRecord(const Record &rec, const RecordFieldId &)
Construct the object from the value in a record.
casacore::ValueHolder
Definition ValueHolder.h:66
casacore::ValueHolder::getValue
void getValue(Float &value) const
Definition ValueHolder.h:169
casacore::ValueHolder::ValueHolder
ValueHolder(const Array< uChar > &value)
casacore::ValueHolder::ValueHolder
ValueHolder(uShort value)
casacore::ValueHolder::getValue
void getValue(Complex &value) const
Definition ValueHolder.h:171
casacore::ValueHolder::itsRep
std::shared_ptr< ValueHolderRep > itsRep
Definition ValueHolder.h:218
casacore::ValueHolder::asComplex
Complex asComplex() const
Definition ValueHolder.h:247
casacore::ValueHolder::asArrayComplex
const Array< Complex > asArrayComplex() const
Definition ValueHolder.h:271
casacore::ValueHolder::ValueHolder
ValueHolder(const Array< uInt > &value)
casacore::ValueHolder::asArrayString
const Array< String > asArrayString() const
Definition ValueHolder.h:275
casacore::ValueHolder::~ValueHolder
~ValueHolder()
Destructor.
Definition ValueHolder.h:115
casacore::ValueHolder::asuInt
uInt asuInt() const
Definition ValueHolder.h:239
casacore::ValueHolder::ValueHolder
ValueHolder(ValueHolderRep *rep)
Create a ValueHolder from a ValueHolderRep.
Definition ValueHolder.h:107
casacore::ValueHolder::ValueHolder
ValueHolder(Float value)
casacore::ValueHolder::asArrayDComplex
const Array< DComplex > asArrayDComplex() const
Definition ValueHolder.h:273
casacore::ValueHolder::asDouble
Double asDouble() const
Definition ValueHolder.h:245
casacore::ValueHolder::ValueHolder
ValueHolder(const Array< Bool > &value)
casacore::ValueHolder::asInt64
Int64 asInt64() const
Definition ValueHolder.h:241
casacore::ValueHolder::ValueHolder
ValueHolder(uInt ndim, Bool dummy)
Create an empty N-dim array (gets type TpOther).
casacore::ValueHolder::toRecord
void toRecord(Record &, const RecordFieldId &) const
Put the value as a field in a record.
Definition ValueHolder.h:224
casacore::ValueHolder::getValue
void getValue(Array< Float > &value) const
Definition ValueHolder.h:188
casacore::ValueHolder::ValueHolder
ValueHolder(const Array< DComplex > &value)
casacore::ValueHolder::ValueHolder
ValueHolder(const DComplex &value)
casacore::ValueHolder::ValueHolder
ValueHolder(const Array< Float > &value)
casacore::ValueHolder::getValue
void getValue(Array< uShort > &value) const
Definition ValueHolder.h:180
casacore::ValueHolder::fromRecord
static ValueHolder fromRecord(const Record &, const RecordFieldId &)
Construct the object from the value in a record.
Definition ValueHolder.h:226
casacore::ValueHolder::getValue
void getValue(String &value) const
Definition ValueHolder.h:173
casacore::ValueHolder::asFloat
Float asFloat() const
Definition ValueHolder.h:243
casacore::ValueHolder::getValue
void getValue(Array< uChar > &value) const
Definition ValueHolder.h:176
casacore::ValueHolder::asInt
Int asInt() const
Definition ValueHolder.h:237
casacore::ValueHolder::isNull
Bool isNull() const
Is this a null object?
Definition ValueHolder.h:122
casacore::ValueHolder::asArrayInt64
const Array< Int64 > asArrayInt64() const
Definition ValueHolder.h:265
casacore::ValueHolder::asShort
Short asShort() const
Definition ValueHolder.h:233
casacore::ValueHolder::getValue
void getValue(Bool &value) const
Get the data in a way useful for templates.
Definition ValueHolder.h:162
casacore::ValueHolder::getValue
void getValue(Array< String > &value) const
Definition ValueHolder.h:196
casacore::ValueHolder::ValueHolder
ValueHolder(const Array< String > &value)
casacore::ValueHolder::ValueHolder
ValueHolder(const Array< Short > &value)
casacore::ValueHolder::operator<<
friend std::ostream & operator<<(std::ostream &os, const ValueHolder &vh)
Write the ValueHolder to an output stream.
Definition ValueHolder.h:213
casacore::ValueHolder::getValue
void getValue(Array< DComplex > &value) const
Definition ValueHolder.h:194
casacore::ValueHolder::asArrayuChar
const Array< uChar > asArrayuChar() const
Definition ValueHolder.h:255
casacore::ValueHolder::ValueHolder
ValueHolder(const Array< Complex > &value)
casacore::ValueHolder::asuChar
uChar asuChar() const
Definition ValueHolder.h:231
casacore::ValueHolder::ValueHolder
ValueHolder(Short value)
casacore::ValueHolder::asArrayuShort
const Array< uShort > asArrayuShort() const
Definition ValueHolder.h:259
casacore::ValueHolder::ValueHolder
ValueHolder(const Array< Int > &value)
casacore::ValueHolder::asArrayuInt
const Array< uInt > asArrayuInt() const
Definition ValueHolder.h:263
casacore::ValueHolder::ValueHolder
ValueHolder(const Complex &value)
casacore::ValueHolder::getValue
void getValue(uShort &value) const
Definition ValueHolder.h:165
casacore::ValueHolder::getValue
void getValue(Array< Short > &value) const
Definition ValueHolder.h:178
casacore::ValueHolder::ValueHolder
ValueHolder(const ValueHolder &)
Copy constructor (reference semantics).
casacore::ValueHolder::asRecord
const Record & asRecord() const
Definition ValueHolder.h:277
casacore::ValueHolder::getValue
void getValue(DComplex &value) const
Definition ValueHolder.h:172
casacore::ValueHolder::ValueHolder
ValueHolder()
Construct a null object.
Definition ValueHolder.h:69
casacore::ValueHolder::ValueHolder
ValueHolder(const Record &value)
casacore::ValueHolder::asString
const String & asString() const
Definition ValueHolder.h:251
casacore::ValueHolder::getValue
void getValue(Short &value) const
Definition ValueHolder.h:164
casacore::ValueHolder::asuShort
uShort asuShort() const
Definition ValueHolder.h:235
casacore::ValueHolder::getValue
void getValue(Array< Double > &value) const
Definition ValueHolder.h:190
casacore::ValueHolder::getValue
void getValue(Array< uInt > &value) const
Definition ValueHolder.h:184
casacore::ValueHolder::getValue
void getValue(Array< Bool > &value) const
Definition ValueHolder.h:174
casacore::ValueHolder::getValue
void getValue(Double &value) const
Definition ValueHolder.h:170
casacore::ValueHolder::asArrayFloat
const Array< Float > asArrayFloat() const
Definition ValueHolder.h:267
casacore::ValueHolder::asArrayBool
const Array< Bool > asArrayBool() const
Definition ValueHolder.h:253
casacore::ValueHolder::getValue
void getValue(Int &value) const
Definition ValueHolder.h:166
casacore::ValueHolder::getValue
void getValue(Array< Int > &value) const
Definition ValueHolder.h:182
casacore::ValueHolder::dataType
DataType dataType() const
Get the data type (as defined in DataType.h).
Definition ValueHolder.h:222
casacore::ValueHolder::operator<
bool operator<(const ValueHolder &right) const
Compare two ValueHolder objects.
Definition ValueHolder.h:208
casacore::ValueHolder::ValueHolder
ValueHolder(Int value)
casacore::ValueHolder::getValue
void getValue(uInt &value) const
Definition ValueHolder.h:167
casacore::ValueHolder::ValueHolder
ValueHolder(uInt value)
casacore::ValueHolder::asArrayShort
const Array< Short > asArrayShort() const
Definition ValueHolder.h:257
casacore::ValueHolder::ValueHolder
ValueHolder(const Array< Double > &value)
casacore::ValueHolder::ValueHolder
ValueHolder(Int64 value)
casacore::ValueHolder::asBool
Bool asBool() const
Get the value.
Definition ValueHolder.h:229
casacore::ValueHolder::asArrayInt
const Array< Int > asArrayInt() const
Definition ValueHolder.h:261
casacore::ValueHolder::operator=
ValueHolder & operator=(const ValueHolder &)
Assignment (reference semantics).
casacore::ValueHolder::asArrayDouble
const Array< Double > asArrayDouble() const
Definition ValueHolder.h:269
casacore::ValueHolder::ValueHolder
ValueHolder(Double value)
casacore::ValueHolder::getValue
void getValue(Int64 &value) const
Definition ValueHolder.h:168
casacore::ValueHolder::asDComplex
DComplex asDComplex() const
Definition ValueHolder.h:249
casacore::ValueHolder::ValueHolder
ValueHolder(const Char *value)
casacore::ValueHolder::getValue
void getValue(uChar &value) const
Definition ValueHolder.h:163
casacore::ValueHolder::ValueHolder
ValueHolder(const Array< uShort > &value)
casacore::ValueHolder::ValueHolder
ValueHolder(uChar value)
casacore::ValueHolder::ValueHolder
ValueHolder(Bool value)
Create the object for the given value.
casacore::ValueHolder::ValueHolder
ValueHolder(const String &value)
casacore::ValueHolder::ValueHolder
ValueHolder(const Array< Int64 > &value)
casacore::ValueHolder::getValue
void getValue(Array< Int64 > &value) const
Definition ValueHolder.h:186
casacore::ValueHolder::getValue
void getValue(Array< Complex > &value) const
Definition ValueHolder.h:192
casacore::Record
Record()
casacore
this file contains all the compiler specific defines
Definition mainpage.dox:28
casacore::uChar
unsigned char uChar
Definition aipstype.h:45
casacore::ndim
LatticeExprNode ndim(const LatticeExprNode &expr)
1-argument function to get the dimensionality of a lattice.
casacore::Short
short Short
Definition aipstype.h:46
casacore::uInt
unsigned int uInt
Definition aipstype.h:49
casacore::uShort
unsigned short uShort
Definition aipstype.h:47
casacore::Int64
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size).
Definition aipsxtype.h:36
casacore::Float
float Float
Definition aipstype.h:52
casacore::Int
int Int
Definition aipstype.h:48
casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
casacore::value
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:368
casacore::Double
double Double
Definition aipstype.h:53
casacore::Char
char Char
Definition aipstype.h:44