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

📄 simple_n.cpp

📁 simulation routing in wsn
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//-----------------------------------------
//
// Generated by NEDC version 2.3
// date:	Fri Mar 18 15:37:40 2005
//
// Input file:	simple0.ned
// Output file:	simple0_n.cpp
//-----------------------------------------


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

#define check_error() \
    {(void)0;}
#define check_memory() \
    {if (memoryIsLow()) {throw new cException(eNOMEM); }}
#define check_module_count(num, mod, parentmod) \
    {if ((int)num<=0) {throw new cException("Negative or zero module vector size %s[%d] in compound module %s", \
                          mod,(int)num,parentmod);}}
#define check_gate_count(num, mod, gate, parentmod) \
    {if ((int)num<0) {throw new cException("Negative gate vector size %s.%s[%d] in compound module %s", \
                          mod,gate,(int)num,parentmod);}}
#define check_loop_bounds(lower, upper, parentmod) \
    {if ((int)lower<0) \
        {throw new cException("Bad loop bounds (%d..%d) in compound module %s", \
                 (int)lower,(int)upper,parentmod);}}
#define check_module_index(index,modvar,modname,parentmod) \
    {if (index<0 || index>=modvar[0]->size()) {throw new cException("Bad submodule index %s[%d] in compound module %s", \
          modname,(int)index,parentmod);}}
#define check_channel_params(delay, err, channel) \
    {if ((double)delay<0.0) \
        {throw new cException("Negative delay value %lf in channel %s",(double)delay,channel);} \
     if ((double)err<0.0 || (double)err>1.0) \
        {throw new cException("Incorrect error value %lf in channel %s",(double)err,channel);}}
#define check_modtype(modtype, modname) \
    {if ((modtype)==NULL) {throw new cException("Simple module type definition %s not found", \
                                     modname);}}
#define check_function(funcptr, funcname) \
    {if ((funcptr)==NULL) {throw new cException("Function %s not found", \
                                     funcname);}}
#define check_function_retnull(funcptr, funcname) \
    {if ((funcptr)==NULL) {throw new cException("Function %s not found", \
                                     funcname);return NULL;}}
#define check_gate(gateindex, modname, gatename) \
    {if ((int)gateindex==-1) {throw new cException("Gate %s.%s not found",modname,gatename);}}
#define check_anc_param(ptr,parname,compoundmod) \
    {if ((ptr)==NULL) {throw new cException("Unknown ancestor parameter named %s in compound module %s", \
                                parname,compoundmod);}}
#define check_param(ptr,parname) \
    {if ((ptr)==NULL) {throw new cException("Unknown parameter named %s", \
                                parname);}}
#ifndef __cplusplus
#  error Compile as C++!
#endif
#ifdef __BORLANDC__
#  if !defined(__FLAT__) && !defined(__LARGE__)
#    error Compile as 16-bit LARGE model or 32-bit DPMI!
#  endif
#endif

// Disable warnings about unused variables:
#ifdef _MSC_VER
#  pragma warning(disable:4101)
#endif
#ifdef __BORLANDC__
#  pragma warn -waus
#  pragma warn -wuse
#endif
// for GCC, seemingly there's no way to emulate the -Wunused command-line
// flag from a source file...

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

//--------------------------------------------
// Following code generated from: simple.ned
//--------------------------------------------

ModuleInterface( node )
	Machine( default )
	Parameter( nodeID, ParType_Numeric ParType_Const )
	Parameter( nwavelength, ParType_Numeric )
	Parameter( num_node, ParType_Numeric )
	Parameter( convert, ParType_Numeric )
	Gate( nin[], GateDir_Input )
	Gate( nout[], GateDir_Output )
EndInterface

Register_ModuleInterface( node )

class node : public cCompoundModule
{
  public:
    node(const char *name, cModule *parentmod) :
      cCompoundModule(name, parentmod) {}
  protected:
    virtual void doBuildInside();
};

Define_Module( node );

void node::doBuildInside()
{
	cModule *mod = this;
	// temporary variables:
	cPar value, *par;
	cPar::ExprElem *expr_tab; int k;
	cFunctionType *functype;
	const char *type_name;
	char b1[64], b2[64];
	cArray machines;
	bool islocal, do_this_block;
	int n;

	// const parameters:
	// Submodules:
	cModuleType *modtype = NULL;
	long sub_nr = 0;
	long sub_i = 0;

	// receiver
	modtype = findModuleType( "recei" );
	check_modtype( modtype, "recei" );
	cModule *receiver_mod;

	// an empty actual machine list for the next module
	par = new cPar();
	*par = mod->machinePar("default");
	machines.add( par );
	check_error(); check_memory();

	// module creation:
	islocal = simulation.netInterface()==NULL ||
	          simulation.netInterface()->isLocalMachineIn( machines );
	receiver_mod = modtype->create( "receiver", mod, islocal);
	check_error(); check_memory();

	// set machine list:
	receiver_mod->setMachinePar( "default", ((cPar *)machines[0])->stringValue() );
	check_error(); check_memory();

	// 'parameters:' section
	par = &mod->ancestorPar( "nodeID" );
	check_anc_param(par,"nodeID","node");
	value.cancelRedirection();
	value = *par;
	par = &(receiver_mod->par("nodeID"));
	check_param(par, "nodeID");
	*par = value;

	par = &mod->ancestorPar( "num_node" );
	check_anc_param(par,"num_node","node");
	value.cancelRedirection();
	value = *par;
	par = &(receiver_mod->par("num_node"));
	check_param(par, "num_node");
	*par = value;

	par = &mod->ancestorPar( "convert" );
	check_anc_param(par,"convert","node");
	value.cancelRedirection();
	value = *par;
	par = &(receiver_mod->par("convert"));
	check_param(par, "convert");
	*par = value;

	par = &mod->ancestorPar( "nwavelength" );
	check_anc_param(par,"nwavelength","node");
	value.cancelRedirection();
	value = *par;
	par = &(receiver_mod->par("nwavelength"));
	check_param(par, "nwavelength");
	*par = value;

	n = receiver_mod->params();
	for(k=0;k<n;k++)
	   if(receiver_mod->par(k).isInput())
	      {receiver_mod->par(k).read();check_error();}

	// 'gatesizes:' section
	n = mod->par( "num_node" );
	check_gate_count( n, "receiver","rin","node");
	receiver_mod->setGateSize("rin", n );

	receiver_mod->setDisplayString(dispSUBMOD, "p=92,108;b=72,40" );

	// build function call:
	receiver_mod->buildInside();
	machines.clear();

	// generator
	modtype = findModuleType( "gene" );
	check_modtype( modtype, "gene" );
	cModule *generator_mod;

	// an empty actual machine list for the next module
	par = new cPar();
	*par = mod->machinePar("default");
	machines.add( par );
	check_error(); check_memory();

	// module creation:
	islocal = simulation.netInterface()==NULL ||
	          simulation.netInterface()->isLocalMachineIn( machines );
	generator_mod = modtype->create( "generator", mod, islocal);
	check_error(); check_memory();

	// set machine list:
	generator_mod->setMachinePar( "default", ((cPar *)machines[0])->stringValue() );
	check_error(); check_memory();

	// 'parameters:' section
	par = &mod->ancestorPar( "nodeID" );
	check_anc_param(par,"nodeID","node");
	value.cancelRedirection();
	value = *par;
	par = &(generator_mod->par("nodeID"));
	check_param(par, "nodeID");
	*par = value;

	par = &mod->ancestorPar( "num_node" );
	check_anc_param(par,"num_node","node");
	value.cancelRedirection();
	value = *par;
	par = &(generator_mod->par("num_node"));
	check_param(par, "num_node");
	*par = value;

	par = &mod->ancestorPar( "convert" );
	check_anc_param(par,"convert","node");
	value.cancelRedirection();
	value = *par;
	par = &(generator_mod->par("convert"));
	check_param(par, "convert");
	*par = value;

	par = &mod->ancestorPar( "nwavelength" );
	check_anc_param(par,"nwavelength","node");
	value.cancelRedirection();
	value = *par;
	par = &(generator_mod->par("nwavelength"));
	check_param(par, "nwavelength");
	*par = value;

	value.cancelRedirection();
	value = 0L;
	value.setPrompt( NULL );
	value.setInput( true );
	par = &(generator_mod->par("holdTime"));
	check_param(par, "holdTime");
	*par = value;

	value.cancelRedirection();
	value = 0L;
	value.setPrompt( NULL );
	value.setInput( true );
	par = &(generator_mod->par("interArrivalTime"));
	check_param(par, "interArrivalTime");
	*par = value;

	n = generator_mod->params();
	for(k=0;k<n;k++)
	   if(generator_mod->par(k).isInput())
	      {generator_mod->par(k).read();check_error();}

	generator_mod->setDisplayString(dispSUBMOD, "p=276,108;b=72,40" );

	// build function call:
	generator_mod->buildInside();
	machines.clear();

⌨️ 快捷键说明

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