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. Registering name and description.
Example. More...

#include <TClassRegistration.h>

Classes

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

Public Types

typedef TClosure< T *, const P & > callback_t
 Callback closure type for creating instances.
typedef std::vector< entry_t > entries_t
 Vector type to register implementations in.
typedef TVector< std::string > strings_t
 Type used to report the list of implementations in.

Public Member Functions

 TClassRegistration (entries_t &entries, entry_t *&current)
 Constructor for the base class.
 TClassRegistration (const TClassRegistration &inst)
 Copy constructor.
 TClassRegistration (TClassRegistration &&inst) noexcept
 Move constructor.
TClassRegistration & operator= (const TClassRegistration &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. When not found it returns.
T * create (const std::string &name, const P &params=P{}) const
 Find and create registered class by name.
T * create (size_t index, const P &params=P{}) const
 Function create registered class by index.
size_t size () const
 Returns the amount of registered entries.
std::string getRegisterName (const T *inst) const
 Gets the register name of the passed instance.
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. This automatically is called from the callback_t when a class is registered.

Static Public Attributes

static auto constexpr npos = std::numeric_limits<size_t>::max()
 Index value for when not found.

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.

Member Typedef Documentation

◆ callback_t

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

Callback closure type for creating instances.

◆ entries_t

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

Vector type to register implementations in.

◆ strings_t

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

Type used to report the list of implementations in.

Constructor & Destructor Documentation

◆ TClassRegistration() [1/3]

template<typename T, typename P>
sf::TClassRegistration< T, P >::TClassRegistration ( entries_t & entries,
entry_t *& current )
explicit

Constructor for the base class.

◆ TClassRegistration() [2/3]

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

Copy constructor.

◆ TClassRegistration() [3/3]

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

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 = P{} ) const

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 = P{} ) const

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>
strings_t sf::TClassRegistration< T, P >::getNames ( ) const

Gets the all the registered names.

◆ getRegisterName()

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

Gets the register name of the passed instance.

◆ indexOf()

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

Find a registered class structure index. When not found it returns.

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 & sf::TClassRegistration< T, P >::operator= ( const TClassRegistration< T, P > & inst)

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 )

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>
void sf::TClassRegistration< T, P >::setRegisterName ( T * inst,
const char * name )
static

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.

Member Data Documentation

◆ npos

template<typename T, typename P>
auto constexpr sf::TClassRegistration< T, P >::npos = std::numeric_limits<size_t>::max()
staticconstexpr

Index value for when not found.


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