Main Page Modules Class Hierarchy Compound List File List Compound Members

# ctypes.h

    00001 //==========================================================================
    00002 //   CTYPES.H  - header for
    00003 //                             OMNeT++
    00004 //            Discrete System Simulation in C++
    00005 //
    00006 //  Declaration of the following functions:
    00007 //    createOne( char *classname )
    00008 //
    00009 //  Declaration of the following classes:
    00010 //    cModuleInterface: defines a module interface (gates+parameters)
    00011 //    cModuleType     : module class + interface pairs
    00012 //    cLinkType       : channel type (propagation delay, error rate, data rate)
    00013 //    cNetworkType    : network
    00014 //    cClassRegister  : creates an object of a specific type
    00015 //    cInspectorFactory : inspector creation
    00016 //
    00017 //==========================================================================
    00018
    00019 /*--------------------------------------------------------------*
    00020   Copyright (C) 1992-2003 Andras Varga
    00021
    00022   This file is distributed WITHOUT ANY WARRANTY. See the file
    00023   `license' for details on this and other legal matters.
    00024 *--------------------------------------------------------------*/
    00025
    00026 #ifndef __CTYPES_H
    00027 #define __CTYPES_H
    00028
    00029 #include "defs.h"
    00030
    00031 #include <stdarg.h>
    00032 #include "chead.h"
    00033 #include "cobject.h"
    00034
    00035 //=========================================================================
    00036 //=== classes declared here
    00037 class  cModuleInterface;
    00038 class  cModuleType;
    00039 class  cLinkType;
    00040 class  cNetworkType;
    00041 class  cFunctionType;
    00042 class  cInspectorFactory;
    00043
    00044 //=== class mentioned
    00045 class  cModule;
    00046 class  cPar;
    00047
    00048 //=== function types used by cModuleType & cLinkType
    00049
    00055 typedef cModule *(*ModuleCreateFunc)(const char *, cModule *);
    00056
    00062 typedef cPar *(*ParCreateFunc)();
    00063
    00064 //==========================================================================
    00065
    00102 class SIM_API cModuleInterface : public cObject
    00103 {
    00104   public:
    00105     // used by the ModuleInterface macro
    00106     struct sDescrItem {
    00107         char what;
    00108         char *name;
    00109         char *types;
    00110         char type;
    00111     };
    00112
    00113   protected:
    00114     // structures used in a cModuleInterface
    00115     struct sGateInfo {
    00116        char *name;
    00117        char type;
    00118        bool vect;
    00119     };
    00120
    00121     struct sParamInfo {
    00122        char *name;
    00123        char *types;
    00124     };
    00125
    00126     struct sMachineInfo {
    00127        char *name;
    00128     };
    00129
    00130   protected:
    00131     int ngate;
    00132     sGateInfo *gatev;
    00133     int nparam;
    00134     sParamInfo *paramv;
    00135     int nmachine;            // NET
    00136     sMachineInfo *machinev;  // NET
    00137
    00138   private:
    00139     // internal
    00140     void allocate(int ngte, int npram, int nmach);
    00141
    00142     // internal
    00143     void check_consistency();
    00144
    00145     // internal
    00146     void setup(sDescrItem *descr_table);
    00147
    00148   public:
    00151
    00155     cModuleInterface(const char *name, sDescrItem *descr_table);
    00156
    00160     cModuleInterface(const cModuleInterface& mi);
    00161
    00165     virtual ~cModuleInterface();
    00166
    00170     cModuleInterface& operator=(const cModuleInterface& mi);
    00172
    00175
    00180     virtual cObject *dup() const  {return new cModuleInterface(*this);}
    00182
    00185
    00189     void addParametersGatesTo(cModule *module);
    00190
    00196     void checkParametersOf(cModule *module);
    00198 };
    00199
    00200 //==========================================================================
    00201
    00219 class SIM_API cModuleType : public cObject
    00220 {
    00221     friend class cModule;
    00222   private:
    00223     char *interface_name;
    00224     cModuleInterface *iface;
    00225     ModuleCreateFunc create_func;
    00226
    00227   public:
    00230
    00234     cModuleType(const char *classname, const char *interf_name, ModuleCreateFunc cf);
    00235
    00239     cModuleType(const cModuleType& mi);
    00240
    00244     virtual ~cModuleType();
    00245
    00249     cModuleType& operator=(const cModuleType& mi);
    00251
    00254
    00259     virtual cObject *dup() const     {return new cModuleType(*this);}
    00261
    00264
    00270     cModule *create(const char *name, cModule *parentmod, bool local=true);
    00271
    00276     void buildInside(cModule *mod);
    00277
    00294     cModule *createScheduleInit(char *name, cModule *parentmod);
    00295
    00302     cModuleInterface *moduleInterface();
    00304 };
    00305
    00306
    00307 //==========================================================================
    00308
    00318 class SIM_API cLinkType : public cObject
    00319 {
    00320   private:
    00321     cPar *(*delayfunc)();     // delay
    00322     cPar *(*errorfunc)();     // bit error rate
    00323     cPar *(*dataratefunc)();  // data rate
    00324
    00325   public:
    00328
    00334     cLinkType(const char *name, cPar *(*d)(), cPar *(*e)(), cPar *(*dr)() );
    00335
    00339     cLinkType(const cLinkType& li);
    00340
    00344     virtual ~cLinkType()    {}
    00345
    00349     cLinkType& operator=(const cLinkType& o);
    00351
    00354
    00359     virtual cObject *dup() const     {return new cLinkType(*this);}
    00361
    00364
    00369     cPar *createDelay() const;
    00370
    00375     cPar *createError() const;
    00376
    00381     cPar *createDataRate() const;
    00383 };
    00384
    00385 //==========================================================================
    00386
    00398 class SIM_API cNetworkType : public cObject
    00399 {
    00400   public:
    00403
    00407     cNetworkType(const cNetworkType& n)  {setName(n.name());operator=(n);}
    00408
    00412     cNetworkType(const char *name=NULL) : cObject(name) {}
    00413
    00417     virtual ~cNetworkType() {}
    00418
    00422     cNetworkType& operator=(const cNetworkType&)  {copyNotSupported();return *this;}
    00424
    00428     virtual void setupNetwork() = 0;
    00429
    00430 };
    00431
    00432 //==========================================================================
    00433
    00441 class SIM_API cFunctionType : public cObject
    00442 {
    00443   private:
    00444     MathFunc f;
    00445     int argc;
    00446   public:
    00449
    00453     cFunctionType(const cFunctionType& ft)  {setName(ft.name());operator=(ft);}
    00454
    00458     cFunctionType(const char *name, MathFuncNoArg f, int argc=-1);
    00459
    00463     cFunctionType(const char *name, MathFunc1Arg f, int argc=-1);
    00464
    00469     cFunctionType(const char *name, MathFunc2Args f, int argc=-1);
    00470
    00474     cFunctionType(const char *name, MathFunc3Args f, int argc=-1);
    00475
    00479     cFunctionType(const char *name, MathFunc4Args f, int argc=-1);
    00480
    00484     virtual ~cFunctionType() {}
    00485
    00489     cFunctionType& operator=(const cFunctionType&)  {copyNotSupported();return *this;}
    00491
    00494
    00499     virtual cObject *dup() const  {return new cFunctionType(*this);}
    00501
    00507     int argCount() {return argc;}
    00508
    00513     MathFunc mathFunc()  {return f;}
    00514
    00519     MathFuncNoArg mathFuncNoArg();
    00520
    00525     MathFunc1Arg mathFunc1Arg();
    00526
    00531     MathFunc2Args mathFunc2Args();
    00532
    00537     MathFunc3Args mathFunc3Args();
    00538
    00543     MathFunc4Args mathFunc4Args();
    00545
    00546 };
    00547
    00548 cFunctionType *findfunctionbyptr(MathFunc f);
    00549
    00550 //==========================================================================
    00551
    00561 class SIM_API cClassRegister : public cObject
    00562 {
    00563     void *(*creatorfunc)();
    00564
    00565   public:
    00568
    00572     cClassRegister(const cClassRegister& c)  {setName(c.name());operator=(c);}
    00573
    00577     cClassRegister(const char *name, void *(*f)());
    00578
    00582     virtual ~cClassRegister() {}
    00583
    00587     cClassRegister& operator=(const cClassRegister&)  {copyNotSupported();return *this;}
    00589
    00592
    00597     virtual cObject *dup() const  {return new cClassRegister(*this);}
    00599
    00602
    00607     void *createOne() const  {return creatorfunc();}
    00609 };
    00610
    00616
    00633 // FIXME into some class, as static member!!!
    00634 SIM_API void *createOne(const char *classname);
    00636
    00637 //==========================================================================
    00638
    00639 #endif
    00640
    00641