X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fhla%2FHLAFixedRecordDataElement.cxx;h=000339823eda0fa58a9b5c2edc0b6cef397fc6b1;hb=d6361dfee43c0595a19d409b438c6d1cdd65d2ea;hp=d0980b957d22eab206cdf61bfde561e5651ad6a1;hpb=baf511684119e219906fa37f3e7c7f43151bb435;p=simgear.git diff --git a/simgear/hla/HLAFixedRecordDataElement.cxx b/simgear/hla/HLAFixedRecordDataElement.cxx index d0980b95..00033982 100644 --- a/simgear/hla/HLAFixedRecordDataElement.cxx +++ b/simgear/hla/HLAFixedRecordDataElement.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2009 - 2010 Mathias Froehlich - Mathias.Froehlich@web.de +// Copyright (C) 2009 - 2012 Mathias Froehlich - Mathias.Froehlich@web.de // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public @@ -15,11 +15,19 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + #include "HLAFixedRecordDataElement.hxx" #include #include #include + +#include "HLADataElementVisitor.hxx" #include "HLADataTypeVisitor.hxx" namespace simgear { @@ -33,6 +41,18 @@ HLAAbstractFixedRecordDataElement::~HLAAbstractFixedRecordDataElement() { } +void +HLAAbstractFixedRecordDataElement::accept(HLADataElementVisitor& visitor) +{ + visitor.apply(*this); +} + +void +HLAAbstractFixedRecordDataElement::accept(HLAConstDataElementVisitor& visitor) const +{ + visitor.apply(*this); +} + bool HLAAbstractFixedRecordDataElement::decode(HLADecodeStream& stream) { @@ -76,24 +96,32 @@ HLAAbstractFixedRecordDataElement::setDataType(const HLAFixedRecordDataType* dat unsigned HLAAbstractFixedRecordDataElement::getNumFields() const { + if (!_dataType.valid()) + return 0; return _dataType->getNumFields(); } unsigned HLAAbstractFixedRecordDataElement::getFieldNumber(const std::string& name) const { + if (!_dataType.valid()) + return ~0u; return _dataType->getFieldNumber(name); } const HLADataType* HLAAbstractFixedRecordDataElement::getFieldDataType(unsigned i) const { + if (!_dataType.valid()) + return 0; return _dataType->getFieldDataType(i); } const HLADataType* HLAAbstractFixedRecordDataElement::getFieldDataType(const std::string& name) const { + if (!_dataType.valid()) + return 0; return getFieldDataType(getFieldNumber(name)); } @@ -106,6 +134,16 @@ HLAFixedRecordDataElement::HLAFixedRecordDataElement(const HLAFixedRecordDataTyp HLAFixedRecordDataElement::~HLAFixedRecordDataElement() { + clearStamp(); +} + +bool +HLAFixedRecordDataElement::setDataType(const HLADataType* dataType) +{ + if (!HLAAbstractFixedRecordDataElement::setDataType(dataType)) + return false; + _fieldVector.resize(getNumFields()); + return true; } bool @@ -167,7 +205,12 @@ HLAFixedRecordDataElement::setField(unsigned index, HLADataElement* value) { if (getNumFields() <= index) return; + if (_fieldVector[index].valid()) + _fieldVector[index]->clearStamp(); _fieldVector[index] = value; + if (value) + value->attachStamp(*this); + setDirty(true); } void @@ -176,4 +219,15 @@ HLAFixedRecordDataElement::setField(const std::string& name, HLADataElement* val setField(getFieldNumber(name), value); } +void +HLAFixedRecordDataElement::_setStamp(Stamp* stamp) +{ + HLAAbstractFixedRecordDataElement::_setStamp(stamp); + for (FieldVector::iterator i = _fieldVector.begin(); i != _fieldVector.end(); ++i) { + if (!i->valid()) + continue; + (*i)->attachStamp(*this); + } +} + }