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

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...
 

Detailed Description

template<typename T>
class ponder::ClassBuilder< T >

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.

Constructor & Destructor Documentation

◆ ClassBuilder()

template<typename T >
ponder::ClassBuilder< T >::ClassBuilder ( Class target)

Construct the builder with a target metaclass to fill.

Parameters
targetMetaclass to build

Member Function Documentation

◆ base()

template<typename T >
template<typename U >
ClassBuilder<T>& ponder::ClassBuilder< T >::base ( )

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.

Note
We do not support virtual inheritance fully here due to the associated problems with compiler specific class layouts. e.g. see Class::applyOffset.
Returns
Reference to this, in order to chain other calls
Exceptions
ClassNotFoundno metaclass is bound to U

◆ constructor()

template<typename T >
template<typename... A>
ClassBuilder<T>& ponder::ClassBuilder< T >::constructor ( )

Declare a constructor for the metaclass.

Variable number of parameters can be passed.

Returns
Reference to this, in order to chain other calls

◆ external()

template<typename T >
template<template< typename > class U>
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:

template <typename T>
class MyClassMapper
{
public:
MyClassMapper();
size_t propertyCount();
ponder::Property* property(size_t index);
size_t functionCount();
ponder::Function* function(size_t index);
};

Example of usage:

ponder::Class::declare<MyClass>("MyClass")
.external<MyClassMapper>()
...
Returns
Reference to this, in order to chain other calls

◆ function()

template<typename T >
template<typename F , typename... P>
ClassBuilder<T>& ponder::ClassBuilder< T >::function ( IdRef  name,
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.

Parameters
nameName of the function (must be unique within the metaclass)
functionC++ callable entity to bind to the function
policiesOptional policies applied to function exposer
Returns
Reference to this, in order to chain other calls
See also
property(), ponder::policy, Shapes Example

◆ operator()()

template<typename T >
template<typename... U>
ClassBuilder<T>& ponder::ClassBuilder< T >::operator() ( U &&...  uds)
inline

Add user data to the last declared member type.

ponder::Class::declare<MyClass>("MyClass")
.function("foo", &MyClass::foo)( ponder::UserData("user", 3) );
Returns
Reference to this, in order to chain other calls

◆ property() [1/2]

template<typename T >
template<typename F >
ClassBuilder<T>& ponder::ClassBuilder< T >::property ( IdRef  name,
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:

struct Point
{
float x, y;
float length() const;
};
ponder::Class::declare<Point>("Point")
.property("x", &Point::x) // getter + setter
.property("y", &Point::y) // getter + setter
.property("length", &Point::length); // getter only
Parameters
nameName of the property (must be unique within the metaclass)
accessorAccessor to the C++ implementation of the property
Returns
Reference to this, in order to chain other calls

◆ property() [2/2]

template<typename T >
template<typename F1 , typename F2 >
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:

struct Point {float x, y;};
class Entity
{
public:
Point p;
};
ponder::Class::declare<Entity>("Entity")
.property("x", &Point::x, &Entity::p) // will internally resolve to e.p.x
.property("y", &Point::y, &Entity::p); // will internally resolve to e.p.y
Parameters
nameName of the property (must be unique within the metaclass)
accessor1First accessor to the C++ implementation of the property (getter)
accessor2Second accessor to the C++ implementation of the property (setter or getter to compose)
Returns
Reference to this, in order to chain other calls

The documentation for this class was generated from the following files:
ponder::Property
Abstract representation of a property.
Definition: property.hpp:51
ponder::ClassBuilder::property
ClassBuilder< T > & property(IdRef name, F accessor)
Declare a new property from a single accessor.
ponder::Function
Abstract representation of a function.
Definition: function.hpp:55
ponder::UserData
Name-value user data.
Definition: userdata.hpp:47