Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
sf::TClassRegistration< T, P > Class Template Reference

Template class used to register derived classes from a (virtual) interface class. More...

#include <TClassRegistration.h>

Classes

struct  entry_t
 Type of registered entry in the list. More...
 

Public Types

typedef TClassRegistration< T, P > self_t
 
typedef TClosure< T *, const P & > callback_t
 
typedef std::vector< entry_tentries_t
 
typedef TVector< std::string > strings_t
 

Public Member Functions

 TClassRegistration (entries_t &entries)
 Constructor for the base class.
 
 TClassRegistration (const TClassRegistration< T, P > &inst)
 Copy constructor.
 
 TClassRegistration (TClassRegistration< T, P > &&inst)
 Move constructor.
 
TClassRegistration< T, P > & operator= (const TClassRegistration< T, P > &inst)
 Assignment operator.
 
size_t registerClass (const char *name, const char *description, const callback_t &callback)
 Register a derived class.
 
size_t indexOf (const std::string &name) const
 Find a registered class structure index.
 
T * create (const std::string &name, const P &params) const
 Find and create registered class by name.
 
T * create (size_t index, const P &params) const
 Function create registered class by index.
 
size_t size () const
 Returns the amount of registered entries.
 
const std::string & getRegisterName (T *inst) const
 Gets the register name of the passed.
 
const char * getName (size_t index) const
 Gets the name of the class from the passed index.
 
strings_t getNames () const
 Gets the all the registered names.
 
const char * getDescription (size_t index) const
 Returns the description of the class from the passed index.
 

Static Public Member Functions

static void setRegisterName (T *inst, const char *name)
 Sets the register name on the passed instance.
 

Detailed Description

template<typename T, typename P>
class sf::TClassRegistration< T, P >

Template class used to register derived classes from a (virtual) interface class.

Registering name and description.
Example

Template Parameters
TBase type of the class being registered
PParameter type passed to the constructor.
FCallback function to create the instance.

Member Typedef Documentation

◆ callback_t

template<typename T , typename P >
typedef TClosure<T*, const P&> sf::TClassRegistration< T, P >::callback_t

◆ entries_t

template<typename T , typename P >
typedef std::vector<entry_t> sf::TClassRegistration< T, P >::entries_t

◆ self_t

template<typename T , typename P >
typedef TClassRegistration<T, P> sf::TClassRegistration< T, P >::self_t

◆ strings_t

template<typename T , typename P >
typedef TVector<std::string> sf::TClassRegistration< T, P >::strings_t

Constructor & Destructor Documentation

◆ TClassRegistration() [1/3]

template<typename T , typename P >
sf::TClassRegistration< T, P >::TClassRegistration ( entries_t entries)
inlineexplicit

Constructor for the base class.

◆ TClassRegistration() [2/3]

template<typename T , typename P >
sf::TClassRegistration< T, P >::TClassRegistration ( const TClassRegistration< T, P > &  inst)
inline

Copy constructor.

◆ TClassRegistration() [3/3]

template<typename T , typename P >
sf::TClassRegistration< T, P >::TClassRegistration ( TClassRegistration< T, P > &&  inst)
inline

Move constructor.

Member Function Documentation

◆ create() [1/2]

template<typename T , typename P >
T * sf::TClassRegistration< T, P >::create ( const std::string &  name,
const P &  params 
) const
inline

Find and create registered class by name.

Parameters
nameRegistered name of the class
paramsParameter type instance for the constructor.
Returns
nullptr on failure on success a new instance of the registered class.

◆ create() [2/2]

template<typename T , typename P >
T * sf::TClassRegistration< T, P >::create ( size_t  index,
const P &  params 
) const
inline

Function create registered class by index.

Parameters
indexIndex in the list of classes.
paramsParameter structure.
Returns
nullptr on failure on success a new instance of the registered class.

◆ getDescription()

template<typename T , typename P >
const char * sf::TClassRegistration< T, P >::getDescription ( size_t  index) const

Returns the description of the class from the passed index.

◆ getName()

template<typename T , typename P >
const char * sf::TClassRegistration< T, P >::getName ( size_t  index) const

Gets the name of the class from the passed index.

◆ getNames()

template<typename T , typename P >
TClassRegistration< T, P >::strings_t sf::TClassRegistration< T, P >::getNames ( ) const

Gets the all the registered names.

◆ getRegisterName()

template<typename T , typename P >
const std::string & sf::TClassRegistration< T, P >::getRegisterName ( T *  inst) const
inline

Gets the register name of the passed.

◆ indexOf()

template<typename T , typename P >
size_t sf::TClassRegistration< T, P >::indexOf ( const std::string &  name) const
inline

Find a registered class structure index.

Parameters
nameRegistered name of the class.
Returns
Nonzero index/position of the class in the registration list where Zero means not found.

◆ operator=()

template<typename T , typename P >
TClassRegistration< T, P > & sf::TClassRegistration< T, P >::operator= ( const TClassRegistration< T, P > &  inst)
inline

Assignment operator.

◆ registerClass()

template<typename T , typename P >
size_t sf::TClassRegistration< T, P >::registerClass ( const char *  name,
const char *  description,
const callback_t callback 
)
inline

Register a derived class.

Parameters
nameName of the class.
descriptionDescription of the class.
callbackCallback function to create instance of the class.

◆ setRegisterName()

template<typename T , typename P >
static void sf::TClassRegistration< T, P >::setRegisterName ( T *  inst,
const char *  name 
)
inlinestatic

Sets the register name on the passed instance.

This automatically is called from the callback_t when a class is registered.

◆ size()

template<typename T , typename P >
size_t sf::TClassRegistration< T, P >::size ( ) const

Returns the amount of registered entries.

Returns
Derived instance of type T.

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