]> git.mxchange.org Git - simgear.git/blobdiff - simgear/hla/HLAArrayDataElement.hxx
Windows versionhelpers.h support.
[simgear.git] / simgear / hla / HLAArrayDataElement.hxx
index 9bdd71054f87be3cc5ffea6629eac86497b423c9..c6a83aea7ab5ccbe838e9fd8008b135830bdd99a 100644 (file)
@@ -63,6 +63,8 @@ public:
     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 setDataType(const HLADataType* dataType);
+
     virtual bool setNumElements(unsigned size);
     virtual bool decodeElement(HLADecodeStream& stream, unsigned i);
     virtual unsigned getNumElements() const;
@@ -297,6 +299,7 @@ private:
 
 typedef HLAVec2Data<float> HLAVec2fData;
 typedef HLAVec2Data<double> HLAVec2dData;
+typedef HLAVec2Data<int> HLAVec2iData;
 
 template<typename T>
 class HLAVec3DataElement : public HLAAbstractArrayDataElement {
@@ -389,6 +392,7 @@ private:
 
 typedef HLAVec3Data<float> HLAVec3fData;
 typedef HLAVec3Data<double> HLAVec3dData;
+typedef HLAVec3Data<int> HLAVec3iData;
 
 template<typename T>
 class HLAVec4DataElement : public HLAAbstractArrayDataElement {
@@ -481,18 +485,20 @@ private:
 
 typedef HLAVec4Data<float> HLAVec4fData;
 typedef HLAVec4Data<double> HLAVec4dData;
+typedef HLAVec4Data<int> HLAVec4iData;
 
 template<typename T>
 class HLAQuatDataElement : public HLAAbstractArrayDataElement {
 public:
     HLAQuatDataElement(const HLAArrayDataType* dataType = 0) :
         HLAAbstractArrayDataElement(dataType),
-        _value(SGQuat<T>::zeros())
+        _value(SGQuat<T>::unit())
     {}
     HLAQuatDataElement(const HLAArrayDataType* dataType, const SGQuat<T>& value) :
         HLAAbstractArrayDataElement(dataType),
         _value(value)
     {}
+
     const SGQuat<T>& getValue() const
     { return _value; }
     void setValue(const SGQuat<T>& value)
@@ -537,6 +543,151 @@ private:
     SGQuat<T> _value;
 };
 
+template<typename T>
+class HLAQuatData {
+public:
+    HLAQuatData() :
+        _value(new HLAQuatDataElement<T>(0))
+    { }
+    HLAQuatData(const SGQuat<T>& value) :
+        _value(new HLAQuatDataElement<T>(0, value))
+    { }
+
+    operator const SGQuat<T>&() const
+    { return _value->getValue(); }
+    HLAQuatData& operator=(const SGQuat<T>& value)
+    { _value->setValue(value); return *this; }
+
+    const SGQuat<T>& getValue() const
+    { return _value->getValue(); }
+    void setValue(const SGQuat<T>& value)
+    { _value->setValue(value); }
+
+    const HLAQuatDataElement<T>* getDataElement() const
+    { return _value.get(); }
+    HLAQuatDataElement<T>* getDataElement()
+    { return _value.get(); }
+
+    const HLAArrayDataType* getDataType() const
+    { return _value->getDataType(); }
+    void setDataType(const HLAArrayDataType* dataType)
+    { _value->setDataType(dataType); }
+
+private:
+    SGSharedPtr<HLAQuatDataElement<T> > _value;
+};
+
+typedef HLAQuatData<float> HLAQuatfData;
+typedef HLAQuatData<double> HLAQuatdData;
+
+template<typename T>
+class HLAQuat3DataElement : public HLAAbstractArrayDataElement {
+public:
+    HLAQuat3DataElement(const HLAArrayDataType* dataType = 0) :
+        HLAAbstractArrayDataElement(dataType),
+        _value(SGQuat<T>::unit()),
+        _imag(SGQuat<T>::unit().getPositiveRealImag())
+    {}
+    HLAQuat3DataElement(const HLAArrayDataType* dataType, const SGQuat<T>& value) :
+        HLAAbstractArrayDataElement(dataType),
+        _value(value),
+        _imag(value.getPositiveRealImag())
+    {}
+
+    const SGQuat<T>& getValue() const
+    { return _value; }
+    void setValue(const SGQuat<T>& value)
+    { _value = value; _imag = _value.getPositiveRealImag(); setDirty(true); }
+
+    virtual bool encode(HLAEncodeStream& stream) const
+    {
+        return HLAAbstractArrayDataElement::encode(stream);
+    }
+    virtual bool decode(HLADecodeStream& stream)
+    {
+        if (!HLAAbstractArrayDataElement::decode(stream))
+            return false;
+        _value = SGQuat<T>::fromPositiveRealImag(_imag);
+        return true;
+    }
+
+    virtual bool setNumElements(unsigned count)
+    {
+        for (unsigned i = count; i < 3; ++i)
+            _imag[i] = 0;
+        return true;
+    }
+    virtual bool decodeElement(HLADecodeStream& stream, unsigned i)
+    {
+        if (i < 3) {
+            HLATemplateDecodeVisitor<typename SGQuat<T>::value_type> visitor(stream);
+            getElementDataType()->accept(visitor);
+            _imag[i] = visitor.getValue();
+        } else {
+            HLADataTypeDecodeVisitor visitor(stream);
+            getElementDataType()->accept(visitor);
+        }
+        return true;
+    }
+
+    virtual unsigned getNumElements() const
+    {
+        return 3;
+    }
+    virtual bool encodeElement(HLAEncodeStream& stream, unsigned i) const
+    {
+        if (i < 3) {
+            HLATemplateEncodeVisitor<typename SGQuat<T>::value_type> visitor(stream, _imag[i]);
+            getElementDataType()->accept(visitor);
+        } else {
+            HLADataTypeEncodeVisitor visitor(stream);
+            getElementDataType()->accept(visitor);
+        }
+        return true;
+    }
+
+private:
+    SGQuat<T> _value;
+    SGVec3<T> _imag;
+};
+
+template<typename T>
+class HLAQuat3Data {
+public:
+    HLAQuat3Data() :
+        _value(new HLAQuat3DataElement<T>(0))
+    { }
+    HLAQuat3Data(const SGQuat<T>& value) :
+        _value(new HLAQuat3DataElement<T>(0, value))
+    { }
+
+    operator const SGQuat<T>&() const
+    { return _value->getValue(); }
+    HLAQuat3Data& operator=(const SGQuat<T>& value)
+    { _value->setValue(value); return *this; }
+
+    const SGQuat<T>& getValue() const
+    { return _value->getValue(); }
+    void setValue(const SGQuat<T>& value)
+    { _value->setValue(value); }
+
+    const HLAQuat3DataElement<T>* getDataElement() const
+    { return _value.get(); }
+    HLAQuat3DataElement<T>* getDataElement()
+    { return _value.get(); }
+
+    const HLAArrayDataType* getDataType() const
+    { return _value->getDataType(); }
+    void setDataType(const HLAArrayDataType* dataType)
+    { _value->setDataType(dataType); }
+
+private:
+    SGSharedPtr<HLAQuat3DataElement<T> > _value;
+};
+
+typedef HLAQuat3Data<float> HLAQuat3fData;
+typedef HLAQuat3Data<double> HLAQuat3dData;
+
 }
 
 #endif