📄 world_n.cc
字号:
//-----------------------------------------
//
// Generated by nedtool, version 3.0
// date: Sun Sep 11 21:44:12 2005
//
//-----------------------------------------
#include <math.h>
#include "omnetpp.h"
// NEDC version check
#define NEDC_VERSION 0x0300
#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 cException("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 cException("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 cException("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 cException("%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 cException("%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 cException("%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 cException("%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 cException("%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 cException("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 cException("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 cException(!pathexpr ? "xmldoc(\"%s\"): element not found" : "xmldoc(\"%s\", \"%s\"): element not found",fname,pathexpr);
return node;
}
ModuleInterface(World)
// parameters:
Parameter(dim, ParType_Numeric)
Parameter(width, ParType_Numeric)
Parameter(height, ParType_Numeric)
EndInterface
Register_ModuleInterface(World);
class World : public cCompoundModule
{
public:
World(const char *name, cModule *parent) :
cCompoundModule(name, parent) {}
protected:
virtual void doBuildInside();
};
Define_Module(World);
namespace { // unnamed namespace to avoid name clashes
// evaluator for expression at world.ned:18
class Expr0 : public cDoubleExpression
{
private:
cModule *mod;
double width24;
MathFunc2Args intuniform27;
public:
Expr0(cModule *mod, double width24) {
this->mod=mod;
this->width24=width24;
this->intuniform27=_getFunction("intuniform",2)->mathFunc2Args();
}
cExpression *dup() {return new Expr0(mod, width24);}
double evaluate() {return intuniform27(5, (double)(width24)-(double)(5));}
};
// evaluator for expression at world.ned:19
class Expr1 : public cDoubleExpression
{
private:
cModule *mod;
double height31;
MathFunc2Args intuniform34;
public:
Expr1(cModule *mod, double height31) {
this->mod=mod;
this->height31=height31;
this->intuniform34=_getFunction("intuniform",2)->mathFunc2Args();
}
cExpression *dup() {return new Expr1(mod, height31);}
double evaluate() {return intuniform34(5, (double)(height31)-(double)(5));}
};
} // end unnamed namespace
void World::doBuildInside()
{
cModule *mod = this;
// temporary variables:
cPar tmpval;
const char *modtypename;
mod->setBackgroundDisplayString("p=5,5;b=$width,$height");
// submodules:
cModuleType *modtype = NULL;
int submodindex;
//
// submodule 'N':
//
modtype = _getModuleType("MobileHost");
int N_size = (int)(mod->par("dim"));
_checkModuleVectorSize(N_size,"N");
cModule **N_p = new cModule *[N_size];
for (submodindex=0; submodindex<N_size; submodindex++)
{
N_p[submodindex] = modtype->create("N", mod, N_size, submodindex);
// parameter assignments:
N_p[submodindex]->par("numHost") = mod->par("dim");
N_p[submodindex]->par("Xbound") = mod->par("width");
N_p[submodindex]->par("Ybound") = mod->par("height");
N_p[submodindex]->par("x") = tmpval.setDoubleValue(new Expr0(mod, mod->par("width")));
N_p[submodindex]->par("y") = tmpval.setDoubleValue(new Expr1(mod, mod->par("height")));
_readModuleParameters(N_p[submodindex]);
N_p[submodindex]->setDisplayString("b=10,10,oval");
}
//
// this level is done -- recursively build submodules too
//
for (submodindex=0; submodindex<N_size; submodindex++)
N_p[submodindex]->buildInside();
delete [] N_p;
}
class world : public cNetworkType
{
public:
world(const char *name) : cNetworkType(name) {}
world(const world& n) {setName(n.name());operator=(n);}
virtual void setupNetwork();
};
Define_Network(world);
void world::setupNetwork()
{
// temporary variables:
cPar tmpval;
const char *modtypename;
cModuleType *modtype;
modtype = _getModuleType("World");
cModule *world_p = modtype->create("world", NULL);
// parameter assignments:
world_p->par("dim") = (tmpval=0L, tmpval.setInput(true), tmpval);
world_p->par("width") = (tmpval=0L, tmpval.setInput(true), tmpval);
world_p->par("height") = (tmpval=0L, tmpval.setInput(true), tmpval);
_readModuleParameters(world_p);
// build submodules recursively (if it has any):
world_p->buildInside();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -