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 #include "HLAFixedRecordDataElement.hxx"
22 #include <simgear/debug/logstream.hxx>
24 #include "HLADataElementVisitor.hxx"
25 #include "HLADataTypeVisitor.hxx"
29 HLAAbstractFixedRecordDataElement::HLAAbstractFixedRecordDataElement(const HLAFixedRecordDataType* dataType) :
34 HLAAbstractFixedRecordDataElement::~HLAAbstractFixedRecordDataElement()
39 HLAAbstractFixedRecordDataElement::accept(HLADataElementVisitor& visitor)
45 HLAAbstractFixedRecordDataElement::accept(HLAConstDataElementVisitor& visitor) const
51 HLAAbstractFixedRecordDataElement::decode(HLADecodeStream& stream)
53 if (!_dataType.valid())
55 return _dataType->decode(stream, *this);
59 HLAAbstractFixedRecordDataElement::encode(HLAEncodeStream& stream) const
61 if (!_dataType.valid())
63 return _dataType->encode(stream, *this);
66 const HLAFixedRecordDataType*
67 HLAAbstractFixedRecordDataElement::getDataType() const
69 return _dataType.get();
73 HLAAbstractFixedRecordDataElement::setDataType(const HLADataType* dataType)
75 const HLAFixedRecordDataType* fixedRecordDataType = dataType->toFixedRecordDataType();
76 if (!fixedRecordDataType) {
77 SG_LOG(SG_NETWORK, SG_WARN, "HLAFixedRecordDataType: unable to set data type!");
80 setDataType(fixedRecordDataType);
85 HLAAbstractFixedRecordDataElement::setDataType(const HLAFixedRecordDataType* dataType)
91 HLAAbstractFixedRecordDataElement::getNumFields() const
93 return _dataType->getNumFields();
97 HLAAbstractFixedRecordDataElement::getFieldNumber(const std::string& name) const
99 return _dataType->getFieldNumber(name);
103 HLAAbstractFixedRecordDataElement::getFieldDataType(unsigned i) const
105 return _dataType->getFieldDataType(i);
109 HLAAbstractFixedRecordDataElement::getFieldDataType(const std::string& name) const
111 return getFieldDataType(getFieldNumber(name));
115 HLAFixedRecordDataElement::HLAFixedRecordDataElement(const HLAFixedRecordDataType* dataType) :
116 HLAAbstractFixedRecordDataElement(dataType)
118 _fieldVector.resize(getNumFields());
121 HLAFixedRecordDataElement::~HLAFixedRecordDataElement()
126 HLAFixedRecordDataElement::decodeField(HLADecodeStream& stream, unsigned i)
128 HLADataElement* dataElement = getField(i);
130 return dataElement->decode(stream);
132 HLADataTypeDecodeVisitor visitor(stream);
133 getDataType()->getFieldDataType(i)->accept(visitor);
139 HLAFixedRecordDataElement::encodeField(HLAEncodeStream& stream, unsigned i) const
141 const HLADataElement* dataElement = getField(i);
143 return dataElement->encode(stream);
145 HLADataTypeEncodeVisitor visitor(stream);
146 getDataType()->getFieldDataType(i)->accept(visitor);
152 HLAFixedRecordDataElement::getField(const std::string& name)
154 return getField(getFieldNumber(name));
157 const HLADataElement*
158 HLAFixedRecordDataElement::getField(const std::string& name) const
160 return getField(getFieldNumber(name));
164 HLAFixedRecordDataElement::getField(unsigned i)
166 if (_fieldVector.size() <= i)
168 return _fieldVector[i].get();
171 const HLADataElement*
172 HLAFixedRecordDataElement::getField(unsigned i) const
174 if (_fieldVector.size() <= i)
176 return _fieldVector[i].get();
180 HLAFixedRecordDataElement::setField(unsigned index, HLADataElement* value)
182 if (getNumFields() <= index)
184 _fieldVector[index] = value;
188 HLAFixedRecordDataElement::setField(const std::string& name, HLADataElement* value)
190 setField(getFieldNumber(name), value);