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-2001 Andras Varga
00018   Technical University of Budapest, Dept. of Telecommunications,
00019   Stoczek u.2, H-1111 Budapest, Hungary.
00020 
00021   This file is distributed WITHOUT ANY WARRANTY. See the file
00022   `license' for details on this and other legal matters.
00023 *--------------------------------------------------------------*/
00024 
00025 #ifndef __MACROS_H
00026 #define __MACROS_H
00027 
00028 #include "ctypes.h"
00029 
00030 //=========================================================================
00031 
00037 
00047 #define Define_Network(NAME,SETUPFUNC) \
00048   void SETUPFUNC(); \
00049   static cNetworkType NAME##__network(#NAME,SETUPFUNC);
00050 
00058 #define Define_Link(NAME,DELAY,ERROR,DATARATE) \
00059   static cLinkType NAME##__link(#NAME, DELAY, ERROR, DATARATE);
00060 
00071 #define Define_Function(FUNCTION,ARGCOUNT) \
00072   cFunctionType FUNCTION##__functype(#FUNCTION,(MathFunc)FUNCTION,ARGCOUNT);
00073 
00080 #define Register_Class(CLASSNAME) \
00081   void *CLASSNAME##__create() {return new CLASSNAME;} \
00082   cClassRegister CLASSNAME##__reg(#CLASSNAME,CLASSNAME##__create);
00083 
00090 #define Register_InspectorFactory(FACTORYNAME,FUNCTION) \
00091   TInspector *FUNCTION(cObject *, int, void *); \
00092   cInspectorFactory FACTORYNAME##__inspfct(#FACTORYNAME,FUNCTION);
00093 
00094 
00095 //=========================================================================
00096 
00102 
00114 #define Define_Module(CLASSNAME) \
00115   static cModule *CLASSNAME##__create(const char *name, cModule *parentmod ) \
00116   { \
00117      return (cModule *) new CLASSNAME(name, parentmod); \
00118   } \
00119   cModuleType CLASSNAME##__type(#CLASSNAME,#CLASSNAME,(ModuleCreateFunc)CLASSNAME##__create);
00120 
00128 #define Define_Module_Like(CLASSNAME,INTERFACE) \
00129   static cModule *CLASSNAME##__create(const char *name, cModule *parentmod ) \
00130   { \
00131      return (cModule *) new CLASSNAME(name, parentmod); \
00132   } \
00133   cModuleType CLASSNAME##__type(#CLASSNAME,#INTERFACE,(ModuleCreateFunc)CLASSNAME##__create);
00134 
00155 #define Module_Class_Members(CLASSNAME,BASECLASS,STACK) \
00156     public: \
00157       CLASSNAME(const char *name, cModule *parentmod, unsigned stk=STACK) : \
00158            BASECLASS(name, parentmod, stk) {} \
00159       virtual const char *className() const {return #CLASSNAME;}
00160 
00161 
00162 //=========================================================================
00163 
00164 // internal: declaration of a module interface (module gates and params)
00165 // example:
00166 //    Interface(CLASSNAME)
00167 //        Gate(NAME,TYPE)
00168 //        Parameter(NAME,TYPES)
00169 //        Machine(NAME)
00170 //    EndInterface
00171 //
00172 #define Interface(CLASSNAME)    static sDescrItem CLASSNAME##__descr[] = {
00173 #define Gate(NAME,TYPE)         {'G', #NAME, NULL,  TYPE},
00174 #define Parameter(NAME,TYPES)   {'P', #NAME, TYPES, 0   },
00175 #define Machine(NAME)           {'M', #NAME, NULL,  0   },
00176 #define EndInterface            {'E', NULL,  NULL,  0   }};
00177 
00178 // internal: registers a module interface specified with the Interface..EndInterface macros
00179 #define Register_Interface(CLASSNAME) \
00180   static cModuleInterface CLASSNAME##__interface( #CLASSNAME, CLASSNAME##__descr);
00181 
00182 // internal: gate types. To be used with module interface declarations.
00183 #define GateDir_Input      'I'
00184 #define GateDir_Output     'O'
00185 
00186 // internal: parameter allowed types. To be used with module interface declarations.
00187 #define ParType_Const      "#"
00188 #define ParType_Any        "*"
00189 #define ParType_Numeric    "LDXFT"
00190 #define ParType_Bool       "B"
00191 #define ParType_String     "S"
00192 
00193 #endif
00194 

Generated at Sat May 4 15:45:49 2002 for OMNeT++ by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001