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 #ifndef HLAVariantRecordDataType_hxx
19 #define HLAVariantRecordDataType_hxx
23 #include "simgear/structure/SGSharedPtr.hxx"
24 #include "HLADataType.hxx"
25 #include "HLAEnumeratedDataType.hxx"
29 class HLAAbstractVariantRecordDataElement;
31 class HLAVariantRecordDataType : public HLADataType {
33 HLAVariantRecordDataType(const std::string& name = "HLAVariantRecordDataType");
34 virtual ~HLAVariantRecordDataType();
36 virtual void accept(HLADataTypeVisitor& visitor) const;
38 virtual const HLAVariantRecordDataType* toVariantRecordDataType() const;
40 virtual void releaseDataTypeReferences();
42 virtual bool decode(HLADecodeStream& stream, HLAAbstractVariantRecordDataElement& value) const;
43 virtual bool encode(HLAEncodeStream& stream, const HLAAbstractVariantRecordDataElement& value) const;
45 const HLAEnumeratedDataType* getEnumeratedDataType() const
46 { return _enumeratedDataType.get(); }
47 void setEnumeratedDataType(HLAEnumeratedDataType* dataType);
49 bool addAlternative(const std::string& name, const std::string& enumerator,
50 const HLADataType* dataType, const std::string& semantics);
52 unsigned getNumAlternatives() const
53 { return _alternativeList.size(); }
55 unsigned getAlternativeIndex(const std::string& enumerator) const
57 if (!_enumeratedDataType.valid())
59 return _enumeratedDataType->getIndex(enumerator);
62 const HLADataType* getAlternativeDataType(unsigned index) const
64 if (_alternativeList.size() <= index)
66 return _alternativeList[index]._dataType.get();
68 const HLADataType* getAlternativeDataType(const std::string& enumerator) const
69 { return getAlternativeDataType(getAlternativeIndex(enumerator)); }
71 std::string getAlternativeName(unsigned index) const
73 if (_alternativeList.size() <= index)
75 return _alternativeList[index]._name;
77 std::string getAlternativeName(const std::string& enumerator) const
78 { return getAlternativeName(getAlternativeIndex(enumerator)); }
80 std::string getAlternativeSemantics(unsigned index) const
82 if (_alternativeList.size() <= index)
84 return _alternativeList[index]._semantics;
86 std::string getAlternativeSemantics(const std::string& enumerator) const
87 { return getAlternativeSemantics(getAlternativeIndex(enumerator)); }
90 virtual void _recomputeAlignmentImplementation();
93 SGSharedPtr<HLAEnumeratedDataType> _enumeratedDataType;
97 SGSharedPtr<const HLADataType> _dataType;
98 std::string _semantics;
101 typedef std::vector<Alternative> AlternativeList;
102 AlternativeList _alternativeList;
105 } // namespace simgear