]> git.mxchange.org Git - simgear.git/blob - simgear/hla/HLADataTypeVisitor.cxx
hla: Initially request update for subscribed unowned attributes.
[simgear.git] / simgear / hla / HLADataTypeVisitor.cxx
1 // Copyright (C) 2009 - 2010  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 #include "HLADataTypeVisitor.hxx"
19
20 #include "HLAArrayDataElement.hxx"
21 #include "HLABasicDataElement.hxx"
22 #include "HLADataTypeVisitor.hxx"
23 #include "HLAEnumeratedDataElement.hxx"
24 #include "HLAFixedRecordDataElement.hxx"
25 #include "HLAVariantDataElement.hxx"
26
27 namespace simgear {
28
29 HLADataElementFactoryVisitor::~HLADataElementFactoryVisitor()
30 {
31 }
32
33 void
34 HLADataElementFactoryVisitor::apply(const HLADataType& dataType)
35 {
36     SG_LOG(SG_NETWORK, SG_ALERT, "HLA: Can not find a suitable data element for data type \""
37            << dataType.getName() << "\"");
38 }
39
40 void
41 HLADataElementFactoryVisitor::apply(const HLAInt8DataType& dataType)
42 {
43     _dataElement = new HLASCharDataElement(&dataType);
44 }
45
46 void
47 HLADataElementFactoryVisitor::apply(const HLAUInt8DataType& dataType)
48 {
49     _dataElement = new HLAUCharDataElement(&dataType);
50 }
51
52 void
53 HLADataElementFactoryVisitor::apply(const HLAInt16DataType& dataType)
54 {
55     _dataElement = new HLAShortDataElement(&dataType);
56 }
57
58 void
59 HLADataElementFactoryVisitor::apply(const HLAUInt16DataType& dataType)
60 {
61     _dataElement = new HLAUShortDataElement(&dataType);
62 }
63
64 void
65 HLADataElementFactoryVisitor::apply(const HLAInt32DataType& dataType)
66 {
67     _dataElement = new HLAIntDataElement(&dataType);
68 }
69
70 void
71 HLADataElementFactoryVisitor::apply(const HLAUInt32DataType& dataType)
72 {
73     _dataElement = new HLAUIntDataElement(&dataType);
74 }
75
76 void
77 HLADataElementFactoryVisitor::apply(const HLAInt64DataType& dataType)
78 {
79     _dataElement = new HLALongDataElement(&dataType);
80 }
81
82 void
83 HLADataElementFactoryVisitor::apply(const HLAUInt64DataType& dataType)
84 {
85     _dataElement = new HLAULongDataElement(&dataType);
86 }
87
88 void
89 HLADataElementFactoryVisitor::apply(const HLAFloat32DataType& dataType)
90 {
91     _dataElement = new HLAFloatDataElement(&dataType);
92 }
93
94 void
95 HLADataElementFactoryVisitor::apply(const HLAFloat64DataType& dataType)
96 {
97     _dataElement = new HLADoubleDataElement(&dataType);
98 }
99
100 class HLADataElementFactoryVisitor::ArrayDataElementFactory : public HLAArrayDataElement::DataElementFactory {
101 public:
102     virtual HLADataElement* createElement(const HLAArrayDataElement& element, unsigned index)
103     {
104         const HLADataType* dataType = element.getElementDataType();
105         if (!dataType)
106             return 0;
107         
108         HLADataElementFactoryVisitor visitor;
109         dataType->accept(visitor);
110         return visitor.getDataElement();
111     }
112 };
113
114 void
115 HLADataElementFactoryVisitor::apply(const HLAFixedArrayDataType& dataType)
116 {
117     if (dataType.getIsString()) {
118         _dataElement = new HLAStringDataElement(&dataType);
119     } else {
120         SGSharedPtr<HLAArrayDataElement> arrayDataElement;
121         arrayDataElement = new HLAArrayDataElement(&dataType);
122         arrayDataElement->setDataElementFactory(new ArrayDataElementFactory);
123         arrayDataElement->setNumElements(dataType.getNumElements());
124         _dataElement = arrayDataElement;
125     }
126 }
127
128 void
129 HLADataElementFactoryVisitor::apply(const HLAVariableArrayDataType& dataType)
130 {
131     if (dataType.getIsString()) {
132         _dataElement = new HLAStringDataElement(&dataType);
133     } else {
134         SGSharedPtr<HLAArrayDataElement> arrayDataElement;
135         arrayDataElement = new HLAArrayDataElement(&dataType);
136         arrayDataElement->setDataElementFactory(new ArrayDataElementFactory);
137         _dataElement = arrayDataElement;
138     }
139 }
140
141 void
142 HLADataElementFactoryVisitor::apply(const HLAEnumeratedDataType& dataType)
143 {
144     _dataElement = new HLAEnumeratedDataElement(&dataType);
145 }
146
147 void
148 HLADataElementFactoryVisitor::apply(const HLAFixedRecordDataType& dataType)
149 {
150     SGSharedPtr<HLAFixedRecordDataElement> recordDataElement;
151     recordDataElement = new HLAFixedRecordDataElement(&dataType);
152
153     unsigned numFields = dataType.getNumFields();
154     for (unsigned i = 0; i < numFields; ++i) {
155         HLADataElementFactoryVisitor visitor;
156         dataType.getFieldDataType(i)->accept(visitor);
157         recordDataElement->setField(i, visitor._dataElement.get());
158     }
159
160     _dataElement = recordDataElement;
161 }
162
163 class HLADataElementFactoryVisitor::VariantDataElementFactory : public HLAVariantDataElement::DataElementFactory {
164 public:
165     virtual HLADataElement* createElement(const HLAVariantDataElement& element, unsigned index)
166     {
167         const HLAVariantDataType* dataType = element.getDataType();
168         if (!dataType)
169             return 0;
170         const HLADataType* alternativeDataType = element.getAlternativeDataType();
171         if (!alternativeDataType)
172             return 0;
173         HLADataElementFactoryVisitor visitor;
174         alternativeDataType->accept(visitor);
175         return visitor.getDataElement();
176     }
177 };
178
179 void
180 HLADataElementFactoryVisitor::apply(const HLAVariantDataType& dataType)
181 {
182     SGSharedPtr<HLAVariantDataElement> variantDataElement;
183     variantDataElement = new HLAVariantDataElement(&dataType);
184     variantDataElement->setDataElementFactory(new VariantDataElementFactory);
185     _dataElement = variantDataElement;
186 }
187
188 } // namespace simgear