SCL  1.0
Standard Control Library : Control, dynamics, physics, and simulation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Groups Pages
Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
sutil::CRegisteredDynamicTypes< Idx > Class Template Reference

#include <CRegisteredDynamicTypes.hpp>

Inheritance diagram for sutil::CRegisteredDynamicTypes< Idx >:
Inheritance graph
[legend]
Collaboration diagram for sutil::CRegisteredDynamicTypes< Idx >:
Collaboration graph
[legend]

Static Public Member Functions

static bool typeRegistered (const Idx &arg_type_name)
 
static bool getObjectForType (const Idx &arg_type_name, void *&ret_object)
 
static bool resetDynamicTypes ()
 

Private Types

typedef CSingleton
< CMappedPointerList< Idx,
CDynamicTypeBase< Idx >, true > > 
singleton
 

Private Member Functions

 CRegisteredDynamicTypes ()
 
 CRegisteredDynamicTypes (const CRegisteredDynamicTypes &)
 
CRegisteredDynamicTypesoperator= (const CRegisteredDynamicTypes &)
 

Static Private Member Functions

static bool registerType (const Idx &arg_type_name, CDynamicTypeBase< Idx > *arg_type_object)
 
static CMappedPointerList< Idx,
CDynamicTypeBase< Idx >, true > * 
getData ()
 
static bool resetData ()
 

Private Attributes

CMappedPointerList< Idx,
CDynamicTypeBase< Idx >, true > 
data_
 

Static Private Attributes

static CSingletonsingleton_
 

Friends

class CDynamicTypeBase< Idx >
 

Detailed Description

template<typename Idx>
class sutil::CRegisteredDynamicTypes< Idx >

This class implements a type factory singleton. In plain English, it is a one-of-a-kind class that can give you an object based on its name.

Enabling this requires creating a DynamicTypeBase (like the one specified above). The factory creates an object of the DynamicTypeBase and uses that object to generate more of its kind. It uses a map to find the right object create.

Use Case : This is mostly useful when your types are subclassed from some generic class and implement its functions differently.

Eg. This would work very well for dynamic typing: CPainter { void paintScreen() = 0;} CBluePainter CRedPainter CGreenPainter etc.. — Dynamic typing saves you tons of if/else statements here. — It also helps you create generic code that you can package in a library

Example usage: sutil::CDynamicType<IndexType,Type> type(IndexType("Type")); type.registerType(); OR: sutil::CDynamicType<std::string,int> type(std::string("int")); type.registerType();

void obj=NULL; sutil::CRegisteredDynamicTypes<std::string>::getObjectForType(std::string("int"), obj); int *x = reinterpret_cast<int>(obj);

NOTE : This follows a different convention from the callbacks, objects and printables because this acts as a dynamic type factory, while those act as lookup tables.

Constructor & Destructor Documentation

template<typename Idx >
sutil::CRegisteredDynamicTypes< Idx >::CRegisteredDynamicTypes ( )
private

Private for the singleton

template<typename Idx >
sutil::CRegisteredDynamicTypes< Idx >::CRegisteredDynamicTypes ( const CRegisteredDynamicTypes< Idx > &  )
private

Private for the singleton

Member Function Documentation

static CMappedPointerList< Idx, CDynamicTypeBase< Idx >, true > * sutil::CSingleton< CMappedPointerList< Idx, CDynamicTypeBase< Idx >, true > >::getData ( )
staticinherited

Creates a singleton if necessary and returns it.

Returns a pointer instead of a reference to support a 0 return when there is an error

template<typename Idx >
static bool sutil::CRegisteredDynamicTypes< Idx >::getObjectForType ( const Idx &  arg_type_name,
void *&  ret_object 
)
inlinestatic

This function creates new objects of an indexed type (if the type has already been registered with the singleton)

template<typename Idx >
CRegisteredDynamicTypes& sutil::CRegisteredDynamicTypes< Idx >::operator= ( const CRegisteredDynamicTypes< Idx > &  )
private

Private for the singleton

template<typename Idx >
static bool sutil::CRegisteredDynamicTypes< Idx >::registerType ( const Idx &  arg_type_name,
CDynamicTypeBase< Idx > *  arg_type_object 
)
inlinestaticprivate

This function registers new dynamic types with the factory. You can get objects of this type by calling the getObjectForType function

static bool sutil::CSingleton< CMappedPointerList< Idx, CDynamicTypeBase< Idx >, true > >::resetData ( )
staticinherited

Deletes the singleton instance and creates a new one.

template<typename Idx >
static bool sutil::CRegisteredDynamicTypes< Idx >::resetDynamicTypes ( )
inlinestatic

Deletes the singleton object and creates a new one in its stead

template<typename Idx >
static bool sutil::CRegisteredDynamicTypes< Idx >::typeRegistered ( const Idx &  arg_type_name)
inlinestatic

Checks whether this type has been registered with the factory

Member Data Documentation

CMappedPointerList< Idx, CDynamicTypeBase< Idx >, true > sutil::CSingleton< CMappedPointerList< Idx, CDynamicTypeBase< Idx >, true > >::data_
protectedinherited

Shared Memory: The publicly available data that will be shared across the different subsystems

CSingleton* sutil::CSingleton< CMappedPointerList< Idx, CDynamicTypeBase< Idx >, true > >::singleton_
staticprotectedinherited

The singleton instance

This initializes the pointer to null


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