Orxonox  0.0.5 Codename: Arcturus
Classes | Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
orxonox::MultiType Class Reference

The MultiType can hold a value of many possible types and convert them to other types. More...

#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/libraries/util/MultiType.h>

Classes

class  MT_ValueBase
 MT_ValueBase is an almost pure virtual baseclass of MT_Value<T>, which holds the value of the MultiType. More...
 

Public Member Functions

 MultiType ()
 Default constructor: Assigns no value and no type. The type will be determined by the first assignment of a value. More...
 
template<typename V >
 MultiType (const V &value)
 Constructor: Assigns the given value and sets the type. More...
 
 MultiType (const MultiType &other)
 Copyconstructor: Assigns value and type of the other MultiType. More...
 
 MultiType (MultiType &&other)
 Moveconstructor: Moves the value and its type from the other MultiType. More...
 
 ~MultiType ()
 Destructor: Deletes the MT_Value. More...
 
template<typename T >
bool convert ()
 Converts the current value to type T. More...
 
template<>
bool convert ()
 
void copy (const MultiType &other)
 Copies the other MultiType by assigning value and type. More...
 
template<>
void createNewValueContainer (const char &value)
 
template<>
void createNewValueContainer (const unsigned char &value)
 
template<>
void createNewValueContainer (const short &value)
 
template<>
void createNewValueContainer (const unsigned short &value)
 
template<>
void createNewValueContainer (const int &value)
 
template<>
void createNewValueContainer (const unsigned int &value)
 
template<>
void createNewValueContainer (const long &value)
 
template<>
void createNewValueContainer (const unsigned long &value)
 
template<>
void createNewValueContainer (const long long &value)
 
template<>
void createNewValueContainer (const unsigned long long &value)
 
template<>
void createNewValueContainer (const float &value)
 
template<>
void createNewValueContainer (const double &value)
 
template<>
void createNewValueContainer (const long double &value)
 
template<>
void createNewValueContainer (const bool &value)
 
template<>
void createNewValueContainer (void *const &value)
 
template<>
void createNewValueContainer (const std::string &value)
 
template<>
void createNewValueContainer (const orxonox::Vector2 &value)
 
template<>
void createNewValueContainer (const orxonox::Vector3 &value)
 
template<>
void createNewValueContainer (const orxonox::Vector4 &value)
 
template<>
void createNewValueContainer (const orxonox::ColourValue &value)
 
template<>
void createNewValueContainer (const orxonox::Quaternion &value)
 
template<>
void createNewValueContainer (const orxonox::Radian &value)
 
template<>
void createNewValueContainer (const orxonox::Degree &value)
 
template<>
_UtilExport void createNewValueContainer (const char &value)
 
template<>
_UtilExport void createNewValueContainer (const unsigned char &value)
 
template<>
_UtilExport void createNewValueContainer (const short &value)
 
template<>
_UtilExport void createNewValueContainer (const unsigned short &value)
 
template<>
_UtilExport void createNewValueContainer (const int &value)
 
template<>
_UtilExport void createNewValueContainer (const unsigned int &value)
 
template<>
_UtilExport void createNewValueContainer (const long &value)
 
template<>
_UtilExport void createNewValueContainer (const unsigned long &value)
 
template<>
_UtilExport void createNewValueContainer (const long long &value)
 
template<>
_UtilExport void createNewValueContainer (const unsigned long long &value)
 
template<>
_UtilExport void createNewValueContainer (const float &value)
 
template<>
_UtilExport void createNewValueContainer (const double &value)
 
template<>
_UtilExport void createNewValueContainer (const bool &value)
 
template<>
_UtilExport void createNewValueContainer (const long double &value)
 
template<>
_UtilExport void createNewValueContainer (void *const &value)
 
template<>
_UtilExport void createNewValueContainer (const std::string &value)
 
template<>
_UtilExport void createNewValueContainer (const orxonox::Vector2 &value)
 
template<>
_UtilExport void createNewValueContainer (const orxonox::Vector3 &value)
 
template<>
_UtilExport void createNewValueContainer (const orxonox::Vector4 &value)
 
template<>
_UtilExport void createNewValueContainer (const orxonox::ColourValue &value)
 
template<>
_UtilExport void createNewValueContainer (const orxonox::Quaternion &value)
 
template<>
_UtilExport void createNewValueContainer (const orxonox::Radian &value)
 
template<>
_UtilExport void createNewValueContainer (const orxonox::Degree &value)
 
void exportData (uint8_t *&mem) const
 Saves the value of the MT to a bytestream (pointed at by mem) and increases mem pointer by size of MT. More...
 
template<typename T , typename V >
bool force (const V &value)
 Changes the type to T and assigns the new value (which might be of another type than T - it gets converted). More...
 
template<typename T >
std::enable_if<!std::is_pointer< T >::value, T >::type get () const
 Returns the current value, converted to the requested type. More...
 
template<typename T >
std::enable_if< std::is_pointer< T >::value, T >::type get () const
 Returns the current value, converted to a pointer of the requested type. More...
 
uint32_t getNetworkSize () const
 
std::string getTypename () const
 Returns the name of the current type. More...
 
template<typename T >
bool getValue (T *value) const
 Assigns the value to the given pointer. The value gets converted if the types don't match. More...
 
void importData (uint8_t *&mem)
 Loads the value of the MT from a bytestream (pointed at by mem) and increases mem pointer by size of MT. More...
 
template<typename T >
bool isType () const
 Returns true if the type of the current value is T. More...
 
template<>
bool isType () const
 
bool lastConversionSuccessful () const
 Checks whether the last conversion was successful. More...
 
bool null () const
 Checks if the MT contains no value. More...
 
template<class T >
 operator T () const
 Conversion operator for all types. More...
 
uint8_t *& operator<< (uint8_t *&mem)
 Saves the value of the MT to a bytestream and increases pointer to bytestream by size of MT. More...
 
template<typename V >
MultiTypeoperator= (const V &value)
 Assigns a new value. The value will be converted to the current type of the MultiType. More...
 
template<typename V >
MultiTypeoperator= (V *value)
 Assigns a pointer. More...
 
MultiTypeoperator= (const MultiType &other)
 Assigns the value of the other MultiType and converts it to the current type of the MultiType. More...
 
MultiTypeoperator= (MultiType &&other)
 Moves the value and the type of the other MultiType to this one. More...
 
void operator>> (uint8_t *&mem) const
 Loads the value of the MT to a bytestream and increases pointer to bytestream by size of MT. More...
 
void reset ()
 Resets value and type. Type will be void afterwards and null() returns true. More...
 
template<typename T >
void reset ()
 Resets the value and changes the internal type to T. More...
 
void resetValue ()
 Current value gets overridden with default zero value. More...
 
template<typename V >
bool set (const V &value)
 Assigns the given value and converts it to the current type. More...
 
template<typename V >
bool set (V *value)
 Assigns a pointer. More...
 
bool set (const MultiType &other)
 Assigns the value of the other MultiType and converts it to the current type. More...
 
template<>
bool set (const char *value)
 
template<>
bool set (const mbool &value)
 

Static Public Attributes

static const MultiType Null
 

Private Types

enum  Type : uint8_t {
  Type::Null, Type::Char, Type::UnsignedChar, Type::Short,
  Type::UnsignedShort, Type::Int, Type::UnsignedInt, Type::Long,
  Type::UnsignedLong, Type::LongLong, Type::UnsignedLongLong, Type::Float,
  Type::Double, Type::LongDouble, Type::Bool, Type::VoidPointer,
  Type::String, Type::Vector2, Type::Vector3, Type::Vector4,
  Type::ColourValue, Type::Quaternion, Type::Radian, Type::Degree
}
 Enum of all possible types of a MultiType. More...
 

Private Member Functions

template<typename T >
void assignValue (const T &value)
 Assigns a new value by changing type and creating a new container. More...
 
template<typename T >
void assignValue (T *const &value)
 Assigns a new value by changing type and creating a new container (overload for pointers). More...
 
template<typename T >
void changeValueContainer (const T &value)
 Changes the value container. More...
 
bool convert (Type type)
 Converts the current value to the given type. More...
 
template<typename T >
std::enable_if<!std::is_enum< T >::value >::type createNewValueContainer (const T &value)
 Creates a new value container (works only with specialized types). More...
 
template<typename T >
std::enable_if< std::is_enum< T >::value >::type createNewValueContainer (const T &value)
 Creates a new value container (implementation for enum classes that must be cast to the underlying type). More...
 
Type getType () const
 Returns the current type. More...
 
void setType (Type type)
 Resets the value and changes the internal type to the given type. More...
 

Private Attributes

MT_ValueBasevalue_
 A pointer to the value container. More...
 

Friends

template<typename T >
class MT_Value
 
_UtilExport friend std::ostream & operator<< (std::ostream &outstream, const MultiType &mt)
 Puts the MultiType on a stream by using the native << operator of the current type. More...
 

Detailed Description

The MultiType can hold a value of many possible types and convert them to other types.

The following types are supported by the MultiType:

For more information and some examples see the description here.

See also
MultiType.h

Member Enumeration Documentation

enum orxonox::MultiType::Type : uint8_t
strongprivate

Enum of all possible types of a MultiType.

Enumerator
Null 
Char 
UnsignedChar 
Short 
UnsignedShort 
Int 
UnsignedInt 
Long 
UnsignedLong 
LongLong 
UnsignedLongLong 
Float 
Double 
LongDouble 
Bool 
VoidPointer 
String 
Vector2 
Vector3 
Vector4 
ColourValue 
Quaternion 
Radian 
Degree 

Constructor & Destructor Documentation

orxonox::MultiType::MultiType ( )
inline

Default constructor: Assigns no value and no type. The type will be determined by the first assignment of a value.

template<typename V >
orxonox::MultiType::MultiType ( const V &  value)
inline

Constructor: Assigns the given value and sets the type.

orxonox::MultiType::MultiType ( const MultiType other)
inline

Copyconstructor: Assigns value and type of the other MultiType.

orxonox::MultiType::MultiType ( MultiType &&  other)
inline

Moveconstructor: Moves the value and its type from the other MultiType.

orxonox::MultiType::~MultiType ( )
inline

Destructor: Deletes the MT_Value.

Member Function Documentation

template<typename T >
void orxonox::MultiType::assignValue ( const T &  value)
inlineprivate

Assigns a new value by changing type and creating a new container.

template<typename T >
void orxonox::MultiType::assignValue ( T *const &  value)
inlineprivate

Assigns a new value by changing type and creating a new container (overload for pointers).

template<typename T >
void orxonox::MultiType::changeValueContainer ( const T &  value)
inlineprivate

Changes the value container.

template<typename T >
bool orxonox::MultiType::convert ( )
inline

Converts the current value to type T.

bool orxonox::MultiType::convert ( Type  type)
private

Converts the current value to the given type.

Converts the current value of the MultiType to a new type.

Parameters
typeThe type
template<>
bool orxonox::MultiType::convert ( )
inline
void orxonox::MultiType::copy ( const MultiType other)
inline

Copies the other MultiType by assigning value and type.

template<>
void orxonox::MultiType::createNewValueContainer ( const char &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( const unsigned char &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( const short &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( const unsigned short &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( const int &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( const unsigned int &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( const long &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( const unsigned long &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( const long long &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( const unsigned long long &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( const float &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( const double &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( const long double &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( const bool &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( void *const &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( const std::string &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( const orxonox::Vector2 &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( const orxonox::Vector3 &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( const orxonox::Vector4 &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( const orxonox::ColourValue &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( const orxonox::Quaternion &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( const orxonox::Radian &  value)
template<>
void orxonox::MultiType::createNewValueContainer ( const orxonox::Degree &  value)
template<typename T >
std::enable_if<!std::is_enum<T>::value>::type orxonox::MultiType::createNewValueContainer ( const T &  value)
inlineprivate

Creates a new value container (works only with specialized types).

template<typename T >
std::enable_if<std::is_enum<T>::value>::type orxonox::MultiType::createNewValueContainer ( const T &  value)
inlineprivate

Creates a new value container (implementation for enum classes that must be cast to the underlying type).

template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const char &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const unsigned char &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const short &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const unsigned short &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const int &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const unsigned int &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const long &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const unsigned long &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const long long &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const unsigned long long &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const float &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const double &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const bool &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const long double &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( void *const &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const std::string &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const orxonox::Vector2 &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const orxonox::Vector3 &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const orxonox::Vector4 &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const orxonox::ColourValue &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const orxonox::Quaternion &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const orxonox::Radian &  value)
template<>
_UtilExport void orxonox::MultiType::createNewValueContainer ( const orxonox::Degree &  value)
void orxonox::MultiType::exportData ( uint8_t *&  mem) const
inline

Saves the value of the MT to a bytestream (pointed at by mem) and increases mem pointer by size of MT.

template<typename T , typename V >
bool orxonox::MultiType::force ( const V &  value)
inline

Changes the type to T and assigns the new value (which might be of another type than T - it gets converted).

template<typename T >
std::enable_if<!std::is_pointer<T>::value, T>::type orxonox::MultiType::get ( ) const
inline

Returns the current value, converted to the requested type.

template<typename T >
std::enable_if<std::is_pointer<T>::value, T>::type orxonox::MultiType::get ( ) const
inline

Returns the current value, converted to a pointer of the requested type.

uint32_t orxonox::MultiType::getNetworkSize ( ) const
inline
Type orxonox::MultiType::getType ( ) const
inlineprivate

Returns the current type.

std::string orxonox::MultiType::getTypename ( ) const

Returns the name of the current type.

Returns
The name
template<typename T >
bool orxonox::MultiType::getValue ( T *  value) const
inline

Assigns the value to the given pointer. The value gets converted if the types don't match.

void orxonox::MultiType::importData ( uint8_t *&  mem)
inline

Loads the value of the MT from a bytestream (pointed at by mem) and increases mem pointer by size of MT.

template<typename T >
bool orxonox::MultiType::isType ( ) const
inline

Returns true if the type of the current value is T.

template<>
bool orxonox::MultiType::isType ( ) const
inline
bool orxonox::MultiType::lastConversionSuccessful ( ) const
inline

Checks whether the last conversion was successful.

bool orxonox::MultiType::null ( ) const
inline

Checks if the MT contains no value.

template<class T >
orxonox::MultiType::operator T ( ) const
inline

Conversion operator for all types.

uint8_t*& orxonox::MultiType::operator<< ( uint8_t *&  mem)
inline

Saves the value of the MT to a bytestream and increases pointer to bytestream by size of MT.

template<typename V >
MultiType& orxonox::MultiType::operator= ( const V &  value)
inline

Assigns a new value. The value will be converted to the current type of the MultiType.

template<typename V >
MultiType& orxonox::MultiType::operator= ( V *  value)
inline

Assigns a pointer.

MultiType& orxonox::MultiType::operator= ( const MultiType other)
inline

Assigns the value of the other MultiType and converts it to the current type of the MultiType.

MultiType& orxonox::MultiType::operator= ( MultiType &&  other)
inline

Moves the value and the type of the other MultiType to this one.

void orxonox::MultiType::operator>> ( uint8_t *&  mem) const
inline

Loads the value of the MT to a bytestream and increases pointer to bytestream by size of MT.

void orxonox::MultiType::reset ( )
inline

Resets value and type. Type will be void afterwards and null() returns true.

template<typename T >
void orxonox::MultiType::reset ( )
inline

Resets the value and changes the internal type to T.

void orxonox::MultiType::resetValue ( )
inline

Current value gets overridden with default zero value.

template<typename V >
bool orxonox::MultiType::set ( const V &  value)
inline

Assigns the given value and converts it to the current type.

template<typename V >
bool orxonox::MultiType::set ( V *  value)
inline

Assigns a pointer.

bool orxonox::MultiType::set ( const MultiType other)
inline

Assigns the value of the other MultiType and converts it to the current type.

template<>
bool orxonox::MultiType::set ( const char *  value)
inline
template<>
bool orxonox::MultiType::set ( const mbool value)
inline
void orxonox::MultiType::setType ( Type  type)
inlineprivate

Resets the value and changes the internal type to the given type.

Friends And Related Function Documentation

template<typename T >
friend class MT_Value
friend
_UtilExport friend std::ostream& operator<< ( std::ostream &  outstream,
const MultiType mt 
)
friend

Puts the MultiType on a stream by using the native << operator of the current type.

Member Data Documentation

const MultiType orxonox::MultiType::Null
static
MT_ValueBase* orxonox::MultiType::value_
private

A pointer to the value container.


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