]> git.mxchange.org Git - simgear.git/blob - simgear/hla/HLAVariantDataType.hxx
hla: for rti13 queue all callbacks.
[simgear.git] / simgear / hla / HLAVariantDataType.hxx
1 // Copyright (C) 2009 - 2010  Mathias Froehlich - Mathias.Froehlich@web.de
2 //
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.
7 //
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.
12 //
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.
16 //
17
18 #ifndef HLAVariantDataType_hxx
19 #define HLAVariantDataType_hxx
20
21 #include <string>
22 #include <vector>
23 #include "simgear/structure/SGSharedPtr.hxx"
24 #include "HLADataType.hxx"
25 #include "HLAEnumeratedDataType.hxx"
26
27 namespace simgear {
28
29 class HLAAbstractVariantDataElement;
30
31 class HLAVariantDataType : public HLADataType {
32 public:
33     HLAVariantDataType(const std::string& name = "HLAVariantDataType");
34     virtual ~HLAVariantDataType();
35
36     virtual void accept(HLADataTypeVisitor& visitor) const;
37
38     virtual const HLAVariantDataType* toVariantDataType() const;
39
40     virtual bool decode(HLADecodeStream& stream, HLAAbstractVariantDataElement& value) const;
41     virtual bool encode(HLAEncodeStream& stream, const HLAAbstractVariantDataElement& value) const;
42
43     const HLAEnumeratedDataType* getEnumeratedDataType() const
44     { return _enumeratedDataType.get(); }
45     void setEnumeratedDataType(HLAEnumeratedDataType* dataType);
46
47     bool addAlternative(const std::string& name, const std::string& enumerator,
48                         const HLADataType* dataType, const std::string& semantics);
49
50     unsigned getNumAlternatives() const
51     { return _alternativeList.size(); }
52
53     unsigned getAlternativeIndex(const std::string& enumerator) const
54     {
55         if (!_enumeratedDataType.valid())
56             return ~unsigned(0);
57         return _enumeratedDataType->getIndex(enumerator);
58     }
59
60     const HLADataType* getAlternativeDataType(unsigned index) const
61     {
62         if (_alternativeList.size() <= index)
63             return 0;
64         return _alternativeList[index]._dataType.get();
65     }
66     const HLADataType* getAlternativeDataType(const std::string& enumerator) const
67     { return getAlternativeDataType(getAlternativeIndex(enumerator)); }
68
69     std::string getAlternativeName(unsigned index) const
70     {
71         if (_alternativeList.size() <= index)
72             return std::string();
73         return _alternativeList[index]._name;
74     }
75     std::string getAlternativeName(const std::string& enumerator) const
76     { return getAlternativeName(getAlternativeIndex(enumerator)); }
77
78     std::string getAlternativeSemantics(unsigned index) const
79     {
80         if (_alternativeList.size() <= index)
81             return std::string();
82         return _alternativeList[index]._semantics;
83     }
84     std::string getAlternativeSemantics(const std::string& enumerator) const
85     { return getAlternativeSemantics(getAlternativeIndex(enumerator)); }
86
87 private:
88     SGSharedPtr<HLAEnumeratedDataType> _enumeratedDataType;
89
90     struct Alternative {
91         std::string _name;
92         SGSharedPtr<const HLADataType> _dataType;
93         std::string _semantics;
94     };
95
96     typedef std::vector<Alternative> AlternativeList;
97     AlternativeList _alternativeList;
98 };
99
100 } // namespace simgear
101
102 #endif