cisst-saw
Loading...
Searching...
No Matches
cmnClassRegisterMacros.h File Reference

Class registration macros. More...

Go to the source code of this file.

Macros

#define _cmnClassRegisterMacros_h
Methods declaration

These macros are used to declare the required methods and data members for the class registration (see also cmnClassRegister). Every class which needs to be registered should include one of these macros within its declaration AND be derived from cmnGenericObject.

To declare a registered class without dynamic creation, the header file myClass.h should have:

class CISST_EXPORT myClass: public cmnGenericObject
{
public:
...
};
Base class for high level objects.
Definition cmnGenericObject.h:53
const int CMN_NO_DYNAMIC_CREATION
Definition cmnClassRegisterMacros.h:325
#define CMN_DECLARE_SERVICES(hasDynamicCreation, lod)
Definition cmnClassRegisterMacros.h:113
#define CISST_EXPORT
Definition cmnExportMacros.h:50
#define CMN_LOG_DEFAULT_LOD
Definition cmnLogLoD.h:98

The macro CMN_DECLARE_SERVICES defines amongst other things a static method which can not be inlined. Therefore, when one wants to create a Dll (shared libraries on Windows) with a C++ compiler from Microsoft, one must explicitly export it. In most cases, the class itself is "exported" using CISST_EXPORT. If the class is not wholly exported, it is possible to export some methods explicitly. In this case, the macro CMN_DECLARE_SERVICES_EXPORT should be used:

class myClass: public cmnGenericObject
{
public:
CISST_EXPORT void MethodA(void);
...
};
#define CMN_DECLARE_SERVICES_EXPORT(hasDynamicCreation, lod)
Definition cmnClassRegisterMacros.h:127

Finally, the macro CMN_DECLARE_SERVICES_EXPORT_ALWAYS was introduced as a temporary fix for template classes, such as mtsGenericObjectProxy.

Parameters
hasDynamicCreationSet this parameter to CMN_DYNAMIC_CREATION to enable dynamic creation and CMN_NO_DYNAMIC_CREATION to disable dynamic creation. Dynamic creation requires a public default constructor.
lodThe default Level of Detail used for this class (see also CMN_LOG and CMN_LOG_DEFAULT_LOD.
#define CMN_DECLARE_SERVICES(hasDynamicCreation, lod)
#define CMN_DECLARE_SERVICES_EXPORT(hasDynamicCreation, lod)
#define CMN_DECLARE_SERVICES_EXPORT_ALWAYS(hasDynamicCreation, lod)
Global function declaration

The templated function cmnClassServicesInstantiate is used to generate a unique object of type cmnClassServices for each class defined in cisst. It contains a static data member which will be constructed the first time it is called. The header file myClass.h should have to following code after the class declaration of myClass:

#define CMN_DECLARE_SERVICES_INSTANTIATION_EXPORT(className)
Definition cmnClassRegisterMacros.h:206

In most case, CMN_DECLARE_SERVICES_INSTANTIATION_EXPORT should be used. One case where CMN_DECLARE_SERVICES_INSTANTIATION should be used in when the class instantiation will reside in the executable, i.e. the programmer is not creating a library but is linking all is binaries directly into and executable.

For a template class, it is necessary to specify which template specialization is being registered. To do so, it is recommended to create a typedef before using this macro:

template <class _templateParameter>
myClass<_templateParameter>: public cmnGenericObject
{
public:
...
};
typedef myClass<double> myClassDouble;
Parameters
classNameThe name of the class being registered, without any quote.
#define CMN_DECLARE_SERVICES_INSTANTIATION(className)
#define CMN_DECLARE_SERVICES_INSTANTIATION_EXPORT(className)
Methods and function implementation

These macros implements the methods and function declared by CMN_DECLARE_SERVICES and CMN_DECLARE_SERVICES_INSTANTIATION_EXPORT. For a non templated class, the source file myClass.cpp must have:

#define CMN_IMPLEMENT_SERVICES(className)
Definition cmnClassRegisterMacros.h:264

For a templated class specialized and define using typedef ... myClassDouble, the source file must have:

#define CMN_IMPLEMENT_SERVICES_TEMPLATED(className)
Definition cmnClassRegisterMacros.h:297
Parameters
classNameThe name of the class being registered, without any quote.
#define LIBRARY_NAME_FOR_CISST_REGISTER   ""
#define CMN_IMPLEMENT_SERVICES_INTERNAL(className, parentServices, argType)
#define CMN_IMPLEMENT_SERVICES(className)
#define CMN_IMPLEMENT_SERVICES_DERIVED(className, parentName)
#define CMN_IMPLEMENT_SERVICES_TEMPLATED_INTERNAL(className, parentServices, argType)
#define CMN_IMPLEMENT_SERVICES_TEMPLATED(className)
#define CMN_IMPLEMENT_SERVICES_DERIVED_TEMPLATED(className, parentName)

Variables

Possible values used in combination with
const int CMN_NO_DYNAMIC_CREATION = 0
const int CMN_DYNAMIC_CREATION_DEFAULT = 1
const int CMN_DYNAMIC_CREATION_COPY = 2
const int CMN_DYNAMIC_CREATION = 3
const int CMN_DYNAMIC_CREATION_SETNAME = 5
const int CMN_DYNAMIC_CREATION_ONEARG = 8

Detailed Description

Class registration macros.

These macros can be divided in three sets, one of each should be used for any registered class.

The macros ending with _EXPORT are required to handle the generation of DLLs correctly with the different Microsoft compilers (see also CISST_EXPORT) and the macro ending with _TEMPLATED is required to register a specialized version of a templated class.

Finally, the definitions CMN_DYNAMIC_CREATION and CMN_NO_DYNAMIC_CREATION are provided to increase the code readability.

Macro Definition Documentation

◆ _cmnClassRegisterMacros_h

#define _cmnClassRegisterMacros_h

◆ CMN_DECLARE_SERVICES

#define CMN_DECLARE_SERVICES ( hasDynamicCreation,
lod )
Value:
public: \
enum {HAS_DYNAMIC_CREATION = hasDynamicCreation}; \
enum {InitialLoD = lod}; \
static cmnClassServicesBase * ClassServices(void); \
const cmnClassServicesBase * Services(void) const override; \
private: \
static cmnClassServicesBase * ClassServicesPointer;

◆ CMN_DECLARE_SERVICES_EXPORT

#define CMN_DECLARE_SERVICES_EXPORT ( hasDynamicCreation,
lod )
Value:
public: \
enum {HAS_DYNAMIC_CREATION = hasDynamicCreation}; \
enum {InitialLoD = lod}; \
CISST_EXPORT static cmnClassServicesBase * ClassServices(void); \
CISST_EXPORT const cmnClassServicesBase * Services(void) const override; \
private: \
static cmnClassServicesBase * ClassServicesPointer;

◆ CMN_DECLARE_SERVICES_EXPORT_ALWAYS

#define CMN_DECLARE_SERVICES_EXPORT_ALWAYS ( hasDynamicCreation,
lod )
Value:
CMN_DECLARE_SERVICES_EXPORT(hasDynamicCreation, lod)

◆ CMN_DECLARE_SERVICES_INSTANTIATION

#define CMN_DECLARE_SERVICES_INSTANTIATION ( className)
Value:
template<> \
Base class for class services.
Definition cmnClassServicesBase.h:46
cmnClassServicesBase * cmnClassServicesInstantiate(void)

◆ CMN_DECLARE_SERVICES_INSTANTIATION_EXPORT

#define CMN_DECLARE_SERVICES_INSTANTIATION_EXPORT ( className)
Value:
template<> CISST_EXPORT \
cmnClassServicesBase * cmnClassServicesInstantiate<className>(void);

◆ CMN_IMPLEMENT_SERVICES

#define CMN_IMPLEMENT_SERVICES ( className)
Value:
CMN_IMPLEMENT_SERVICES_INTERNAL(className, 0, className)
#define CMN_IMPLEMENT_SERVICES_INTERNAL(className, parentServices, argType)
Definition cmnClassRegisterMacros.h:244

◆ CMN_IMPLEMENT_SERVICES_DERIVED

#define CMN_IMPLEMENT_SERVICES_DERIVED ( className,
parentName )
Value:
CMN_IS_DERIVED_FROM_ASSERT(className, parentName) \
CMN_IMPLEMENT_SERVICES_INTERNAL(className, parentName::ClassServices(), className)
#define CMN_IS_DERIVED_FROM_ASSERT(Derived, Base)
Definition cmnTypeTraits.h:657

◆ CMN_IMPLEMENT_SERVICES_DERIVED_TEMPLATED

#define CMN_IMPLEMENT_SERVICES_DERIVED_TEMPLATED ( className,
parentName )
Value:
CMN_IS_DERIVED_FROM_ASSERT(className, parentName) \
CMN_IMPLEMENT_SERVICES_TEMPLATED_INTERNAL(className, parentName::ClassServices(), className)

◆ CMN_IMPLEMENT_SERVICES_INTERNAL

#define CMN_IMPLEMENT_SERVICES_INTERNAL ( className,
parentServices,
argType )
Value:
cmnClassServicesBase * className::ClassServices(void) \
{ \
return classServices; \
} \
cmnClassServicesBase * className::ClassServicesPointer = className::ClassServices(); \
const cmnClassServicesBase * className::Services(void) const \
{ \
return this->ClassServices(); \
} \
template<> \
cmnClassServicesBase * cmnClassServicesInstantiate<className>(void) \
{ \
static cmnClassServices<className::HAS_DYNAMIC_CREATION, className, argType> \
classServices(#className, &typeid(className), parentServices, LIBRARY_NAME_FOR_CISST_REGISTER, className::InitialLoD); \
return static_cast<cmnClassServicesBase *>(&classServices); \
} \
static cmnClassServicesBase * className##ClassServicesPointer = className::ClassServices();
#define LIBRARY_NAME_FOR_CISST_REGISTER
Definition cmnClassRegisterMacros.h:237

◆ CMN_IMPLEMENT_SERVICES_TEMPLATED

#define CMN_IMPLEMENT_SERVICES_TEMPLATED ( className)
Value:
#define CMN_IMPLEMENT_SERVICES_TEMPLATED_INTERNAL(className, parentServices, argType)
Definition cmnClassRegisterMacros.h:274

◆ CMN_IMPLEMENT_SERVICES_TEMPLATED_INTERNAL

#define CMN_IMPLEMENT_SERVICES_TEMPLATED_INTERNAL ( className,
parentServices,
argType )
Value:
template<> \
{ \
classServices(#className, &typeid(className), parentServices, LIBRARY_NAME_FOR_CISST_REGISTER, className::InitialLoD); \
return static_cast<cmnClassServicesBase *>(&classServices); \
} \
template<> \
cmnClassServicesBase * className::ClassServices(void) \
{ \
return classServices; \
} \
template<> \
cmnClassServicesBase * className::ClassServicesPointer = className::ClassServices(); \
template<> \
const cmnClassServicesBase * className::Services(void) const \
{ \
return this->ClassServices(); \
} \
static cmnClassServicesBase * className##ClassServicesPointer = className::ClassServices();
Class services.
Definition cmnClassServices.h:315

◆ LIBRARY_NAME_FOR_CISST_REGISTER

#define LIBRARY_NAME_FOR_CISST_REGISTER   ""

Variable Documentation

◆ CMN_DYNAMIC_CREATION

const int CMN_DYNAMIC_CREATION = 3

◆ CMN_DYNAMIC_CREATION_COPY

const int CMN_DYNAMIC_CREATION_COPY = 2

◆ CMN_DYNAMIC_CREATION_DEFAULT

const int CMN_DYNAMIC_CREATION_DEFAULT = 1

◆ CMN_DYNAMIC_CREATION_ONEARG

const int CMN_DYNAMIC_CREATION_ONEARG = 8

◆ CMN_DYNAMIC_CREATION_SETNAME

const int CMN_DYNAMIC_CREATION_SETNAME = 5

◆ CMN_NO_DYNAMIC_CREATION

const int CMN_NO_DYNAMIC_CREATION = 0