ponder
3.2
C++ reflection library
|
ponder::Class represents a metaclass composed of properties and functions More...
#include <class.hpp>
Public Types | |
typedef View< const Function &, FunctionTable::const_iterator > | FunctionView |
typedef View< const Property &, PropertyTable::const_iterator > | PropertyView |
Public Member Functions | |
IdReturn | name () const |
Return the name of the metaclass. More... | |
size_t | baseCount () const |
Return the total number of base metaclasses of this metaclass. More... | |
const Class & | base (size_t index) const |
Return a base metaclass from its index. More... | |
size_t | constructorCount () const |
Return the total number of constructors of this metaclass. More... | |
const Constructor * | constructor (size_t index) const |
Access constructors by index. More... | |
void | destruct (const UserObject &uobj, bool destruct) const |
Destroy a UserObject instance. More... | |
size_t | functionCount () const |
Return the total number of functions of this metaclass. More... | |
bool | hasFunction (IdRef name) const |
Check if this metaclass contains the given function. More... | |
const Function & | function (size_t index) const |
Get a function from its index in this metaclass. More... | |
const Function & | function (IdRef name) const |
Get a function from its name. More... | |
FunctionView | functions () const |
Get a function iterator. More... | |
bool | tryFunction (const IdRef name, const Function *&funcRet) const |
Look up a function by name and return success. More... | |
size_t | propertyCount () const |
Return the total number of properties of this metaclass. More... | |
bool | hasProperty (IdRef name) const |
Check if this metaclass contains the given property. More... | |
const Property & | property (size_t index) const |
Get a property from its index in this metaclass. More... | |
const Property & | property (IdRef name) const |
Get a property from its name. More... | |
PropertyView | properties () const |
Get a property iterator. More... | |
bool | tryProperty (const IdRef name, const Property *&propRet) const |
Look up a property by name and return success. More... | |
size_t | sizeOf () const |
Return the memory size of a class instance. More... | |
UserObject | getUserObjectFromPointer (void *ptr) const |
Create a UserObject from an opaque user pointer. More... | |
void | visit (ClassVisitor &visitor) const |
Start visitation of a class. More... | |
void * | applyOffset (void *pointer, const Class &target) const |
Convert a pointer to an object compatible with a base or derived metaclass. More... | |
bool | operator== (const Class &other) const |
Operator == to check equality between two metaclasses. More... | |
bool | operator!= (const Class &other) const |
Operator != to check inequality between two metaclasses. More... | |
Static Public Member Functions | |
template<typename T > | |
static ClassBuilder< T > | declare (IdRef id=ponder::IdRef()) |
Declare a new metaclass. More... | |
template<typename T > | |
static void | undeclare () |
Undeclare an existing metaclass. More... | |
Friends | |
template<typename T > | |
class | ClassBuilder |
class | detail::ClassManager |
Related Functions | |
(Note that these are not member functions.) | |
size_t | classCount () |
Get the total number of existing metaclasses. More... | |
detail::ClassManager::ClassView | classes () |
Get an iterator that can be used to iterate over all registered classes. More... | |
const Class & | classByName (IdRef name) |
Get a metaclass from its name. More... | |
template<typename T > | |
const Class & | classByObject (const T &object) |
Get a metaclass from a C++ object. More... | |
template<typename T > | |
const Class & | classByType () |
Get a metaclass from its C++ type. More... | |
template<typename T > | |
const Class * | classByTypeSafe () |
Get a metaclass from its C++ type. More... | |
ponder::Class represents a metaclass composed of properties and functions
ponder::Class is the main class of the Ponder API. It defines a metaclass, which is an abstract representation of a C++ class with its own properties, functions, constructors, base classes, etc.
Classes are declared, bound to a C++ type and filled with the Class::declare() function.
It then provides a set of accessors to retrieve its member functions and properties. See Class::function() and Class::property().
Another way to inspect a class, which is more type-safe, is to use a ClassVisitor.
It also allows to create and destroy instances of the bound C++ class.
void* ponder::Class::applyOffset | ( | void * | pointer, |
const Class & | target | ||
) | const |
Convert a pointer to an object compatible with a base or derived metaclass.
The target metaclass may be a base or a derived of this, both cases are properly handled.
pointer | Pointer to convert |
target | Target metaclass to convert to |
ClassUnrelated | target is not a base nor a derived class of this |
const Class& ponder::Class::base | ( | size_t | index | ) | const |
Return a base metaclass from its index.
index | Index of the base to get |
OutOfRange | index is out of range |
size_t ponder::Class::baseCount | ( | ) | const |
Return the total number of base metaclasses of this metaclass.
const Constructor* ponder::Class::constructor | ( | size_t | index | ) | const |
size_t ponder::Class::constructorCount | ( | ) | const |
Return the total number of constructors of this metaclass.
|
static |
Declare a new metaclass.
Call this to create a new metaclass. The template parameter T is the C++ class that will be bound to the metaclass.
id | Name of the metaclass in Ponder. This name identifies the metaclass and thus has to be unique. If not specified, the C++ type id is used. |
void ponder::Class::destruct | ( | const UserObject & | uobj, |
bool | destruct | ||
) | const |
Destroy a UserObject instance.
uobj | User object to destruct |
destruct | True for destruct (placement new), else destroy (new) |
const Function& ponder::Class::function | ( | IdRef | name | ) | const |
Get a function from its name.
name | Name of the function to get (case sensitive) |
FunctionNotFound | name is not a function of the metaclass |
const Function& ponder::Class::function | ( | size_t | index | ) | const |
Get a function from its index in this metaclass.
index | Index of the function to get |
OutOfRange | index is out of range |
size_t ponder::Class::functionCount | ( | ) | const |
Return the total number of functions of this metaclass.
FunctionView ponder::Class::functions | ( | ) | const |
Get a function iterator.
UserObject ponder::Class::getUserObjectFromPointer | ( | void * | ptr | ) | const |
Create a UserObject from an opaque user pointer.
bool ponder::Class::hasFunction | ( | IdRef | name | ) | const |
Check if this metaclass contains the given function.
name | Name of the function to check |
bool ponder::Class::hasProperty | ( | IdRef | name | ) | const |
Check if this metaclass contains the given property.
name | Name of the property to check |
IdReturn ponder::Class::name | ( | ) | const |
Return the name of the metaclass.
bool ponder::Class::operator!= | ( | const Class & | other | ) | const |
Operator != to check inequality between two metaclasses.
other | Metaclass to compare with this |
bool ponder::Class::operator== | ( | const Class & | other | ) | const |
Operator == to check equality between two metaclasses.
Two metaclasses are equal if their name is the same.
other | Metaclass to compare with this |
PropertyView ponder::Class::properties | ( | ) | const |
Get a property iterator.
const Property& ponder::Class::property | ( | IdRef | name | ) | const |
Get a property from its name.
name | Name of the property to get (case sensitive) |
PropertyNotFound | name is not a property of the metaclass |
const Property& ponder::Class::property | ( | size_t | index | ) | const |
Get a property from its index in this metaclass.
index | Index of the property to get |
OutOfRange | index is out of range |
size_t ponder::Class::propertyCount | ( | ) | const |
Return the total number of properties of this metaclass.
size_t ponder::Class::sizeOf | ( | ) | const |
Return the memory size of a class instance.
bool ponder::Class::tryFunction | ( | const IdRef | name, |
const Function *& | funcRet | ||
) | const |
Look up a function by name and return success.
name | Name of the function to get (case sensitive) |
funcRet | Function returned, if return was true |
bool ponder::Class::tryProperty | ( | const IdRef | name, |
const Property *& | propRet | ||
) | const |
Look up a property by name and return success.
name | Name of the property to get (case sensitive) |
propRet | Property returned, if return was true |
|
static |
Undeclare an existing metaclass.
Use this to undeclare a metaclass that you no longer require. E.g. from a dynamically loaded library that is being unloaded.
void ponder::Class::visit | ( | ClassVisitor & | visitor | ) | const |
Start visitation of a class.
visitor | Visitor to use for visitation |
|
related |
Get a metaclass from its name.
name | Name of the metaclass to retrieve (case sensitive) |
ClassNotFound | name is not a valid metaclass name |
|
related |
Get a metaclass from a C++ object.
object | object to get the metaclass of |
ClassNotFound | no metaclass has been declared for T or any of its bases |
|
related |
Get a metaclass from its C++ type.
ClassNotFound | no metaclass has been declared for T |
|
related |
Get a metaclass from its C++ type.
|
related |
Get the total number of existing metaclasses.
|
related |
Get an iterator that can be used to iterate over all registered classes.