From: Mathias Froehlich Date: Tue, 4 Oct 2011 18:21:12 +0000 (+0200) Subject: hla: provide a data type visitor building a default data element tree. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=595328963a34ba8040d16e825f89973d70ad8b3d;p=simgear.git hla: provide a data type visitor building a default data element tree. --- diff --git a/simgear/hla/CMakeLists.txt b/simgear/hla/CMakeLists.txt index 207210ab..a822fc24 100644 --- a/simgear/hla/CMakeLists.txt +++ b/simgear/hla/CMakeLists.txt @@ -32,6 +32,7 @@ set(HLA_SOURCES HLABasicDataType.cxx HLADataElement.cxx HLADataType.cxx + HLADataTypeVisitor.cxx HLAEnumeratedDataElement.cxx HLAEnumeratedDataType.cxx HLAFederate.cxx diff --git a/simgear/hla/HLADataTypeVisitor.hxx b/simgear/hla/HLADataTypeVisitor.hxx index d3cd9b22..2af1012c 100644 --- a/simgear/hla/HLADataTypeVisitor.hxx +++ b/simgear/hla/HLADataTypeVisitor.hxx @@ -24,7 +24,7 @@ #include #include "HLAArrayDataType.hxx" #include "HLABasicDataType.hxx" -#include "HLADataTypeVisitor.hxx" +#include "HLADataElement.hxx" #include "HLAEnumeratedDataType.hxx" #include "HLAFixedRecordDataType.hxx" #include "HLAVariantDataType.hxx" @@ -629,6 +629,43 @@ inline void HLADataTypeEncodeVisitor::apply(const HLAVariableArrayDataType& data dataType.getSizeDataType()->accept(numElementsVisitor); } +/// Generate standard data elements according to the traversed type +class HLADataElementFactoryVisitor : public HLADataTypeVisitor { +public: + virtual ~HLADataElementFactoryVisitor(); + + virtual void apply(const HLADataType& dataType); + + virtual void apply(const HLAInt8DataType& dataType); + virtual void apply(const HLAUInt8DataType& dataType); + virtual void apply(const HLAInt16DataType& dataType); + virtual void apply(const HLAUInt16DataType& dataType); + virtual void apply(const HLAInt32DataType& dataType); + virtual void apply(const HLAUInt32DataType& dataType); + virtual void apply(const HLAInt64DataType& dataType); + virtual void apply(const HLAUInt64DataType& dataType); + virtual void apply(const HLAFloat32DataType& dataType); + virtual void apply(const HLAFloat64DataType& dataType); + + virtual void apply(const HLAFixedArrayDataType& dataType); + virtual void apply(const HLAVariableArrayDataType& dataType); + + virtual void apply(const HLAEnumeratedDataType& dataType); + + virtual void apply(const HLAFixedRecordDataType& dataType); + + virtual void apply(const HLAVariantDataType& dataType); + + HLADataElement* getDataElement() + { return _dataElement.release(); } + +protected: + class ArrayDataElementFactory; + class VariantDataElementFactory; + + SGSharedPtr _dataElement; +}; + } // namespace simgear #endif diff --git a/simgear/hla/HLAObjectInstance.cxx b/simgear/hla/HLAObjectInstance.cxx index 0324d328..ae726ee4 100644 --- a/simgear/hla/HLAObjectInstance.cxx +++ b/simgear/hla/HLAObjectInstance.cxx @@ -123,7 +123,7 @@ HLAObjectInstance::getAttributeDataElement(unsigned index) const return _rtiObjectInstance->getDataElement(index); } -class HLAObjectInstance::DataElementFactoryVisitor : public HLADataTypeVisitor { +class HLAObjectInstance::DataElementFactoryVisitor : public HLADataElementFactoryVisitor { public: DataElementFactoryVisitor(const HLAPathElementMap& pathElementMap) : _pathElementMap(pathElementMap) @@ -150,7 +150,7 @@ public: if (_dataElement.valid()) return; - _dataElement = new HLASCharDataElement(&dataType); + HLADataElementFactoryVisitor::apply(dataType); } virtual void apply(const HLAUInt8DataType& dataType) { @@ -158,7 +158,7 @@ public: if (_dataElement.valid()) return; - _dataElement = new HLAUCharDataElement(&dataType); + HLADataElementFactoryVisitor::apply(dataType); } virtual void apply(const HLAInt16DataType& dataType) { @@ -166,7 +166,7 @@ public: if (_dataElement.valid()) return; - _dataElement = new HLAShortDataElement(&dataType); + HLADataElementFactoryVisitor::apply(dataType); } virtual void apply(const HLAUInt16DataType& dataType) { @@ -174,7 +174,7 @@ public: if (_dataElement.valid()) return; - _dataElement = new HLAUShortDataElement(&dataType); + HLADataElementFactoryVisitor::apply(dataType); } virtual void apply(const HLAInt32DataType& dataType) { @@ -182,7 +182,7 @@ public: if (_dataElement.valid()) return; - _dataElement = new HLAIntDataElement(&dataType); + HLADataElementFactoryVisitor::apply(dataType); } virtual void apply(const HLAUInt32DataType& dataType) { @@ -190,7 +190,7 @@ public: if (_dataElement.valid()) return; - _dataElement = new HLAUIntDataElement(&dataType); + HLADataElementFactoryVisitor::apply(dataType); } virtual void apply(const HLAInt64DataType& dataType) { @@ -198,7 +198,7 @@ public: if (_dataElement.valid()) return; - _dataElement = new HLALongDataElement(&dataType); + HLADataElementFactoryVisitor::apply(dataType); } virtual void apply(const HLAUInt64DataType& dataType) { @@ -206,7 +206,7 @@ public: if (_dataElement.valid()) return; - _dataElement = new HLAULongDataElement(&dataType); + HLADataElementFactoryVisitor::apply(dataType); } virtual void apply(const HLAFloat32DataType& dataType) { @@ -214,7 +214,7 @@ public: if (_dataElement.valid()) return; - _dataElement = new HLAFloatDataElement(&dataType); + HLADataElementFactoryVisitor::apply(dataType); } virtual void apply(const HLAFloat64DataType& dataType) { @@ -222,7 +222,7 @@ public: if (_dataElement.valid()) return; - _dataElement = new HLADoubleDataElement(&dataType); + HLADataElementFactoryVisitor::apply(dataType); } class ArrayDataElementFactory : public HLAArrayDataElement::DataElementFactory { @@ -287,7 +287,7 @@ public: if (_dataElement.valid()) return; - _dataElement = new HLAEnumeratedDataElement(&dataType); + HLADataElementFactoryVisitor::apply(dataType); } virtual void apply(const HLAFixedRecordDataType& dataType) @@ -357,9 +357,6 @@ public: _dataElement = variantDataElement; } - const SGSharedPtr& getDataElement() const - { return _dataElement; } - private: SGSharedPtr createDataElement(const HLADataElement::Path& path, const HLADataType& dataType) { @@ -381,7 +378,6 @@ private: return dataElement; } - SGSharedPtr _dataElement; const HLAPathElementMap& _pathElementMap; HLADataElement::Path _path; }; diff --git a/simgear/hla/Makefile.am b/simgear/hla/Makefile.am index 67542ddb..e214e6a0 100644 --- a/simgear/hla/Makefile.am +++ b/simgear/hla/Makefile.am @@ -35,6 +35,7 @@ libsghla_a_SOURCES = \ HLABasicDataType.cxx \ HLADataElement.cxx \ HLADataType.cxx \ + HLADataTypeVisitor.cxx \ HLAEnumeratedDataElement.cxx \ HLAEnumeratedDataType.cxx \ HLAFederate.cxx \