ponder 3.2
C++ reflection library
Shapes Example
#include <ponder/classbuilder.hpp>
#include <iostream>
static void declare();
enum class ShapeType
{
Circle,
Rectangle
};
struct Vec2
{
Vec2(float x_, float y_) : x(x_), y(y_) {}
float x,y;
};
class Shape
{
public:
virtual ~Shape() {}
ShapeType getType() const { return m_type; }
protected:
Shape(ShapeType shape) : m_type(shape) {}
private:
ShapeType m_type;
};
class Circle : public Shape
{
public:
Circle(Vec2 pos, float radius)
: Shape(ShapeType::Circle)
, m_pos(pos)
, m_radius(radius)
{}
float getRadius() const { return m_radius; }
private:
Vec2 m_pos;
float m_radius;
};
PONDER_AUTO_TYPE(ShapeType, declare); // enum
PONDER_AUTO_TYPE(Vec2, declare); // class
PONDER_AUTO_TYPE(Shape, declare);
PONDER_AUTO_TYPE(Circle, declare);
static void declare()
{
ponder::Enum::declare<ShapeType>()
;
ponder::Class::declare<Vec2>()
.constructor<float,float>()
.property("x", &Vec2::x) // expose member variables
.property("y", &Vec2::y)
;
ponder::Class::declare<Shape>()
.property("type", &Shape::getType) // expose getter member function
;
ponder::Class::declare<Circle>()
.base<Shape>()
//.constructor<Vec2,float>()
.property("type", &Shape::getType)
.property("radius", &Circle::getRadius)
;
}
PONDER_AUTO_TYPE
#define PONDER_AUTO_TYPE(TYPE, REGISTER_FN)
Macro used to register a C++ type to Ponder with automatic, on-demand metaclass creation.
Definition: pondertype.hpp:148
PONDER_POLYMORPHIC
#define PONDER_POLYMORPHIC()
Macro used to activate the Ponder RTTI system into a hierarchy of classes.
Definition: pondertype.hpp:268
runtime.hpp
Runtime uses for Ponder registered data.