cisst-saw
Loading...
Searching...
No Matches
cmnClassRegister Class Reference

Main register for classes. More...

#include <cmnClassRegister.h>

Public Types

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

Public Member Functions

cmnClassServicesBaseFindClassServicesInstance (const std::string &className)
cmnClassServicesBaseFindClassServicesInstance (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 cmnClassRegisterInstance (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 cmnClassServicesBaseFindClassServices (const std::string &className)
static cmnClassServicesBaseFindClassServices (const std::type_info &typeInfo)
static cmnGenericObjectCreate (const std::string &className)
static cmnGenericObjectCreate (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)

Detailed Description

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:

  • Create dynamically an object based on a name provided as a string. This feature is required for the deserialization process (from a buffer and a name, create a new object of a given type defined by a string).
  • Modify the logging level of detail for a given class. See cmnLogger for more details regarding the logging in cisst.

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.

Member Typedef Documentation

◆ const_iterator

typedef ServicesContainerType::const_iterator cmnClassRegister::const_iterator

◆ const_reverse_iterator

typedef ServicesContainerType::const_reverse_iterator cmnClassRegister::const_reverse_iterator

◆ EntryType

typedef ServicesContainerType::value_type cmnClassRegister::EntryType

◆ ServicesContainerType

Simple typedefs to ease the declaration of iterators

◆ size_type

typedef ServicesContainerType::size_type cmnClassRegister::size_type

Constructor & Destructor Documentation

◆ cmnClassRegister()

cmnClassRegister::cmnClassRegister ( void )
inlineprotected

Constructor. The only constructor must be private in order to ensure that the class register is a singleton.

Member Function Documentation

◆ begin()

const_iterator cmnClassRegister::begin ( void )
inlinestatic

Begin const iterator.

◆ beginInstance()

const_iterator cmnClassRegister::beginInstance ( void ) const
inline

Instance specific implementation of begin.

See also
begin

◆ Create() [1/2]

cmnGenericObject * cmnClassRegister::Create ( const std::string & className)
static

Dynamic creation of objects using the default constructor.

Parameters
classNameThe name of the class of the object to be created.
Returns
A pointer on cmnGenericObject, NULL if the register doesn't have this class registered.

◆ Create() [2/2]

cmnGenericObject * cmnClassRegister::Create ( const std::string & className,
const cmnGenericObject & other )
static

Dynamic creation of objects using copy constructor

Parameters
classNameThe name of the class of the object to be created.
otherThe object to be copied
Returns
A pointer on cmnGenericObject, NULL if the register doesn't have this class registered or if the object provided is not of the right class type.

◆ end()

const_iterator cmnClassRegister::end ( void )
inlinestatic

End const iterator.

◆ endInstance()

const_iterator cmnClassRegister::endInstance ( void ) const
inline

Instance specific implementation of end.

See also
end

◆ FindClassServices() [1/2]

cmnClassServicesBase * cmnClassRegister::FindClassServices ( const std::string & className)
inlinestatic

Get the class services by name. Returns null if the class is not registered.

Parameters
classNameThe name to look up.
Returns
The pointer to the cmnClassServicesBase object corresponding to the className, or null if not registered.

◆ FindClassServices() [2/2]

cmnClassServicesBase * cmnClassRegister::FindClassServices ( const std::type_info & typeInfo)
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.

Parameters
typeInfoThe std::type_info to look up.
Returns
The pointer to the cmnClassServicesBase object corresponding to the type info, or null if not registered.

◆ FindClassServicesInstance() [1/2]

cmnClassServicesBase * cmnClassRegister::FindClassServicesInstance ( const std::string & className)

Instance specific implementation of FindClassServices.

See also
FindClassServices

◆ FindClassServicesInstance() [2/2]

cmnClassServicesBase * cmnClassRegister::FindClassServicesInstance ( const std::type_info & typeInfo)

Instance specific implementation of FindClassServices.

See also
FindClassServices

◆ Instance()

cmnClassRegister * cmnClassRegister::Instance ( void )
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.

Returns
A pointer to the class register.

◆ Register()

const std::string * cmnClassRegister::Register ( cmnClassServicesBase * classServicesPointer,
const std::string & className )
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.

Parameters
classServicesPointerThe pointer to the cmnClassServices object.
classNameThe name given to the class as a string. To enforce the consistency, we use the macro string conversion (#).

PK: FIX THIS

Returns
bool True if successful, false if the class has not been registered (e.g. one can not register twice). This might happen if a programmer doesn't give the right string name for the class to be registered with the macros CMN_DECLARE_SERVICES, CMN_DECLARE_SERVICES_INSTANTIATION and CMN_IMPLEMENT_SERVICES.

◆ RegisterInstance()

const std::string * cmnClassRegister::RegisterInstance ( cmnClassServicesBase * classServicesPointer,
const std::string & className )

Instance specific implementation of Register.

See also
Register

◆ SetLoD()

bool CISST_DEPRECATED cmnClassRegister::SetLoD ( const std::string & className,
cmnLogMask mask )
inlinestatic

◆ SetLoDForAllClasses()

bool CISST_DEPRECATED cmnClassRegister::SetLoDForAllClasses ( cmnLogMask mask)
inlinestatic

◆ SetLoDForMatchingClasses()

bool CISST_DEPRECATED cmnClassRegister::SetLoDForMatchingClasses ( const std::string & stringToMatch,
cmnLogMask mask )
inlinestatic

◆ SetLogMaskClass()

bool cmnClassRegister::SetLogMaskClass ( const std::string & className,
cmnLogMask mask )
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.

Parameters
classNameThe name of the class
maskThe log mask to be applied
Returns
bool True if the class is registered.

◆ SetLogMaskClassAll()

bool cmnClassRegister::SetLogMaskClassAll ( cmnLogMask mask)
inlinestatic

The SetLogMaskClassAll method allows the user to specify the log mask for all registered classes.

Parameters
maskThe log mask to be applied
Returns
bool True if there is at least one class log mask was modified

◆ SetLogMaskClassAllInstance()

bool cmnClassRegister::SetLogMaskClassAllInstance ( cmnLogMask mask)

Instance specific implementation of SetLogMaskClassAll

See also
SetLogMaskClassAll

◆ SetLogMaskClassMatching()

bool cmnClassRegister::SetLogMaskClassMatching ( const std::string & stringToMatch,
cmnLogMask mask )
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).

Parameters
stringToMatchA string found in class names (e.g. "cmn")
maskThe log mask to be applied
Returns
bool True if there is at least one class log mask was modified

◆ SetLogMaskClassMatchingInstance()

bool cmnClassRegister::SetLogMaskClassMatchingInstance ( const std::string & stringToMatch,
cmnLogMask mask )

Instance specific implementation of SetLogMaskClassMatching.

See also
SetLogMaskClassMatching

◆ size()

size_type cmnClassRegister::size ( void )
inlinestatic

Size of class register, i.e. number of classes.

◆ sizeInstance()

size_type cmnClassRegister::sizeInstance ( void ) const
inline

Instance specific implementation of size.

See also
size

◆ ToStream()

void cmnClassRegister::ToStream ( std::ostream & outputStream)
inlinestatic

Print the register content to a text stream.

◆ ToStreamInstance()

void cmnClassRegister::ToStreamInstance ( std::ostream & outputStream) const

Instance specific implementation of ToStream.

See also
ToStream.

◆ ToString()

std::string cmnClassRegister::ToString ( void )
static

Print the register content to an STL string and returns a copy of this string.

◆ ToStringInstance()

std::string cmnClassRegister::ToStringInstance ( void ) const

Instance specific implementation of ToString.

See also
ToString

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