]> git.mxchange.org Git - simgear.git/blob - simgear/hla/HLAFixedRecordDataType.hxx
hla: Remove deprecated methods from HLAObjectClass
[simgear.git] / simgear / hla / HLAFixedRecordDataType.hxx
1 // Copyright (C) 2009 - 2012  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 HLAFixedRecordDataType_hxx
19 #define HLAFixedRecordDataType_hxx
20
21 #include <string>
22 #include <vector>
23 #include <simgear/structure/SGSharedPtr.hxx>
24 #include "HLADataType.hxx"
25
26 namespace simgear {
27
28 class HLAAbstractFixedRecordDataElement;
29
30 class HLAFixedRecordDataType : public HLADataType {
31 public:
32     HLAFixedRecordDataType(const std::string& name = "HLAFixedRecordDataType");
33     virtual ~HLAFixedRecordDataType();
34
35     virtual void accept(HLADataTypeVisitor& visitor) const;
36
37     virtual const HLAFixedRecordDataType* toFixedRecordDataType() const;
38
39     virtual void releaseDataTypeReferences();
40
41     virtual bool decode(HLADecodeStream& stream, HLAAbstractFixedRecordDataElement& value) const;
42     virtual bool encode(HLAEncodeStream& stream, const HLAAbstractFixedRecordDataElement& value) const;
43
44     unsigned getNumFields() const
45     { return _fieldList.size(); }
46
47     std::string getFieldName(unsigned i) const
48     {
49         if (_fieldList.size() <= i)
50             return std::string();
51         return _fieldList[i].getName();
52     }
53     const HLADataType* getFieldDataType(unsigned i) const
54     {
55         if (_fieldList.size() <= i)
56             return 0;
57         return _fieldList[i].getDataType();
58     }
59
60     unsigned getFieldNumber(const std::string& name) const
61     {
62         for (unsigned i = 0; i < _fieldList.size(); ++i) {
63             if (_fieldList[i].getName() != name)
64                 continue;
65             return i;
66         }
67         return ~0u;
68     }
69
70     void addField(const std::string& name, const HLADataType* dataType);
71
72 protected:
73     virtual void _recomputeAlignmentImplementation();
74
75 private:
76     struct Field {
77         Field(const std::string& name, const HLADataType* dataType) :
78             _name(name), _dataType(dataType) {}
79         const std::string& getName() const
80         { return _name; }
81
82         const HLADataType* getDataType() const
83         { return _dataType.get(); }
84         void releaseDataTypeReferences()
85         { _dataType = 0; }
86
87     private:
88         std::string _name;
89         SGSharedPtr<const HLADataType> _dataType;
90     };
91
92     typedef std::vector<Field> FieldList;
93     FieldList _fieldList;
94 };
95
96 } // namespace simgear
97
98 #endif