cisst-saw
Loading...
Searching...
No Matches
cmnClassRegisterMacros.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3
4/*
5 Author(s): Anton Deguet
6 Created on: 2006-10-30
7
8 (C) Copyright 2006-2023 Johns Hopkins University (JHU), All Rights Reserved.
9
10--- begin cisst license - do not edit ---
11
12This software is provided "as is" under an open source license, with
13no warranty. The complete license can be found in license.txt and
14http://www.cisst.org/cisst/license.txt.
15
16--- end cisst license ---
17*/
18
19#pragma once
20
21#ifndef _cmnClassRegisterMacros_h
22#define _cmnClassRegisterMacros_h
23
25
57
58
59
110#ifdef CMN_DECLARE_SERVICES
111#undef CMN_DECLARE_SERVICES
112#endif
113#define CMN_DECLARE_SERVICES(hasDynamicCreation, lod) \
114 public: \
115 enum {HAS_DYNAMIC_CREATION = hasDynamicCreation}; \
116 enum {InitialLoD = lod}; \
117 static cmnClassServicesBase * ClassServices(void); \
118 const cmnClassServicesBase * Services(void) const override; \
119 private: \
120 static cmnClassServicesBase * ClassServicesPointer;
121
122
123
124#ifdef CMN_DECLARE_SERVICES_EXPORT
125#undef CMN_DECLARE_SERVICES_EXPORT
126#endif
127#define CMN_DECLARE_SERVICES_EXPORT(hasDynamicCreation, lod) \
128 public: \
129 enum {HAS_DYNAMIC_CREATION = hasDynamicCreation}; \
130 enum {InitialLoD = lod}; \
131 CISST_EXPORT static cmnClassServicesBase * ClassServices(void); \
132 CISST_EXPORT const cmnClassServicesBase * Services(void) const override; \
133 private: \
134 static cmnClassServicesBase * ClassServicesPointer;
135
136#ifdef CMN_DECLARE_SERVICES_EXPORT_ALWAYS
137#undef CMN_DECLARE_SERVICES_EXPORT_ALWAYS
138#endif
139#if WIN32 && _MSC_VER && CISST_DLL
140#define CMN_DECLARE_SERVICES_EXPORT_ALWAYS(hasDynamicCreation, lod) \
141 public: \
142 enum {HAS_DYNAMIC_CREATION = hasDynamicCreation}; \
143 enum {InitialLoD = lod}; \
144 _declspec(dllexport) static cmnClassServicesBase * ClassServices(void); \
145 _declspec(dllexport) const cmnClassServicesBase * Services(void) const override; \
146 private: \
147 static cmnClassServicesBase * ClassServicesPointer;
148#else
149#define CMN_DECLARE_SERVICES_EXPORT_ALWAYS(hasDynamicCreation, lod) CMN_DECLARE_SERVICES_EXPORT(hasDynamicCreation, lod)
150#endif
151
153
154
195
196#ifdef CMN_DECLARE_SERVICES_INSTANTIATION
197#undef CMN_DECLARE_SERVICES_INSTANTIATION
198#endif
199#define CMN_DECLARE_SERVICES_INSTANTIATION(className) \
200template<> \
201cmnClassServicesBase * cmnClassServicesInstantiate<className>(void);
202
203#ifdef CMN_DECLARE_SERVICES_INSTANTIATION_EXPORT
204#undef CMN_DECLARE_SERVICES_INSTANTIATION_EXPORT
205#endif
206#define CMN_DECLARE_SERVICES_INSTANTIATION_EXPORT(className) \
207template<> CISST_EXPORT \
208cmnClassServicesBase * cmnClassServicesInstantiate<className>(void);
209
210
211
212
235
236#ifndef LIBRARY_NAME_FOR_CISST_REGISTER
237#define LIBRARY_NAME_FOR_CISST_REGISTER ""
238#endif
239
241#ifdef CMN_IMPLEMENT_SERVICES
242#undef CMN_IMPLEMENT_SERVICES
243#endif
244#define CMN_IMPLEMENT_SERVICES_INTERNAL(className, parentServices, argType) \
245cmnClassServicesBase * className::ClassServices(void) \
246{ \
247 static cmnClassServicesBase * classServices = cmnClassServicesInstantiate<className>(); \
248 return classServices; \
249} \
250cmnClassServicesBase * className::ClassServicesPointer = className::ClassServices(); \
251const cmnClassServicesBase * className::Services(void) const \
252{ \
253 return this->ClassServices(); \
254} \
255template<> \
256cmnClassServicesBase * cmnClassServicesInstantiate<className>(void) \
257{ \
258 static cmnClassServices<className::HAS_DYNAMIC_CREATION, className, argType> \
259 classServices(#className, &typeid(className), parentServices, LIBRARY_NAME_FOR_CISST_REGISTER, className::InitialLoD); \
260 return static_cast<cmnClassServicesBase *>(&classServices); \
261} \
262static cmnClassServicesBase * className##ClassServicesPointer = className::ClassServices();
263
264#define CMN_IMPLEMENT_SERVICES(className) \
265 CMN_IMPLEMENT_SERVICES_INTERNAL(className, 0, className)
266
267#define CMN_IMPLEMENT_SERVICES_DERIVED(className, parentName) \
268 CMN_IS_DERIVED_FROM_ASSERT(className, parentName) \
269 CMN_IMPLEMENT_SERVICES_INTERNAL(className, parentName::ClassServices(), className)
270
271#ifdef CMN_IMPLEMENT_SERVICES_TEMPLATED
272#undef CMN_IMPLEMENT_SERVICES_TEMPLATED
273#endif
274#define CMN_IMPLEMENT_SERVICES_TEMPLATED_INTERNAL(className, parentServices, argType) \
275template<> \
276cmnClassServicesBase * cmnClassServicesInstantiate<className>(void) \
277{ \
278 static cmnClassServices<className::HAS_DYNAMIC_CREATION, className, argType> \
279 classServices(#className, &typeid(className), parentServices, LIBRARY_NAME_FOR_CISST_REGISTER, className::InitialLoD); \
280 return static_cast<cmnClassServicesBase *>(&classServices); \
281} \
282template<> \
283cmnClassServicesBase * className::ClassServices(void) \
284{ \
285 static cmnClassServicesBase * classServices = cmnClassServicesInstantiate<className>(); \
286 return classServices; \
287} \
288template<> \
289cmnClassServicesBase * className::ClassServicesPointer = className::ClassServices(); \
290template<> \
291const cmnClassServicesBase * className::Services(void) const \
292{ \
293 return this->ClassServices(); \
294} \
295static cmnClassServicesBase * className##ClassServicesPointer = className::ClassServices();
296
297#define CMN_IMPLEMENT_SERVICES_TEMPLATED(className) \
298 CMN_IMPLEMENT_SERVICES_TEMPLATED_INTERNAL(className, 0, className)
299
300#define CMN_IMPLEMENT_SERVICES_DERIVED_TEMPLATED(className, parentName) \
301 CMN_IS_DERIVED_FROM_ASSERT(className, parentName) \
302 CMN_IMPLEMENT_SERVICES_TEMPLATED_INTERNAL(className, parentName::ClassServices(), className)
303
305
306
311/* This parameter allows to either register a class without dynamic
312 creation (just for logging, usually a "processing" class) or
313 register the class with dynamic creation (the log is still
314 available, mostly for "data" objects). Dynamic creation can be used
315 to create an object of a given type based on its name provided as a
316 string.
317
318 It is important to note that a class registered to allow dynamic
319 creation must provide a default constructor. The C++ compiler will
320 not be able to compile the code generated if the default constructor
321 is missing.
322*/
323
324// Possible options for dynamic creation
325const int CMN_NO_DYNAMIC_CREATION = 0; // no dynamic creation
326const int CMN_DYNAMIC_CREATION_DEFAULT = 1; // dynamic creation with default constructor
327const int CMN_DYNAMIC_CREATION_COPY = 2; // dynamic creation with copy constructor
328const int CMN_DYNAMIC_CREATION = 3; // dynamic creation with default and/or copy constructor (backward compatibility)
329const int CMN_DYNAMIC_CREATION_SETNAME = 5; // dynamic creation with default constructor and SetName method
330const int CMN_DYNAMIC_CREATION_ONEARG = 8; // dynamic creation with one argument constructor (but not copy constructor)
331
333
334#endif // _cmnClassRegisterMacros_h
const int CMN_DYNAMIC_CREATION_ONEARG
Definition cmnClassRegisterMacros.h:330
const int CMN_NO_DYNAMIC_CREATION
Definition cmnClassRegisterMacros.h:325
const int CMN_DYNAMIC_CREATION_DEFAULT
Definition cmnClassRegisterMacros.h:326
const int CMN_DYNAMIC_CREATION_SETNAME
Definition cmnClassRegisterMacros.h:329
const int CMN_DYNAMIC_CREATION
Definition cmnClassRegisterMacros.h:328
const int CMN_DYNAMIC_CREATION_COPY
Definition cmnClassRegisterMacros.h:327
Declaration of the class cmnTypeTraits.