1 // Copyright (C) 2009 - 2012 Mathias Froehlich - Mathias.Froehlich@web.de
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # include <simgear_config.h>
22 #include <simgear/compiler.h>
24 #include "HLAVariantRecordDataElement.hxx"
26 #include <simgear/debug/logstream.hxx>
28 #include "HLADataElementVisitor.hxx"
32 HLAAbstractVariantRecordDataElement::HLAAbstractVariantRecordDataElement(const HLAVariantRecordDataType* dataType) :
37 HLAAbstractVariantRecordDataElement::~HLAAbstractVariantRecordDataElement()
42 HLAAbstractVariantRecordDataElement::accept(HLADataElementVisitor& visitor)
48 HLAAbstractVariantRecordDataElement::accept(HLAConstDataElementVisitor& visitor) const
54 HLAAbstractVariantRecordDataElement::decode(HLADecodeStream& stream)
56 if (!_dataType.valid())
58 return _dataType->decode(stream, *this);
62 HLAAbstractVariantRecordDataElement::encode(HLAEncodeStream& stream) const
64 if (!_dataType.valid())
66 return _dataType->encode(stream, *this);
69 const HLAVariantRecordDataType*
70 HLAAbstractVariantRecordDataElement::getDataType() const
72 return _dataType.get();
76 HLAAbstractVariantRecordDataElement::setDataType(const HLADataType* dataType)
78 const HLAVariantRecordDataType* variantRecordDataType = dataType->toVariantRecordDataType();
79 if (!variantRecordDataType) {
80 SG_LOG(SG_NETWORK, SG_WARN, "HLAVariantRecordDataType: unable to set data type!");
83 setDataType(variantRecordDataType);
88 HLAAbstractVariantRecordDataElement::setDataType(const HLAVariantRecordDataType* dataType)
94 HLAAbstractVariantRecordDataElement::getAlternativeName() const
96 if (!_dataType.valid())
98 return _dataType->getAlternativeName(getAlternativeIndex());
102 HLAAbstractVariantRecordDataElement::getAlternativeDataType() const
104 if (!_dataType.valid())
106 return _dataType->getAlternativeDataType(getAlternativeIndex());
110 HLAVariantRecordDataElement::DataElementFactory::~DataElementFactory()
114 HLAVariantRecordDataElement::HLAVariantRecordDataElement(const HLAVariantRecordDataType* dataType) :
115 HLAAbstractVariantRecordDataElement(dataType),
116 _alternativeIndex(~0u)
120 HLAVariantRecordDataElement::~HLAVariantRecordDataElement()
126 HLAVariantRecordDataElement::setAlternativeIndex(unsigned index)
128 if (_alternativeIndex == index)
130 SGSharedPtr<HLADataElement> dataElement = newElement(index);
131 if (!dataElement.valid())
133 _dataElement.swap(dataElement);
134 _alternativeIndex = index;
140 HLAVariantRecordDataElement::decodeAlternative(HLADecodeStream& stream)
142 return _dataElement->decode(stream);
146 HLAVariantRecordDataElement::getAlternativeIndex() const
148 return _alternativeIndex;
152 HLAVariantRecordDataElement::encodeAlternative(HLAEncodeStream& stream) const
154 return _dataElement->encode(stream);
158 HLAVariantRecordDataElement::setDataElementFactory(HLAVariantRecordDataElement::DataElementFactory* dataElementFactory)
160 _dataElementFactory = dataElementFactory;
163 HLAVariantRecordDataElement::DataElementFactory*
164 HLAVariantRecordDataElement::getDataElementFactory()
166 return _dataElementFactory;
170 HLAVariantRecordDataElement::_setStamp(Stamp* stamp)
172 HLAAbstractVariantRecordDataElement::_setStamp(stamp);
173 if (!_dataElement.valid())
175 _dataElement->attachStamp(*this);
179 HLAVariantRecordDataElement::newElement(unsigned index)
181 if (!_dataElementFactory.valid())
183 HLADataElement* dataElement = _dataElementFactory->createElement(*this, index);
186 dataElement->attachStamp(*this);