cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
cmnClassRegister Class Reference

Main register for classes. More...

#include <cmnClassRegister.h>

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)
 
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
 

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:

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

typedef ServicesContainerType::const_iterator cmnClassRegister::const_iterator
typedef ServicesContainerType::const_reverse_iterator cmnClassRegister::const_reverse_iterator
typedef ServicesContainerType::value_type cmnClassRegister::EntryType

Simple typedefs to ease the declaration of iterators

typedef ServicesContainerType::size_type cmnClassRegister::size_type

Constructor & Destructor Documentation

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

static const_iterator cmnClassRegister::begin ( void  )
inlinestatic

Begin const iterator.

const_iterator cmnClassRegister::beginInstance ( void  ) const
inline

Instance specific implementation of begin.

See Also
begin
static 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.
static 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.
static const_iterator cmnClassRegister::end ( void  )
inlinestatic

End const iterator.

const_iterator cmnClassRegister::endInstance ( void  ) const
inline

Instance specific implementation of end.

See Also
end
static 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.
static 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.
cmnClassServicesBase* cmnClassRegister::FindClassServicesInstance ( const std::string &  className)

Instance specific implementation of FindClassServices.

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

Instance specific implementation of FindClassServices.

See Also
FindClassServices
static 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.
static 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.
const std::string* cmnClassRegister::RegisterInstance ( cmnClassServicesBase classServicesPointer,
const std::string &  className 
)

Instance specific implementation of Register.

See Also
Register
static bool CISST_DEPRECATED cmnClassRegister::SetLoD ( const std::string &  className,
cmnLogMask  mask 
)
inlinestatic
static bool CISST_DEPRECATED cmnClassRegister::SetLoDForAllClasses ( cmnLogMask  mask)
inlinestatic
static bool CISST_DEPRECATED cmnClassRegister::SetLoDForMatchingClasses ( const std::string &  stringToMatch,
cmnLogMask  mask 
)
inlinestatic
static 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.
static 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
bool cmnClassRegister::SetLogMaskClassAllInstance ( cmnLogMask  mask)

Instance specific implementation of SetLogMaskClassAll

See Also
SetLogMaskClassAll
static 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
bool cmnClassRegister::SetLogMaskClassMatchingInstance ( const std::string &  stringToMatch,
cmnLogMask  mask 
)

Instance specific implementation of SetLogMaskClassMatching.

See Also
SetLogMaskClassMatching
static size_type cmnClassRegister::size ( void  )
inlinestatic

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

size_type cmnClassRegister::sizeInstance ( void  ) const
inline

Instance specific implementation of size.

See Also
size
static void cmnClassRegister::ToStream ( std::ostream &  outputStream)
inlinestatic

Print the register content to a text stream.

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

Instance specific implementation of ToStream.

See Also
ToStream.
static std::string cmnClassRegister::ToString ( void  )
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.

See Also
ToString

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