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

📄 objectclassset.cc

📁 分布式仿真 开放源码
💻 CC
📖 第 1 页 / 共 2 页
字号:
// ----------------------------------------------------------------------------// 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: ObjectClassSet.cc,v 3.14 2003/05/23 13:21:48 breholee Exp $// ----------------------------------------------------------------------------#include "ObjectClassSet.hh"// Project#include <config.h>#include "ObjectClassBroadcastList.hh"#include "PrettyDebug.hh"// Standard#include <iostream>using std::list ;using std::cout ;using std::endl ;namespace certi {static pdCDebug D("OBJECTCLASSSET", "(ObjClSet) - ");// ----------------------------------------------------------------------------//! The class is not allocated, only the pointer is memorized.voidObjectClassSet::addClass(ObjectClass *newClass){    D.Out(pdInit, "Adding new object class %d.", newClass->getHandle());    newClass->server = server ;    push_front(newClass);}// ----------------------------------------------------------------------------/*! Build a Parent-Child relation between two object class, by setting the  Child's Parent handle, and registering the child in the Parent's sonSet.  Also copy all parent's Attributes in the child Class.*/voidObjectClassSet::buildParentRelation(ObjectClass *child, ObjectClass *parent){    // Register Parent to Son    child->Father = parent->getHandle();    // Transfer Security Level    child->setLevelId(parent->getLevelId());    // Register Son to Parent    parent->sonSet.push_front(child->getHandle());    // Copy Parent Attribute into Child class.    parent->addAttributesToChild(child);}// ----------------------------------------------------------------------------//! Constructor.ObjectClassSet::ObjectClassSet(SecurityServer *theSecurityServer)    : list<ObjectClass *>(){    // It can be NULL on the RTIA.    server = theSecurityServer ;}// ----------------------------------------------------------------------------//! Destructor.ObjectClassSet::~ObjectClassSet(){    while (!empty()) {        delete front();        pop_front();    }}// ----------------------------------------------------------------------------//! deleteObject.voidObjectClassSet::deleteObject(FederateHandle federate,                             ObjectHandle object,                             const char *tag)    throw (DeletePrivilegeNotHeld, ObjectNotKnown, RTIinternalError){    // It may throw ObjectNotKnown    ObjectClass *oclass = getInstanceClass(object);    D.Out(pdRegister,          "Federate %d attempts to delete instance %d in class %d.",          federate, object, oclass->getHandle());    // It may throw a bunch of exceptions.    ObjectClassBroadcastList *ocbList = oclass->deleteInstance(federate,                                                               object,                                                               tag);    // Broadcast RemoveObject message recursively    ObjectClassHandle current_class = 0 ;    if (ocbList != 0) {        current_class = oclass->Father ;        while (current_class) {            D.Out(pdRegister,                  "Broadcasting Remove msg to parent class %d for instance %d.",                  current_class, object);            // It may throw ObjectClassNotDefined            oclass = getWithHandle(current_class);            oclass->broadcastClassMessage(ocbList);            current_class = oclass->Father ;        }        delete ocbList ;    }    D.Out(pdRegister, "Instance %d has been deleted.", object);}// ----------------------------------------------------------------------------//! Print the ObjectClasses tree to the standard output.voidObjectClassSet::display() const{    cout << " ObjectClasses :" << endl ;    list<ObjectClass *>::const_iterator i ;    for (i = begin(); i != end(); i++) {        (*i)->display();    }}// ----------------------------------------------------------------------------//! getAttributeHandle.AttributeHandleObjectClassSet::getAttributeHandle(const char *the_name,                                   ObjectClassHandle the_class) const    throw (NameNotFound, ObjectClassNotDefined, RTIinternalError){    ObjectClass *objectClass = 0 ;    if (the_name == 0)        throw RTIinternalError();    D.Out(pdRequest, "Looking for attribute \"%s\" of class %u...",          the_name, the_class);    // It may throw ObjectClassNotDefined.    objectClass = getWithHandle(the_class);    return objectClass->getAttributeHandle(the_name);}// ----------------------------------------------------------------------------//! getAttributeName.const char *ObjectClassSet::getAttributeName(AttributeHandle the_handle,                                 ObjectClassHandle the_class) const    throw (AttributeNotDefined,           ObjectClassNotDefined,           RTIinternalError){    ObjectClass *objectClass = NULL ;    D.Out(pdRequest, "Looking for attribute %u of class %u...",          the_handle, the_class);    // It may throw ObjectClassNotDefined.    objectClass = getWithHandle(the_class);    return objectClass->getAttributeName(the_handle);}// ----------------------------------------------------------------------------//! getInstanceClass.ObjectClass *ObjectClassSet::getInstanceClass(ObjectHandle theObjectHandle) const    throw (ObjectNotKnown){    // Try to find Instance's Class    list<ObjectClass *>::const_iterator i ;    for (i = begin(); i != end(); i++) {        if ((*i)->isInstanceInClass(theObjectHandle) == true)            return (*i);    }    D.Out(pdExcept, "Object instance %d not found in any object class.",          theObjectHandle);    throw ObjectNotKnown();}// ----------------------------------------------------------------------------//! getObjectClassHandle.ObjectClassHandleObjectClassSet::getObjectClassHandle(const char *the_name) const    throw (NameNotFound, RTIinternalError){    if (the_name == 0)        throw RTIinternalError();    D.Out(pdRequest, "Looking for class \"%s\"...", the_name);    list<ObjectClass *>::const_iterator i ;    for (i = begin(); i != end(); i++) {        if (strcmp((*i)->getName(), the_name) == 0)            return (*i)->getHandle();    }    throw NameNotFound();}// ----------------------------------------------------------------------------//! getObjectClassName.const char *ObjectClassSet::getObjectClassName(ObjectClassHandle the_handle) const    throw (ObjectClassNotDefined,           RTIinternalError){    D.Out(pdRequest, "Looking for class %u...", the_handle);    return getWithHandle(the_handle)->getName();}// ----------------------------------------------------------------------------//! getWithHandle (private method).ObjectClass *ObjectClassSet::getWithHandle(ObjectClassHandle theHandle) const    throw (ObjectClassNotDefined){    list<ObjectClass *>::const_iterator i ;    for (i = begin(); i != end(); i++) {        if ((*i)->getHandle() == theHandle)            return (*i);    }    D.Out(pdExcept, "Unknown Object Class Handle %d .", theHandle);    throw ObjectClassNotDefined("Unknow class handle.");}// ----------------------------------------------------------------------------//! killFederate.void ObjectClassSet::killFederate(FederateHandle theFederate)    throw (){    ObjectClassBroadcastList *ocbList = NULL ;    ObjectClassHandle currentClass = 0 ;    list<ObjectClass *>::iterator i ;    for (i = begin(); i != end(); i++) {        // Call KillFederate on that class until it returns NULL.        do {            D.Out(pdExcept, "Kill Federate Handle %d .", theFederate);            ocbList = (*i)->killFederate(theFederate);            D.Out(pdExcept, "Federate Handle %d Killed.", theFederate);            // Broadcast RemoveObject message recursively            if (ocbList != 0) {                currentClass = (*i)->Father ;                D.Out(pdExcept, "List not NULL");                while (currentClass != 0) {                    D.Out(pdRegister,                          "Broadcasting Remove msg to parent class %d(Killed).",                          currentClass);                    // It may throw ObjectClassNotDefined                    (*i) = getWithHandle(currentClass);                    (*i)->broadcastClassMessage(ocbList);                    currentClass = (*i)->Father ;                }                delete ocbList ;            }        } while (ocbList != NULL);    }    D.Out(pdExcept, "End of the KillFederate Procedure.");}// ----------------------------------------------------------------------------//! publishvoidObjectClassSet::publish(FederateHandle theFederateHandle,                        ObjectClassHandle theClassHandle,                        AttributeHandle *theAttributeList,                        UShort theListSize,                        bool PubOrUnpub)    throw (ObjectClassNotDefined,           AttributeNotDefined,           RTIinternalError,           SecurityError){    // It may throw ObjectClassNotDefined    ObjectClass *theClass = getWithHandle(theClassHandle);    if (PubOrUnpub == RTI_TRUE)        D.Out(pdInit, "Federate %d attempts to publish Object Class %d.",              theFederateHandle, theClassHandle);    else        D.Out(pdTerm, "Federate %d attempts to unpublish Object Class %d.",              theFederateHandle, theClassHandle);    // It may throw AttributeNotDefined    theClass->publish(theFederateHandle,                      theAttributeList,                      theListSize,                      PubOrUnpub);}// ----------------------------------------------------------------------------//! recursiveDiscovering.voidObjectClassSet::recursiveDiscovering(ObjectClassHandle theClassHandle,                                     FederateHandle theFederate,                                     ObjectClassHandle theOriginalClass){    // It may throw ObjectClassNotDefined    ObjectClass *theClass = getWithHandle(theClassHandle);    D.Out(pdInit, "Recursive Discovering on class %d for Federate %d.",          theClassHandle, theFederate);    Boolean result ;

⌨️ 快捷键说明

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