OMNeT++ API
6.1
Discrete Event Simulation Library
regmacros.h
1
//==========================================================================
2
// REGMACROS.H - part of
3
// OMNeT++/OMNEST
4
// Discrete System Simulation in C++
5
//
6
//==========================================================================
7
8
/*--------------------------------------------------------------*
9
Copyright (C) 1992-2017 Andras Varga
10
Copyright (C) 2006-2017 OpenSim Ltd.
11
12
This file is distributed WITHOUT ANY WARRANTY. See the file
13
`license' for details on this and other legal matters.
14
*--------------------------------------------------------------*/
15
16
#ifndef __OMNETPP_REGMACROS_H
17
#define __OMNETPP_REGMACROS_H
18
19
#include "simkerneldefs.h"
20
#include "simutil.h"
// opp_typename
21
22
namespace
omnetpp {
23
42
#define Define_NED_Math_Function(NAME,ARGCOUNT) \
43
EXECUTE_ON_STARTUP(omnetpp::internal::nedFunctions.getInstance()->add(new omnetpp::cNedMathFunction(#NAME,NAME,ARGCOUNT));)
44
52
#define Define_NED_Math_Function2(NAME,FUNCTION,ARGCOUNT) \
53
EXECUTE_ON_STARTUP(omnetpp::internal::nedFunctions.getInstance()->add(new omnetpp::cNedMathFunction(#NAME,FUNCTION,ARGCOUNT));)
54
60
#define Define_NED_Math_Function3(NAME,ARGCOUNT,CATEGORY,DESCRIPTION) \
61
EXECUTE_ON_STARTUP(omnetpp::internal::nedFunctions.getInstance()->add(new omnetpp::cNedMathFunction(#NAME,NAME,ARGCOUNT,CATEGORY,DESCRIPTION));)
62
68
#define Define_NED_Math_Function4(NAME,FUNCTION,ARGCOUNT,CATEGORY,DESCRIPTION) \
69
EXECUTE_ON_STARTUP(omnetpp::internal::nedFunctions.getInstance()->add(new omnetpp::cNedMathFunction(#NAME,FUNCTION,ARGCOUNT,CATEGORY,DESCRIPTION));)
70
96
#define Define_NED_Function(FUNCTION,SIGNATURE) \
97
EXECUTE_ON_STARTUP(omnetpp::internal::nedFunctions.getInstance()->add(new omnetpp::cNedFunction(FUNCTION,SIGNATURE));)
98
105
#define Define_NED_Function2(FUNCTION,SIGNATURE,CATEGORY,DESCRIPTION) \
106
EXECUTE_ON_STARTUP(omnetpp::internal::nedFunctions.getInstance()->add(new omnetpp::cNedFunction(FUNCTION,SIGNATURE,CATEGORY,DESCRIPTION));)
107
117
#define Register_Class(CLASSNAME) __REGISTER_CLASS(CLASSNAME, omnetpp::cObject, "class")
118
128
#define Register_Abstract_Class(CLASSNAME) __REGISTER_ABSTRACT_CLASS(CLASSNAME, omnetpp::cObject, "class")
129
136
#define Define_Module(CLASSNAME) __REGISTER_CLASS(CLASSNAME, omnetpp::cModule, "module")
137
144
#define Define_Channel(CLASSNAME) __REGISTER_CLASS(CLASSNAME, omnetpp::cChannel, "channel")
145
146
// internal
147
#define __REGISTER_CLASS(CLASSNAME, BASECLASS, DESC) \
148
__REGISTER_CLASS_X(CLASSNAME, BASECLASS, DESC,
/*nothing*/
)
149
150
// internal
151
#define __REGISTER_CLASS_X(CLASSNAME, BASECLASS, DESC, EXTRACODE) \
152
static omnetpp::cObject *MAKE_UNIQUE_WITHIN_FILE(__factoryfunc_)() {BASECLASS *ret = new CLASSNAME; return ret; } \
153
static void *MAKE_UNIQUE_WITHIN_FILE(__castfunc_)(omnetpp::cObject *obj) {return (void*)dynamic_cast<CLASSNAME*>(obj);} \
154
EXECUTE_ON_STARTUP(omnetpp::internal::classes.getInstance()->add(new omnetpp::cObjectFactory(omnetpp::opp_typename(typeid(CLASSNAME)), MAKE_UNIQUE_WITHIN_FILE(__factoryfunc_), MAKE_UNIQUE_WITHIN_FILE(__castfunc_), DESC)); EXTRACODE; )
155
156
// internal
157
#define __REGISTER_ABSTRACT_CLASS(CLASSNAME, BASECLASS
/*unused*/
, DESC) \
158
static void *MAKE_UNIQUE_WITHIN_FILE(__castfunc_)(omnetpp::cObject *obj) {return (void*)dynamic_cast<CLASSNAME*>(obj);} \
159
EXECUTE_ON_STARTUP(omnetpp::internal::classes.getInstance()->add(new omnetpp::cObjectFactory(omnetpp::opp_typename(typeid(CLASSNAME)), nullptr, MAKE_UNIQUE_WITHIN_FILE(__castfunc_), DESC));)
160
166
#define Register_ClassDescriptor(DESCRIPTORCLASS) \
167
EXECUTE_ON_STARTUP(omnetpp::internal::classDescriptors.getInstance()->add(new DESCRIPTORCLASS());)
168
169
// internal
170
#define __REGISTER_CONFIGOPTION(ID, ARGLIST) \
171
omnetpp::cConfigOption *ID; \
172
EXECUTE_ON_STARTUP(omnetpp::internal::configOptions.getInstance()->add(ID = new omnetpp::cConfigOption ARGLIST);)
173
179
#define Register_GlobalConfigOption(ID, NAME, TYPE, DEFAULTVALUE, DESCRIPTION) \
180
__REGISTER_CONFIGOPTION(ID, (NAME, true, omnetpp::cConfigOption::TYPE, nullptr, DEFAULTVALUE, DESCRIPTION))
181
187
#define Register_PerRunConfigOption(ID, NAME, TYPE, DEFAULTVALUE, DESCRIPTION) \
188
__REGISTER_CONFIGOPTION(ID, (NAME, false, omnetpp::cConfigOption::TYPE, nullptr, DEFAULTVALUE, DESCRIPTION))
189
196
#define Register_GlobalConfigOptionU(ID, NAME, UNIT, DEFAULTVALUE, DESCRIPTION) \
197
__REGISTER_CONFIGOPTION(ID, (NAME, true, omnetpp::cConfigOption::CFG_DOUBLE, UNIT, DEFAULTVALUE, DESCRIPTION))
198
205
#define Register_PerRunConfigOptionU(ID, NAME, UNIT, DEFAULTVALUE, DESCRIPTION) \
206
__REGISTER_CONFIGOPTION(ID, (NAME, false, omnetpp::cConfigOption::CFG_DOUBLE, UNIT, DEFAULTVALUE, DESCRIPTION))
207
213
#define Register_PerObjectConfigOption(ID, NAME, KIND, TYPE, DEFAULTVALUE, DESCRIPTION) \
214
__REGISTER_CONFIGOPTION(ID, (NAME, omnetpp::cConfigOption::KIND, omnetpp::cConfigOption::TYPE, nullptr, DEFAULTVALUE, DESCRIPTION))
215
222
#define Register_PerObjectConfigOptionU(ID, NAME, KIND, UNIT, DEFAULTVALUE, DESCRIPTION) \
223
__REGISTER_CONFIGOPTION(ID, (NAME, omnetpp::cConfigOption::KIND, omnetpp::cConfigOption::CFG_DOUBLE, UNIT, DEFAULTVALUE, DESCRIPTION))
224
230
#define Register_MessagePrinter(CLASSNAME) \
231
EXECUTE_ON_STARTUP(omnetpp::internal::messagePrinters.getInstance()->add(new CLASSNAME());)
232
233
// helps to remove one layer of parentheses
234
#define __OPP_IDENTITY(...) __VA_ARGS__
235
251
#define Register_Enum(NAME, VALUES) \
252
EXECUTE_ON_STARTUP( \
253
omnetpp::cEnum *tmp = new omnetpp::cEnum(omnetpp::opp_typename(typeid(NAME))); \
254
tmp->registerNames(#VALUES); \
255
tmp->registerValues<NAME>( std::initializer_list<NAME> { __OPP_IDENTITY VALUES } ); \
256
omnetpp::internal::enums.getInstance()->add(tmp); \
257
)
258
278
#define Register_Enum2(VAR, NAMESTR, VALUES) \
279
omnetpp::cEnum *VAR; \
280
EXECUTE_ON_STARTUP(VAR = new omnetpp::cEnum(NAMESTR); VAR->bulkInsert VALUES; omnetpp::internal::enums.getInstance()->add(VAR))
281
298
#define Register_Enum_WithVar(VAR, NAME, VALUES) \
299
omnetpp::cEnum *VAR; \
300
EXECUTE_ON_STARTUP( \
301
omnetpp::cEnum *tmp = VAR = new omnetpp::cEnum(omnetpp::opp_typename(typeid(NAME))); \
302
tmp->registerNames(#VALUES); \
303
tmp->registerValues<NAME>( std::initializer_list<NAME> { __OPP_IDENTITY VALUES } ); \
304
omnetpp::internal::enums.getInstance()->add(tmp); \
305
)
306
324
#define Register_Enum_Custom(VAR, NAME, NAME_VALUE_PAIRS) \
325
omnetpp::cEnum *VAR; \
326
EXECUTE_ON_STARTUP( \
327
omnetpp::cEnum *tmp = VAR = new omnetpp::cEnum(omnetpp::opp_typename(typeid(NAME))); \
328
tmp->addPairs(std::initializer_list<std::pair<const char*,NAME>> { __OPP_IDENTITY NAME_VALUE_PAIRS } ); \
329
omnetpp::internal::enums.getInstance()->add(tmp); \
330
)
331
346
#define Register_Figure(NAME, CLASSNAME) \
347
__REGISTER_CLASS_X(CLASSNAME, omnetpp::cFigure, "figure", omnetpp::internal::figureTypes[NAME] = omnetpp::opp_typename(typeid(CLASSNAME)))
348
351
}
// namespace omnetpp
352
353
354
#endif
355
include
omnetpp
regmacros.h
Generated by
1.8.17