1 // Copyright (C) 2009 - 2010 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 HLAVariantDataType_hxx
19 #define HLAVariantDataType_hxx
23 #include "simgear/structure/SGSharedPtr.hxx"
24 #include "HLADataType.hxx"
25 #include "HLAEnumeratedDataType.hxx"
29 class HLAAbstractVariantDataElement;
31 class HLAVariantDataType : public HLADataType {
33 HLAVariantDataType(const std::string& name = "HLAVariantDataType");
34 virtual ~HLAVariantDataType();
36 virtual void accept(HLADataTypeVisitor& visitor) const;
38 virtual const HLAVariantDataType* toVariantDataType() const;
40 virtual bool decode(HLADecodeStream& stream, HLAAbstractVariantDataElement& value) const;
41 virtual bool encode(HLAEncodeStream& stream, const HLAAbstractVariantDataElement& value) const;
43 const HLAEnumeratedDataType* getEnumeratedDataType() const
44 { return _enumeratedDataType.get(); }
45 void setEnumeratedDataType(HLAEnumeratedDataType* dataType);
47 bool addAlternative(const std::string& name, const std::string& enumerator,
48 const HLADataType* dataType, const std::string& semantics);
50 unsigned getNumAlternatives() const
51 { return _alternativeList.size(); }
53 unsigned getAlternativeIndex(const std::string& enumerator) const
55 if (!_enumeratedDataType.valid())
57 return _enumeratedDataType->getIndex(enumerator);
60 const HLADataType* getAlternativeDataType(unsigned index) const
62 if (_alternativeList.size() <= index)
64 return _alternativeList[index]._dataType.get();
66 const HLADataType* getAlternativeDataType(const std::string& enumerator) const
67 { return getAlternativeDataType(getAlternativeIndex(enumerator)); }
69 std::string getAlternativeName(unsigned index) const
71 if (_alternativeList.size() <= index)
73 return _alternativeList[index]._name;
75 std::string getAlternativeName(const std::string& enumerator) const
76 { return getAlternativeName(getAlternativeIndex(enumerator)); }
78 std::string getAlternativeSemantics(unsigned index) const
80 if (_alternativeList.size() <= index)
82 return _alternativeList[index]._semantics;
84 std::string getAlternativeSemantics(const std::string& enumerator) const
85 { return getAlternativeSemantics(getAlternativeIndex(enumerator)); }
88 SGSharedPtr<HLAEnumeratedDataType> _enumeratedDataType;
92 SGSharedPtr<const HLADataType> _dataType;
93 std::string _semantics;
96 typedef std::vector<Alternative> AlternativeList;
97 AlternativeList _alternativeList;
100 } // namespace simgear