ponder 3.1
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)
;
}