cisst-saw
|
Class registration macros. More...
#include <cisstCommon/cmnTypeTraits.h>
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: {
public:
...
};
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: {
public:
...
};
Finally, the macro CMN_DECLARE_SERVICES_EXPORT_ALWAYS was introduced as a temporary fix for template classes, such as mtsGenericObjectProxy.
| |||||
#define | CMN_DECLARE_SERVICES(hasDynamicCreation, lod) | ||||
#define | CMN_DECLARE_SERVICES_EXPORT(hasDynamicCreation, lod) | ||||
#define | CMN_DECLARE_SERVICES_EXPORT_ALWAYS(hasDynamicCreation, lod) CMN_DECLARE_SERVICES_EXPORT(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: 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 template <class _templateParameter>
myClass<_templateParameter>: public cmnGenericObject
{
public:
...
};
typedef myClass<double> myClassDouble;
CMN_DECLARE_SERVICES_INSTANTIATION_EXPORT(myClassDouble)
| |||||
#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: CMN_IMPLEMENT_SERVICES(myClass);
For a templated class specialized and define using CMN_IMPLEMENT_SERVICES_TEMPLATED(myClassDouble);
| |||||
#define | LIBRARY_NAME_FOR_CISST_REGISTER "" | ||||
#define | CMN_IMPLEMENT_SERVICES_INTERNAL(className, parentServices, argType) | ||||
#define | CMN_IMPLEMENT_SERVICES(className) CMN_IMPLEMENT_SERVICES_INTERNAL(className, 0, className) | ||||
#define | CMN_IMPLEMENT_SERVICES_DERIVED(className, parentName) | ||||
#define | CMN_IMPLEMENT_SERVICES_TEMPLATED_INTERNAL(className, parentServices, argType) | ||||
#define | CMN_IMPLEMENT_SERVICES_TEMPLATED(className) CMN_IMPLEMENT_SERVICES_TEMPLATED_INTERNAL(className, 0, 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 |
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.
#define _cmnClassRegisterMacros_h |
#define CMN_DECLARE_SERVICES | ( | hasDynamicCreation, | |
lod | |||
) |
#define CMN_DECLARE_SERVICES_EXPORT | ( | hasDynamicCreation, | |
lod | |||
) |
#define CMN_DECLARE_SERVICES_EXPORT_ALWAYS | ( | hasDynamicCreation, | |
lod | |||
) | CMN_DECLARE_SERVICES_EXPORT(hasDynamicCreation, lod) |
#define CMN_DECLARE_SERVICES_INSTANTIATION | ( | className | ) |
#define CMN_DECLARE_SERVICES_INSTANTIATION_EXPORT | ( | className | ) |
#define CMN_IMPLEMENT_SERVICES | ( | className | ) | CMN_IMPLEMENT_SERVICES_INTERNAL(className, 0, className) |
#define CMN_IMPLEMENT_SERVICES_DERIVED | ( | className, | |
parentName | |||
) |
#define CMN_IMPLEMENT_SERVICES_DERIVED_TEMPLATED | ( | className, | |
parentName | |||
) |
#define CMN_IMPLEMENT_SERVICES_INTERNAL | ( | className, | |
parentServices, | |||
argType | |||
) |
#define CMN_IMPLEMENT_SERVICES_TEMPLATED | ( | className | ) | CMN_IMPLEMENT_SERVICES_TEMPLATED_INTERNAL(className, 0, className) |
#define CMN_IMPLEMENT_SERVICES_TEMPLATED_INTERNAL | ( | className, | |
parentServices, | |||
argType | |||
) |
#define LIBRARY_NAME_FOR_CISST_REGISTER "" |
const int CMN_DYNAMIC_CREATION = 3 |
const int CMN_DYNAMIC_CREATION_COPY = 2 |
const int CMN_DYNAMIC_CREATION_DEFAULT = 1 |
const int CMN_DYNAMIC_CREATION_ONEARG = 8 |
const int CMN_DYNAMIC_CREATION_SETNAME = 5 |
const int CMN_NO_DYNAMIC_CREATION = 0 |