]> git.mxchange.org Git - simgear.git/blob - simgear/hla/HLAFixedRecordDataType.cxx
hla: Use HLADataElementIndices for HLAInteractionClass.
[simgear.git] / simgear / hla / HLAFixedRecordDataType.cxx
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 #ifdef HAVE_CONFIG_H
19 #  include <simgear_config.h>
20 #endif
21
22 #include <simgear/compiler.h>
23
24 #include "HLAFixedRecordDataType.hxx"
25
26 #include "HLADataTypeVisitor.hxx"
27 #include "HLAFixedRecordDataElement.hxx"
28
29 namespace simgear {
30
31 HLAFixedRecordDataType::HLAFixedRecordDataType(const std::string& name) :
32     HLADataType(name)
33 {
34 }
35
36 HLAFixedRecordDataType::~HLAFixedRecordDataType()
37 {
38 }
39
40 void
41 HLAFixedRecordDataType::accept(HLADataTypeVisitor& visitor) const
42 {
43     visitor.apply(*this);
44 }
45
46 const HLAFixedRecordDataType*
47 HLAFixedRecordDataType::toFixedRecordDataType() const
48 {
49     return this;
50 }
51
52 void
53 HLAFixedRecordDataType::releaseDataTypeReferences()
54 {
55     unsigned numFields = getNumFields();
56     for (unsigned i = 0; i < numFields; ++i)
57         _fieldList[i].releaseDataTypeReferences();
58 }
59
60 bool
61 HLAFixedRecordDataType::decode(HLADecodeStream& stream, HLAAbstractFixedRecordDataElement& value) const
62 {
63     stream.alignOffsetForSize(getAlignment());
64     unsigned numFields = getNumFields();
65     for (unsigned i = 0; i < numFields; ++i)
66         if (!value.decodeField(stream, i))
67             return false;
68     return true;
69 }
70
71 bool
72 HLAFixedRecordDataType::encode(HLAEncodeStream& stream, const HLAAbstractFixedRecordDataElement& value) const
73 {
74     stream.alignOffsetForSize(getAlignment());
75     unsigned numFields = getNumFields();
76     for (unsigned i = 0; i < numFields; ++i)
77         if (!value.encodeField(stream, i))
78             return false;
79     return true;
80 }
81
82 void
83 HLAFixedRecordDataType::addField(const std::string& name, const HLADataType* dataType)
84 {
85     _fieldList.push_back(Field(name, dataType));
86 }
87
88 void
89 HLAFixedRecordDataType::_recomputeAlignmentImplementation()
90 {
91     unsigned alignment = 1;
92     for (unsigned i = 0; i < getNumFields(); ++i) {
93         if (const HLADataType* dataType = getFieldDataType(i))
94             alignment = std::max(alignment, dataType->getAlignment());
95     }
96     setAlignment(alignment);
97 }
98
99 } // namespace simgear