SCL
1.0
Standard Control Library : Control, dynamics, physics, and simulation
|
#include <CRegisteredDynamicTypes.hpp>
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 &) | |
CRegisteredDynamicTypes & | operator= (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 CSingleton * | singleton_ |
Friends | |
class | CDynamicTypeBase< 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.
|
private |
Private for the singleton
|
private |
Private for the singleton
|
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
|
inlinestatic |
This function creates new objects of an indexed type (if the type has already been registered with the singleton)
|
private |
Private for the singleton
|
inlinestaticprivate |
This function registers new dynamic types with the factory. You can get objects of this type by calling the getObjectForType function
|
staticinherited |
Deletes the singleton instance and creates a new one.
|
inlinestatic |
Deletes the singleton object and creates a new one in its stead
|
inlinestatic |
Checks whether this type has been registered with the factory
|
protectedinherited |
Shared Memory: The publicly available data that will be shared across the different subsystems
|
staticprotectedinherited |
The singleton instance
This initializes the pointer to null