⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_n.cc

📁 topdisc算法的omnet仿真.平台:omnet+vc 6.0
💻 CC
字号:
//-----------------------------------------
//
// Generated by nedtool, version 3.3
// date: Wed Jun 06 12:30:23 2007
//
//-----------------------------------------


#include <math.h>
#include "omnetpp.h"

// NEDC version check
#define NEDC_VERSION 0x0303
#if (NEDC_VERSION!=OMNETPP_VERSION)
#    error Version mismatch! Probably this file was generated by an earlier version of nedc: 'make clean' should help.
#endif

// Disable warnings about unused variables. For MSVC and BC only:
// GCC has no way to turn on its -Wunused option in a source file :(
#ifdef _MSC_VER
#  pragma warning(disable:4101)
#endif
#ifdef __BORLANDC__
#  pragma warn -waus
#  pragma warn -wuse
#endif

static cModuleType *_getModuleType(const char *modname)
{
    cModuleType *modtype = findModuleType(modname);
    if (!modtype)
        throw new cRuntimeError("Module type definition %s not found (Define_Module() missing from C++ code?)", modname);
    return modtype;
}

static void _checkModuleVectorSize(int vectorsize, const char *mod)
{
    if (vectorsize<0)
        throw new cRuntimeError("Negative module vector size %s[%d]", mod, vectorsize);
}

static void _readModuleParameters(cModule *mod)
{
    int n = mod->params();
    for (int k=0; k<n; k++)
        if (mod->par(k).isInput())
            mod->par(k).read();
}

static int _checkModuleIndex(int index, int vectorsize, const char *modname)
{
    if (index<0 || index>=vectorsize)
        throw new cRuntimeError("Submodule index %s[%d] out of range, sizeof(%s) is %d", modname, index, modname, vectorsize);
    return index;
}

static cGate *_checkGate(cModule *mod, const char *gatename)
{
    cGate *g = mod->gate(gatename);
    if (!g)
        throw new cRuntimeError("%s has no gate named %s",mod->fullPath().c_str(), gatename);
    return g;
}

static cGate *_checkGate(cModule *mod, const char *gatename, int gateindex)
{
    cGate *g = mod->gate(gatename, gateindex);
    if (!g)
        throw new cRuntimeError("%s has no gate %s[%d]",mod->fullPath().c_str(), gatename, gateindex);
    return g;
}

static cGate *_getFirstUnusedParentModGate(cModule *mod, const char *gatename)
{
    int baseId = mod->findGate(gatename);
    if (baseId<0)
        throw new cRuntimeError("%s has no %s[] gate",mod->fullPath().c_str(), gatename);
    int n = mod->gate(baseId)->size();
    for (int i=0; i<n; i++)
        if (!mod->gate(baseId+i)->isConnectedInside())
            return mod->gate(baseId+i);
    throw new cRuntimeError("%s[] gates are all connected, no gate left for `++' operator",mod->fullPath().c_str(), gatename);
}

static cGate *_getFirstUnusedSubmodGate(cModule *mod, const char *gatename)
{
    int baseId = mod->findGate(gatename);
    if (baseId<0)
        throw new cRuntimeError("%s has no %s[] gate",mod->fullPath().c_str(), gatename);
    int n = mod->gate(baseId)->size();
    for (int i=0; i<n; i++)
        if (!mod->gate(baseId+i)->isConnectedOutside())
            return mod->gate(baseId+i);
    int newBaseId = mod->setGateSize(gatename,n+1);
    return mod->gate(newBaseId+n);
}

static cFunctionType *_getFunction(const char *funcname, int argcount)
{
    cFunctionType *functype = findFunction(funcname,argcount);
    if (!functype)
        throw new cRuntimeError("Function %s with %d args not found", funcname, argcount);
    return functype;
}

static cChannel *_createChannel(const char *channeltypename)
{
    cChannelType *channeltype = findChannelType(channeltypename);
    if (!channeltype)
        throw new cRuntimeError("Channel type %s not found", channeltypename);
    cChannel *channel = channeltype->create("channel");
    return channel;
}

static cChannel *_createNonTypedBasicChannel(double delay, double error, double datarate)
{
    cBasicChannel *channel = new cBasicChannel("channel");
    if (delay!=0) channel->setDelay(delay);
    if (error!=0) channel->setError(error);
    if (datarate!=0) channel->setDatarate(datarate);
    return channel;
}

static cXMLElement *_getXMLDocument(const char *fname, const char *pathexpr=NULL)
{
    cXMLElement *node = ev.getXMLDocument(fname, pathexpr);
    if (!node)
        throw new cRuntimeError(!pathexpr ? "xmldoc(\"%s\"): element not found" : "xmldoc(\"%s\", \"%s\"): element not found",fname,pathexpr);
    return node;
}

ModuleInterface(application)
    // gates:
    Gate(lowergate_in, GateDir_Input)
    Gate(uppergate_in, GateDir_Input)
    Gate(blackboard_in, GateDir_Input)
    Gate(lowergate_out, GateDir_Output)
    Gate(uppergate_out, GateDir_Output)
EndInterface

Register_ModuleInterface(application)

//// Sample code:
// class application : public cSimpleModule
// {
//     Module_Class_Members(application,cSimpleModule,16384)
//     virtual void activity();
//     // Add you own member functions here!
// };
//
// Define_Module(application);
//
// void application::activity()
// {
//     // Put code for simple module activity here!
// }
//

ModuleInterface(layer0)
    // gates:
    Gate(lowergate_in[], GateDir_Input)
    Gate(uppergate_in, GateDir_Input)
    Gate(blackboard_in, GateDir_Input)
    Gate(lowergate_out[], GateDir_Output)
    Gate(uppergate_out, GateDir_Output)
EndInterface

Register_ModuleInterface(layer0)

//// Sample code:
// class layer0 : public cSimpleModule
// {
//     Module_Class_Members(layer0,cSimpleModule,16384)
//     virtual void activity();
//     // Add you own member functions here!
// };
//
// Define_Module(layer0);
//
// void layer0::activity()
// {
//     // Put code for simple module activity here!
// }
//

ModuleInterface(sensornode)
    // parameters:
    Parameter(MCONNECT, ParType_Numeric)
    Parameter(KIND, ParType_Numeric)
    Parameter(COLOR, ParType_Numeric)
    Parameter(TYPE, ParType_Numeric)
    Parameter(PX, ParType_Numeric)
    Parameter(PY, ParType_Numeric)
    // gates:
    Gate(in[], GateDir_Input)
    Gate(out[], GateDir_Output)
EndInterface

Register_ModuleInterface(sensornode);

class sensornode : public cCompoundModule
{
  public:
    sensornode() : cCompoundModule() {}
  protected:
    virtual void doBuildInside();
};

Define_Module(sensornode);

void sensornode::doBuildInside()
{
    cModule *mod = this;

    // temporary variables:
    cPar tmpval;
    const char *modtypename;

    mod->setBackgroundDisplayString("b=290,485,rect;o=white");

    // submodules:
    cModuleType *modtype = NULL;
    int submodindex;

    //
    // submodule 'sm_layer0':
    //
    int sm_layer0_size = 1;
    modtype = _getModuleType("layer0");
    cModule *sm_layer0_p = modtype->create("sm_layer0", mod);
    {
        cContextSwitcher __ctx(sm_layer0_p); // do the rest in this module's context

        // gatesizes:
        sm_layer0_p->setGateSize("lowergate_in", (int)(mod->par("MCONNECT")));
        sm_layer0_p->setGateSize("lowergate_out", (int)(mod->par("MCONNECT")));

        _readModuleParameters(sm_layer0_p);
        sm_layer0_p->setDisplayString("p=110,162;i=layer0");
    }

    //
    // submodule 'sm_application':
    //
    int sm_application_size = 1;
    modtype = _getModuleType("application");
    cModule *sm_application_p = modtype->create("sm_application", mod);
    {
        cContextSwitcher __ctx(sm_application_p); // do the rest in this module's context

        _readModuleParameters(sm_application_p);
        sm_application_p->setDisplayString("p=110,30;i=application");
    }

    //
    // connections:
    //
    cGate *srcgate, *destgate;

    cChannel *channel;
    cPar *par;
    // for loop:
    {
        long start = (long)(0);
        long end = (long)((double)(mod->par("MCONNECT"))-(double)(1));
        for (long i_var=start; i_var<=end; i_var++)
        {
            // connection
            srcgate = _checkGate(mod, "in", (int)(i_var));
            destgate = _checkGate(sm_layer0_p, "lowergate_in", (int)(i_var));
            srcgate->connectTo(destgate);

            // connection
            srcgate = _checkGate(sm_layer0_p, "lowergate_out", (int)(i_var));
            destgate = _checkGate(mod, "out", (int)(i_var));
            srcgate->connectTo(destgate);

        }
    }
    // connection
    srcgate = _checkGate(sm_layer0_p, "uppergate_out");
    destgate = _checkGate(sm_application_p, "lowergate_in");
    srcgate->connectTo(destgate);

    // connection
    srcgate = _checkGate(sm_application_p, "lowergate_out");
    destgate = _checkGate(sm_layer0_p, "uppergate_in");
    srcgate->connectTo(destgate);


    //
    // this level is done -- recursively build submodules too
    //
    sm_layer0_p->buildInside();
    sm_application_p->buildInside();
}

ModuleInterface(manager)
    // parameters:
    Parameter(P_FMAP, ParType_Numeric)
    Parameter(N_FMAP, ParType_Numeric)
    // gates:
    Gate(in, GateDir_Input)
    Gate(out, GateDir_Output)
EndInterface

Register_ModuleInterface(manager)

//// Sample code:
// class manager : public cSimpleModule
// {
//     Module_Class_Members(manager,cSimpleModule,16384)
//     virtual void activity();
//     // Add you own member functions here!
// };
//
// Define_Module(manager);
//
// void manager::activity()
// {
//     // Put code for simple module activity here!
// }
//

ModuleInterface(test)
    // parameters:
    Parameter(NNODES, ParType_Numeric)
EndInterface

Register_ModuleInterface(test);

class test : public cCompoundModule
{
  public:
    test() : cCompoundModule() {}
  protected:
    virtual void doBuildInside();
};

Define_Module(test);

void test::doBuildInside()
{
    cModule *mod = this;

    // temporary variables:
    cPar tmpval;
    const char *modtypename;

    mod->setBackgroundDisplayString("p=0,0;b=860,560,rect;o=white");

    // submodules:
    cModuleType *modtype = NULL;
    int submodindex;

    //
    // submodule 'snode':
    //
    int snode_size = (int)(mod->par("NNODES"));
    _checkModuleVectorSize(snode_size,"snode");
    cModule **snode_p = new cModule *[snode_size];
    if (snode_size>0)
    {
        modtype = _getModuleType("sensornode");
    }
    for (submodindex=0; submodindex<snode_size; submodindex++)
    {
        snode_p[submodindex] = modtype->create("snode", mod, snode_size, submodindex);
        cContextSwitcher __ctx(snode_p[submodindex]); // do the rest in this module's context

        // parameter assignments:
        snode_p[submodindex]->par("MCONNECT") = mod->par("NNODES");
        snode_p[submodindex]->par("KIND") = 2;
        snode_p[submodindex]->par("TYPE") = -1;
        snode_p[submodindex]->par("COLOR") = 2;
        snode_p[submodindex]->par("PX") = 0;
        snode_p[submodindex]->par("PY") = 0;

        // gatesizes:
        snode_p[submodindex]->setGateSize("in", (int)(mod->par("NNODES")));
        snode_p[submodindex]->setGateSize("out", (int)(mod->par("NNODES")));

        _readModuleParameters(snode_p[submodindex]);
        snode_p[submodindex]->setDisplayString("p=52,48;b=40,24");
    }

    //
    // submodule 'man':
    //
    int man_size = 1;
    modtype = _getModuleType("manager");
    cModule *man_p = modtype->create("man", mod);
    {
        cContextSwitcher __ctx(man_p); // do the rest in this module's context

        // parameter assignments:
        man_p->par("P_FMAP") = 0;
        man_p->par("N_FMAP") = 0;

        _readModuleParameters(man_p);
    }

    //
    // connections:
    //
    cGate *srcgate, *destgate;

    cChannel *channel;
    cPar *par;

    //
    // this level is done -- recursively build submodules too
    //
    for (submodindex=0; submodindex<snode_size; submodindex++)
        snode_p[submodindex]->buildInside();
    delete [] snode_p;
    man_p->buildInside();
}

class thetest : public cNetworkType
{
  public:
    thetest(const char *name) : cNetworkType(name) {}
    thetest(const thetest& n) : cNetworkType(n.name()) {operator=(n);}
    virtual void setupNetwork();
};

Define_Network(thetest);

void thetest::setupNetwork()
{
    // temporary variables:
    cPar tmpval;
    const char *modtypename;

    cModuleType *modtype;

    modtype = _getModuleType("test");
    cModule *thetest_p = modtype->create("thetest", NULL);

    cContextSwitcher __ctx(thetest_p); // do the rest in this module's context
    _readModuleParameters(thetest_p);
    // build submodules recursively (if it has any):
    thetest_p->buildInside();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -