strusBase  0.17
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
strus::NumericVariant Class Reference

Atomic type that can hold numeric values of different type. More...

#include <numericVariant.hpp>

Classes

class  String
 

Public Types

enum  Type { Null, Int, UInt, Float }
 Enumeration of all types an numeric variant can have. More...
 
typedef int64_t IntType
 
typedef uint64_t UIntType
 
typedef double FloatType
 

Public Member Functions

 NumericVariant (int64_t value)
 Constructor from a signed integer. More...
 
 NumericVariant (uint64_t value)
 Constructor from an unsigned integer. More...
 
 NumericVariant (double value)
 Constructor from a single precision floating point number. More...
 
 NumericVariant (const char *val_)
 Constructor from a string. More...
 
 NumericVariant ()
 Default constructor (as undefined value) More...
 
 NumericVariant (const NumericVariant &o)
 Copy constructor. More...
 
void init ()
 
String tostring (int precision=-1) const
 
bool initFromString (const char *src)
 Initialize numeric variant parsed from a Ascii source string. More...
 
bool defined () const
 Find out if this value is defined. More...
 
template<typename TYPE >
TYPE cast () const
 Template for casting to a defined value type. More...
 
 operator double () const
 Cast to a single precision floating point number. More...
 
 operator int64_t () const
 Cast to a signed integer. More...
 
 operator uint64_t () const
 Cast to an unsigned integer. More...
 
int64_t toint () const
 Cast to a signed integer. More...
 
uint64_t touint () const
 Cast to an unsigned integer. More...
 
double tofloat () const
 Cast to an unsigned integer. More...
 
bool operator== (const NumericVariant &o) const
 Test for equality. More...
 
bool operator!= (const NumericVariant &o) const
 Test for inequality. More...
 
bool operator>= (const NumericVariant &o) const
 Test for greater or equal. More...
 
bool operator> (const NumericVariant &o) const
 Test for greater. More...
 
bool operator<= (const NumericVariant &o) const
 Test for smaller or equal. More...
 
bool operator< (const NumericVariant &o) const
 Test for smaller. More...
 
bool isequal (const NumericVariant &o) const
 Test for equality. More...
 
int compare (const NumericVariant &o) const
 Comparison of numbers. More...
 
NumericVariantoperator= (int64_t value)
 Assignment operator for a singed integer. More...
 
NumericVariantoperator= (uint64_t value)
 Assignment operator for an unsinged integer. More...
 
NumericVariantoperator= (double value)
 Assignment operator for a single precision floating point number. More...
 
NumericVariantoperator= (const NumericVariant &o)
 Assignment operator. More...
 

Static Public Member Functions

static NumericVariant asint (int64_t val)
 
static NumericVariant asuint (uint64_t val)
 
static NumericVariant asdouble (double val)
 
static const char * typeName (Type type)
 Get the name of a type as string. More...
 

Public Attributes

Type type
 Type of this numeric variant. More...
 
union {
   int64_t   Int
 value in case of a signed integer More...
 
   uint64_t   UInt
 value in case of an unsigned integer More...
 
   double   Float
 value in case of a floating point number More...
 
variant
 Value of this numeric variant. More...
 

Detailed Description

Atomic type that can hold numeric values of different type.

Member Typedef Documentation

Member Enumeration Documentation

Enumeration of all types an numeric variant can have.

Enumerator
Null 

uninitialized variant value

Int 

signed integer number value

UInt 

unsigned integer number value

Float 

floating point number value

Constructor & Destructor Documentation

strus::NumericVariant::NumericVariant ( int64_t  value)
inline

Constructor from a signed integer.

Parameters
[in]valuevalue to assign to this numeric variant
strus::NumericVariant::NumericVariant ( uint64_t  value)
inline

Constructor from an unsigned integer.

Parameters
[in]valuevalue to assign to this numeric variant
strus::NumericVariant::NumericVariant ( double  value)
inline

Constructor from a single precision floating point number.

Parameters
[in]valuevalue to assign to this numeric variant
strus::NumericVariant::NumericVariant ( const char *  val_)
inline

Constructor from a string.

Parameters
[in]valuevalue to parse and assign to this numeric variant
strus::NumericVariant::NumericVariant ( )
inline

Default constructor (as undefined value)

strus::NumericVariant::NumericVariant ( const NumericVariant o)
inline

Copy constructor.

Parameters
[in]onumeric variant to copy

Member Function Documentation

static NumericVariant strus::NumericVariant::asdouble ( double  val)
inlinestatic
static NumericVariant strus::NumericVariant::asint ( int64_t  val)
inlinestatic
static NumericVariant strus::NumericVariant::asuint ( uint64_t  val)
inlinestatic
template<typename TYPE >
TYPE strus::NumericVariant::cast ( ) const
inline

Template for casting to a defined value type.

Template Parameters
TYPEwhat type to cast this numeric variant to
int strus::NumericVariant::compare ( const NumericVariant o) const

Comparison of numbers.

Parameters
[in]onumeric variant to compare
Returns
-1 <, +1 >, 0 =
bool strus::NumericVariant::defined ( ) const
inline

Find out if this value is defined.

Returns
true, if yes
void strus::NumericVariant::init ( )
inline
bool strus::NumericVariant::initFromString ( const char *  src)

Initialize numeric variant parsed from a Ascii source string.

Parameters
[in]srcsource string to parse
Returns
bool true on success, false on failure
bool strus::NumericVariant::isequal ( const NumericVariant o) const

Test for equality.

Parameters
[in]onumeric variant to compare
Returns
true, if yes
strus::NumericVariant::operator double ( ) const
inline

Cast to a single precision floating point number.

strus::NumericVariant::operator int64_t ( ) const
inline

Cast to a signed integer.

strus::NumericVariant::operator uint64_t ( ) const
inline

Cast to an unsigned integer.

bool strus::NumericVariant::operator!= ( const NumericVariant o) const
inline

Test for inequality.

Parameters
[in]onumeric variant to compare
Returns
true, if yes
bool strus::NumericVariant::operator< ( const NumericVariant o) const
inline

Test for smaller.

Parameters
[in]onumeric variant to compare
Returns
true, if yes
bool strus::NumericVariant::operator<= ( const NumericVariant o) const
inline

Test for smaller or equal.

Parameters
[in]onumeric variant to compare
Returns
true, if yes
NumericVariant& strus::NumericVariant::operator= ( int64_t  value)
inline

Assignment operator for a singed integer.

Parameters
[in]valuevalue to assign to this numeric variant
NumericVariant& strus::NumericVariant::operator= ( uint64_t  value)
inline

Assignment operator for an unsinged integer.

Parameters
[in]valuevalue to assign to this numeric variant
NumericVariant& strus::NumericVariant::operator= ( double  value)
inline

Assignment operator for a single precision floating point number.

Parameters
[in]valuevalue to assign to this numeric variant
NumericVariant& strus::NumericVariant::operator= ( const NumericVariant o)
inline

Assignment operator.

Parameters
[in]onumeric variant to copy
bool strus::NumericVariant::operator== ( const NumericVariant o) const
inline

Test for equality.

Parameters
[in]onumeric variant to compare
Returns
true, if yes
bool strus::NumericVariant::operator> ( const NumericVariant o) const
inline

Test for greater.

Parameters
[in]onumeric variant to compare
Returns
true, if yes
bool strus::NumericVariant::operator>= ( const NumericVariant o) const
inline

Test for greater or equal.

Parameters
[in]onumeric variant to compare
Returns
true, if yes
double strus::NumericVariant::tofloat ( ) const
inline

Cast to an unsigned integer.

int64_t strus::NumericVariant::toint ( ) const
inline

Cast to a signed integer.

String strus::NumericVariant::tostring ( int  precision = -1) const
inline
uint64_t strus::NumericVariant::touint ( ) const
inline

Cast to an unsigned integer.

static const char* strus::NumericVariant::typeName ( Type  type)
static

Get the name of a type as string.

Member Data Documentation

double strus::NumericVariant::Float

value in case of a floating point number

int64_t strus::NumericVariant::Int

value in case of a signed integer

Type strus::NumericVariant::type

Type of this numeric variant.

uint64_t strus::NumericVariant::UInt

value in case of an unsigned integer

union { ... } strus::NumericVariant::variant

Value of this numeric variant.


The documentation for this class was generated from the following file: