ponder 3.2
C++ reflection library
ponder::runtime::ObjectFactory Class Reference

This object is used to create instances of metaclasses. More...

#include <runtime.hpp>

Public Member Functions

 ObjectFactory (const Class &cls)
 Constructor. More...
 
const ClassgetClass () const
 Get the class begin used. More...
 
UserObject construct (const Args &args=Args::empty, void *ptr=nullptr) const
 Construct a new instance of the C++ class bound to the metaclass. More...
 
template<typename ... A>
UserObject create (A... args) const
 Create a new instance of the class bound to the metaclass. More...
 
void destroy (const UserObject &object) const
 Destroy an instance of the C++ class bound to the metaclass. More...
 
void destruct (const UserObject &object) const
 Destruct an object created using placement new. More...
 

Detailed Description

This object is used to create instances of metaclasses.

There are helpers for this class, see ponder::runtime::construct() and ponder::runtime::create().

Example of use:

runtime::ObjectFactory fact(classByType<MyClass>.function("fpp"));
fact.create("bar");

Constructor & Destructor Documentation

◆ ObjectFactory()

ponder::runtime::ObjectFactory::ObjectFactory ( const Class cls)
inline

Constructor.

Parameters
clsThe Class to be called
Returns
a Class reference

Member Function Documentation

◆ construct()

UserObject ponder::runtime::ObjectFactory::construct ( const Args args = Args::empty,
void *  ptr = nullptr 
) const

Construct a new instance of the C++ class bound to the metaclass.

If no constructor can match the provided arguments, UserObject::nothing is returned. If a pointer is provided then placement new is used instead of the new instance being dynamically allocated using new. The new instance is wrapped into a UserObject.

Note
It must be destroyed with the appropriate destruction function: Class::destroy for new and Class::destruct for placement new.
Parameters
argsArguments to pass to the constructor (empty by default)
ptrOptional pointer to the location to construct the object (placement new)
Returns
New instance wrapped into a UserObject, or UserObject::nothing if it failed
See also
create()

◆ create()

template<typename... A>
UserObject ponder::runtime::ObjectFactory::create ( A...  args) const
inline

Create a new instance of the class bound to the metaclass.

Create an object without having to create an Args list. See notes for Class::construct(). If you need to create an argument list at runtime and use it to create an object then see Class::construct().

Parameters
argsAn argument list.
Returns
New instance wrapped into a UserObject, or UserObject::nothing if it failed
See also
construct()

◆ destroy()

void ponder::runtime::ObjectFactory::destroy ( const UserObject object) const

Destroy an instance of the C++ class bound to the metaclass.

This function must be called to destroy every instance created with Class::construct.

Parameters
objectObject to be destroyed
See also
construct

◆ destruct()

void ponder::runtime::ObjectFactory::destruct ( const UserObject object) const

Destruct an object created using placement new.

This function must be called to destroy every instance created with Class::construct.

Parameters
objectObject to be destroyed
See also
construct

◆ getClass()

const Class& ponder::runtime::ObjectFactory::getClass ( ) const
inline

Get the class begin used.

Returns
a Class reference

The documentation for this class was generated from the following file: