ponder 3.2
C++ reflection library
ponder::Value Class Reference

Variant class which is used to wrap values in the Ponder system. More...

#include <value.hpp>

Public Member Functions

 Value ()
 Default constructor, constructs a null value.
 
template<typename T >
 Value (const T &val)
 Construct the value from a variable of type T. More...
 
 Value (const Value &other)
 Copy constructor. More...
 
 Value (Value &&other)
 Move constructor. More...
 
void operator= (const Value &other)
 Assignment operator. More...
 
ValueKind kind () const
 Return the Ponder runtime kind of the value. More...
 
template<typename T >
to () const
 Convert the value to the type T. More...
 
template<typename T >
T & ref ()
 Get a reference to the value data contained. More...
 
template<typename T >
const T & cref () const
 Get a const reference to the value data contained. More...
 
template<typename T >
bool isCompatible () const
 Check if the stored value can be converted to a type T. More...
 
template<typename T >
T::result_type visit (T visitor) const
 Visit the value with a unary visitor. More...
 
template<typename T >
T::result_type visit (T visitor, const Value &other) const
 Visit the value and another one with a binary visitor. More...
 
bool operator== (const Value &other) const
 Operator == to compare equality between two values. More...
 
bool operator!= (const Value &other) const
 Operator != to compare equality between two values. More...
 
bool operator< (const Value &other) const
 Operator < to compare two values. More...
 
bool operator> (const Value &other) const
 Operator > to compare two values. More...
 
bool operator<= (const Value &other) const
 Operator <= to compare two values. More...
 
bool operator>= (const Value &other) const
 Operator >= to compare two values. More...
 

Static Public Attributes

static const Value nothing
 Special Value instance representing an empty value.
 

Detailed Description

Variant class which is used to wrap values in the Ponder system.

The Value class can store any type of variable, and supports conversion to any type compatible with the stored type.

ponder::Value v1 = true;
ponder::Value v2 = 10;
ponder::Value v3 = "24.5";
ponder::Value v4 = myObject;
bool b = v1; // b == true
String s = v2; // s == "10"
float f = v3; // f == 24.5
MyObject o = v4; // o == myObject

It also supports unary and binary visitation for type-safe processing depending on the stored type.

Remarks
The set of supported types can be extended by specializing the ponder_ext::ValueMapper template.
See also
ValueVisitor, ponder_ext::ValueMapper

Constructor & Destructor Documentation

◆ Value() [1/3]

template<typename T >
ponder::Value::Value ( const T &  val)

Construct the value from a variable of type T.

Parameters
valValue to store

◆ Value() [2/3]

ponder::Value::Value ( const Value other)

Copy constructor.

Parameters
otherValue to copy

◆ Value() [3/3]

ponder::Value::Value ( Value &&  other)

Move constructor.

Parameters
otherValue to move

Member Function Documentation

◆ cref()

template<typename T >
const T& ponder::Value::cref ( ) const

Get a const reference to the value data contained.

Get a const reference to the contained value of type T. The user is responsible for ensuring that the type passed is correct. See ref() for a const reference, or to() to convert the value.

Returns
A const reference to the contained data.

◆ isCompatible()

template<typename T >
bool ponder::Value::isCompatible ( ) const

Check if the stored value can be converted to a type T.

If this function returns true, then calling to<T>() or operator T() will succeed.

Returns
True if conversion is possible, false otherwise

◆ kind()

ValueKind ponder::Value::kind ( ) const

Return the Ponder runtime kind of the value.

Returns
Type of the value

◆ operator!=()

bool ponder::Value::operator!= ( const Value other) const
inline

Operator != to compare equality between two values.

See also
operator==
Returns
True if both values are not the same, false otherwise

◆ operator<()

bool ponder::Value::operator< ( const Value other) const

Operator < to compare two values.

Parameters
otherValue to compare with this
Returns
True if this < other

◆ operator<=()

bool ponder::Value::operator<= ( const Value other) const
inline

Operator <= to compare two values.

Parameters
otherValue to compare with this
Returns
True if this <= other

◆ operator=()

void ponder::Value::operator= ( const Value other)

Assignment operator.

Parameters
otherValue to assign to this

◆ operator==()

bool ponder::Value::operator== ( const Value other) const

Operator == to compare equality between two values.

Two values are equal if their Ponder type and value are equal. It uses the == operator of the stored type.

Parameters
otherValue to compare with this
Returns
True if both values are the same, false otherwise

◆ operator>()

bool ponder::Value::operator> ( const Value other) const
inline

Operator > to compare two values.

Parameters
otherValue to compare with this
Returns
True if this > other

◆ operator>=()

bool ponder::Value::operator>= ( const Value other) const
inline

Operator >= to compare two values.

Parameters
otherValue to compare with this
Returns
True if this >= other

◆ ref()

template<typename T >
T& ponder::Value::ref ( )

Get a reference to the value data contained.

Get a reference to the contained value of type T. The user is responsible for ensuring that the type passed is correct. See cref() for a non-const reference, or to() to convert the value.

Returns
A non-const reference to the contained data.

◆ to()

template<typename T >
T ponder::Value::to ( ) const

Convert the value to the type T.

Convert the value contained to the type provided. An exception is throw if the target type is not compatible. The value returned will be a copy. See ref() and cref() for referencing the internal data.

Returns
Value converted to T
Exceptions
BadTypethe stored value is not convertible to T

◆ visit() [1/2]

template<typename T >
T::result_type ponder::Value::visit ( visitor) const

Visit the value with a unary visitor.

Using this function allows to dispatch an operation depending on the stored type.

Parameters
visitorVisitor to apply (must inherit from ValueVisitor<type_to_return>)
Returns
Value returned by the visitor

◆ visit() [2/2]

template<typename T >
T::result_type ponder::Value::visit ( visitor,
const Value other 
) const

Visit the value and another one with a binary visitor.

Using this function allows to dispatch a binary operation depending on the stored type of both values.

Parameters
visitorVisitor to apply (must inherit from ValueVisitor<type_to_return>)
otherOther value to visit
Returns
Value returned by the visitor

The documentation for this class was generated from the following file:
ponder::ValueKind::String
@ String
String types (char*, ponder::String)
ponder::Value
Variant class which is used to wrap values in the Ponder system.
Definition: value.hpp:73