-// 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
#include <simgear/math/SGMath.hxx>
#include "HLAArrayDataType.hxx"
#include "HLADataElement.hxx"
-#include "HLAVariantDataElement.hxx"
+#include "HLAVariantRecordDataElement.hxx"
#include "HLADataTypeVisitor.hxx"
namespace simgear {
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;
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 setDataType(const HLADataType* dataType);
+
virtual bool setNumElements(unsigned size);
virtual bool decodeElement(HLADecodeStream& stream, unsigned i);
virtual unsigned getNumElements() const;
void setDataElementFactory(DataElementFactory* dataElementFactory);
DataElementFactory* getDataElementFactory();
+protected:
+ virtual void _setStamp(Stamp* stamp);
+
private:
HLADataElement* newElement(unsigned index);
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<SGSharedPtr<HLAVariantDataElement> > ElementVector;
+ typedef std::vector<SGSharedPtr<HLAVariantRecordDataElement> > ElementVector;
ElementVector _elementVector;
SGSharedPtr<AlternativeDataElementFactory> _alternativeDataElementFactory;
const std::string& getValue() const
{ return _value; }
void setValue(const std::string& value)
- { _value = value; }
+ { _value = value; setDirty(true); }
virtual bool setNumElements(unsigned count)
{
const SGVec2<T>& getValue() const
{ return _value; }
void setValue(const SGVec2<T>& 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;
}
SGVec2<T> _value;
};
+template<typename T>
+class HLAVec2Data {
+public:
+ HLAVec2Data() :
+ _value(new HLAVec2DataElement<T>(0))
+ { }
+ HLAVec2Data(const SGVec2<T>& value) :
+ _value(new HLAVec2DataElement<T>(0, value))
+ { }
+
+ operator const SGVec2<T>&() const
+ { return _value->getValue(); }
+ HLAVec2Data& operator=(const SGVec2<T>& value)
+ { _value->setValue(value); return *this; }
+
+ const SGVec2<T>& getValue() const
+ { return _value->getValue(); }
+ void setValue(const SGVec2<T>& value)
+ { _value->setValue(value); }
+
+ const HLAVec2DataElement<T>* getDataElement() const
+ { return _value.get(); }
+ HLAVec2DataElement<T>* getDataElement()
+ { return _value.get(); }
+
+ const HLAArrayDataType* getDataType() const
+ { return _value->getDataType(); }
+ void setDataType(const HLAArrayDataType* dataType)
+ { _value->setDataType(dataType); }
+
+private:
+ SGSharedPtr<HLAVec2DataElement<T> > _value;
+};
+
+typedef HLAVec2Data<float> HLAVec2fData;
+typedef HLAVec2Data<double> HLAVec2dData;
+
template<typename T>
class HLAVec3DataElement : public HLAAbstractArrayDataElement {
public:
const SGVec3<T>& getValue() const
{ return _value; }
void setValue(const SGVec3<T>& 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;
}
SGVec3<T> _value;
};
+template<typename T>
+class HLAVec3Data {
+public:
+ HLAVec3Data() :
+ _value(new HLAVec3DataElement<T>(0))
+ { }
+ HLAVec3Data(const SGVec3<T>& value) :
+ _value(new HLAVec3DataElement<T>(0, value))
+ { }
+
+ operator const SGVec3<T>&() const
+ { return _value->getValue(); }
+ HLAVec3Data& operator=(const SGVec3<T>& value)
+ { _value->setValue(value); return *this; }
+
+ const SGVec3<T>& getValue() const
+ { return _value->getValue(); }
+ void setValue(const SGVec3<T>& value)
+ { _value->setValue(value); }
+
+ const HLAVec3DataElement<T>* getDataElement() const
+ { return _value.get(); }
+ HLAVec3DataElement<T>* getDataElement()
+ { return _value.get(); }
+
+ const HLAArrayDataType* getDataType() const
+ { return _value->getDataType(); }
+ void setDataType(const HLAArrayDataType* dataType)
+ { _value->setDataType(dataType); }
+
+private:
+ SGSharedPtr<HLAVec3DataElement<T> > _value;
+};
+
+typedef HLAVec3Data<float> HLAVec3fData;
+typedef HLAVec3Data<double> HLAVec3dData;
+
template<typename T>
class HLAVec4DataElement : public HLAAbstractArrayDataElement {
public:
const SGVec4<T>& getValue() const
{ return _value; }
void setValue(const SGVec4<T>& 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;
}
SGVec4<T> _value;
};
+template<typename T>
+class HLAVec4Data {
+public:
+ HLAVec4Data() :
+ _value(new HLAVec4DataElement<T>(0))
+ { }
+ HLAVec4Data(const SGVec4<T>& value) :
+ _value(new HLAVec4DataElement<T>(0, value))
+ { }
+
+ operator const SGVec4<T>&() const
+ { return _value->getValue(); }
+ HLAVec4Data& operator=(const SGVec4<T>& value)
+ { _value->setValue(value); return *this; }
+
+ const SGVec4<T>& getValue() const
+ { return _value->getValue(); }
+ void setValue(const SGVec4<T>& value)
+ { _value->setValue(value); }
+
+ const HLAVec4DataElement<T>* getDataElement() const
+ { return _value.get(); }
+ HLAVec4DataElement<T>* getDataElement()
+ { return _value.get(); }
+
+ const HLAArrayDataType* getDataType() const
+ { return _value->getDataType(); }
+ void setDataType(const HLAArrayDataType* dataType)
+ { _value->setDataType(dataType); }
+
+private:
+ SGSharedPtr<HLAVec4DataElement<T> > _value;
+};
+
+typedef HLAVec4Data<float> HLAVec4fData;
+typedef HLAVec4Data<double> HLAVec4dData;
+
template<typename T>
class HLAQuatDataElement : public HLAAbstractArrayDataElement {
public:
const SGQuat<T>& getValue() const
{ return _value; }
void setValue(const SGQuat<T>& 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;
}