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.
18 #include "HLAVariantRecordDataType.hxx"
20 #include "HLADataTypeVisitor.hxx"
21 #include "HLAVariantRecordDataElement.hxx"
25 HLAVariantRecordDataType::HLAVariantRecordDataType(const std::string& name) :
30 HLAVariantRecordDataType::~HLAVariantRecordDataType()
35 HLAVariantRecordDataType::accept(HLADataTypeVisitor& visitor) const
40 const HLAVariantRecordDataType*
41 HLAVariantRecordDataType::toVariantRecordDataType() const
47 HLAVariantRecordDataType::decode(HLADecodeStream& stream, HLAAbstractVariantRecordDataElement& value) const
49 if (!stream.alignOffsetForSize(getAlignment()))
51 if (!_enumeratedDataType.valid())
54 if (!_enumeratedDataType->decode(stream, index))
56 if (!value.setAlternativeIndex(index))
58 if (!value.decodeAlternative(stream))
64 HLAVariantRecordDataType::encode(HLAEncodeStream& stream, const HLAAbstractVariantRecordDataElement& value) const
66 if (!stream.alignOffsetForSize(getAlignment()))
68 if (!_enumeratedDataType.valid())
70 unsigned index = value.getAlternativeIndex();
71 if (!_enumeratedDataType->encode(stream, index))
73 if (!value.encodeAlternative(stream))
79 HLAVariantRecordDataType::setEnumeratedDataType(HLAEnumeratedDataType* dataType)
81 _enumeratedDataType = dataType;
85 HLAVariantRecordDataType::addAlternative(const std::string& name, const std::string& enumerator,
86 const HLADataType* dataType, const std::string& semantics)
88 if (!_enumeratedDataType.valid())
90 unsigned index = _enumeratedDataType->getIndex(enumerator);
91 if (_enumeratedDataType->getNumEnumerators() <= index)
93 _alternativeList.resize(_enumeratedDataType->getNumEnumerators());
94 _alternativeList[index]._name = name;
95 _alternativeList[index]._dataType = dataType;
96 _alternativeList[index]._semantics = semantics;
97 setAlignment(SGMisc<unsigned>::max(getAlignment(), dataType->getAlignment()));
101 } // namespace simgear