cisst-saw
Toggle main menu visibility
Loading...
Searching...
No Matches
tmp
cisst-saw
cisst
cisstCommon
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
12
This software is provided "as is" under an open source license, with
13
no warranty. The complete license can be found in license.txt and
14
http://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
24
#include <
cisstCommon/cmnTypeTraits.h
>
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) \
200
template<> \
201
cmnClassServicesBase * 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) \
207
template<> CISST_EXPORT \
208
cmnClassServicesBase * 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) \
245
cmnClassServicesBase * className::ClassServices(void) \
246
{ \
247
static cmnClassServicesBase * classServices = cmnClassServicesInstantiate<className>(); \
248
return classServices; \
249
} \
250
cmnClassServicesBase * className::ClassServicesPointer = className::ClassServices(); \
251
const cmnClassServicesBase * className::Services(void) const \
252
{ \
253
return this->ClassServices(); \
254
} \
255
template<> \
256
cmnClassServicesBase * 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
} \
262
static 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) \
275
template<> \
276
cmnClassServicesBase * 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
} \
282
template<> \
283
cmnClassServicesBase * className::ClassServices(void) \
284
{ \
285
static cmnClassServicesBase * classServices = cmnClassServicesInstantiate<className>(); \
286
return classServices; \
287
} \
288
template<> \
289
cmnClassServicesBase * className::ClassServicesPointer = className::ClassServices(); \
290
template<> \
291
const cmnClassServicesBase * className::Services(void) const \
292
{ \
293
return this->ClassServices(); \
294
} \
295
static 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
325
const
int
CMN_NO_DYNAMIC_CREATION
= 0;
// no dynamic creation
326
const
int
CMN_DYNAMIC_CREATION_DEFAULT
= 1;
// dynamic creation with default constructor
327
const
int
CMN_DYNAMIC_CREATION_COPY
= 2;
// dynamic creation with copy constructor
328
const
int
CMN_DYNAMIC_CREATION
= 3;
// dynamic creation with default and/or copy constructor (backward compatibility)
329
const
int
CMN_DYNAMIC_CREATION_SETNAME
= 5;
// dynamic creation with default constructor and SetName method
330
const
int
CMN_DYNAMIC_CREATION_ONEARG
= 8;
// dynamic creation with one argument constructor (but not copy constructor)
331
333
334
#endif
// _cmnClassRegisterMacros_h
CMN_DYNAMIC_CREATION_ONEARG
const int CMN_DYNAMIC_CREATION_ONEARG
Definition
cmnClassRegisterMacros.h:330
CMN_NO_DYNAMIC_CREATION
const int CMN_NO_DYNAMIC_CREATION
Definition
cmnClassRegisterMacros.h:325
CMN_DYNAMIC_CREATION_DEFAULT
const int CMN_DYNAMIC_CREATION_DEFAULT
Definition
cmnClassRegisterMacros.h:326
CMN_DYNAMIC_CREATION_SETNAME
const int CMN_DYNAMIC_CREATION_SETNAME
Definition
cmnClassRegisterMacros.h:329
CMN_DYNAMIC_CREATION
const int CMN_DYNAMIC_CREATION
Definition
cmnClassRegisterMacros.h:328
CMN_DYNAMIC_CREATION_COPY
const int CMN_DYNAMIC_CREATION_COPY
Definition
cmnClassRegisterMacros.h:327
cmnTypeTraits.h
Declaration of the class cmnTypeTraits.
Generated by
1.18.0