CoreComponents 3.0.0
A Modern C++ Toolkit
Loading...
Searching...
No Matches
Variant Class Reference

Duck-typed value. More...

#include <cc/Variant>

Public Member Functions

 Variant ()
 Create a variant without an value.
 
template<class T >
 Variant (T value)
 Create a variant with value.
 
 Variant (int value)
 Convenience function for calling Variant(long)
 
 Variant (float value)
 Convenience function for calling Variant(double)
 
 Variant (const char *value)
 Convenience function for calling Variant(const String &)
 
 Variant (std::initializer_list< const char * > values)
 Create a variant storing a list of strings.
 
 Variant (std::initializer_list< int > values)
 Create a variant storing a list of longs.
 
 Variant (std::initializer_list< long > values)
 Create a variant storing a list of longs.
 
 Variant (std::initializer_list< double > values)
 Create a variant storing a list of doubles.
 
 Variant (const Variant &b)
 Copy-constructor.
 
 Variant (Variant &&b)
 R-value constructor.
 
Variantoperator= (const Variant &b)
 Assignment operator.
 
Variantoperator= (Variant &&b)
 R-value assignment operator.
 
template<class T >
bool is () const
 Check if stored value is of type T.
 
template<class T >
to () const
 Retrieve stored value of type T.
 
template<class T >
 operator T () const
 Retrieve stored value of type T.
 
 operator String () const
 Stringify this variant.
 
bool sameTypeAs (const Variant &b) const
 Check if this variant is of the same type as variant b.
 
const char * typeName () const
 Get the type name of the store value.
 
Variant operator() (const String &key) const
 Convenience method to get the value of a member of this meta-object value.
 
Variantoperator() (const String &key)
 Convenience method to get/set the value of a member of this meta-object value.
 
Variant operator[] (long index) const
 Convenience method to get the child at index of this meta-object value.
 
long count () const
 Convenience method to get the number of children of this meta-object value.
 
bool operator== (const Variant &other) const
 Compare for equality with b.
 
bool operator== (const char *other) const
 Compare for equality with b.
 
std::strong_ordering operator<=> (const Variant &other) const
 Ordering operator.
 

Static Public Member Functions

static Variant read (const String &s)
 Automatically sense type and read value from string s.
 

Detailed Description

Duck-typed value.

Todo

provide iterator for child iteration

introduce VariantTypeMismatch debug exception

Constructor & Destructor Documentation

◆ Variant() [1/11]

Variant ( )

Create a variant without an value.

◆ Variant() [2/11]

template<class T >
Variant ( T value)

Create a variant with value.

◆ Variant() [3/11]

Variant ( int value)

Convenience function for calling Variant(long)

◆ Variant() [4/11]

Variant ( float value)

Convenience function for calling Variant(double)

◆ Variant() [5/11]

Variant ( const char * value)

Convenience function for calling Variant(const String &)

◆ Variant() [6/11]

Variant ( std::initializer_list< const char * > values)

Create a variant storing a list of strings.

◆ Variant() [7/11]

Variant ( std::initializer_list< int > values)

Create a variant storing a list of longs.

◆ Variant() [8/11]

Variant ( std::initializer_list< long > values)

Create a variant storing a list of longs.

◆ Variant() [9/11]

Variant ( std::initializer_list< double > values)

Create a variant storing a list of doubles.

◆ Variant() [10/11]

Variant ( const Variant & b)

Copy-constructor.

◆ Variant() [11/11]

Variant ( Variant && b)

R-value constructor.

Member Function Documentation

◆ read()

Variant read ( const String & s)
static

Automatically sense type and read value from string s.

◆ operator=() [1/2]

Variant & operator= ( const Variant & b)

Assignment operator.

◆ operator=() [2/2]

Variant & operator= ( Variant && b)

R-value assignment operator.

◆ is()

template<class T >
bool is ( ) const

Check if stored value is of type T.

◆ to()

template<class T >
T to ( ) const

Retrieve stored value of type T.

Note
The type of the stored value must be exactly of type T.

◆ operator T()

template<class T >
operator T ( ) const
explicit

Retrieve stored value of type T.

Note
The type of the stored value must be exactly of type T.

◆ operator String()

operator String ( ) const

Stringify this variant.

◆ sameTypeAs()

bool sameTypeAs ( const Variant & b) const

Check if this variant is of the same type as variant b.

◆ typeName()

const char * typeName ( ) const

Get the type name of the store value.

◆ operator()() [1/2]

Variant operator() ( const String & key) const

Convenience method to get the value of a member of this meta-object value.

◆ operator()() [2/2]

Variant & operator() ( const String & key)

Convenience method to get/set the value of a member of this meta-object value.

◆ operator[]()

Variant operator[] ( long index) const

Convenience method to get the child at index of this meta-object value.

◆ count()

long count ( ) const

Convenience method to get the number of children of this meta-object value.

◆ operator==() [1/2]

bool operator== ( const Variant & other) const

Compare for equality with b.

◆ operator==() [2/2]

bool operator== ( const char * other) const

Compare for equality with b.

◆ operator<=>()

std::strong_ordering operator<=> ( const Variant & other) const

Ordering operator.