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.
18 #ifndef HLAEnumeratedDataType_hxx
19 #define HLAEnumeratedDataType_hxx
22 #include <simgear/structure/SGSharedPtr.hxx>
23 #include "HLADataType.hxx"
27 class HLAEnumeratedDataType : public HLADataType {
29 HLAEnumeratedDataType(const std::string& name = "HLAEnumeratedDataType");
30 virtual ~HLAEnumeratedDataType();
32 virtual void accept(HLADataTypeVisitor& visitor) const;
34 virtual const HLAEnumeratedDataType* toEnumeratedDataType() const;
36 virtual bool decode(HLADecodeStream& stream, unsigned& index) const;
37 virtual bool encode(HLAEncodeStream& stream, unsigned index) const;
39 std::string getString(unsigned index) const
43 return _map->getString(index);
45 unsigned getIndex(const std::string& name) const
49 return _map->getIndex(name);
51 unsigned getNumEnumerators() const
55 return _map->getNumEnumerators();
58 bool addEnumerator(const std::string& name, const std::string& number)
62 return _map->add(name, number);
65 void setRepresentation(HLABasicDataType* representation);
66 const HLABasicDataType* getRepresentation() const
70 return _map->getDataType();
74 virtual void _recomputeAlignmentImplementation();
77 class AbstractMap : public SGReferenced {
79 virtual ~AbstractMap() {}
80 virtual bool encode(HLAEncodeStream& stream, unsigned index) const = 0;
81 virtual bool decode(HLADecodeStream& stream, unsigned& index) const = 0;
82 virtual const HLABasicDataType* getDataType() const = 0;
83 virtual bool add(const std::string& name, const std::string& number) = 0;
84 virtual std::string getString(unsigned index) const = 0;
85 virtual unsigned getIndex(const std::string& name) const = 0;
86 virtual unsigned getNumEnumerators() const = 0;
89 template<typename DataType, typename T>
91 class RepresentationVisitor;
93 SGSharedPtr<AbstractMap> _map;
96 } // namespace simgear