ponder 3.2
C++ reflection library
ponder::ValueVisitor< T > Class Template Reference

Base class for writing custom Value visitors. More...

#include <valuevisitor.hpp>

Public Types

using result_type = T
 Type of value visited.
 

Detailed Description

template<typename T = void>
class ponder::ValueVisitor< T >

Base class for writing custom Value visitors.

A value visitor acts like compile-time dispatchers which automatically calls the function which matches the actual type of the stored value. This is a more direct and straight-forward approach than using a runtime switch, based on value.kind() and then converting to the proper type. It also gives access to enum and user objects, which can give useful informations with no knowledge about the actual C++ class or enum.

The template parameter T is the type returned by the visitor.

To handle one of the possible types of the value, just write the corresponding operator() function. Here is the list of the mapping between Ponder types and their corresponding C++ types:

Here an example of a unary visitor which creates an editor for the value based on its type

struct EditorFactory : public ValueVisitor<PropertyEditor*>
{
PropertyEditor* operator()(bool value)
{
return new BooleanEditor(value);
}
PropertyEditor* operator()(long value)
{
return new IntegerEditor(value);
}
PropertyEditor* operator()(double value)
{
return new RealEditor(value);
}
PropertyEditor* operator()(IdRef value)
{
return new StringEditor(value);
}
PropertyEditor* operator()(const ponder::EnumObject& value)
{
return new EnumEditor(value);
}
PropertyEditor* operator()(const ponder::UserObject& value)
{
return new UserEditor(value);
}
};
ponder::Value value(5.4);
PropertyEditor* editor = value.visit(EditorFactory());

The documentation for this class was generated from the following file:
ponder::Value
Variant class which is used to wrap values in the Ponder system.
Definition: value.hpp:73
ponder::UserObject
Wrapper to manipulate user objects in the Ponder system.
Definition: userobject.hpp:62
ponder::EnumObject
Wrapper to manipulate enumerated values in the Ponder system.
Definition: enumobject.hpp:48