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

# ctypes.h

    00001 //==========================================================================
    00002 //  CTYPES.H - part of
    00003 //                     OMNeT++/OMNEST
    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 //    cChannelType    : 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-2005 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 <stdarg.h>
    00030 #include "defs.h"
    00031 #include "globals.h"
    00032 #include "cobject.h"
    00033
    00034 //=========================================================================
    00035 //=== classes declared here
    00036 class  cModuleInterface;
    00037 class  cModuleType;
    00038 class  cChannelType;
    00039 class  cNetworkType;
    00040 class  cFunctionType;
    00041 class  cInspectorFactory;
    00042
    00043 //=== class mentioned
    00044 class  cModule;
    00045 class  cPar;
    00046 class  cChannel;
    00047
    00048 //=== function types used by cModuleType & cChannelType
    00049
    00055 typedef cModule *(*ModuleCreateFunc)();
    00056
    00062 typedef cPar *(*ParCreateFunc)();
    00063
    00064 //==========================================================================
    00065
    00107 class SIM_API cModuleInterface : public cObject
    00108 {
    00109   public:
    00110     // used by the ModuleInterface macro
    00111     struct DeclarationItem
    00112     {
    00113         char what;
    00114         char *name;
    00115         char *types;
    00116         char type;
    00117     };
    00118
    00119   protected:
    00120     struct GateDecl
    00121     {
    00122        char *name;
    00123        char type;
    00124        bool vect;
    00125     };
    00126
    00127     struct ParamDecl
    00128     {
    00129        char *name;
    00130        char *types;
    00131     };
    00132
    00133     int maxnumgates;  // allocated room for gate declarations
    00134     int numgates;     // actually used
    00135     GateDecl *gatev;  // the vector
    00136
    00137     int maxnumparams; // as above
    00138     int numparams;
    00139     ParamDecl *paramv;
    00140
    00141   protected:
    00142     // internal
    00143     void checkConsistency();
    00144
    00145     // internal
    00146     void setup(DeclarationItem *decltable);
    00147
    00148   public:
    00151
    00155     cModuleInterface(const char *name);
    00156
    00160     cModuleInterface(const char *name, DeclarationItem *decltable);
    00161
    00165     cModuleInterface(const cModuleInterface& mi);
    00166
    00170     virtual ~cModuleInterface();
    00171
    00175     cModuleInterface& operator=(const cModuleInterface& mi);
    00177
    00180
    00185     virtual cPolymorphic *dup() const  {return new cModuleInterface(*this);}
    00187
    00193     void allocateGateDecls(int maxnumgates);
    00194
    00198     void allocateParamDecls(int maxnumparams);
    00199
    00203     void addGateDecl(const char *name, const char type, bool isvector=false);
    00204
    00208     void addParamDecl(const char *name, const char *types);
    00210
    00216     int numParams();
    00217
    00221     int findParam(const char *name);
    00222
    00226     const char *paramName(int k);
    00227
    00231     const char *paramType(int k);
    00232
    00236     bool isParamConst(int k);
    00237
    00241     int numGates();
    00242
    00246     int findGate(const char *name);
    00247
    00251     const char *gateName(int k);
    00252
    00256     char gateType(int k);
    00257
    00261     bool isGateVector(int k);
    00263
    00266
    00270     void addParametersGatesTo(cModule *module);
    00271
    00277     void checkParametersOf(cModule *module);
    00279 };
    00280
    00281 //==========================================================================
    00282
    00300 class SIM_API cModuleType : public cObject
    00301 {
    00302     friend class cModule;
    00303
    00304   protected:
    00305     char *interface_name;
    00306     cModuleInterface *iface;
    00307     ModuleCreateFunc create_func;
    00308
    00309     // internal: here it invokes create_func
    00310     virtual cModule *createModuleObject();
    00311
    00312   public:
    00315
    00319     cModuleType(const char *classname, const char *interf_name, ModuleCreateFunc cf);
    00320
    00324     cModuleType(const cModuleType& mi);
    00325
    00329     virtual ~cModuleType();
    00330
    00334     cModuleType& operator=(const cModuleType& mi);
    00336
    00339
    00344     virtual cPolymorphic *dup() const     {return new cModuleType(*this);}
    00346
    00349
    00356     virtual cModule *create(const char *name, cModule *parentmod);
    00357
    00363     virtual cModule *create(const char *name, cModule *parentmod, int vectorsize, int index);
    00364
    00369     virtual void buildInside(cModule *mod);
    00370
    00387     virtual cModule *createScheduleInit(char *name, cModule *parentmod);
    00388
    00395     virtual cModuleInterface *moduleInterface();
    00397 };
    00398
    00399
    00400 //==========================================================================
    00401
    00410 class SIM_API cChannelType : public cObject
    00411 {
    00412   public:
    00415
    00419     cChannelType(const char *name=NULL);
    00420
    00424     virtual ~cChannelType() {}
    00425
    00429     cChannelType& operator=(const cChannelType&)  {copyNotSupported();return *this;}
    00431
    00434
    00438     virtual cChannel *create(const char *name) = 0;
    00440 };
    00441
    00442
    00451 class SIM_API cLinkType : public cChannelType
    00452 {
    00453   private:
    00454     cPar *(*delayfunc)();     // delay
    00455     cPar *(*errorfunc)();     // bit error rate
    00456     cPar *(*dataratefunc)();  // data rate
    00457
    00458   public:
    00461
    00467     cLinkType(const char *name, cPar *(*d)(), cPar *(*e)(), cPar *(*dr)());
    00468
    00472     cLinkType(const cLinkType& li);
    00473
    00477     virtual ~cLinkType() {}
    00478
    00482     cLinkType& operator=(const cLinkType&)  {copyNotSupported();return *this;}
    00484
    00487
    00492     virtual cPolymorphic *dup() const  {return new cLinkType(*this);}
    00494
    00497
    00501     virtual cChannel *create(const char *name);
    00503 };
    00504
    00505 //==========================================================================
    00506
    00518 class SIM_API cNetworkType : public cObject
    00519 {
    00520   public:
    00523
    00527     cNetworkType(const cNetworkType& n) : cObject() {setName(n.name());operator=(n);}
    00528
    00532     cNetworkType(const char *name=NULL) : cObject(name) {}
    00533
    00537     virtual ~cNetworkType() {}
    00538
    00542     cNetworkType& operator=(const cNetworkType&)  {copyNotSupported();return *this;}
    00544
    00548     virtual void setupNetwork() = 0;
    00549
    00550 };
    00551
    00552 //==========================================================================
    00553
    00562 class SIM_API cFunctionType : public cObject
    00563 {
    00564   private:
    00565     MathFunc f;
    00566     int argc;
    00567   public:
    00570
    00574     cFunctionType(const cFunctionType& ft) : cObject() {setName(ft.name());operator=(ft);}
    00575
    00579     cFunctionType(const char *name, MathFuncNoArg f, int argc=-1);
    00580
    00584     cFunctionType(const char *name, MathFunc1Arg f, int argc=-1);
    00585
    00590     cFunctionType(const char *name, MathFunc2Args f, int argc=-1);
    00591
    00595     cFunctionType(const char *name, MathFunc3Args f, int argc=-1);
    00596
    00600     cFunctionType(const char *name, MathFunc4Args f, int argc=-1);
    00601
    00605     virtual ~cFunctionType() {}
    00606
    00610     cFunctionType& operator=(const cFunctionType&)  {copyNotSupported();return *this;}
    00612
    00615
    00620     virtual cPolymorphic *dup() const  {return new cFunctionType(*this);}
    00622
    00628     int argCount() {return argc;}
    00629
    00634     MathFunc mathFunc()  {return f;}
    00635
    00640     MathFuncNoArg mathFuncNoArg();
    00641
    00646     MathFunc1Arg mathFunc1Arg();
    00647
    00652     MathFunc2Args mathFunc2Args();
    00653
    00658     MathFunc3Args mathFunc3Args();
    00659
    00664     MathFunc4Args mathFunc4Args();
    00666
    00667 };
    00668
    00669 cFunctionType *findfunctionbyptr(MathFunc f);
    00670
    00671 //==========================================================================
    00672
    00682 class SIM_API cClassRegister : public cObject
    00683 {
    00684     cPolymorphic *(*creatorfunc)();
    00685
    00686   public:
    00689
    00693     cClassRegister(const cClassRegister& c) : cObject() {setName(c.name());operator=(c);}
    00694
    00698     cClassRegister(const char *name, cPolymorphic *(*f)());
    00699
    00703     virtual ~cClassRegister() {}
    00704
    00708     cClassRegister& operator=(const cClassRegister&)  {copyNotSupported();return *this;}
    00710
    00713
    00718     virtual cPolymorphic *dup() const  {return new cClassRegister(*this);}
    00720
    00723
    00729     cPolymorphic *createOne() const  {return creatorfunc();}
    00731 };
    00732
    00733
    00739
    00761 // TBD could go into some class, as static member
    00762 SIM_API cPolymorphic *createOne(const char *classname);
    00763
    00771 // TBD could go into some class, as static member
    00772 SIM_API cPolymorphic *createOneIfClassIsKnown(const char *classname);
    00774
    00775 //==========================================================================
    00776
    00777 #endif
    00778
    00779