X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fhla%2FHLAArrayDataElement.hxx;h=9bdd71054f87be3cc5ffea6629eac86497b423c9;hb=d4310a7f3b27b8403ba1ec030cfd3b4c6c565f24;hp=f1acf8ef096a012dcdc4fcf370126e947609a1eb;hpb=feab25d0bee2c65a9b5c0a27802fb71c9a1a1190;p=simgear.git diff --git a/simgear/hla/HLAArrayDataElement.hxx b/simgear/hla/HLAArrayDataElement.hxx index f1acf8ef..9bdd7105 100644 --- a/simgear/hla/HLAArrayDataElement.hxx +++ b/simgear/hla/HLAArrayDataElement.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2009 - 2010 Mathias Froehlich - Mathias.Froehlich@web.de +// Copyright (C) 2009 - 2012 Mathias Froehlich - Mathias.Froehlich@web.de // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public @@ -23,7 +23,7 @@ #include #include "HLAArrayDataType.hxx" #include "HLADataElement.hxx" -#include "HLAVariantDataElement.hxx" +#include "HLAVariantRecordDataElement.hxx" #include "HLADataTypeVisitor.hxx" namespace simgear { @@ -33,6 +33,9 @@ public: HLAAbstractArrayDataElement(const HLAArrayDataType* dataType); virtual ~HLAAbstractArrayDataElement(); + virtual void accept(HLADataElementVisitor& visitor); + virtual void accept(HLAConstDataElementVisitor& visitor) const; + virtual bool decode(HLADecodeStream& stream); virtual bool encode(HLAEncodeStream& stream) const; @@ -56,6 +59,10 @@ public: HLAArrayDataElement(const HLAArrayDataType* dataType = 0); virtual ~HLAArrayDataElement(); + virtual bool setDataElement(HLADataElementIndex::const_iterator begin, HLADataElementIndex::const_iterator end, HLADataElement* dataElement); + virtual HLADataElement* getDataElement(HLADataElementIndex::const_iterator begin, HLADataElementIndex::const_iterator end); + virtual const HLADataElement* getDataElement(HLADataElementIndex::const_iterator begin, HLADataElementIndex::const_iterator end) const; + virtual bool setNumElements(unsigned size); virtual bool decodeElement(HLADecodeStream& stream, unsigned i); virtual unsigned getNumElements() const; @@ -75,6 +82,9 @@ public: void setDataElementFactory(DataElementFactory* dataElementFactory); DataElementFactory* getDataElementFactory(); +protected: + virtual void _setStamp(Stamp* stamp); + private: HLADataElement* newElement(unsigned index); @@ -99,20 +109,23 @@ public: virtual unsigned getNumElements() const; virtual bool encodeElement(HLAEncodeStream& stream, unsigned i) const; - const HLAVariantDataElement* getElement(unsigned index) const; - HLAVariantDataElement* getElement(unsigned index); - HLAVariantDataElement* getOrCreateElement(unsigned index); - void setElement(unsigned index, HLAVariantDataElement* value); + const HLAVariantRecordDataElement* getElement(unsigned index) const; + HLAVariantRecordDataElement* getElement(unsigned index); + HLAVariantRecordDataElement* getOrCreateElement(unsigned index); + void setElement(unsigned index, HLAVariantRecordDataElement* value); - typedef HLAVariantDataElement::DataElementFactory AlternativeDataElementFactory; + typedef HLAVariantRecordDataElement::DataElementFactory AlternativeDataElementFactory; void setAlternativeDataElementFactory(AlternativeDataElementFactory* alternativeDataElementFactory); AlternativeDataElementFactory* getAlternativeDataElementFactory(); +protected: + virtual void _setStamp(Stamp* stamp); + private: - HLAVariantDataElement* newElement(); + HLAVariantRecordDataElement* newElement(); - typedef std::vector > ElementVector; + typedef std::vector > ElementVector; ElementVector _elementVector; SGSharedPtr _alternativeDataElementFactory; @@ -130,7 +143,7 @@ public: const std::string& getValue() const { return _value; } void setValue(const std::string& value) - { _value = value; } + { _value = value; setDirty(true); } virtual bool setNumElements(unsigned count) { @@ -207,11 +220,11 @@ public: const SGVec2& getValue() const { return _value; } void setValue(const SGVec2& value) - { _value = value; } + { _value = value; setDirty(true); } virtual bool setNumElements(unsigned count) { - for (unsigned i = 2; i < count; ++i) + for (unsigned i = count; i < 2; ++i) _value[i] = 0; return true; } @@ -248,6 +261,43 @@ private: SGVec2 _value; }; +template +class HLAVec2Data { +public: + HLAVec2Data() : + _value(new HLAVec2DataElement(0)) + { } + HLAVec2Data(const SGVec2& value) : + _value(new HLAVec2DataElement(0, value)) + { } + + operator const SGVec2&() const + { return _value->getValue(); } + HLAVec2Data& operator=(const SGVec2& value) + { _value->setValue(value); return *this; } + + const SGVec2& getValue() const + { return _value->getValue(); } + void setValue(const SGVec2& value) + { _value->setValue(value); } + + const HLAVec2DataElement* getDataElement() const + { return _value.get(); } + HLAVec2DataElement* getDataElement() + { return _value.get(); } + + const HLAArrayDataType* getDataType() const + { return _value->getDataType(); } + void setDataType(const HLAArrayDataType* dataType) + { _value->setDataType(dataType); } + +private: + SGSharedPtr > _value; +}; + +typedef HLAVec2Data HLAVec2fData; +typedef HLAVec2Data HLAVec2dData; + template class HLAVec3DataElement : public HLAAbstractArrayDataElement { public: @@ -262,11 +312,11 @@ public: const SGVec3& getValue() const { return _value; } void setValue(const SGVec3& value) - { _value = value; } + { _value = value; setDirty(true); } virtual bool setNumElements(unsigned count) { - for (unsigned i = 3; i < count; ++i) + for (unsigned i = count; i < 3; ++i) _value[i] = 0; return true; } @@ -303,6 +353,43 @@ private: SGVec3 _value; }; +template +class HLAVec3Data { +public: + HLAVec3Data() : + _value(new HLAVec3DataElement(0)) + { } + HLAVec3Data(const SGVec3& value) : + _value(new HLAVec3DataElement(0, value)) + { } + + operator const SGVec3&() const + { return _value->getValue(); } + HLAVec3Data& operator=(const SGVec3& value) + { _value->setValue(value); return *this; } + + const SGVec3& getValue() const + { return _value->getValue(); } + void setValue(const SGVec3& value) + { _value->setValue(value); } + + const HLAVec3DataElement* getDataElement() const + { return _value.get(); } + HLAVec3DataElement* getDataElement() + { return _value.get(); } + + const HLAArrayDataType* getDataType() const + { return _value->getDataType(); } + void setDataType(const HLAArrayDataType* dataType) + { _value->setDataType(dataType); } + +private: + SGSharedPtr > _value; +}; + +typedef HLAVec3Data HLAVec3fData; +typedef HLAVec3Data HLAVec3dData; + template class HLAVec4DataElement : public HLAAbstractArrayDataElement { public: @@ -317,11 +404,11 @@ public: const SGVec4& getValue() const { return _value; } void setValue(const SGVec4& value) - { _value = value; } + { _value = value; setDirty(true); } virtual bool setNumElements(unsigned count) { - for (unsigned i = 4; i < count; ++i) + for (unsigned i = count; i < 4; ++i) _value[i] = 0; return true; } @@ -358,6 +445,43 @@ private: SGVec4 _value; }; +template +class HLAVec4Data { +public: + HLAVec4Data() : + _value(new HLAVec4DataElement(0)) + { } + HLAVec4Data(const SGVec4& value) : + _value(new HLAVec4DataElement(0, value)) + { } + + operator const SGVec4&() const + { return _value->getValue(); } + HLAVec4Data& operator=(const SGVec4& value) + { _value->setValue(value); return *this; } + + const SGVec4& getValue() const + { return _value->getValue(); } + void setValue(const SGVec4& value) + { _value->setValue(value); } + + const HLAVec4DataElement* getDataElement() const + { return _value.get(); } + HLAVec4DataElement* getDataElement() + { return _value.get(); } + + const HLAArrayDataType* getDataType() const + { return _value->getDataType(); } + void setDataType(const HLAArrayDataType* dataType) + { _value->setDataType(dataType); } + +private: + SGSharedPtr > _value; +}; + +typedef HLAVec4Data HLAVec4fData; +typedef HLAVec4Data HLAVec4dData; + template class HLAQuatDataElement : public HLAAbstractArrayDataElement { public: @@ -372,11 +496,11 @@ public: const SGQuat& getValue() const { return _value; } void setValue(const SGQuat& value) - { _value = value; } + { _value = value; setDirty(true); } virtual bool setNumElements(unsigned count) { - for (unsigned i = 4; i < count; ++i) + for (unsigned i = count; i < 4; ++i) _value[i] = 0; return true; }