- Main Page
- Modules
- Classes
- Files
- Directories
- Related Pages

# macros.h

    00001 //==========================================================================
    00002 //  MACROS.H - part of
    00003 //                     OMNeT++/OMNEST
    00004 //            Discrete System Simulation in C++
    00005 //
    00006 //  Definition of the following macros:
    00007 //    Define_Network, Define_Link
    00008 //    ModuleInterface..End
    00009 //    Define_Module
    00010 //    Module_Class_Members
    00011 //    Define_Function
    00012 //    Register_Class
    00013 //
    00014 //==========================================================================
    00015
    00016 /*--------------------------------------------------------------*
    00017   Copyright (C) 1992-2005 Andras Varga
    00018
    00019   This file is distributed WITHOUT ANY WARRANTY. See the file
    00020   `license' for details on this and other legal matters.
    00021 *--------------------------------------------------------------*/
    00022
    00023 #ifndef __MACROS_H
    00024 #define __MACROS_H
    00025
    00026 #include "onstartup.h"
    00027 #include "carray.h"
    00028 #include "ctypes.h"
    00029
    00030 //=========================================================================
    00031
    00037
    00047 #define Define_Network(NAME) \
    00048   EXECUTE_ON_STARTUP(NAME##__net, networks.instance()->add(new NAME(#NAME));)
    00049
    00055 #define Define_Channel(NAME) \
    00056   EXECUTE_ON_STARTUP(NAME##__channelt, channeltypes.instance()->add(new NAME(#NAME));)
    00057
    00068 #define Define_Function(NAME,ARGCOUNT) \
    00069   EXECUTE_ON_STARTUP(NAME##__##ARGCOUNT##__func, functions.instance()->add(new cFunctionType(#NAME,NAME,ARGCOUNT));)
    00070
    00078 #define Define_Function2(NAME,FUNCTION,ARGCOUNT) \
    00079   EXECUTE_ON_STARTUP(NAME##__##ARGCOUNT##__func, functions.instance()->add(new cFunctionType(#NAME,FUNCTION,ARGCOUNT));)
    00080
    00089 #define Register_Class(CLASSNAME) \
    00090   cPolymorphic *CLASSNAME##__create() {return new CLASSNAME;} \
    00091   EXECUTE_ON_STARTUP(CLASSNAME##__class, classes.instance()->add(new cClassRegister(#CLASSNAME,CLASSNAME##__create));)
    00092
    00094
    00095 //=========================================================================
    00096
    00102
    00114 #define Define_Module(CLASSNAME) \
    00115   static cModule *CLASSNAME##__create() {return new CLASSNAME();} \
    00116   EXECUTE_ON_STARTUP(CLASSNAME##__mod, modtypes.instance()->add(new cModuleType(#CLASSNAME,#CLASSNAME,(ModuleCreateFunc)CLASSNAME##__create));)
    00117
    00129 #define Define_Module_Like(CLASSNAME,INTERFACENAME) \
    00130   static cModule *CLASSNAME##__create() {return new CLASSNAME();} \
    00131   EXECUTE_ON_STARTUP(CLASSNAME##__mod, modtypes.instance()->add(new cModuleType(#CLASSNAME,#INTERFACENAME,(ModuleCreateFunc)CLASSNAME##__create));)
    00132
    00150 // TODO dummy args can be removed in a later version, when all models have been ported
    00151 #define Module_Class_Members(CLASSNAME,BASECLASS,STACK) \
    00152     public: \
    00153       CLASSNAME(const char *dummy1=0, cModule *dummy2=0, unsigned stk=STACK) : BASECLASS(0,0,stk) {}
    00154
    00155
    00156 //=========================================================================
    00157
    00158 //
    00159 // Internal: declaration of a module interface (module gates and params).
    00160 // Example:
    00161 //    ModuleInterface(CLASSNAME)
    00162 //        Gate(NAME,TYPE)
    00163 //        Parameter(NAME,TYPES)
    00164 //    EndInterface
    00165 //
    00166 #define ModuleInterface(CLASSNAME)    static cModuleInterface::DeclarationItem CLASSNAME##__descr[] = {
    00167 #define Gate(NAME,TYPE)         {'G', #NAME, NULL,  TYPE},
    00168 #define Parameter(NAME,TYPES)   {'P', #NAME, TYPES, 0   },
    00169 #define EndInterface            {'E', NULL,  NULL,  0   }};
    00170
    00171 // internal: registers a module interface specified with the Interface..EndInterface macros
    00172 #define Register_ModuleInterface(CLASSNAME) \
    00173   EXECUTE_ON_STARTUP(CLASSNAME##__if, modinterfaces.instance()->add(new cModuleInterface(#CLASSNAME, CLASSNAME##__descr));)
    00174
    00175 // internal: gate types. To be used with module interface declarations.
    00176 #define GateDir_Input      'I'
    00177 #define GateDir_Output     'O'
    00178
    00179 // internal: parameter allowed types. To be used with module interface declarations.
    00180 #define ParType_Const      "#"
    00181 #define ParType_Any        "*"
    00182 #define ParType_Numeric    "LDCXFTB"
    00183 #define ParType_Bool       "LDCXFTB"
    00184 #define ParType_String     "S"
    00185 #define ParType_XML        "M"
    00186
    00187 #endif
    00188