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.
19 # include <simgear_config.h>
22 #include <simgear/compiler.h>
24 #include "HLAFixedRecordDataType.hxx"
26 #include "HLADataTypeVisitor.hxx"
27 #include "HLAFixedRecordDataElement.hxx"
31 HLAFixedRecordDataType::HLAFixedRecordDataType(const std::string& name) :
36 HLAFixedRecordDataType::~HLAFixedRecordDataType()
41 HLAFixedRecordDataType::accept(HLADataTypeVisitor& visitor) const
46 const HLAFixedRecordDataType*
47 HLAFixedRecordDataType::toFixedRecordDataType() const
53 HLAFixedRecordDataType::releaseDataTypeReferences()
55 unsigned numFields = getNumFields();
56 for (unsigned i = 0; i < numFields; ++i)
57 _fieldList[i].releaseDataTypeReferences();
61 HLAFixedRecordDataType::decode(HLADecodeStream& stream, HLAAbstractFixedRecordDataElement& value) const
63 stream.alignOffsetForSize(getAlignment());
64 unsigned numFields = getNumFields();
65 for (unsigned i = 0; i < numFields; ++i)
66 if (!value.decodeField(stream, i))
72 HLAFixedRecordDataType::encode(HLAEncodeStream& stream, const HLAAbstractFixedRecordDataElement& value) const
74 stream.alignOffsetForSize(getAlignment());
75 unsigned numFields = getNumFields();
76 for (unsigned i = 0; i < numFields; ++i)
77 if (!value.encodeField(stream, i))
83 HLAFixedRecordDataType::addField(const std::string& name, const HLADataType* dataType)
85 _fieldList.push_back(Field(name, dataType));
89 HLAFixedRecordDataType::_recomputeAlignmentImplementation()
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());
96 setAlignment(alignment);
99 } // namespace simgear