//*-- Author : Valeriy Onuchin 11/09/2000
//
//
////////////////////////////////////////////////////////////////////////////////
//
// Class rooNumericValue corresponds to Numeric_Value class
//
// The class rooNumericValue is a self-describing data type for
// persistent numeric values. An instance of this class, called a
// numeric value, contains up to 64 bits of raw data and a code
// indicating the basic numeric type of the data. The data can be
// any fundamental character, integer, floating-point, or pointer type.
//
// All numeric data in persistent objects is transferred to an Active Schema
// application as numeric values. Encapsulating the data within a
// numeric value avoids the inherent risk that the data may be transferred
// to program memory under mistaken assumptions about alignment, precision,
// or integral versus floating-point representation.
// Typically, an Active Schema application does not work with numeric values
// explicitly, but instead works with the basic numeric data types such as
// int8, float32, uint64.
//
// When you pass a number of a basic numeric type as a parameter to a member
// function that expects a numeric value, the appropriate constructor converts
// the parameter to an instance of rooNumericValue.
// Certain member functions return an instance of rooNumericValue on the
// stack. If you call such a function, assigning its returned value to a
// variable of the correct basic numeric type, the appropriate conversion
// function converts the return value to the required type.
//
// If you examine persistent data in the federated database, you may obtain a
// numeric value (for example, the value of an attribute) without knowing
// what type of data it contains. In that situation, you can call its type
// member function and then cast the numeric value to the correct basic
// numeric type. For example, if a numeric value's type member function
// returns kooUINT32, you can cast it to the basic numeric type
// uint32 ( UInt_t in ROOT case ).
//
////////////////////////////////////////////////////////////////////////////////
#include "rooObjy.h"
#include <ooas.h>
#include <oo.h>
ClassImp(rooNumericValue)
////////////////////////////////////////////////////////////////////////////////
//______________________________________________________________________________
rooNumericValue::rooNumericValue()
{
// default ctor
fImp = new Numeric_Value();
}
//______________________________________________________________________________
rooNumericValue::~rooNumericValue()
{
// destructor
}
//______________________________________________________________________________
rooNumericValue::rooNumericValue(void* val, Int_t basetype)
{
// Constructs a numeric value from a number of basic numeric type.
fImp = new Numeric_Value(val,(ooBaseType)basetype);
}
//______________________________________________________________________________
rooNumericValue::rooNumericValue(Long_t val, Int_t basetype)
{
// Constructs a numeric value from a number of basic numeric type.
fImp = new Numeric_Value((int64)val,(ooBaseType)basetype);
}
//______________________________________________________________________________
rooNumericValue::rooNumericValue(ULong_t val, Int_t basetype)
{
// Constructs a numeric value from a number of basic numeric type.
fImp = new Numeric_Value((uint64)val,(ooBaseType)basetype);
}
//______________________________________________________________________________
rooNumericValue::rooNumericValue(Double_t val, Int_t basetype)
{
// Constructs a numeric value from a number of basic numeric type.
fImp = new Numeric_Value((float64)val,(ooBaseType)basetype);
}
//______________________________________________________________________________
rooNumericValue::rooNumericValue(Char_t val)
{
// Constructs a numeric value from a number of basic numeric type.
fImp = new Numeric_Value((int8)val);
}
//______________________________________________________________________________
rooNumericValue::rooNumericValue(UChar_t val)
{
// Constructs a numeric value from a number of basic numeric type.
fImp = new Numeric_Value((uint8)val);
}
//______________________________________________________________________________
rooNumericValue::rooNumericValue(Short_t val)
{
// Constructs a numeric value from a number of basic numeric type.
fImp = new Numeric_Value((int16)val);
}
//______________________________________________________________________________
rooNumericValue::rooNumericValue(UShort_t val)
{
// Constructs a numeric value from a number of basic numeric type.
fImp = new Numeric_Value((uint16)val);
}
//______________________________________________________________________________
rooNumericValue::rooNumericValue(Int_t val)
{
// Constructs a numeric value from a number of basic numeric type.
fImp = new Numeric_Value((int32)val);
}
//______________________________________________________________________________
rooNumericValue::rooNumericValue(UInt_t val)
{
// Constructs a numeric value from a number of basic numeric type.
fImp = new Numeric_Value((uint32)val);
}
//______________________________________________________________________________
rooNumericValue::rooNumericValue(Long_t val)
{
// Constructs a numeric value from a number of basic numeric type.
fImp = new Numeric_Value((int64)val);
}
//______________________________________________________________________________
rooNumericValue::rooNumericValue(ULong_t val)
{
// Constructs a numeric value from a number of basic numeric type.
fImp = new Numeric_Value((uint64)val);
}
//______________________________________________________________________________
rooNumericValue::rooNumericValue(Float_t val)
{
// Constructs a numeric value from a number of basic numeric type.
fImp = new Numeric_Value((float32)val);
}
//______________________________________________________________________________
rooNumericValue::rooNumericValue(Double_t val)
{
// Constructs a numeric value from a number of basic numeric type.
fImp = new Numeric_Value((float64)val);
}
//______________________________________________________________________________
rooNumericValue::rooNumericValue(void* val)
{
// Constructs a numeric value from a number of basic numeric type.
fImp = new Numeric_Value(val);
}
//______________________________________________________________________________
rooNumericValue::operator Char_t() const
{
// Converts this numeric value to an 8-bit character.
return fImp ? (int8)(*(Numeric_Value*)fImp) : 0;
}
//______________________________________________________________________________
rooNumericValue::operator UChar_t() const
{
// Converts this numeric value to an 8-bit unsigned integer.
return fImp ? (uint8)(*(Numeric_Value*)fImp) : 0;
}
//______________________________________________________________________________
rooNumericValue::operator Short_t() const
{
// Converts this numeric value to a 16-bit signed integer.
return fImp ? (int16)(*(Numeric_Value*)fImp) : 0;
}
//______________________________________________________________________________
rooNumericValue::operator UShort_t() const
{
// Converts this numeric value to a 16-bit unsigned integer.
return fImp ? (uint16)(*(Numeric_Value*)fImp) : 0;
}
//______________________________________________________________________________
rooNumericValue::operator Int_t() const
{
// Converts this numeric value to a 32-bit signed integer.
return fImp ? (int32)(*(Numeric_Value*)fImp) : 0;
}
//______________________________________________________________________________
rooNumericValue::operator UInt_t() const
{
// Converts this numeric value to a 32-bit unsigned integer.
return fImp ? (uint32)(*(Numeric_Value*)fImp) : 0;
}
//______________________________________________________________________________
rooNumericValue::operator Float_t() const
{
// Converts this numeric value to a single-precision floating-point number.
//
// This member function throws an IllegalNumericConvert exception if this
// numeric value contains an unsigned 64-bit integer that cannot be
// converted to floating-point.
return fImp ? (float32)(*(Numeric_Value*)fImp) : 0;
}
//______________________________________________________________________________
rooNumericValue::operator Double_t() const
{
// Converts this numeric value to a double-precision floating-point number.
//
// This member function throws an IllegalNumericConvert exception if this
// numeric value contains an unsigned 64-bit integer that cannot be
// converted to floating-point.
return fImp ? (float64)(*(Numeric_Value*)fImp) : 0;
}
//______________________________________________________________________________
rooNumericValue::operator Long_t() const
{
// Converts this numeric value to a 64-bit signed integer.
return fImp ? (int64)(*(Numeric_Value*)fImp) : 0;
}
//______________________________________________________________________________
rooNumericValue::operator ULong_t() const
{
// Converts this numeric value to a 64-bit unsigned integer.
return fImp ? (uint64)(*(Numeric_Value*)fImp) : 0;
}
//______________________________________________________________________________
rooNumericValue::operator void*() const
{
// Converts this numeric value to a 32-bit pointer
return fImp ? (void*)(*(Numeric_Value*)fImp) : 0;
}
//______________________________________________________________________________
Bool_t rooNumericValue::operator==(const rooNumericValue & val)
{
// Equality operator; tests whether this numeric value is equal to the
// specified numeric value.
//
// This member function performs any necessary type conversion before
// comparing the data in the two numeric values. Thus, if the two numeric
// values represent the same numeric quantity, they are considered equal
// even if their data is of different numeric types.
// For example, an equal comparison of an int8(Char_t) value 2 with a
// float32(Float_t) value 2.0 succeeds (returns kTRUE).
// This member function throws an IllegalNumericCompare exception if the
// two numeric values cannot be compared. This situation occurs when
// comparing afloating-point value with a 64-bit integer value or when
// comparing an unsigned64-bit integer value with a signed 64-bit integer
// value.
//
// See also operator!=
if(!fImp) return 0;
Numeric_Value* imp = (Numeric_Value*)val.getImp();
return *((Numeric_Value*)fImp) == *imp;
}
//______________________________________________________________________________
Bool_t rooNumericValue::operator!=(const rooNumericValue & val)
{
// Inequality operator; tests whether this numeric value is different from
// the specified numeric value.
//
// The numeric value to be compared with this numeric value.
// Returns kTRUE if the two numeric values are different and kFALSE if they
// are equal.
//
// This member function performs any necessary type conversion before
// comparing the data in the two numeric values. Thus, if the two numeric
// values represent thesame numeric quantity, they are considered equal
// even if their data is of different numeric types. For example, an
// inequality comparison of an int8 value 2 with a float32 value 2.0 fails
// (returns kFALSE).
//
// This member function throws an IllegalNumericCompare exception if the
// two numeric values cannot be compared. This situation occurs when
// comparing a floating-point value with a 64-bit integer value or when
// comparing an unsigned 64-bit integer value with a signed 64-bit integer
// value.
//
// See also operator==
if(!fImp) return 0;
Numeric_Value* imp = (Numeric_Value*)val.getImp();
return *((Numeric_Value*)fImp) != *imp;
}
//______________________________________________________________________________
Bool_t rooNumericValue::operator>(const rooNumericValue & val)
{
// Greater-than operator; tests whether this numeric value is greater than
// the specified numeric value.
//
// Returns kTRUE if this numeric value is greater than val; otherwise, kFALSE.
//
// This member function performs any necessary type conversion before
// comparing the data in the two numeric values.
// It throws an IllegalNumericCompare exception if the two numeric values
// cannot be compared. This situation occurs when comparing a floating-point
// value with a 64-bit integer value or when comparing an unsigned 64-bit
// integer value with a signed 64-bit integer value.
//
// See also operator<
if(!fImp) return 0;
Numeric_Value* imp = (Numeric_Value*)val.getImp();
return *((Numeric_Value*)fImp)> *imp;
}
//______________________________________________________________________________
Bool_t rooNumericValue::operator<(const rooNumericValue & val)
{
// Less-than operator; tests whether this numeric value is less than
// the specified numeric value.
//
// The numeric value to be compared with this numeric value.
// Returns kTRUE if this numeric value is less than val; otherwise, kFALSE.
//
// This member function performs any necessary type conversion before
// comparing the data in the two numeric values.
// It throws an IllegalNumericCompare exception if the two numeric values
// cannot be compared. This situation occurs when comparing a floating-point
// value with a 64-bit integer value or when comparing an unsigned 64-bit
// integer value with a signed 64-bit integer value.
//
// See also operator<=
if(!fImp) return 0;
Numeric_Value* imp = (Numeric_Value*)val.getImp();
return *((Numeric_Value*)fImp) < *imp;
}
//______________________________________________________________________________
Bool_t rooNumericValue::operator>=(const rooNumericValue & val)
{
// Greater-than-or-equal-to operator; tests whether this numeric value is
// greater than or equal to the specified numeric value.
//
// Returns kTRUE if this numeric value is greater than or equal to val;
// otherwise, kFALSE.
//
// This member function performs any necessary type conversion before
// comparing the data in the two numeric values. Thus, if the two numeric
// values represent the same numeric quantity, they are considered equal
// even if their data is of different numeric types.
// For example, a greater-than-or-equal-to comparison of an int8 value 2
// with a float32 value 2.0 succeeds (returns kTRUE).
// This member function throws an IllegalNumericCompare exception if the
// two numeric values cannot be compared. This situation occurs when
// comparing a floating-point value with a 64-bit integer value or when
// comparing an unsigned 64-bit integer value with a signed 64-bit integer
// value.
//
// See also operator<=
if(!fImp) return 0;
Numeric_Value* imp = (Numeric_Value*)val.getImp();
return *((Numeric_Value*)fImp) >= *imp;
}
//______________________________________________________________________________
Bool_t rooNumericValue::operator<=(const rooNumericValue & val)
{
// Less-than-or-equal-to operator; tests whether this numeric value is less
// than or equal to the specified numeric value.
//
// The numeric value to be compared with this numeric value.
//
// Returns kTRUE if this numeric value is less than or equal to val;
// otherwise, kFALSE.
//
// This member function performs any necessary type conversion before
// comparing the data in the two numeric values. Thus, if the two numeric
// values represent the same numeric quantity, they are considered equal
// even if their data is of different numeric types. For example, a
// less-than-or-equal-to comparison of an int8 valuev 2 with a float32 value
// 2.0 succeeds (returns kTRUE).
//
// This member function throws an IllegalNumericCompare exception if the
// two numeric values cannot be compared. This situation occurs when
// comparing a floating-point value with a 64-bit integer value or when
// comparing an unsigned 64-bit integer value with a signed 64-bit integer
// value.
//
// See also operator<
if(!fImp) return 0;
Numeric_Value* imp = (Numeric_Value*)val.getImp();
return *((Numeric_Value*)fImp) <= *imp;
}
//______________________________________________________________________________
Bool_t rooNumericValue::is_valid() const
{
// Tests whether this is a valid numeric value.
//
// Returns kTRUE if this is a valid numeric value; otherwise, kFALSE.
//
// A numeric value is valid if it has a valid numeric type; it is invalid
// if its type isv kooNONE.
if(!fImp) return 0;
return ((Numeric_Value*)fImp)->is_valid();
}
//______________________________________________________________________________
Int_t rooNumericValue::type() const
{
// Gets the type of numeric data that this numeric value contains.
//
// Returns: The type of numeric data; one of the following:
//
// kooCHAR indicates an 8-bit character.
// kooINT8 indicates an 8-bit signed integer.
// kooINT16 indicates a 16-bit signed integer.
// kooINT32 indicates a 32-bit signed integer.
// kooINT64 indicates a 64-bit signed integer.
// kooUINT8 indicates an 8-bit unsigned integer.
// kooUINT16 indicates a 16-bit unsigned integer.
// kooUINT32 indicates a 32-bit unsigned integer.
// kooUINT64 indicates a 64-bit unsigned integer.
// kooFLOAT32 indicates a 32-bit (single-precision) floating-point number.
// kooFLOAT64 indicates a 64-bit (double-precision) floating-point number.
// kooPTR indicates a 32-bit pointer.
// kooNONE indicates that this numeric value is invalid.
return fImp ? ((Numeric_Value*)fImp)->type() : 0;
}
ROOT page - Class index - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.