All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Radiant::Variant Class Reference

A single variant. More...

#include <Radiant/ConfigReader.hpp>

Public Member Functions

const QString & documentation () const
 Returns the documentation. More...
 
void dump (std::ostream &os) const
 Prints the value to given stream. More...
 
double getDouble (double def=0.0f) const
 Returns the value as a double. More...
 
int getDoubles (double *target, int n)
 Reads an array of doubles from the value. More...
 
float getFloat (float def=0.f) const
 Returns the value as a float. More...
 
int getFloats (float *target, int n)
 Reads an array of floats from the value. More...
 
uint64_t getFromHex64 (uint64_t def=0) const
 Returns the value as unsigned 64 bit integer (interpreted as hexadecimal) More...
 
int getInt (int def=0) const
 Returns the value as int. More...
 
int getInts (int *target, int n)
 Reads an array of integers from the value. More...
 
const QString & getString (const QString &def) const
 Returns the value as string or the given default value if the value has not been set. More...
 
const QString & getString () const
 Returns the value as string. More...
 
bool hasDocumentation () const
 Returns true if the variable has been documented. More...
 
bool isEmpty () const
 Returns true if the value has not been set. More...
 
 operator const QString & () const
 Returns the value as string. More...
 
 operator double () const
 Returns the value as double. More...
 
 operator int () const
 Returns the value as integer. More...
 
void set (const QString &s)
 Sets the value. More...
 
 Variant ()
 Constructor.
 
 Variant (const QString &a, const char *doc=0)
 Constructs a new variable and sets it value. More...
 
 Variant (const char *str, const char *doc=0)
 Constructs a new variable and sets it value. More...
 
 Variant (int v, const char *doc=0)
 Constructs a new int variable. More...
 
 Variant (unsigned v, const char *doc=0)
 Constructs a new unsigned int variable. More...
 
 Variant (double v, const char *doc=0)
 Constructs a double variable. More...
 
 Variant (const float *arr, int n, const char *doc=0)
 Constructs an array of floating point numbers. More...
 
 Variant (const int *arr, int n, const char *doc=0)
 Constructs an array of integers. More...
 
 ~Variant ()
 Destructor.
 

Detailed Description

A single variant.

All variants are stored as text strings. This class provides methods to convert the string to the most simple variable types including integers, doubles and float vectors.

In addition to the actual variable information, a variant may contain a documentation string.

Author
Tommi Ilmonen (may contain original code by Janne Kontkanen)

Constructor & Destructor Documentation

Radiant::Variant::Variant ( const QString &  a,
const char *  doc = 0 
)

Constructs a new variable and sets it value.

Parameters
aValue as a string
docDocumentation of the variable
Radiant::Variant::Variant ( const char *  str,
const char *  doc = 0 
)

Constructs a new variable and sets it value.

Parameters
strValue as a string
docDocumentation of the variable
Radiant::Variant::Variant ( int  v,
const char *  doc = 0 
)

Constructs a new int variable.

Parameters
vValue to represent
docDocumentation of the variable
Radiant::Variant::Variant ( unsigned  v,
const char *  doc = 0 
)

Constructs a new unsigned int variable.

Parameters
vValue to represent
docDocumentation of the variable
Radiant::Variant::Variant ( double  v,
const char *  doc = 0 
)

Constructs a double variable.

Parameters
vValue to represent
docDocumentation of the variable
Radiant::Variant::Variant ( const float *  arr,
int  n,
const char *  doc = 0 
)

Constructs an array of floating point numbers.

Parameters
arrArray of floating points
nLength of an array
docDocumentation of the variable
Radiant::Variant::Variant ( const int *  arr,
int  n,
const char *  doc = 0 
)

Constructs an array of integers.

Parameters
arrArray of integers
nLength of an array
docDocumentation of the variable

Member Function Documentation

const QString& Radiant::Variant::documentation ( ) const

Returns the documentation.

Returns
Documentation of the varuable
void Radiant::Variant::dump ( std::ostream &  os) const

Prints the value to given stream.

Parameters
osStream where the value is printed
double Radiant::Variant::getDouble ( double  def = 0.0f) const

Returns the value as a double.

Parameters
defDefault value. Is returned if the value can't be represented as double.
Returns
Value as double
int Radiant::Variant::getDoubles ( double *  target,
int  n 
)

Reads an array of doubles from the value.

Parameters
[out]targetArray where the doubles are stored
nMaximum number of doubles to be read
Returns
Number of doubles read
float Radiant::Variant::getFloat ( float  def = 0.f) const

Returns the value as a float.

Parameters
defDefault value. Is returned if the value can't be represented as float.
Returns
Value as float
int Radiant::Variant::getFloats ( float *  target,
int  n 
)

Reads an array of floats from the value.

Parameters
[out]targetArray where the floats are stored
nMaximum number of floats to be read
Returns
Number of floats read
uint64_t Radiant::Variant::getFromHex64 ( uint64_t  def = 0) const

Returns the value as unsigned 64 bit integer (interpreted as hexadecimal)

Parameters
defDefault value. Is returned if the value can't be represented as 64bit unsigned.
Returns
Value as 64bit unsigned
int Radiant::Variant::getInt ( int  def = 0) const

Returns the value as int.

Parameters
defDefault value. Is returned if the value can't be represented as integer.
Returns
Value as integer
int Radiant::Variant::getInts ( int *  target,
int  n 
)

Reads an array of integers from the value.

Parameters
[out]targetArray where the integers are stored
nMaximum number of integers to be read
Returns
Number of integers read
const QString& Radiant::Variant::getString ( const QString &  def) const

Returns the value as string or the given default value if the value has not been set.

Parameters
defDefault value. Is returned if the value is not yet set.
Returns
Value as string
const QString& Radiant::Variant::getString ( ) const

Returns the value as string.

Returns
Value as a string. Empty string if not set
bool Radiant::Variant::hasDocumentation ( ) const

Returns true if the variable has been documented.

Returns
True if the variable has documentation ie. is not empty
bool Radiant::Variant::isEmpty ( ) const

Returns true if the value has not been set.

Returns
True if value is not set ie. it is empty.
Radiant::Variant::operator const QString & ( ) const

Returns the value as string.

Returns
Value as a string
Radiant::Variant::operator double ( ) const

Returns the value as double.

Returns
Value as double. Zero if value could not represented as integer
Radiant::Variant::operator int ( ) const

Returns the value as integer.

Returns
Value as integer. Zero if value could not represented as integer
void Radiant::Variant::set ( const QString &  s)

Sets the value.

Parameters
sValue to set