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 #ifndef HLAPropertyDataElement_hxx
19 #define HLAPropertyDataElement_hxx
22 #include <simgear/props/props.hxx>
23 #include "HLADataElement.hxx"
27 class HLAPropertyReference : public SGReferenced {
29 HLAPropertyReference()
31 HLAPropertyReference(const std::string& relativePath) :
32 _relativePath(relativePath)
35 void setIntValue(int value)
37 if (!_propertyNode.valid())
39 _propertyNode->setIntValue(value);
41 int getIntValue() const
43 if (!_propertyNode.valid())
45 return _propertyNode->getIntValue();
48 void setLongValue(long value)
50 if (!_propertyNode.valid())
52 _propertyNode->setLongValue(value);
54 long getLongValue() const
56 if (!_propertyNode.valid())
58 return _propertyNode->getLongValue();
61 void setFloatValue(float value)
63 if (!_propertyNode.valid())
65 _propertyNode->setFloatValue(value);
67 float getFloatValue() const
69 if (!_propertyNode.valid())
71 return _propertyNode->getFloatValue();
74 void setDoubleValue(double value)
76 if (!_propertyNode.valid())
78 _propertyNode->setDoubleValue(value);
80 double getDoubleValue() const
82 if (!_propertyNode.valid())
84 return _propertyNode->getDoubleValue();
87 void setStringValue(const std::string& value)
89 if (!_propertyNode.valid())
91 _propertyNode->setStringValue(value);
93 std::string getStringValue() const
95 if (!_propertyNode.valid())
97 return _propertyNode->getStringValue();
100 SGPropertyNode* getPropertyNode()
101 { return _propertyNode.get(); }
103 void setRootNode(SGPropertyNode* rootNode)
106 _propertyNode.clear();
108 _propertyNode = rootNode->getNode(_relativePath, true);
112 std::string _relativePath;
113 SGSharedPtr<SGPropertyNode> _propertyNode;
116 class HLAPropertyReferenceSet : public SGReferenced {
118 void insert(const SGSharedPtr<HLAPropertyReference>& propertyReference)
120 _propertyReferenceSet.insert(propertyReference);
121 propertyReference->setRootNode(_rootNode.get());
123 void remove(const SGSharedPtr<HLAPropertyReference>& propertyReference)
125 PropertyReferenceSet::iterator i = _propertyReferenceSet.find(propertyReference);
126 if (i == _propertyReferenceSet.end())
128 _propertyReferenceSet.erase(i);
129 propertyReference->setRootNode(0);
132 void setRootNode(SGPropertyNode* rootNode)
134 _rootNode = rootNode;
135 for (PropertyReferenceSet::iterator i = _propertyReferenceSet.begin();
136 i != _propertyReferenceSet.end(); ++i) {
137 (*i)->setRootNode(_rootNode.get());
140 SGPropertyNode* getRootNode()
141 { return _rootNode.get(); }
144 SGSharedPtr<SGPropertyNode> _rootNode;
146 typedef std::set<SGSharedPtr<HLAPropertyReference> > PropertyReferenceSet;
147 PropertyReferenceSet _propertyReferenceSet;
150 class HLAPropertyDataElement : public HLADataElement {
152 HLAPropertyDataElement(HLAPropertyReference* propertyReference);
153 HLAPropertyDataElement(const simgear::HLADataType* dataType, HLAPropertyReference* propertyReference);
154 ~HLAPropertyDataElement();
156 virtual bool encode(HLAEncodeStream& stream) const;
157 virtual bool decode(HLADecodeStream& stream);
159 virtual const HLADataType* getDataType() const;
160 virtual bool setDataType(const HLADataType* dataType);
166 SGSharedPtr<const HLADataType> _dataType;
167 SGSharedPtr<HLAPropertyReference> _propertyReference;
170 } // namespace simgear