ponder 3.2
C++ reflection library
ponder::UserData Class Reference

Name-value user data. More...

#include <userdata.hpp>

Public Member Functions

 UserData (IdRef name, Value &&value)
 Constructor. More...
 
IdReturn getName () const
 Get the UserData name. More...
 
const ValuegetValue () const
 Get the Value. More...
 

Detailed Description

Name-value user data.

This is used to store user data for declared Types. The name is a string and the Value can store any of the allowed types.

class Vec2D
{
public:
Vec2D(float x_, float y_) : x(x_), y(y_) {}
Vec2D operator+(const Vec2D& o) const { return Vec2D(x+o.x, y+o.y); }
float x,y;
};
static void declare()
{
using namespace ponder;
Class::declare<Vec2D>("Vec2D")
( UserData("help", "2D vector") )
.constructor<float,float>()
.property("x", &Vec2D::x)( UserData("default", 0.f) )
.property("y", &Vec2D::y)( UserData("default", 0.f) )
.function("add", &Vec2D::operator+)
(
UserData("help", "add vector to this and return result"),
UserData("eg", "result = a + b")
)
;
}
static void test()
{
auto const& cls = ponder::classByType<Vec2D>();
// print help about the class
const ponder::Value* help = ponder::userDataStore()->getValue(cls, "help");
std::cout << "Class " << cls.name() << ": ";
std::cout << (help ? help->to<ponder::Id>() : "no help") << std::endl;
// print functions and any help
for (auto const& fn : cls.functions())
{
std::cout << "\t" << fn.name() << ": ";
help = ponder::userDataStore()->getValue(fn, "help");
if (help)
std::cout << (help ? help->to<ponder::Id>() : "no help") << std::endl;
}
}

Constructor & Destructor Documentation

◆ UserData()

ponder::UserData::UserData ( IdRef  name,
Value &&  value 
)
inline

Constructor.

Parameters
name: Id string
value: user Value

Member Function Documentation

◆ getName()

IdReturn ponder::UserData::getName ( ) const
inline

Get the UserData name.

Returns
Id name

◆ getValue()

const Value& ponder::UserData::getValue ( ) const
inline

Get the Value.

Returns
const Value

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::UserData::UserData
UserData(IdRef name, Value &&value)
Constructor.
Definition: userdata.hpp:53
ponder::Value::to
T to() const
Convert the value to the type T.
ponder
Root namespace that encapsulates all of Ponder.
Definition: args.hpp:38
PONDER_TYPE
#define PONDER_TYPE(...)
Macro used to register a C++ type to Ponder.
Definition: pondertype.hpp:104