Clarisse 4.0 SP6 SDK  4.0.0.0.6
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
CoreVariant Class Reference

Public Types

enum  Type {
  TYPE_VOID,
  TYPE_BOOL,
  TYPE_LONG,
  TYPE_DOUBLE,
  TYPE_STRING,
  TYPE_POINTER,
  TYPE_CORE_BASE_OBJECT_PTR,
  TYPE_COUNT
}
 

Public Member Functions

 CoreVariant (const CoreVariant &src)
 
 CoreVariant (CoreVariant &&src) noexcept
 
 CoreVariant (bool value)
 
 CoreVariant (long value)
 
 CoreVariant (double value)
 
 CoreVariant (const CoreBasicString &value)
 
 CoreVariant (const char *value)
 
 CoreVariant (void *value)
 
 CoreVariant (const CoreBaseObject *value)
 
 CoreVariant (int value)
 
 CoreVariant (unsigned int value)
 
 ~CoreVariant ()
 
size_t get_memory_size () const
 
const Type & get_type () const
 
 operator bool () const
 
 operator long () const
 
 operator double () const
 
 operator CoreString () const
 
 operator void * () const
 
 operator const CoreBaseObject * () const
 
 operator CoreBaseObject * () const
 
CoreVariantoperator= (const CoreVariant &value)
 
CoreVariantoperator= (CoreVariant &&value) noexcept
 
CoreVariantoperator= (bool value)
 
CoreVariantoperator= (long value)
 
CoreVariantoperator= (double value)
 
CoreVariantoperator= (const CoreBasicString &value)
 
CoreVariantoperator= (void *value)
 
CoreVariantoperator= (const CoreBaseObject *value)
 
bool operator== (const CoreVariant &other) const
 
bool operator!= (const CoreVariant &other) const
 

Static Public Member Functions

static CoreString get_type_name (const Type &type)
 

Static Public Attributes

static CoreVariant null_value
 

Detailed Description

Variant class. Note that due to legacy, all its constructors, assignment operators and cast operators are implicit. This can lead to some nasty bug, so be careful when using them. For instance:

CoreVariant string("hello");
string = "world";
printf("%s\n", static_cast<CoreString>(string).get_data());
// 1

This is because CoreVariant doesn't have an assignment operator which takes a const char * right value, so the compiler will cast the string literal to a CoreVariant. And CoreVariant(bool) is perfectly valid, so some compilers will use this one, resulting in not quite what you expected (the CoreVariant is of type bool, and when you want to get the string value, the boolean value is converted to a string, resulting in either "1" or "0"...)

To fix this specific bug, for the compiler to use the correct operator:

CoreVariant string("hello");
string = CoreVariant("world");

At some point, we'll have to refactor this, but it would break quite a lot of code, so in the meantime, use with care and when in doubt, don't rely on implicit operators/constructors.

Constructor & Destructor Documentation

CoreVariant::CoreVariant ( int  value)
inlineexplicit

Constructor from an int value

CoreVariant::CoreVariant ( unsigned int  value)
inlineexplicit

Constructor from an unsigned int value

CoreVariant::~CoreVariant ( )
inline

Destructor

Member Function Documentation

size_t CoreVariant::get_memory_size ( void  ) const
inline

Get the runtime size for this variant

const CoreVariant::Type & CoreVariant::get_type ( ) const
inline

Get the type of the value currently stored

bool CoreVariant::operator!= ( const CoreVariant other) const
inline

Inequality operator.

bool CoreVariant::operator== ( const CoreVariant other) const
inline

Strict equality operator. This will check the type and the value of the variants.