Cute Chess 0.1
ClassRegistry< T > Class Template Reference

A class for creating objects based on the class' runtime name or key (a string). More...

#include <classregistry.h>

Public Types

typedef T *(* Factory) (void)

Public Member Functions

void add (Factory f, const QString &key)
T * create (const QString &key)
const QMap< QString, Factory > & items () const

Static Public Member Functions

template<class Subclass>
static T * factory ()

Detailed Description

template<class T>
class ClassRegistry< T >

A class for creating objects based on the class' runtime name or key (a string).

The created objects of a registry must have the same base class.

Member Typedef Documentation

◆ Factory

template<class T>
typedef T *(* ClassRegistry< T >::Factory) (void)

Typedef to the factory function.

Member Function Documentation

◆ add()

template<class T>
void ClassRegistry< T >::add ( Factory f,
const QString & key )
inline

Adds a new factory associated with key.

◆ create()

template<class T>
T * ClassRegistry< T >::create ( const QString & key)
inline

Creates and returns an object whose type is associated with key.

Returns 0 if there is no type that matches key.

◆ factory()

template<class T>
template<class Subclass>
T * ClassRegistry< T >::factory ( )
inlinestatic

Factory function for creating an object of type Subclass, which must be a subclass of T.

◆ items()

template<class T>
const QMap< QString, Factory > & ClassRegistry< T >::items ( ) const
inline

Returns a list of factory functions.


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