ponder
3.2
C++ reflection library
|
Proxy class which fills a metaclass with its members. More...
#include <classbuilder.hpp>
Public Member Functions | |
ClassBuilder (Class &target) | |
Construct the builder with a target metaclass to fill. More... | |
template<typename U > | |
ClassBuilder< T > & | base () |
Declare a base metaclass. More... | |
template<typename F > | |
ClassBuilder< T > & | property (IdRef name, F accessor) |
Declare a new property from a single accessor. More... | |
template<typename F1 , typename F2 > | |
ClassBuilder< T > & | property (IdRef name, F1 accessor1, F2 accessor2) |
Declare a new property from a pair of accessors. More... | |
template<typename F , typename... P> | |
ClassBuilder< T > & | function (IdRef name, F function, P... policies) |
Declare a new function from any bindable type. More... | |
template<typename... A> | |
ClassBuilder< T > & | constructor () |
Declare a constructor for the metaclass. More... | |
template<template< typename > class U> | |
ClassBuilder< T > & | external () |
Add properties and/or functions from an external source. More... | |
template<typename... U> | |
ClassBuilder< T > & | operator() (U &&... uds) |
Add user data to the last declared member type. More... | |
Proxy class which fills a metaclass with its members.
This class is returned by Class::declare<T> in order construct a new metaclass. It contains functions to declare and bind metaproperties, metafunctions, base metaclasses, metaconstructors, etc. with many overloads in order to accept as many types of binds as possible.
ClassBuilder also contains functions to set attributes of metafunctions and metaproperties.
This class should never be explicitely instantiated, unless you need to split the metaclass creation in multiple parts.
ponder::ClassBuilder< T >::ClassBuilder | ( | Class & | target | ) |
Construct the builder with a target metaclass to fill.
target | Metaclass to build |
Declare a base metaclass.
The template parameter U is the C++ base class of T.
This function makes the target metaclass inherit of all the metaproperties and metafunctions of the given base metaclass.
ClassNotFound | no metaclass is bound to U |
ClassBuilder<T>& ponder::ClassBuilder< T >::constructor | ( | ) |
Declare a constructor for the metaclass.
Variable number of parameters can be passed.
ClassBuilder<T>& ponder::ClassBuilder< T >::external | ( | ) |
Add properties and/or functions from an external source.
The purpose of this function is to allow the binding of classes that already use a similar system of metaproperties and metafunctions, with a direct mapping from external attributes to Ponder ones.
The mapping process must be done in a specific mapper class (see below), thus avoiding to manually write the mapping for every class.
The mapper class must accept a template parameter (which is the target C++ class) and be compatible with the following interface:
Example of usage:
ClassBuilder<T>& ponder::ClassBuilder< T >::function | ( | IdRef | name, |
F | function, | ||
P... | policies | ||
) |
Declare a new function from any bindable type.
The function parameter can be any valid type: a non-member function, member function, const, non-const, lambda, etc. Polices can be applied to the function to affect things like the way objects are returned. See ponder::policy.
name | Name of the function (must be unique within the metaclass) |
function | C++ callable entity to bind to the function |
policies | Optional policies applied to function exposer |
|
inline |
Add user data to the last declared member type.
ClassBuilder<T>& ponder::ClassBuilder< T >::property | ( | IdRef | name, |
F | accessor | ||
) |
Declare a new property from a single accessor.
The accessor parameter can be a getter of any valid type, or a direct pointer-to-member (which is considered both a getter and a setter)
Example:
name | Name of the property (must be unique within the metaclass) |
accessor | Accessor to the C++ implementation of the property |
ClassBuilder<T>& ponder::ClassBuilder< T >::property | ( | IdRef | name, |
F1 | accessor1, | ||
F2 | accessor2 | ||
) |
Declare a new property from a pair of accessors.
The accessor1 and accessor2 parameters can be a pair of getter/setter, or two getters which must be composed to form a single getter. If F1 is a direct pointer-to-member, it is considered both a getter and a setter.
Having two getters allows to expose a property which requires an extra level of indirection to be accessed (for example, a property of a member of the class instead of a property of the class itself).
Example:
name | Name of the property (must be unique within the metaclass) |
accessor1 | First accessor to the C++ implementation of the property (getter) |
accessor2 | Second accessor to the C++ implementation of the property (setter or getter to compose) |