ponder 3.2
C++ reflection library
ponder_ext::ValueMapper Class Reference

Template providing a mapping between C++ types/values and Ponder types/values. More...

#include <valuemapper.hpp>

Detailed Description

Template providing a mapping between C++ types/values and Ponder types/values.

ValueMapper<T> defines a mapping to and from type T to a Value. It defines three things in order to make T fully compliant with the system:

  • The abstract Ponder type that T is mapped to
  • A function to convert from T to the mapped Ponder type
  • A function to convert from all supported Ponder types to T

Pseudo-code:

template <> struct ValueMapper<TypeSpecialised>
{
static PonderValueKind to(ValueKind value) { return convertToPonderType(value); }
static TypeSpecialised from(PonderValueKind pv) { return convertPonderToType(pc); }
};

ValueMapper is specialized for every supported type, and can be specialized for any of your own types in order to extend the system.

Here is an example of mapping for a custom string class:

namespace ponder_ext
{
template <>
struct ValueMapper<MyStringClass>
{
// The corresponding Ponder type is "string"
// Convert from MyStringClass to ponder::String
static ponder::String to(const MyStringClass& source)
{
return source.to_std_string();
}
// Convert from any type to MyStringClass
// Be smart, just reuse ValueMapper<ponder::String> :)
template <typename T>
static MyStringClass from(const T& source)
{
return MyStringClass(ValueMapper<ponder::String>::from(source));
}
};
}

Generic version of ValueMapper – T doesn't match with any specialization and is thus treated as a user object


The documentation for this class was generated from the following file:
ponder::ValueKind::String
@ String
String types (char*, ponder::String)
ponder::ValueKind
ValueKind
Enumeration of abstract value types supported by Ponder Values.
Definition: type.hpp:70
ponder_ext
Ponder user extendable namespace.
Definition: arraymapper.hpp:38