📄 message.cc
字号:
// ----------------------------------------------------------------------------// 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: Message.cc,v 3.23 2003/11/10 14:43:01 breholee Exp $// ----------------------------------------------------------------------------#include <config.h>#include "Message.hh"#include "RTItypes.hh"#include "PrettyDebug.hh"#include "GAV.hh"#include "converter.hh"#include <cstdio>#include <cstring>using std::vector ;namespace certi {#define NONE -1Message::Message(){ date = 0.0 ; exception = e_NO_EXCEPTION ; exceptionReason[0] = '\0' ; federateName[0] = '\0' ; federationName[0] = '\0' ; tag[0] = '\0' ; name[0] = '\0' ; label[0] = '\0' ; handleArraySize = 0 ;}// ----------------------------------------------------------------------------//! Destructor//Message::~Message(){}// ----------------------------------------------------------------------------//! getValue//char *Message::getValue(int Rank, char *Value) const throw (RTIinternalError){ // Pre-Checking if ((Rank < 0) || (Rank >= handleArraySize)) throw RTIinternalError("Bad Rank in Message."); // Getting Value if (Value != NULL) { strcpy(Value, valueArray[Rank]); return NULL ; } else return strdup(valueArray[Rank]);}// ----------------------------------------------------------------------------// getValueArray//ParameterValue *Message::getValueArray(){ int i ; ParameterValue *NewValueArray = NULL ; NewValueArray = (ParameterValue *) calloc(handleArraySize, sizeof(ParameterValue)); if (NewValueArray == NULL) throw RTIinternalError("No memory."); for (i = 0 ; i < handleArraySize ; i++) getValue(i, NewValueArray[i]); return NewValueArray ;}// ----------------------------------------------------------------------------// setLabel//void Message::setLabel(const char *NewLabel){ if (strlen(NewLabel) > MAX_USER_TAG_LENGTH) throw ValueLengthExceeded("Label too long to fit in Message."); strcpy(label, NewLabel);}// ----------------------------------------------------------------------------// setName//voidMessage::setName(const char *NewName){ if (strlen(NewName) > MAX_USER_TAG_LENGTH) throw ValueLengthExceeded("Name too long to fit in Message."); strcpy(name, NewName);}// ----------------------------------------------------------------------------// setType//voidMessage::setType(Type t){ type = t ;}// ----------------------------------------------------------------------------// setNbExtentsvoidMessage::setNumber(unsigned long nb){ number = nb ;}// ----------------------------------------------------------------------------// setSpacevoidMessage::setSpace(SpaceHandle handle){ space = handle ;}// ----------------------------------------------------------------------------// setRegionvoidMessage::setRegion(long handle){ region = handle ;}// ----------------------------------------------------------------------------// setDimensionvoidMessage::setDimension(DimensionHandle handle){ dimension = handle ;}// ----------------------------------------------------------------------------// setInteractionClassvoidMessage::setInteractionClass(InteractionClassHandle handle){ interactionClass = handle ;}// ----------------------------------------------------------------------------// setObjectClassvoidMessage::setObjectClass(ObjectClassHandle handle){ objectClass = handle ;}// ----------------------------------------------------------------------------// setAttributevoidMessage::setAttribute(AttributeHandle handle){ attribute = handle ;}// ----------------------------------------------------------------------------voidMessage::setResignAction(ResignAction the_action){ resignAction = the_action ;}// ----------------------------------------------------------------------------voidMessage::setFederationTimeDelta(FederationTimeDelta the_lookahead){ lookahead = the_lookahead ;}// ----------------------------------------------------------------------------voidMessage::setFedTime(const FedTime &the_time){ date = (FederationTime) (RTIfedTime(the_time)._fedTime);}// ----------------------------------------------------------------------------voidMessage::setLookahead(const FedTime& the_lookahead){ lookahead = (FederationTimeDelta) ((RTIfedTime&) the_lookahead).getTime();}// ----------------------------------------------------------------------------voidMessage::setFederationTime(FederationTime the_time){ date = the_time ;}// ----------------------------------------------------------------------------voidMessage::setBoolean(Boolean the_bool){ boolean = the_bool ;}// ----------------------------------------------------------------------------voidMessage::setObject(ObjectHandle the_object){ object = the_object ;}// ----------------------------------------------------------------------------voidMessage::setTransportation(TransportationHandle the_transport){ transport = ((the_transport == 1) ? RELIABLE : BEST_EFFORT);}// ----------------------------------------------------------------------------voidMessage::setOrdering(OrderingHandle the_ordering){ order = ((the_ordering == 1) ? RECEIVE : TIMESTAMP);}// ----------------------------------------------------------------------------voidMessage::setEventRetraction(EventRetractionHandle the_event){ eventRetraction = the_event ;}// ----------------------------------------------------------------------------voidMessage::setParameter(ParameterHandle the_parameter){ parameter = the_parameter ;}// ----------------------------------------------------------------------------voidMessage::setException(TypeException the_exception, const char *the_reason){ exception = the_exception ; if (strlen(the_reason) > MAX_EXCEPTION_REASON_LENGTH) throw ValueLengthExceeded("Exception reason too long to fit in" " Message."); strcpy(exceptionReason, the_reason);}// ----------------------------------------------------------------------------voidMessage::setFederate(FederateHandle the_federate){ federate = the_federate ;}// ----------------------------------------------------------------------------AttributeHandleSet*Message::getAHS() const{ AttributeHandleSet *attributeSet ; attributeSet = AttributeHandleSetFactory::create(handleArraySize); for (int i = 0 ; i < handleArraySize ; i++) { attributeSet->add(handleArray[i]); } return attributeSet ;}// ----------------------------------------------------------------------------voidMessage::setAHS(const AttributeHandleSet &the_attributes){ handleArraySize = the_attributes.size(); for (unsigned int i = 0 ; i < the_attributes.size(); ++i) { handleArray[i] = the_attributes.getHandle(i); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -