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

📄 fed.cc

📁 分布式仿真 开放源码
💻 CC
字号:
// ----------------------------------------------------------------------------// CERTI - HLA RunTime Infrastructure// Copyright (C) 2003, 2004  Beno顃 Br閔ol閑//// This file is part of CERTI-libCERTI//// CERTI-libCERTI is free software ; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public License// as published by the Free Software Foundation ; either version 2 of// the License, or (at your option) any later version.//// CERTI-libCERTI is distributed in the hope that it will be useful, but// WITHOUT ANY WARRANTY ; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this program ; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307// USA//// $Id: fed.cc,v 3.4 2004/02/26 00:08:49 breholee Exp $// ----------------------------------------------------------------------------#include "fed.hh"#include "ObjectClassAttribute.hh"#include "Dimension.hh"#include "PrettyDebug.hh"#include <iostream>#include <utility>#include <string>#include <list>using std::cout ;using std::endl ;using std::pair ;using std::string ;using std::list ;extern FILE *yyin ;int yyparse();namespace certi {namespace fedparser {extern std::string arg ;extern OrderType order ;extern TransportType transport ;extern int line_number ;static pdCDebug D("FEDPARSER", __FILE__);static RootObject *root_object = 0 ;static bool verbose = false ;static int indentation = 0 ;const char *fed_filename ;static std::list<ObjectClass *> objects ;static std::list<Interaction *> interactions ;static string federate ;static ObjectClassAttribute *attribute ;static Parameter *parameter ;static RoutingSpace routing_space ;static int objectHandle = 1 ;static int interactionHandle = 1 ;static int attributeHandle = 1 ;static int parameterHandle = 1 ;static int spaceHandle = 1 ;static int dimensionHandle = 1 ;// ----------------------------------------------------------------------------intbuild(const char *filename, RootObject *root, bool v){    fed_filename = filename ;    line_number = 1 ;    verbose = v ;    root_object = root ;    FILE *file = fopen(filename, "r");    if (file == NULL)	return 1 ;    yyin = file ;    indentation = 0 ;    objectHandle = 1 ;    interactionHandle = 1 ;    attributeHandle = 1 ;    parameterHandle = 1 ;    spaceHandle = 1 ;    dimensionHandle = 1 ;    objects.clear();    interactions.clear();    federate = "" ;    attribute = 0 ;    parameter = 0 ;    int result = yyparse();        fclose(file);    return result ;}// ----------------------------------------------------------------------------voidindent(){    cout << endl ;    for (int i = 0 ; i < indentation ; ++i) {	cout << " " << " " << " " << " " ;    }}// ----------------------------------------------------------------------------voidstartFed(){    indent();    cout << "(FED" ;    ++indentation ;}// ----------------------------------------------------------------------------voidendFed(){    --indentation ;    cout << ")" << endl << endl ;}// ----------------------------------------------------------------------------voidaddFederation(){    indent();    cout << "(federation \"" << arg.c_str() << "\")" ;}// ----------------------------------------------------------------------------voidaddFedVersion(){    indent();    cout << "(FEDversion \"" << arg.c_str() << "\")" ;}// ----------------------------------------------------------------------------voidstartSpaces(){    indent();    cout << "(spaces" ;    ++indentation ;}// ----------------------------------------------------------------------------voidend(){    --indentation ;    cout << ")" ;}// ----------------------------------------------------------------------------voidstartObjects(){     indent();     cout << "(objects" ;         ++indentation ;}// ----------------------------------------------------------------------------voidstartInteractions(){     indent();     cout << "(interactions" ;         ++indentation ;}// ----------------------------------------------------------------------------voidstartFederate(){    federate = arg ;}// ----------------------------------------------------------------------------voidendFederate(){    SecurityLevelID level = root_object->GetSecurityLevelID(arg.c_str());    root_object->registerFederate(federate.c_str(), level);    indent();    cout <<"(federate \"" << federate.c_str() << "\" \"" 	 << arg.c_str() << "\")" ;}// ----------------------------------------------------------------------------voidstartObject(){    ObjectClass *object = new ObjectClass();    object->setHandle(objectHandle++);    object->setName(arg.c_str());    if (objects.size() > 0) {	ObjectClass *parent = objects.back();	root_object->ObjectClasses->buildParentRelation(object, parent);    }    objects.push_back(object);    root_object->ObjectClasses->addClass(object);    indent();    cout << "(class \"" << arg.c_str() << "\" (id " 	 << object->getHandle()	<< ")" ;    ++indentation ;}// ----------------------------------------------------------------------------voidaddObjectSecLevel(string name){    SecurityLevelID level = root_object->GetSecurityLevelID(name.c_str());    objects.back()->setLevelId(level);    indent();    cout << "(sec_level \"" << name.c_str() << "\")" ;}// ----------------------------------------------------------------------------voidaddAttribute(){    attribute = new ObjectClassAttribute();    objects.back()->addAttribute(attribute);    attribute->setHandle(attributeHandle++);    attribute->setName(arg.c_str());    attribute->transport = transport ;    attribute->order = order ;    indent();    cout << "(attribute \"" << arg.c_str() << "\" (id "	 << attribute->getHandle() << ")" ;    printTransport();    printOrder();    cout << ")" ;}// ----------------------------------------------------------------------------voidendObject(){    cout << ")" ;    objects.pop_back();        if (objects.size() == 0) attributeHandle = 1 ;    --indentation ;}// ----------------------------------------------------------------------------voidstartInteraction(){    Interaction *interaction = new Interaction();    interaction->setHandle(interactionHandle++);    interaction->setName(arg.c_str());    interaction->transport = transport ;    interaction->order = order ;        if (interactions.size() > 0) {	Interaction *parent = interactions.back();	root_object->Interactions->buildParentRelation(interaction, parent);    }    interactions.push_back(interaction);    root_object->Interactions->addClass(interaction);    indent();    cout << "(interaction \"" << arg.c_str() << "\" (id "	 << interaction->getHandle() << ")" ;    printTransport();    printOrder();    ++indentation ;}// ----------------------------------------------------------------------------voidaddInteractionSecurityLevel(){    SecurityLevelID level = root_object->GetSecurityLevelID(arg.c_str());    interactions.back()->setLevelId(level);    indent();    cout << "(sec_level \"" << arg.c_str() << "\")" ;}// ----------------------------------------------------------------------------voidaddObjectSecurityLevel(){    SecurityLevelID level = root_object->GetSecurityLevelID(arg.c_str());    objects.back()->setLevelId(level);    indent();    cout << "(sec_level \"" << arg.c_str() << "\")" ;}// ----------------------------------------------------------------------------voidaddParameter(){    parameter = new Parameter();    interactions.back()->addParameter(parameter);    parameter->setHandle(parameterHandle++);    parameter->setName(arg.c_str());    indent();    cout << "(parameter \"" << arg.c_str() << "\" (id "	 << parameter->getHandle() << "))" ;}// ----------------------------------------------------------------------------voidendInteraction(){    cout << ")" ;    interactions.pop_back();    if (interactions.size() == 0) parameterHandle = 1 ;    --indentation ;}// ----------------------------------------------------------------------------voidprintOrder(){    switch (order) {      case RECEIVE: cout << " receive" ; break ;      case TIMESTAMP: cout << " timestamp" ; break ;    }}// ----------------------------------------------------------------------------voidprintTransport(){    switch (transport) {      case RELIABLE: cout << " reliable" ; break ;      case BEST_EFFORT: cout << " best_effort" ; break ;    }}// ----------------------------------------------------------------------------voidstartSpace(){    routing_space = RoutingSpace();    routing_space.setHandle(spaceHandle++);    routing_space.setName(arg);    dimensionHandle = 1 ;    indent();    cout << "(space \"" << arg.c_str() << "\" (id " 	 << routing_space.getHandle() << ")" ;    ++indentation ;}// ----------------------------------------------------------------------------voidendSpace(){       root_object->addRoutingSpace(routing_space);     --indentation ;    cout << ")" ;}// ----------------------------------------------------------------------------voidaddDimension(){    Dimension dimension(dimensionHandle++);    dimension.setName(arg);    routing_space.addDimension(dimension);    indent();    cout << "(dimension \"" << arg.c_str() << "\" (id "	 << dimension.getHandle() << "))" ;}}} // namespaces// $Id: fed.cc,v 3.4 2004/02/26 00:08:49 breholee Exp $

⌨️ 快捷键说明

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