Main Page Modules Class Hierarchy Compound List File List Compound Members

# macros.h

    00001 //==========================================================================
    00002 //   MACROS.H  - header for
    00003 //                             OMNeT++
    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-2003 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 "ctypes.h"
    00028
    00029 //=========================================================================
    00030
    00036
    00046 #define Define_Network(NAME) \
    00047   EXECUTE_ON_STARTUP(NAME##__net, (new NAME(#NAME))->setOwner(&networks);)
    00048
    00056 #define Define_Link(NAME,DELAY,ERROR,DATARATE) \
    00057   EXECUTE_ON_STARTUP(NAME##__linkt, (new cLinkType(#NAME, DELAY, ERROR, DATARATE))->setOwner(&linktypes);)
    00058
    00069 #define Define_Function(NAME,ARGCOUNT) \
    00070   EXECUTE_ON_STARTUP(NAME##__##ARGCOUNT##__func, (new cFunctionType(#NAME,NAME,ARGCOUNT))->setOwner(&functions);)
    00071
    00079 #define Define_Function2(NAME,FUNCTION,ARGCOUNT) \
    00080   EXECUTE_ON_STARTUP(NAME##__##ARGCOUNT##__func, (new cFunctionType(#NAME,FUNCTION,ARGCOUNT))->setOwner(&functions);)
    00081
    00088 #define Register_Class(CLASSNAME) \
    00089   void *CLASSNAME##__create() {return new CLASSNAME;} \
    00090   EXECUTE_ON_STARTUP(CLASSNAME##__class, (new cClassRegister(#CLASSNAME,CLASSNAME##__create))->setOwner(&classes);)
    00091
    00093
    00094 //=========================================================================
    00095
    00101
    00113 #define Define_Module(CLASSNAME) \
    00114   static cModule *CLASSNAME##__create(const char *name, cModule *parentmod) \
    00115   { \
    00116      return (cModule *) new CLASSNAME(name, parentmod); \
    00117   } \
    00118   EXECUTE_ON_STARTUP(CLASSNAME##__mod, (new cModuleType(#CLASSNAME,#CLASSNAME,(ModuleCreateFunc)CLASSNAME##__create))->setOwner(&modtypes);)
    00119
    00127 #define Define_Module_Like(CLASSNAME,INTERFACENAME) \
    00128   static cModule *CLASSNAME##__create(const char *name, cModule *parentmod) \
    00129   { \
    00130      return (cModule *) new CLASSNAME(name, parentmod); \
    00131   } \
    00132   EXECUTE_ON_STARTUP(CLASSNAME##__mod, (new cModuleType(#CLASSNAME,#INTERFACENAME,(ModuleCreateFunc)CLASSNAME##__create))->setOwner(&modtypes);)
    00133
    00151 #define Module_Class_Members(CLASSNAME,BASECLASS,STACK) \
    00152     public: \
    00153       CLASSNAME(const char *name, cModule *parentmod, unsigned stk=STACK) : \
    00154            BASECLASS(name, parentmod, stk) {}
    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 //        Machine(NAME)
    00165 //    EndInterface
    00166 //
    00167 #define ModuleInterface(CLASSNAME)    static cModuleInterface::sDescrItem CLASSNAME##__descr[] = {
    00168 #define Gate(NAME,TYPE)         {'G', #NAME, NULL,  TYPE},
    00169 #define Parameter(NAME,TYPES)   {'P', #NAME, TYPES, 0   },
    00170 #define Machine(NAME)           {'M', #NAME, NULL,  0   },
    00171 #define EndInterface            {'E', NULL,  NULL,  0   }};
    00172
    00173 // internal: registers a module interface specified with the Interface..EndInterface macros
    00174 #define Register_ModuleInterface(CLASSNAME) \
    00175   EXECUTE_ON_STARTUP(CLASSNAME##__if, (new cModuleInterface(#CLASSNAME, CLASSNAME##__descr))->setOwner(&modinterfaces);)
    00176
    00177 // internal: gate types. To be used with module interface declarations.
    00178 #define GateDir_Input      'I'
    00179 #define GateDir_Output     'O'
    00180
    00181 // internal: parameter allowed types. To be used with module interface declarations.
    00182 #define ParType_Const      "#"
    00183 #define ParType_Any        "*"
    00184 #define ParType_Numeric    "LDXFT"
    00185 #define ParType_Bool       "B"
    00186 #define ParType_String     "S"
    00187
    00188 #endif
    00189