diff --git a/simgear/hla/HLAPropertyDataElement.cxx b/simgear/hla/HLAPropertyDataElement.cxx index db4f00ba..9b05da43 100644 --- a/simgear/hla/HLAPropertyDataElement.cxx +++ b/simgear/hla/HLAPropertyDataElement.cxx @@ -23,70 +23,70 @@ namespace simgear { class HLAPropertyDataElement::DecodeVisitor : public HLADataTypeDecodeVisitor { public: - DecodeVisitor(HLADecodeStream& stream, HLAPropertyReference& propertyReference) : + DecodeVisitor(HLADecodeStream& stream, SGPropertyNode& propertyNode) : HLADataTypeDecodeVisitor(stream), - _propertyReference(propertyReference) + _propertyNode(propertyNode) { } virtual void apply(const HLAInt8DataType& dataType) { int8_t value = 0; dataType.decode(_stream, value); - _propertyReference.setIntValue(value); + _propertyNode.setIntValue(value); } virtual void apply(const HLAUInt8DataType& dataType) { uint8_t value = 0; dataType.decode(_stream, value); - _propertyReference.setIntValue(value); + _propertyNode.setIntValue(value); } virtual void apply(const HLAInt16DataType& dataType) { int16_t value = 0; dataType.decode(_stream, value); - _propertyReference.setIntValue(value); + _propertyNode.setIntValue(value); } virtual void apply(const HLAUInt16DataType& dataType) { uint16_t value = 0; dataType.decode(_stream, value); - _propertyReference.setIntValue(value); + _propertyNode.setIntValue(value); } virtual void apply(const HLAInt32DataType& dataType) { int32_t value = 0; dataType.decode(_stream, value); - _propertyReference.setIntValue(value); + _propertyNode.setIntValue(value); } virtual void apply(const HLAUInt32DataType& dataType) { uint32_t value = 0; dataType.decode(_stream, value); - _propertyReference.setIntValue(value); + _propertyNode.setIntValue(value); } virtual void apply(const HLAInt64DataType& dataType) { int64_t value = 0; dataType.decode(_stream, value); - _propertyReference.setLongValue(value); + _propertyNode.setLongValue(value); } virtual void apply(const HLAUInt64DataType& dataType) { uint64_t value = 0; dataType.decode(_stream, value); - _propertyReference.setLongValue(value); + _propertyNode.setLongValue(value); } virtual void apply(const HLAFloat32DataType& dataType) { float value = 0; dataType.decode(_stream, value); - _propertyReference.setFloatValue(value); + _propertyNode.setFloatValue(value); } virtual void apply(const HLAFloat64DataType& dataType) { double value = 0; dataType.decode(_stream, value); - _propertyReference.setDoubleValue(value); + _propertyNode.setDoubleValue(value); } virtual void apply(const HLAFixedArrayDataType& dataType) @@ -99,7 +99,7 @@ public: dataType.getElementDataType()->accept(visitor); value.push_back(visitor.getValue()); } - _propertyReference.setStringValue(value); + _propertyNode.setStringValue(value); } virtual void apply(const HLAVariableArrayDataType& dataType) { @@ -113,65 +113,65 @@ public: dataType.getElementDataType()->accept(visitor); value.push_back(visitor.getValue()); } - _propertyReference.setStringValue(value); + _propertyNode.setStringValue(value); } protected: - HLAPropertyReference& _propertyReference; + SGPropertyNode& _propertyNode; }; class HLAPropertyDataElement::EncodeVisitor : public HLADataTypeEncodeVisitor { public: - EncodeVisitor(HLAEncodeStream& stream, const HLAPropertyReference& propertyReference) : + EncodeVisitor(HLAEncodeStream& stream, const SGPropertyNode& propertyNode) : HLADataTypeEncodeVisitor(stream), - _propertyReference(propertyReference) + _propertyNode(propertyNode) { } virtual void apply(const HLAInt8DataType& dataType) { - dataType.encode(_stream, _propertyReference.getIntValue()); + dataType.encode(_stream, _propertyNode.getIntValue()); } virtual void apply(const HLAUInt8DataType& dataType) { - dataType.encode(_stream, _propertyReference.getIntValue()); + dataType.encode(_stream, _propertyNode.getIntValue()); } virtual void apply(const HLAInt16DataType& dataType) { - dataType.encode(_stream, _propertyReference.getIntValue()); + dataType.encode(_stream, _propertyNode.getIntValue()); } virtual void apply(const HLAUInt16DataType& dataType) { - dataType.encode(_stream, _propertyReference.getIntValue()); + dataType.encode(_stream, _propertyNode.getIntValue()); } virtual void apply(const HLAInt32DataType& dataType) { - dataType.encode(_stream, _propertyReference.getIntValue()); + dataType.encode(_stream, _propertyNode.getIntValue()); } virtual void apply(const HLAUInt32DataType& dataType) { - dataType.encode(_stream, _propertyReference.getIntValue()); + dataType.encode(_stream, _propertyNode.getIntValue()); } virtual void apply(const HLAInt64DataType& dataType) { - dataType.encode(_stream, _propertyReference.getLongValue()); + dataType.encode(_stream, _propertyNode.getLongValue()); } virtual void apply(const HLAUInt64DataType& dataType) { - dataType.encode(_stream, _propertyReference.getLongValue()); + dataType.encode(_stream, _propertyNode.getLongValue()); } virtual void apply(const HLAFloat32DataType& dataType) { - dataType.encode(_stream, _propertyReference.getFloatValue()); + dataType.encode(_stream, _propertyNode.getFloatValue()); } virtual void apply(const HLAFloat64DataType& dataType) { - dataType.encode(_stream, _propertyReference.getDoubleValue()); + dataType.encode(_stream, _propertyNode.getDoubleValue()); } virtual void apply(const HLAFixedArrayDataType& dataType) { unsigned numElements = dataType.getNumElements(); - std::string value = _propertyReference.getStringValue(); + std::string value = _propertyNode.getStringValue(); for (unsigned i = 0; i < numElements; ++i) { if (i < value.size()) { HLATemplateEncodeVisitor visitor(_stream, value[i]); @@ -185,7 +185,7 @@ public: virtual void apply(const HLAVariableArrayDataType& dataType) { - std::string value = _propertyReference.getStringValue(); + std::string value = _propertyNode.getStringValue(); HLATemplateEncodeVisitor numElementsVisitor(_stream, value.size()); dataType.getSizeDataType()->accept(numElementsVisitor); for (unsigned i = 0; i < value.size(); ++i) { @@ -195,7 +195,7 @@ public: } protected: - const HLAPropertyReference& _propertyReference; + const SGPropertyNode& _propertyNode; }; HLAPropertyDataElement::HLAPropertyDataElement(HLAPropertyReference* propertyReference) : @@ -203,12 +203,27 @@ HLAPropertyDataElement::HLAPropertyDataElement(HLAPropertyReference* propertyRef { } -HLAPropertyDataElement::HLAPropertyDataElement(const simgear::HLADataType* dataType, HLAPropertyReference* propertyReference) : +HLAPropertyDataElement::HLAPropertyDataElement(const HLADataType* dataType, HLAPropertyReference* propertyReference) : _dataType(dataType), _propertyReference(propertyReference) { } +HLAPropertyDataElement::HLAPropertyDataElement() +{ +} + +HLAPropertyDataElement::HLAPropertyDataElement(SGPropertyNode* propertyNode) +{ + setPropertyNode(propertyNode); +} + +HLAPropertyDataElement::HLAPropertyDataElement(const HLADataType* dataType, SGPropertyNode* propertyNode) : + _dataType(dataType) +{ + setPropertyNode(propertyNode); +} + HLAPropertyDataElement::~HLAPropertyDataElement() { } @@ -218,8 +233,8 @@ HLAPropertyDataElement::encode(HLAEncodeStream& stream) const { if (!_dataType.valid()) return false; - if (_propertyReference.valid()) { - EncodeVisitor visitor(stream, *_propertyReference); + if (const SGPropertyNode* propertyNode = getPropertyNode()) { + EncodeVisitor visitor(stream, *propertyNode); _dataType->accept(visitor); } else { HLADataTypeEncodeVisitor visitor(stream); @@ -233,8 +248,8 @@ HLAPropertyDataElement::decode(HLADecodeStream& stream) { if (!_dataType.valid()) return false; - if (_propertyReference.valid()) { - DecodeVisitor visitor(stream, *_propertyReference); + if (SGPropertyNode* propertyNode = getPropertyNode()) { + DecodeVisitor visitor(stream, *propertyNode); _dataType->accept(visitor); } else { HLADataTypeDecodeVisitor visitor(stream); @@ -266,4 +281,27 @@ HLAPropertyDataElement::setDataType(const HLADataType* dataType) return false; } +void +HLAPropertyDataElement::setPropertyNode(SGPropertyNode* propertyNode) +{ + _propertyReference = new HLAPropertyReference; + _propertyReference->setRootNode(propertyNode); +} + +SGPropertyNode* +HLAPropertyDataElement::getPropertyNode() +{ + if (!_propertyReference.valid()) + return 0; + return _propertyReference->getPropertyNode(); +} + +const SGPropertyNode* +HLAPropertyDataElement::getPropertyNode() const +{ + if (!_propertyReference.valid()) + return 0; + return _propertyReference->getPropertyNode(); +} + } // namespace simgear diff --git a/simgear/hla/HLAPropertyDataElement.hxx b/simgear/hla/HLAPropertyDataElement.hxx index 32dba058..51d1729b 100644 --- a/simgear/hla/HLAPropertyDataElement.hxx +++ b/simgear/hla/HLAPropertyDataElement.hxx @@ -32,71 +32,6 @@ public: _relativePath(relativePath) { } - void setIntValue(int value) - { - if (!_propertyNode.valid()) - return; - _propertyNode->setIntValue(value); - } - int getIntValue() const - { - if (!_propertyNode.valid()) - return 0; - return _propertyNode->getIntValue(); - } - - void setLongValue(long value) - { - if (!_propertyNode.valid()) - return; - _propertyNode->setLongValue(value); - } - long getLongValue() const - { - if (!_propertyNode.valid()) - return 0; - return _propertyNode->getLongValue(); - } - - void setFloatValue(float value) - { - if (!_propertyNode.valid()) - return; - _propertyNode->setFloatValue(value); - } - float getFloatValue() const - { - if (!_propertyNode.valid()) - return 0; - return _propertyNode->getFloatValue(); - } - - void setDoubleValue(double value) - { - if (!_propertyNode.valid()) - return; - _propertyNode->setDoubleValue(value); - } - double getDoubleValue() const - { - if (!_propertyNode.valid()) - return 0; - return _propertyNode->getDoubleValue(); - } - - void setStringValue(const std::string& value) - { - if (!_propertyNode.valid()) - return; - _propertyNode->setStringValue(value); - } - std::string getStringValue() const - { - if (!_propertyNode.valid()) - return std::string(); - return _propertyNode->getStringValue(); - } - SGPropertyNode* getPropertyNode() { return _propertyNode.get(); } @@ -150,7 +85,10 @@ private: class HLAPropertyDataElement : public HLADataElement { public: HLAPropertyDataElement(HLAPropertyReference* propertyReference); - HLAPropertyDataElement(const simgear::HLADataType* dataType, HLAPropertyReference* propertyReference); + HLAPropertyDataElement(const HLADataType* dataType, HLAPropertyReference* propertyReference); + HLAPropertyDataElement(); + HLAPropertyDataElement(SGPropertyNode* propertyNode); + HLAPropertyDataElement(const HLADataType* dataType, SGPropertyNode* propertyNode); virtual ~HLAPropertyDataElement(); virtual bool encode(HLAEncodeStream& stream) const; @@ -159,6 +97,10 @@ public: virtual const HLADataType* getDataType() const; virtual bool setDataType(const HLADataType* dataType); + void setPropertyNode(SGPropertyNode* propertyNode); + SGPropertyNode* getPropertyNode(); + const SGPropertyNode* getPropertyNode() const; + private: class DecodeVisitor; class EncodeVisitor;