cisst-saw
|
Main register for classes. More...
#include <cmnClassRegister.h>
Public Member Functions | |
cmnClassServicesBase * | FindClassServicesInstance (const std::string &className) |
cmnClassServicesBase * | FindClassServicesInstance (const std::type_info &typeInfo) |
const std::string * | RegisterInstance (cmnClassServicesBase *classServicesPointer, const std::string &className) |
bool | SetLogMaskClassAllInstance (cmnLogMask mask) |
bool | SetLogMaskClassMatchingInstance (const std::string &stringToMatch, cmnLogMask mask) |
std::string | ToStringInstance (void) const |
void | ToStreamInstance (std::ostream &outputStream) const |
size_type | sizeInstance (void) const |
const_iterator | beginInstance (void) const |
const_iterator | endInstance (void) const |
Static Public Member Functions | |
static cmnClassRegister * | Instance (void) |
static const std::string * | Register (cmnClassServicesBase *classServicesPointer, const std::string &className) |
static bool | SetLogMaskClass (const std::string &className, cmnLogMask mask) |
static bool CISST_DEPRECATED | SetLoD (const std::string &className, cmnLogMask mask) |
static bool | SetLogMaskClassAll (cmnLogMask mask) |
static bool CISST_DEPRECATED | SetLoDForAllClasses (cmnLogMask mask) |
static bool | SetLogMaskClassMatching (const std::string &stringToMatch, cmnLogMask mask) |
static bool CISST_DEPRECATED | SetLoDForMatchingClasses (const std::string &stringToMatch, cmnLogMask mask) |
static cmnClassServicesBase * | FindClassServices (const std::string &className) |
static cmnClassServicesBase * | FindClassServices (const std::type_info &typeInfo) |
static cmnGenericObject * | Create (const std::string &className) |
static cmnGenericObject * | Create (const std::string &className, const cmnGenericObject &other) |
static std::string | ToString (void) |
static void | ToStream (std::ostream &outputStream) |
static size_type | size (void) |
static const_iterator | begin (void) |
static const_iterator | end (void) |
Protected Member Functions | |
cmnClassRegister (void) | |
typedef std::map< std::string, cmnClassServicesBase * > | ServicesContainerType |
typedef ServicesContainerType::value_type | EntryType |
typedef ServicesContainerType::const_iterator | const_iterator |
typedef ServicesContainerType::const_reverse_iterator | const_reverse_iterator |
typedef ServicesContainerType::size_type | size_type |
Main register for classes.
This class handles the registration of classes. The registration process allows to retrieve by name some information about a specific class from a centralized point. The current version of the class register allows to:
Since the dynamic creation requires a base class, we have introduced the cmnGenericObject class in cisstCommon. One can only register classes derived from cmnGenericObject. The registration requires the use of CMN_DECLARE_SERVICES (or CMN_DECLARE_SERVICES_EXPORT), CMN_DECLARE_SERVICES_INSTANTIATION (or CMN_DECLARE_SERVICES_INSTANTIATION_EXPORT) and CMN_IMPLEMENT_SERVICES (or CMN_IMPLEMENT_SERVICES_TEMPLATED).
Here are the details of the implementation. The macro CMN_DECLARE_SERVICES defines a method called Services() for each registered class. This method returns a pointer on a static data member of type cmnClassServices. This cmnClassServices object is unique for that class. While the reasons for writing a method which returns a pointer on a static data member might seem confusing, they are actually quite simple. This method is used to ensure that the data member is initialized the first time it is used. This is done to avoid problems related to the order of instantiation of the static data members when used before main()
.
When the Services() method defined in the CMN_IMPLEMENT_SERVICES macro is called, the cmnClassServices object registers itself within static class register. This allows us to keep a single list of all the classes that exist in a particular program. The register is implemented as a map of pointers to the cmnClassServices objects that exist.
It is important to note that all classes to be registered will be registered by the time the main()
function is called. Since we rely on the creation of global static objects for the registration and the order of instantiation of these objects before main()
is unknown, classes might be register or not before the main()
execution.
typedef ServicesContainerType::const_iterator cmnClassRegister::const_iterator |
typedef ServicesContainerType::const_reverse_iterator cmnClassRegister::const_reverse_iterator |
typedef ServicesContainerType::value_type cmnClassRegister::EntryType |
typedef std::map<std::string, cmnClassServicesBase*> cmnClassRegister::ServicesContainerType |
Simple typedefs to ease the declaration of iterators
typedef ServicesContainerType::size_type cmnClassRegister::size_type |
|
inlineprotected |
Constructor. The only constructor must be private in order to ensure that the class register is a singleton.
|
inlinestatic |
Begin const iterator.
|
inline |
Instance specific implementation of begin.
|
static |
Dynamic creation of objects using the default constructor.
className | The name of the class of the object to be created. |
|
static |
Dynamic creation of objects using copy constructor
className | The name of the class of the object to be created. |
other | The object to be copied |
|
inlinestatic |
End const iterator.
|
inline |
Instance specific implementation of end.
|
inlinestatic |
Get the class services by name. Returns null if the class is not registered.
className | The name to look up. |
|
inlinestatic |
Get the class services by std::type_info. This allows to find a registered class base on its C++ RTTI type_info, as defined by the standard function typeid()
. Returns null if the class is not registered.
typeInfo | The std::type_info to look up. |
cmnClassServicesBase* cmnClassRegister::FindClassServicesInstance | ( | const std::string & | className | ) |
Instance specific implementation of FindClassServices.
cmnClassServicesBase* cmnClassRegister::FindClassServicesInstance | ( | const std::type_info & | typeInfo | ) |
Instance specific implementation of FindClassServices.
|
static |
The class register is instantiated as a singleton. To access the unique instantiation, one needs to use this static method. The instantiated class register is created at the first call of this method since it is a static variable declared in this method's scope.
|
inlinestatic |
The Register method registers a class pointer in the static register. It MUST NOT be used directly. It is used by the CMN_DECLARE_SERVICES macro.
classServicesPointer | The pointer to the cmnClassServices object. |
className | The name given to the class as a string. To enforce the consistency, we use the macro string conversion (#). |
PK: FIX THIS
const std::string* cmnClassRegister::RegisterInstance | ( | cmnClassServicesBase * | classServicesPointer, |
const std::string & | className | ||
) |
Instance specific implementation of Register.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
static |
The SetLogMaskClass method allows the user to specify the log mask for a specific class. It checks to see if the class is registered. If so, it updates the cmnClassServices object directly. Otherwise, it log a warning message.
className | The name of the class |
mask | The log mask to be applied |
|
inlinestatic |
The SetLogMaskClassAll method allows the user to specify the log mask for all registered classes.
mask | The log mask to be applied |
bool cmnClassRegister::SetLogMaskClassAllInstance | ( | cmnLogMask | mask | ) |
Instance specific implementation of SetLogMaskClassAll
|
inlinestatic |
The SetLogMaskClassMatching method allows the user to specify the log mask for all classes with a name matching a given string. The string matching is case sensitive (exact match).
stringToMatch | A string found in class names (e.g. "cmn") |
mask | The log mask to be applied |
bool cmnClassRegister::SetLogMaskClassMatchingInstance | ( | const std::string & | stringToMatch, |
cmnLogMask | mask | ||
) |
Instance specific implementation of SetLogMaskClassMatching.
|
inlinestatic |
Size of class register, i.e. number of classes.
|
inline |
Instance specific implementation of size.
|
inlinestatic |
Print the register content to a text stream.
void cmnClassRegister::ToStreamInstance | ( | std::ostream & | outputStream | ) | const |
Instance specific implementation of ToStream.
|
static |
Print the register content to an STL string and returns a copy of this string.
std::string cmnClassRegister::ToStringInstance | ( | void | ) | const |
Instance specific implementation of ToString.