www.pudn.com > adHocSimtest.rar > world_n.cc, change:2005-03-22,size:8322b


//----------------------------------------- 
// 
// Generated by NEDC version 2.3 
// date:	Tue Mar 22 16:01:33 2005 
// 
// Input file:	simple.ned 
// Output file:	simple_n.cc 
//----------------------------------------- 
 
 
#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: world.ned 
//-------------------------------------------- 
 
ModuleInterface( World ) 
	Machine( default ) 
	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 *parentmod) : 
      cCompoundModule(name, parentmod) {} 
  protected: 
    virtual void doBuildInside(); 
}; 
 
Define_Module( World ); 
 
void World::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; 
 
	// mobileHost 
	modtype = findModuleType( "MobileHost" ); 
	check_modtype( modtype, "MobileHost" ); 
	sub_nr = mod->par( "dim" ); 
	check_module_count(sub_nr,"mobileHost","World"); 
	cModule **mobileHost_mod = new cModule *[sub_nr]; 
 
	for (sub_i=0; sub_i<sub_nr; sub_i++) 
	{ 
		// 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 ); 
		mobileHost_mod[sub_i] = modtype->create( "mobileHost", mod, islocal); 
		check_error(); check_memory(); 
 
		mobileHost_mod[sub_i]->setIndex(sub_i, sub_nr); 
 
		// set machine list: 
		mobileHost_mod[sub_i]->setMachinePar( "default", ((cPar *)machines[0])->stringValue() ); 
		check_error(); check_memory(); 
 
		// 'parameters:' section 
		par = &(mobileHost_mod[sub_i]->par("numHost")); 
		check_param(par, "numHost"); 
		*par = mod->par( "dim" ); 
 
		par = &(mobileHost_mod[sub_i]->par("Xbound")); 
		check_param(par, "Xbound"); 
		*par = mod->par( "width" ); 
 
		par = &(mobileHost_mod[sub_i]->par("Ybound")); 
		check_param(par, "Ybound"); 
		*par = mod->par( "height" ); 
 
		n = mobileHost_mod[sub_i]->params(); 
		for(k=0;k<n;k++) 
		   if(mobileHost_mod[sub_i]->par(k).isInput()) 
		      {mobileHost_mod[sub_i]->par(k).read();check_error();} 
 
		mobileHost_mod[sub_i]->setDisplayString(dispSUBMOD, "p=165,172;b=20,20,oval" ); 
 
		// build function call: 
		mobileHost_mod[sub_i]->buildInside(); 
	} 
	machines.clear(); 
 
	mod->setDisplayString(dispENCLOSINGMOD, "p=10,10;b=$width,$height" ); 
 
	mod->checkInternalConnections(); 
	delete[] mobileHost_mod; 
	check_error(); check_memory(); 
} 
 
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 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; 
 
	// an empty actual machine list for the next module 
	par = new cPar(); 
	*par = ev.getPhysicalMachineFor("default"); 
	machines.add( par ); 
	check_error(); check_memory(); 
 
	// system module creation 
	cModuleType *modtype; 
	modtype = findModuleType( "World" ); 
	check_modtype( modtype, "World" ); 
	cModule *world_mod; 
 
	// module creation: 
	islocal = simulation.netInterface()==NULL || 
	          simulation.netInterface()->isLocalMachineIn( machines ); 
	if (!islocal) 
	    throw new cException("Local machine `%s' is not among machines specified for this network", 
	              simulation.netInterface()->localhost()); 
	world_mod = modtype->create( "world", NULL, islocal); 
	check_error(); check_memory(); 
 
	// set machine list: 
	world_mod->setMachinePar( "default", ev.getPhysicalMachineFor("default") ); 
	check_error(); check_memory(); 
 
	// 'parameters:' section 
	value.cancelRedirection(); 
	value = 0L; 
	value.setPrompt( NULL ); 
	value.setInput( true ); 
	par = &(world_mod->par("dim")); 
	check_param(par, "dim"); 
	*par = value; 
 
	value.cancelRedirection(); 
	value = 0L; 
	value.setPrompt( NULL ); 
	value.setInput( true ); 
	par = &(world_mod->par("width")); 
	check_param(par, "width"); 
	*par = value; 
 
	value.cancelRedirection(); 
	value = 0L; 
	value.setPrompt( NULL ); 
	value.setInput( true ); 
	par = &(world_mod->par("height")); 
	check_param(par, "height"); 
	*par = value; 
 
	n = world_mod->params(); 
	for(k=0;k<n;k++) 
	   if(world_mod->par(k).isInput()) 
	      {world_mod->par(k).read();check_error();} 
 
	// build function call: 
	world_mod->buildInside(); 
	machines.clear(); 
 
	check_error(); check_memory(); 
}