util::variant Class Reference

A type that can store any numeric/string value and convert between them. More...

#include <util.hpp>

List of all members.

Public Member Functions

 variant ()
 Initialize the variant to an integer with the value 0.
 variant (int)
 Initialize the variant to an integer with the specified value.
 variant (double)
 Initialize the variant to a float with the specified value.
 variant (const std::string &)
 Initialize the variant to a string with the specified value.
variantoperator= (int)
 Set the value to an integer.
variantoperator= (double)
 Set the value to a float.
variantoperator= (const std::string &)
 Set the value to a string.
 operator int ()
 Return the value as an integer, casting if neccessary.
 operator double ()
 Return the value as a float, casting if neccessary.
 operator std::string ()
 Return the value as a string, casting if neccessary.

Protected Types

enum  var_type { type_int, type_float, type_string }

Protected Member Functions

int GetInt ()
 Return the value as an integer, casting if neccessary.
double GetFloat ()
 Return the value as a float, casting if neccessary.
std::string GetString ()
 Return the value as a string, casting if neccessary.
variantSetInt (int)
 Set the value to an integer.
variantSetFloat (double)
 Set the value to a float.
variantSetString (const std::string &)
 Set the value to a string.
int int_length (int)
 Helper function that returns the string length of a number in decimal format.

Protected Attributes

union {
   int   val_int
 Value stored as an integer.
   double   val_float
 Value stored as a float.
}; 
 Integer and float values are a union to save on a few bytes of memory.
std::string val_string
 Value stored as a string.
int type
 Current type the value is stored as.


Detailed Description

A type that can store any numeric/string value and convert between them.

It takes way too much effort to use, so it's only used by the Config class.


Member Enumeration Documentation

enum util::variant::var_type [protected]

Enumerator:
type_int 
type_float 
type_string 


Constructor & Destructor Documentation

util::variant::variant (  ) 

Initialize the variant to an integer with the value 0.

util::variant::variant ( int  i  ) 

Initialize the variant to an integer with the specified value.

util::variant::variant ( double  d  ) 

Initialize the variant to a float with the specified value.

util::variant::variant ( const std::string &  s  ) 

Initialize the variant to a string with the specified value.


Member Function Documentation

int util::variant::GetInt (  )  [protected]

Return the value as an integer, casting if neccessary.

double util::variant::GetFloat (  )  [protected]

Return the value as a float, casting if neccessary.

std::string util::variant::GetString (  )  [protected]

Return the value as a string, casting if neccessary.

variant & util::variant::SetInt ( int  i  )  [protected]

Set the value to an integer.

variant & util::variant::SetFloat ( double  d  )  [protected]

Set the value to a float.

variant & util::variant::SetString ( const std::string &  s  )  [protected]

Set the value to a string.

int util::variant::int_length ( int  x  )  [protected]

Helper function that returns the string length of a number in decimal format.

variant & util::variant::operator= ( int  i  ) 

Set the value to an integer.

variant & util::variant::operator= ( double  d  ) 

Set the value to a float.

variant & util::variant::operator= ( const std::string &  s  ) 

Set the value to a string.

util::variant::operator int (  ) 

Return the value as an integer, casting if neccessary.

util::variant::operator double (  ) 

Return the value as a float, casting if neccessary.

util::variant::operator std::string (  ) 

Return the value as a string, casting if neccessary.


Member Data Documentation

Value stored as an integer.

Value stored as a float.

union { ... } [protected]

Integer and float values are a union to save on a few bytes of memory.

std::string util::variant::val_string [protected]

Value stored as a string.

int util::variant::type [protected]

Current type the value is stored as.

Accessing as this type will need no conversion.


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

Generated on Sun Apr 5 20:28:35 2009 for EOServ by  doxygen 1.5.7.1