X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fhla%2FHLAVariantRecordDataElement.cxx;h=704d4360d459e0e71f72627ea1f4e4e370979c00;hb=2c1fbd558b355cbe9f8902962cbeb492915236f3;hp=db8f1be0aba231d12cc4205350e1f7cdd5438118;hpb=dc9163f8016047f29603c3d40032655132f5c109;p=simgear.git diff --git a/simgear/hla/HLAVariantRecordDataElement.cxx b/simgear/hla/HLAVariantRecordDataElement.cxx index db8f1be0..704d4360 100644 --- a/simgear/hla/HLAVariantRecordDataElement.cxx +++ b/simgear/hla/HLAVariantRecordDataElement.cxx @@ -15,11 +15,18 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + #include "HLAVariantRecordDataElement.hxx" #include #include "HLADataElementVisitor.hxx" +#include "HLADataTypeVisitor.hxx" namespace simgear { @@ -113,6 +120,59 @@ HLAVariantRecordDataElement::HLAVariantRecordDataElement(const HLAVariantRecordD HLAVariantRecordDataElement::~HLAVariantRecordDataElement() { + clearStamp(); +} + +bool +HLAVariantRecordDataElement::setDataElement(HLADataElementIndex::const_iterator begin, HLADataElementIndex::const_iterator end, HLADataElement* dataElement) +{ + // Must have happened in the parent + if (begin == end) + return false; + unsigned index = *begin; + if (++begin != end) { + if (!setAlternativeIndex(index)) + return false; + if (!_dataElement.valid() && getAlternativeDataType()) { + HLADataElementFactoryVisitor visitor; + getAlternativeDataType()->accept(visitor); + _dataElement = visitor.getDataElement(); + } + if (!_dataElement.valid()) + return false; + return _dataElement->setDataElement(begin, end, dataElement); + } else { + if (!setAlternativeIndex(index)) + return false; + if (!dataElement->setDataType(getAlternativeDataType())) + return false; + _dataElement = dataElement; + return true; + } +} + +HLADataElement* +HLAVariantRecordDataElement::getDataElement(HLADataElementIndex::const_iterator begin, HLADataElementIndex::const_iterator end) +{ + if (begin == end) + return this; + if (getAlternativeIndex() != *begin) + return 0; + if (!_dataElement.valid()) + return 0; + return _dataElement->getDataElement(++begin, end); +} + +const HLADataElement* +HLAVariantRecordDataElement::getDataElement(HLADataElementIndex::const_iterator begin, HLADataElementIndex::const_iterator end) const +{ + if (begin == end) + return this; + if (getAlternativeIndex() != *begin) + return 0; + if (!_dataElement.valid()) + return 0; + return _dataElement->getDataElement(++begin, end); } bool @@ -125,6 +185,7 @@ HLAVariantRecordDataElement::setAlternativeIndex(unsigned index) return false; _dataElement.swap(dataElement); _alternativeIndex = index; + setDirty(true); return true; } @@ -158,12 +219,25 @@ HLAVariantRecordDataElement::getDataElementFactory() return _dataElementFactory; } +void +HLAVariantRecordDataElement::_setStamp(Stamp* stamp) +{ + HLAAbstractVariantRecordDataElement::_setStamp(stamp); + if (!_dataElement.valid()) + return; + _dataElement->attachStamp(*this); +} + HLADataElement* HLAVariantRecordDataElement::newElement(unsigned index) { if (!_dataElementFactory.valid()) return 0; - return _dataElementFactory->createElement(*this, index); + HLADataElement* dataElement = _dataElementFactory->createElement(*this, index); + if (!dataElement) + return 0; + dataElement->attachStamp(*this); + return dataElement; } }