Variant class which is used to wrap values in the Ponder system.
More...
#include <value.hpp>
|
| 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 > |
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...
|
|
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.
bool b = v1;
float f = v3;
MyObject o = v4;
It also supports unary and binary visitation for type-safe processing depending on the stored type.
- See also
- ValueVisitor, ponder_ext::ValueMapper
◆ Value() [1/3]
template<typename T >
ponder::Value::Value |
( |
const T & |
val | ) |
|
Construct the value from a variable of type T.
- Parameters
-
◆ Value() [2/3]
ponder::Value::Value |
( |
const Value & |
other | ) |
|
Copy constructor.
- Parameters
-
◆ Value() [3/3]
ponder::Value::Value |
( |
Value && |
other | ) |
|
Move constructor.
- Parameters
-
◆ 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()
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
-
other | Value 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
-
other | Value to compare with this |
- Returns
- True if this <= other
◆ operator=()
void ponder::Value::operator= |
( |
const Value & |
other | ) |
|
Assignment operator.
- Parameters
-
other | Value 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
-
other | Value 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
-
other | Value 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
-
other | Value 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
-
BadType | the stored value is not convertible to T |
◆ visit() [1/2]
template<typename T >
T::result_type ponder::Value::visit |
( |
T |
visitor | ) |
const |
Visit the value with a unary visitor.
Using this function allows to dispatch an operation depending on the stored type.
- Parameters
-
visitor | Visitor 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 |
( |
T |
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
-
visitor | Visitor to apply (must inherit from ValueVisitor<type_to_return>) |
other | Other value to visit |
- Returns
- Value returned by the visitor
The documentation for this class was generated from the following file: