lua::var Class Reference

Base type : untyped variable. More...

#include <luapp_var.hpp>

List of all members.

Public Member Functions

 var ()
 Default constructor.
template<class T >
 var (const T &mValue)
 Value assignment constructor.
 var (const var &mVar)
 Copy constructor.
varoperator= (const var &mVar)
bool operator== (const var &mVar) const
bool operator!= (const var &mVar)
void swap (var &mVar)
 Swaps this value with another.
template<class T >
const T get () const
 Returns the contained value.
bool is_empty () const
 Checks if this variable is empty.
const var_typeget_type () const
 Returns the type of the contained value.
template<class T >
bool is_of_type () const
 Checks the contained value's type.
std::string to_string () const
 Converts this variable to a string.

Static Public Attributes

static const var_typeVALUE_NONE = typeid(void)
static const var_typeVALUE_INT = typeid(int)
static const var_typeVALUE_UINT = typeid(uint)
static const var_typeVALUE_FLOAT = typeid(float)
static const var_typeVALUE_DOUBLE = typeid(double)
static const var_typeVALUE_BOOL = typeid(bool)
static const var_typeVALUE_STRING = typeid(std::string)
static const var_typeVALUE_POINTER = typeid(void*)

Private Attributes

utils::refptr< value_base > pValue_

Detailed Description

Base type : untyped variable.

The purpose of this class is to have an untyped return value / argument. It allows simple manipulation of events, and a lot of other things.

It uses a little bit more memory than a simple object :
sizeof(void*) + sizeof(T)
... and has the overhead of using the v-table (because of inheritance). At last, var does a dynamic_cast (which is not the fastest thing in the world) each time you call get().
So this class is definatly slower than base types : use it wisely.

Note:
This class is highly inspired from boost::any.

Definition at line 25 of file luapp_var.hpp.


Constructor & Destructor Documentation

lua::var::var (  ) 

Default constructor.

Definition at line 15 of file luapp_var.cpp.

template<class T >
lua::var::var ( const T &  mValue  )  [inline]

Value assignment constructor.

Parameters:
mValue The value to assign

Definition at line 36 of file luapp_var.hpp.

lua::var::var ( const var mVar  ) 

Copy constructor.

Parameters:
mVar The var to copy

Definition at line 19 of file luapp_var.cpp.


Member Function Documentation

template<class T >
const T lua::var::get (  )  const [inline]

Returns the contained value.

Returns:
The contained value
Note:
If the provided type doesn't match the contained value's, a Warning is printed in the log, and this function returns a default value.

Definition at line 62 of file luapp_var.hpp.

const var_type & lua::var::get_type (  )  const

Returns the type of the contained value.

Returns:
The type of the contained value
Note:
Returns typeid(void) if the variable is empty.

Definition at line 96 of file luapp_var.cpp.

bool lua::var::is_empty (  )  const

Checks if this variable is empty.

Returns:
'true' if this variable is empty
Note:
Only the default constructor of var returns an empty variable.

Definition at line 90 of file luapp_var.cpp.

template<class T >
bool lua::var::is_of_type (  )  const [inline]

Checks the contained value's type.

Returns:
'true' if the contained value's type is the one you provided

Definition at line 100 of file luapp_var.hpp.

bool lua::var::operator!= ( const var mVar  ) 

Definition at line 80 of file luapp_var.cpp.

var & lua::var::operator= ( const var mVar  ) 

Definition at line 23 of file luapp_var.cpp.

bool lua::var::operator== ( const var mVar  )  const

Definition at line 33 of file luapp_var.cpp.

void lua::var::swap ( var mVar  ) 

Swaps this value with another.

Parameters:
mVar the value to swap with this one

Definition at line 85 of file luapp_var.cpp.

std::string lua::var::to_string (  )  const

Converts this variable to a string.

Returns:
This variable converted to a string

Definition at line 108 of file luapp_var.cpp.


Member Data Documentation

utils::refptr<value_base> lua::var::pValue_ [private]

Definition at line 173 of file luapp_var.hpp.

const var_type & lua::var::VALUE_BOOL = typeid(bool) [static]

Definition at line 122 of file luapp_var.hpp.

const var_type & lua::var::VALUE_DOUBLE = typeid(double) [static]

Definition at line 121 of file luapp_var.hpp.

const var_type & lua::var::VALUE_FLOAT = typeid(float) [static]

Definition at line 120 of file luapp_var.hpp.

const var_type & lua::var::VALUE_INT = typeid(int) [static]

Definition at line 118 of file luapp_var.hpp.

const var_type & lua::var::VALUE_NONE = typeid(void) [static]

Definition at line 117 of file luapp_var.hpp.

const var_type & lua::var::VALUE_POINTER = typeid(void*) [static]

Definition at line 124 of file luapp_var.hpp.

const var_type & lua::var::VALUE_STRING = typeid(std::string) [static]

Definition at line 123 of file luapp_var.hpp.

const var_type & lua::var::VALUE_UINT = typeid(uint) [static]

Definition at line 119 of file luapp_var.hpp.


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

Generated on Sun Apr 29 19:27:31 2012 for lua++ by  doxygen 1.6.1