Project

General

Profile

Statistics
| Branch: | Revision:

root / include / regmacros.h @ b781545c

History | View | Annotate | Download (8.34 KB)

1 01873262 Georg Kunz
//==========================================================================
2
//  REGMACROS.H - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//==========================================================================
7
8
/*--------------------------------------------------------------*
9
  Copyright (C) 1992-2008 Andras Varga
10
  Copyright (C) 2006-2008 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 __REGMACROS_H
17
#define __REGMACROS_H
18
19
#include "simkerneldefs.h"
20
21
NAMESPACE_BEGIN
22
23
/**
24
 * @ingroup Macros
25
 * @defgroup MacrosReg Registration macros
26
 */
27
//@{
28
29
/**
30
 * Registers a C/C++ mathematical function for use in NED and ini files. The function
31
 * may take 0, 1, 2 or 3 double arguments, and must return a double.
32
 * Corresponding C/C++ typedefs: MathFuncNoArg, MathFunc1Arg, MathFunc2Args,
33
 * MathFunc3Args, MathFunc4Args.
34
 *
35
 * Commonly used \<math.h\> functions have Define_Function() lines in the \opp
36
 * simulation kernel.
37
 *
38
 * @see Define_NED_Function
39
 *
40
 * @hideinitializer
41
 */
42
#define Define_Function(NAME,ARGCOUNT) \
43
  EXECUTE_ON_STARTUP(nedFunctions.getInstance()->add(new cMathFunction(#NAME,NAME,ARGCOUNT));)
44
45
/**
46
 * Like Define_Function(), but takes three arguments, the second one being the
47
 * pointer to the function. This macro allows registering a function with a
48
 * different name from its implementation.
49
 *
50
 * @hideinitializer
51
 */
52
#define Define_Function2(NAME,FUNCTION,ARGCOUNT) \
53
  EXECUTE_ON_STARTUP(nedFunctions.getInstance()->add(new cMathFunction(#NAME,FUNCTION,ARGCOUNT));)
54
55
/**
56
 * Like Define_Function(), but takes category and description strings as well.
57
 *
58
 * @hideinitializer
59
 */
60
#define Define_Function3(NAME,ARGCOUNT,CATEGORY,DESCRIPTION) \
61
  EXECUTE_ON_STARTUP(nedFunctions.getInstance()->add(new cMathFunction(#NAME,NAME,ARGCOUNT,CATEGORY,DESCRIPTION));)
62
63
/**
64
 * Like Define_Function2(), but takes category and description strings as well.
65
 *
66
 * @hideinitializer
67
 */
68
#define Define_Function4(NAME,FUNCTION,ARGCOUNT,CATEGORY,DESCRIPTION) \
69
  EXECUTE_ON_STARTUP(nedFunctions.getInstance()->add(new cMathFunction(#NAME,FUNCTION,ARGCOUNT,CATEGORY,DESCRIPTION));)
70
71
/**
72
 * Registers a C/C++ function for use in NED and ini files; see cNEDFunction.
73
 * FUNCTION is a pointer to the function, and SIGNATURE is the function's
74
 * signature in NED.
75
 *
76
 * The C++ function should have the following signature:
77
 * <pre>Value f(cComponent *context, Value argv[], int argc)</pre>
78
 * where Value stands for cDynamicExpression::Value.
79
 *
80
 * SIGNATURE is a string with the following syntax:
81
 * <pre>returntype name(argtype argname,...)</pre>
82
 * where types can be bool, long, double, quantity, string, xml, any
83
 * (where quantity is a double with a unit of measurement); names of
84
 * optional args should end in '?'.
85
 *
86
 * Example:
87
 * <pre>
88
 * Define_NED_Function(uniformFunc,"quantity uniform(quantity a, quantity b, long rng?)")
89
 * </pre>
90
 *
91
 * @hideinitializer
92
 */
93
#define Define_NED_Function(FUNCTION,SIGNATURE) \
94
  EXECUTE_ON_STARTUP(nedFunctions.getInstance()->add(new cNEDFunction(FUNCTION,SIGNATURE));)
95
96
/**
97
 * Like Define_NED_Function(), but allows one to specify a category string
98
 * and documentation as well.
99
 *
100
 * @hideinitializer
101
 */
102
#define Define_NED_Function2(FUNCTION,SIGNATURE,CATEGORY,DESCRIPTION) \
103
  EXECUTE_ON_STARTUP(nedFunctions.getInstance()->add(new cNEDFunction(FUNCTION,SIGNATURE,CATEGORY,DESCRIPTION));)
104
105
/**
106
 * Register class. This defines a factory object which makes it possible
107
 * to create an object by the passing class name to the createOne() function.
108
 * The class must be a subclass of cObject, otherwise a compile-time error
109
 * will occur: <i>"cannot convert..."</i>
110
 *
111
 * @hideinitializer
112
 */
113
#define Register_Class(CLASSNAME) \
114
  static cObject *__FILEUNIQUENAME__() {return new CLASSNAME;} \
115
  EXECUTE_ON_STARTUP(classes.getInstance()->add(new cObjectFactory(opp_typename(typeid(CLASSNAME)),__FILEUNIQUENAME__));)
116
117
/**
118
 * Announces the C++ simple module class to \opp, and couples it with the
119
 * NED simple module declaration of the same name.
120
 *
121
 * @hideinitializer
122
 */
123
// Implementation note: this is basically a Register_Class(), making sure the class subclasses from cModule.
124
#define Define_Module(CLASSNAME) \
125
  static cObject *__FILEUNIQUENAME__() {cModule *ret = new CLASSNAME; return ret; } \
126
  EXECUTE_ON_STARTUP(classes.getInstance()->add(new cObjectFactory(opp_typename(typeid(CLASSNAME)),__FILEUNIQUENAME__,"module"));)
127
128
/**
129
 * Announces the C++ simple module class to \opp, and couples it with the
130
 * NED simple module declaration of the given name.
131
 *
132
 * This macro has been previously marked as deprecated, and was removed in \opp 4.0.
133
 *
134
 * @hideinitializer
135
 */
136
#define Define_Module_Like(CLASSNAME,NEDNAME)  NOTE_the_deprecated_Define_Module_Like_macro_has_been_removed_in_version_4_0;
137
138
/**
139
 * Announces the C++ channel class to \opp, and couples it with the
140
 * NED channel declaration of the same name.
141
 *
142
 * @hideinitializer
143
 */
144
// Implementation note: this is basically a Register_Class().
145
#define Define_Channel(CLASSNAME) \
146
  static cObject *__FILEUNIQUENAME__() {cChannel *ret = new CLASSNAME; return ret; } \
147
  EXECUTE_ON_STARTUP(classes.getInstance()->add(new cObjectFactory(opp_typename(typeid(CLASSNAME)),__FILEUNIQUENAME__, "channel"));)
148
149
/**
150
 * Announces the C++ channel class to \opp, and couples it with the
151
 * NED channel declaration of the given name.
152
 *
153
 * This macro has been previously marked as deprecated, and was removed in \opp 4.0.
154
 *
155
 * @hideinitializer
156
 */
157
// Implementation note: this is basically a Register_Class(), only we lie about the class name.
158
#define Define_Channel_Like(CLASSNAME,NEDNAME) NOTE_the_deprecated_Define_Channel_Like_macro_has_been_removed_in_version_4_0;
159
160
/**
161
 * Internal. Registers a class descriptor which provides reflection information.
162
 *
163
 * @hideinitializer
164
 */
165
#define Register_ClassDescriptor(DESCRIPTORCLASS) \
166
  EXECUTE_ON_STARTUP(classDescriptors.getInstance()->add(new DESCRIPTORCLASS());)
167
168
/**
169
 * This macro has been previously marked as deprecated, and was removed in \opp 4.0.
170
 * Existing occurrences should be replaced with a public default constructor. That is,
171
 *
172
 * <pre>
173
 * Module_Class_Members(Foo, cSimpleModule, 0)
174
 * </pre>
175
 *
176
 * should become
177
 *
178
 * <pre>
179
 * public:
180
 *   Foo() : cSimpleModule() {}
181
 * </pre>
182
 *
183
 * @hideinitializer
184
 */
185
#define Module_Class_Members(CLASSNAME,BASECLASS,STACK)  NOTE_the_deprecated_Module_Class_Members_macro_has_been_removed_in_version_4_0
186
//@}
187
188
189
/**
190
 * @ingroup Macros
191
 * @defgroup MacrosConfigReg Configuration entry declaration macros
192
 */
193
//@{
194
195
// internal
196
#define __REGISTER_CONFIGOPTION(ID, ARGLIST) \
197
  cConfigOption *ID; \
198
  EXECUTE_ON_STARTUP(configOptions.getInstance()->add(ID = new cConfigOption ARGLIST);)
199
200
/**
201
 * Generic, with unit==NULL.
202
 * @hideinitializer
203
 */
204
#define Register_GlobalConfigOption(ID, NAME, TYPE, DEFAULTVALUE, DESCRIPTION) \
205
  __REGISTER_CONFIGOPTION(ID, (NAME, false, true, cConfigOption::TYPE, NULL, DEFAULTVALUE, DESCRIPTION))
206
207
/**
208
 * Generic, with unit==NULL.
209
 * @hideinitializer
210
 */
211
#define Register_PerRunConfigOption(ID, NAME, TYPE, DEFAULTVALUE, DESCRIPTION) \
212
  __REGISTER_CONFIGOPTION(ID, (NAME, false, false, cConfigOption::TYPE, NULL, DEFAULTVALUE, DESCRIPTION))
213
214
/**
215
 * For type==CFG_DOUBLE and a unit.
216
 * @hideinitializer
217
 */
218
#define Register_GlobalConfigOptionU(ID, NAME, UNIT, DEFAULTVALUE, DESCRIPTION) \
219
  __REGISTER_CONFIGOPTION(ID, (NAME, false, true, cConfigOption::CFG_DOUBLE, UNIT, DEFAULTVALUE, DESCRIPTION))
220
221
/**
222
 * For type==CFG_DOUBLE and a unit.
223
 * @hideinitializer
224
 */
225
#define Register_PerRunConfigOptionU(ID, NAME, UNIT, DEFAULTVALUE, DESCRIPTION) \
226
  __REGISTER_CONFIGOPTION(ID, (NAME, false, false, cConfigOption::CFG_DOUBLE, UNIT, DEFAULTVALUE, DESCRIPTION))
227
228
/**
229
 * Per-object option (can be configured per run), with unit==NULL.
230
 * @hideinitializer
231
 */
232
#define Register_PerObjectConfigOption(ID, NAME, TYPE, DEFAULTVALUE, DESCRIPTION) \
233
  __REGISTER_CONFIGOPTION(ID, (NAME, true, false, cConfigOption::TYPE, NULL, DEFAULTVALUE, DESCRIPTION))
234
235
/**
236
 * Per-object option (can be configured per run), for type==CFG_DOUBLE and a unit.
237
 * @hideinitializer
238
 */
239
#define Register_PerObjectConfigOptionU(ID, NAME, UNIT, DEFAULTVALUE, DESCRIPTION) \
240
  __REGISTER_CONFIGOPTION(ID, (NAME, true, false, cConfigOption::CFG_DOUBLE, UNIT, DEFAULTVALUE, DESCRIPTION))
241
242
//@}
243
244
NAMESPACE_END
245
246
247
#endif