fedparser_store.cc

来自「certi-SHM-3.0.tar 不错的开源的分布式方针软件 大家多多支持 他」· CC 代码 · 共 570 行 · 第 1/2 页

CC
570
字号
// -*- mode:C++ ; tab-width:4 ; c-basic-offset:4 ; indent-tabs-mode:nil -*-// ----------------------------------------------------------------------------// CERTI - HLA RunTime Infrastructure// Copyright (C) 2002, 2003  ONERA//// 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: FedParser_Store.cc,v 3.10 2003/03/12 10:04:02 breholee Exp $// ----------------------------------------------------------------------------#include "FedParser.hh"namespace certi {namespace fedparser {static pdCDebug D("CREAD", "(cread) - ");// ----------------------------------------------------------------------------//! Allocate, initialize and register(add to RootObj tree) new Object Class.void FedParser::allocateAndRegisterObjectClass(void)    throw (RTIinternalError){    objStack.push_back(new ObjectClass);    objStack.back()->setHandle(objStack.size());    objStack.back()->Depth = Depth ;    RootObj->ObjectClasses->addClass(objStack.back());}// ----------------------------------------------------------------------------/*! Allocate, initialize and register (add to RootObj tree) new Interaction  Class.*/void FedParser::allocateAndRegisterInteractionClass(void)    throw (RTIinternalError){    intStack.push_back(new Interaction);    intStack.back()->handle = intStack.size();    intStack.back()->depth = Depth ;    RootObj->Interactions->addClass(intStack.back());}// ----------------------------------------------------------------------------//! Frees the allocated memory for object./*! Atom and String objects store a name. In these case, memory allocated to  object name is freed. Object memory is freed.*/voidFedParser::freeObject(Object *x){    switch(x->type) {    case ATOM_TYPE: {        Atom *y = (Atom *) x ;        if (y->name != NULL) {            free(y->name);            y->name = NULL ;        }        break ;    }    case STRING_TYPE: {        String *y = (String *) x ;        if (y->name != NULL) {            free(y->name);            y->name = NULL ;        }        break ;    }    }    free(x);}// ----------------------------------------------------------------------------/*! Return the last registered Object Class handle whose Depth is equal to  (Depth-1).*/ObjectClass *FedParser::findObjectParent(void) const    throw (RTIinternalError){    // The parent class of the current Interaction is the last Interaction    // class whose Depth attribute is equal to(current Depth minus one).    vector<ObjectClass *>::const_reverse_iterator i ;    for (i = objStack.rbegin(); i != objStack.rend(); i++) {        if ((*i)->Depth == (Depth - 1))            return *i ;    }    D.Out(pdError, "Parent Class not found.");    throw RTIinternalError("Parent Class not found.");}// ----------------------------------------------------------------------------/*! Return the last registered Interaction class handle whose Depth is equal  to (Depth-1).*/Interaction *FedParser::findInteractionParent(void) const    throw (RTIinternalError){    // The parent class of the current Interaction is the last Interaction    // class whose Depth attribute is equal to(current Depth minus one).    vector<Interaction *>::const_reverse_iterator i ;    for (i = intStack.rbegin(); i != intStack.rend(); i++) {        if ((*i)->depth == (Depth - 1))            return *i ;    }    D.Out(pdError, "Interaction Parent Class not found.");    throw RTIinternalError("Parent Class not found.");}// ----------------------------------------------------------------------------/*! When a 'attribute' atom is encountered, it means that a new object class  attribute definition is starting. This function process this event.*/void FedParser::processAttributeAtom(Atom *)    throw (RTIinternalError){    attStack.push_back(new ObjectClassAttribute());    attStack.back()->setHandle(objStack.back()->addAttribute(attStack.back()));    D.Out(pdRegister, "Adding new attribute %u to ObjectClass %u.",          attStack.back()->getHandle(), objStack.back()->getHandle());    TypeStack[Depth] = ATTRIB ;}// ----------------------------------------------------------------------------//! Called by storeAtom to process class atom./*! When a 'class' atom is encountered, it means that a new object or  interaction class definition is starting. This function process this kind  of event.*/voidFedParser::processClassAtom(Atom *)    throw (RTIinternalError){    switch(TypeStack[Depth - 1]) {    case OBJ: // Root Object Class(no parent class)        D.Out(pdRegister, "Allocating Root Object Class.");        allocateAndRegisterObjectClass();        if (objStack.size() >= CREAD_MAX_OBJ_COUNT) {            D.Out(pdError, "Maximum Object Class count reached.");            throw RTIinternalError("Maximum Object Class count reached in FED.");        }        TypeStack[Depth] = CLASSOBJ ;        break ;    case INT: // Root Interaction Class(no parent class)        D.Out(pdRegister, "Allocating Root Interaction Class.");        allocateAndRegisterInteractionClass();        if (intStack.size() >= CREAD_MAX_OBJ_COUNT) {            D.Out(pdError, "Maximum Interaction Class count reached.");            throw RTIinternalError("Maximum Inter. Class count reached in FED.");        }        TypeStack[Depth] = CLASSINT ;        break ;    case CLASSOBJ: { // Object Class(with a parent class)        D.Out(pdRegister, "Allocating Child Object Class.");        allocateAndRegisterObjectClass();        if (objStack.size() >= CREAD_MAX_OBJ_COUNT) {            D.Out(pdError, "Maximum Object Class count reached.");            throw RTIinternalError("Maximum Object Class count reached in FED.");        }        // The parent Class is the last one with a Depth attribute equal to        //(the current Depth - 1)        ObjectClass * oc = findObjectParent();        // Build the Parent-Child relation(mutual register, copy attributes...)        RootObj->ObjectClasses->buildParentRelation(objStack.back(), oc);        TypeStack[Depth] = CLASSOBJ ;    }        break ;    case CLASSINT: { // Interaction Class(with parent)        D.Out(pdRegister, "Allocating Child Interaction Class.");        allocateAndRegisterInteractionClass();        // The Parent Interaction Class is the last Interaction Class whose        // Depth is equal to(current Depth minus one)        Interaction * inter = findInteractionParent();        // Build the Parent-Child relation(mutual register, copy attributes...)        RootObj->Interactions->buildParentRelation(intStack.back(), inter);        if (intStack.size() >= CREAD_MAX_OBJ_COUNT) {            D.Out(pdError, "Maximum Interaction Class count reached.");            throw RTIinternalError("Maximum Inter. Class count reached in FED.");        }        TypeStack[Depth] = CLASSINT ;    }        break ;    default:        D.Out(pdError, "Unknown type ProcessClassAtom's switch.");        throw RTIinternalError("Unknown type ProcessClassAtom's switch.");        break ;    }}// ----------------------------------------------------------------------------/*! Process a 'federate' list token, containing a Federate Name and a Security  Level associated with it. This method is called twice, for the Federate  Name string and then for the Federate Level string.*/void FedParser::processFederateString(String *x)    throw (RTIinternalError){    SecurityLevelID LevelID ;    switch(TypeStack[Depth]) {    case FEDERATE_NAME:        // Check and store federate name        if (strlen(x->name) > MAX_FEDERATE_NAME_LENGTH) {            cout << "Federate Name too long in FED file : " << x->name << endl ;            throw RTIinternalError("Federate Name too long in FED file.");        }        strcpy(FederateNameBuffer, x->name);        // Wait for federate level string        TypeStack[Depth] = FEDERATE_LEVEL ;        break ;    case FEDERATE_LEVEL:        // 1- Translate string into SecurityLevelID        LevelID = RootObj->GetSecurityLevelID(x->name);        // 2- Register Federate to Security Server        RootObj->registerFederate(FederateNameBuffer, LevelID);        TypeStack[Depth] = NONE ;        break ;    default:        throw RTIinternalError("Unknown TypeStack value in ProcessFederateSt.");    }}// ----------------------------------------------------------------------------/*! When a 'parameter' atom is encountered, it means that a new interaction  parameter definition is starting. This function process this event.*/void FedParser::processParameterAtom(Atom *)    throw (RTIinternalError){    parStack.push_back(new Parameter);    parStack.back()->Handle = intStack.back()->addParameter(parStack.back());    D.Out(pdRegister, "Adding new parameter %u to Interaction %u.",          parStack.back()->Handle, intStack.back()->handle);

⌨️ 快捷键说明

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