Clarisse 5.0 SP8 SDK  5.0.5.8.0
 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 = 0,
  TYPE_BOOL,
  TYPE_LONG,
  TYPE_DOUBLE,
  TYPE_STRING,
  TYPE_POINTER,
  TYPE_CORE_BASE_OBJECT_PTR,
  TYPE_COUNT
}
 The type of the data. More...
 

Public Member Functions

 CoreVariant (void)
 
 CoreVariant (const CoreVariant &src)
 
 CoreVariant (CoreVariant &&src) noexcept
 
 CoreVariant (bool value)
 
 CoreVariant (long value)
 
 CoreVariant (int value)
 
 CoreVariant (double value)
 
 CoreVariant (unsigned int value)
 
 CoreVariant (const void *value)
 
 CoreVariant (const CoreBaseObject *value)
 
 CoreVariant (const char *value)
 
 CoreVariant (const CoreBasicString &value)
 
 CoreVariant (CoreString &&value)
 
 ~CoreVariant ()
 
size_t get_memory_size () const
 
Type get_type () const
 
 operator bool () const
 
 operator int () const
 
 operator long () const
 
 operator float () const
 
 operator double () const
 
 operator CoreString () const
 
 operator void * () const
 
 operator CoreBaseObject * () const
 
bool to_bool (void) const
 Get the value as a bool. This will convert all types.
 
long to_long (void) const
 Get the value as a long. This will convert all types.
 
double to_double (void) const
 Get the value as a double. This will convert all types.
 
CoreString to_string (void) const
 Get the value as a string. This will convert all types.
 
void * to_pointer (void) const
 
CoreBaseObjectto_object (void) 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.

Member Enumeration Documentation

The type of the data.

Enumerator:
TYPE_VOID 

empty (no value)

TYPE_BOOL 

boolean

TYPE_LONG 

integer

TYPE_DOUBLE 

floating point

TYPE_STRING 

CoreString.

TYPE_POINTER 

void pointer

TYPE_CORE_BASE_OBJECT_PTR 

CoreBaseObject pointer.

TYPE_COUNT 

number of entries in this enum

Constructor & Destructor Documentation

CoreVariant::CoreVariant ( void  )
inline

Empty constructor

CoreVariant::CoreVariant ( const CoreVariant src)
inline

Copy constructor

CoreVariant::CoreVariant ( CoreVariant &&  src)
inlinenoexcept

Move constructor

CoreVariant::CoreVariant ( bool  value)
inline

Boolean constructor

CoreVariant::CoreVariant ( long  value)
inline

Integer constructor

CoreVariant::CoreVariant ( int  value)
inline

Constructor from an int value

CoreVariant::CoreVariant ( double  value)
inline

Floating point constructor

CoreVariant::CoreVariant ( unsigned int  value)
inline

Constructor from an unsigned int value

CoreVariant::CoreVariant ( const void *  value)
inline

void pointer constructor

CoreVariant::CoreVariant ( const CoreBaseObject value)
inline

CoreBaseObject pointer constructor

CoreVariant::CoreVariant ( const char *  value)
inline

C-style string constructor

CoreVariant::CoreVariant ( const CoreBasicString value)
inline

CoreString constructor

CoreVariant::CoreVariant ( CoreString &&  value)
inline

Construct from an rvalue string

CoreVariant::~CoreVariant ( )
inline

Destructor

Member Function Documentation

size_t CoreVariant::get_memory_size ( void  ) const
inline

Get the runtime size for this variant

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.

CoreBaseObject * CoreVariant::to_object ( void  ) const
inline

Get the value as a CoreBaseObject pointer. This one is strict and will only return a value for TYPE_CORE_BASE_OBJECT_PTR. For any other type, returns nullptr.

void * CoreVariant::to_pointer ( void  ) const
inline

Get the value as a void pointer. This one is strict and will only return a value for TYPE_POINTER. For any other type, returns nullptr.