Loading...
Searching...
No Matches
ValueHolderRep.h
Go to the documentation of this file.
//# ValueHolderRep.h: A holder object for the standard CASACORE data
//# 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_VALUEHOLDERREP_H
#define CASA_VALUEHOLDERREP_H
//# Includes
#include <casacore/casa/aips.h>
#include <casacore/casa/Arrays/ArrayFwd.h>
#include <casacore/casa/Utilities/DataType.h>
#include <iosfwd>
namespace casacore { //# NAMESPACE CASACORE - BEGIN
//# Forward Declarations
class AipsIO;
class Record;
class RecordFieldId;
// <summary>
// A holder for a value of any basic type.
// </summary>
// <use visibility=local>
// <reviewed reviewer="" date="" tests="tValueHolder">
// </reviewed>
// <synopsis>
// Class ValueHolderRep is the letter class for the envelope class ValueHolder.
// See <linkto class=ValueHolder>that class</linkto> for more information.
// </synopsis>
// <motivation>
// Copying ValueHolders should be as cheap as possible, so a counted
// referenced letter class is used.
// </motivation>
class ValueHolderRep
{
public:
// Create the object for the given value.
// <group>
explicit ValueHolderRep (Bool value);
explicit ValueHolderRep (uChar value);
explicit ValueHolderRep (Short value);
explicit ValueHolderRep (uShort value);
explicit ValueHolderRep (Int value);
explicit ValueHolderRep (uInt value);
explicit ValueHolderRep (Int64 value);
explicit ValueHolderRep (Float value);
explicit ValueHolderRep (Double value);
explicit ValueHolderRep (const Complex& value);
explicit ValueHolderRep (const DComplex& value);
explicit ValueHolderRep (const Char* value);
explicit ValueHolderRep (const String& value);
explicit ValueHolderRep (const Array<Bool>& value);
explicit ValueHolderRep (const Array<uChar>& value);
explicit ValueHolderRep (const Array<Short>& value);
explicit ValueHolderRep (const Array<uShort>& value);
explicit ValueHolderRep (const Array<Int>& value);
explicit ValueHolderRep (const Array<uInt>& value);
explicit ValueHolderRep (const Array<Int64>& value);
explicit ValueHolderRep (const Array<Float>& value);
explicit ValueHolderRep (const Array<Double>& value);
explicit ValueHolderRep (const Array<Complex>& value);
explicit ValueHolderRep (const Array<DComplex>& value);
explicit ValueHolderRep (const Array<String>& value);
explicit ValueHolderRep (const Record& value);
// </group>
// Create an empty N-dim array.
ValueHolderRep (uInt ndim, Bool dummy);
// Destructor.
~ValueHolderRep();
// Forbid copy ctor and assignment.
//# There is no fundamental reason to forbid them, but it saves
//# implementation work as long as they are not needed.
// <group>
ValueHolderRep (const ValueHolderRep&) = delete;
ValueHolderRep& operator= (const ValueHolderRep&) = delete;
// </group>
// Get the data type (as defined in DataType.h).
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>
// 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 ValueHolderRep* fromRecord (const Record& rec, const RecordFieldId&);
// Write the ValueHolderRep to an output stream.
// Arrays are written as normal arrays using ArrayIO.h.
std::ostream& write (std::ostream& os) const;
// Compare two ValueHolder objects.
// They must have the same data type.
bool operator< (const ValueHolderRep& right) const;
/*
bool operator== (const ValueHolderRep& right) const;
bool near (const ValueHolderRep& right, tolerance=1e-5) const;
bool nearAbs (const ValueHolderRep& right, double tolerance=1e-5) const;
*/
private:
uInt itsNdim;
DataType itsType;
union {
Bool itsBool;
Int64 itsInt64;
Float itsFloat;
Double itsDouble;
void* itsPtr;
};
};
inline DataType ValueHolderRep::dataType() const
{
return itsType;
}
} //# NAMESPACE CASACORE - END
#endif
casacore::AipsIO
Definition AipsIO.h:167
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::fromRecord
static ValueHolderRep * fromRecord(const Record &rec, const RecordFieldId &)
Construct the object from the value in a record.
casacore::ValueHolderRep::asuShort
uShort asuShort() const
casacore::ValueHolderRep::asDouble
Double asDouble() const
casacore::ValueHolderRep::write
std::ostream & write(std::ostream &os) const
Write the ValueHolderRep to an output stream.
casacore::ValueHolderRep::itsNdim
uInt itsNdim
Definition ValueHolderRep.h:163
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(const Array< Int > &value)
casacore::ValueHolderRep::asArrayString
const Array< String > asArrayString() const
casacore::ValueHolderRep::asInt
Int asInt() const
casacore::ValueHolderRep::itsType
DataType itsType
Definition ValueHolderRep.h:164
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(Int64 value)
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(const Array< Short > &value)
casacore::ValueHolderRep::operator=
ValueHolderRep & operator=(const ValueHolderRep &)=delete
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(const ValueHolderRep &)=delete
Forbid copy ctor and assignment.
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(const Array< uInt > &value)
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(const Array< Bool > &value)
casacore::ValueHolderRep::itsFloat
Float itsFloat
Definition ValueHolderRep.h:168
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(const DComplex &value)
casacore::ValueHolderRep::asBool
Bool asBool() const
Get the value.
casacore::ValueHolderRep::asRecord
const Record & asRecord() const
casacore::ValueHolderRep::itsInt64
Int64 itsInt64
Definition ValueHolderRep.h:167
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(uInt value)
casacore::ValueHolderRep::asuInt
uInt asuInt() const
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(const Array< DComplex > &value)
casacore::ValueHolderRep::asuChar
uChar asuChar() const
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(Bool value)
Create the object for the given value.
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(uShort value)
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(const Array< String > &value)
casacore::ValueHolderRep::asComplex
Complex asComplex() const
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(const Complex &value)
casacore::ValueHolderRep::operator<
bool operator<(const ValueHolderRep &right) const
Compare two ValueHolder objects.
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(const Array< Int64 > &value)
casacore::ValueHolderRep::toRecord
void toRecord(Record &, const RecordFieldId &) const
Put the value as a field in a record.
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(const Array< Complex > &value)
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(uInt ndim, Bool dummy)
Create an empty N-dim array.
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(const Char *value)
casacore::ValueHolderRep::asFloat
Float asFloat() const
casacore::ValueHolderRep::asArrayDouble
const Array< Double > asArrayDouble() const
casacore::ValueHolderRep::itsPtr
void * itsPtr
Definition ValueHolderRep.h:170
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(const Record &value)
casacore::ValueHolderRep::asArrayDComplex
const Array< DComplex > asArrayDComplex() const
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(Short value)
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(const Array< Float > &value)
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(uChar value)
casacore::ValueHolderRep::asArrayInt64
const Array< Int64 > asArrayInt64() const
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(const String &value)
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(Float value)
casacore::ValueHolderRep::asArrayShort
const Array< Short > asArrayShort() const
casacore::ValueHolderRep::asArrayuChar
const Array< uChar > asArrayuChar() const
casacore::ValueHolderRep::asArrayBool
const Array< Bool > asArrayBool() const
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(const Array< Double > &value)
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(const Array< uChar > &value)
casacore::ValueHolderRep::dataType
DataType dataType() const
Get the data type (as defined in DataType.h).
Definition ValueHolderRep.h:175
casacore::ValueHolderRep::itsDouble
Double itsDouble
Definition ValueHolderRep.h:169
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(Double value)
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(const Array< uShort > &value)
casacore::ValueHolderRep::asDComplex
DComplex asDComplex() const
casacore::ValueHolderRep::asArrayuShort
const Array< uShort > asArrayuShort() const
casacore::ValueHolderRep::ValueHolderRep
ValueHolderRep(Int value)
casacore::ValueHolderRep::asInt64
Int64 asInt64() const
casacore::ValueHolderRep::asShort
Short asShort() const
casacore::ValueHolderRep::~ValueHolderRep
~ValueHolderRep()
Destructor.
casacore::ValueHolderRep::asArrayComplex
const Array< Complex > asArrayComplex() const
casacore::ValueHolderRep::asArrayuInt
const Array< uInt > asArrayuInt() const
casacore::ValueHolderRep::itsBool
Bool itsBool
Definition ValueHolderRep.h:166
casacore::ValueHolderRep::asArrayInt
const Array< Int > asArrayInt() const
casacore::ValueHolderRep::asString
const String & asString() const
casacore::ValueHolderRep::asArrayFloat
const Array< Float > asArrayFloat() const
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