From: Mathias Froehlich Date: Sat, 18 Feb 2012 10:44:00 +0000 (+0100) Subject: hla: rename HLAVariantData* to HLAVariantRecordData* X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=dc9163f8016047f29603c3d40032655132f5c109;p=simgear.git hla: rename HLAVariantData* to HLAVariantRecordData* Rename to the true name that is used in the standard. --- diff --git a/simgear/hla/CMakeLists.txt b/simgear/hla/CMakeLists.txt index f9c35c5e..02fea298 100644 --- a/simgear/hla/CMakeLists.txt +++ b/simgear/hla/CMakeLists.txt @@ -24,6 +24,8 @@ set(HLA_HEADERS HLARawDataElement.hxx HLAVariantDataElement.hxx HLAVariantDataType.hxx + HLAVariantRecordDataElement.hxx + HLAVariantRecordDataType.hxx ) set(HLA_SOURCES @@ -44,8 +46,8 @@ set(HLA_SOURCES HLAOMTXmlVisitor.cxx HLAPropertyDataElement.cxx HLARawDataElement.cxx - HLAVariantDataElement.cxx - HLAVariantDataType.cxx + HLAVariantRecordDataElement.cxx + HLAVariantRecordDataType.cxx ) simgear_component(hla hla "${HLA_SOURCES}" "${HLA_HEADERS}") diff --git a/simgear/hla/HLAArrayDataElement.cxx b/simgear/hla/HLAArrayDataElement.cxx index 01e40243..3746cbd8 100644 --- a/simgear/hla/HLAArrayDataElement.cxx +++ b/simgear/hla/HLAArrayDataElement.cxx @@ -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 @@ -213,8 +213,8 @@ HLAVariantArrayDataElement::setDataType(const HLADataType* dataType) SG_LOG(SG_NETWORK, SG_WARN, "HLAVariantArrayDataType: unable to set data type, dataType is not an array data type!"); return false; } - const HLAVariantDataType* variantDataType = arrayDataType->getElementDataType()->toVariantDataType(); - if (!variantDataType) { + const HLAVariantRecordDataType* variantRecordDataType = arrayDataType->getElementDataType()->toVariantRecordDataType(); + if (!variantRecordDataType) { SG_LOG(SG_NETWORK, SG_WARN, "HLAVariantArrayDataType: unable to set data type: arrayDataTypes element data type is no a variant data type!"); return false; } @@ -237,7 +237,7 @@ HLAVariantArrayDataElement::setNumElements(unsigned size) bool HLAVariantArrayDataElement::decodeElement(HLADecodeStream& stream, unsigned i) { - HLAVariantDataElement* dataElement = getElement(i); + HLAVariantRecordDataElement* dataElement = getElement(i); if (!dataElement) return false; return dataElement->decode(stream); @@ -258,7 +258,7 @@ HLAVariantArrayDataElement::encodeElement(HLAEncodeStream& stream, unsigned i) c return dataElement->encode(stream); } -const HLAVariantDataElement* +const HLAVariantRecordDataElement* HLAVariantArrayDataElement::getElement(unsigned index) const { if (_elementVector.size() <= index) @@ -266,7 +266,7 @@ HLAVariantArrayDataElement::getElement(unsigned index) const return _elementVector[index].get(); } -HLAVariantDataElement* +HLAVariantRecordDataElement* HLAVariantArrayDataElement::getElement(unsigned index) { if (_elementVector.size() <= index) @@ -274,7 +274,7 @@ HLAVariantArrayDataElement::getElement(unsigned index) return _elementVector[index].get(); } -HLAVariantDataElement* +HLAVariantRecordDataElement* HLAVariantArrayDataElement::getOrCreateElement(unsigned index) { if (_elementVector.size() <= index) @@ -284,7 +284,7 @@ HLAVariantArrayDataElement::getOrCreateElement(unsigned index) } void -HLAVariantArrayDataElement::setElement(unsigned index, HLAVariantDataElement* value) +HLAVariantArrayDataElement::setElement(unsigned index, HLAVariantRecordDataElement* value) { unsigned oldSize = _elementVector.size(); if (oldSize <= index) { @@ -307,7 +307,7 @@ HLAVariantArrayDataElement::getAlternativeDataElementFactory() return _alternativeDataElementFactory.get(); } -HLAVariantDataElement* +HLAVariantRecordDataElement* HLAVariantArrayDataElement::newElement() { const HLAArrayDataType* arrayDataType = getDataType(); @@ -316,12 +316,12 @@ HLAVariantArrayDataElement::newElement() const HLADataType* elementDataType = arrayDataType->getElementDataType(); if (!elementDataType) return 0; - const HLAVariantDataType* variantDataType = elementDataType->toVariantDataType(); - if (!variantDataType) + const HLAVariantRecordDataType* variantRecordDataType = elementDataType->toVariantRecordDataType(); + if (!variantRecordDataType) return 0; - HLAVariantDataElement* variantDataElement = new HLAVariantDataElement(variantDataType); - variantDataElement->setDataElementFactory(_alternativeDataElementFactory.get()); - return variantDataElement; + HLAVariantRecordDataElement* variantRecordDataElement = new HLAVariantRecordDataElement(variantRecordDataType); + variantRecordDataElement->setDataElementFactory(_alternativeDataElementFactory.get()); + return variantRecordDataElement; } } diff --git a/simgear/hla/HLAArrayDataElement.hxx b/simgear/hla/HLAArrayDataElement.hxx index c236c4e4..de3c1d0a 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 { @@ -102,20 +102,20 @@ 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(); private: - HLAVariantDataElement* newElement(); + HLAVariantRecordDataElement* newElement(); - typedef std::vector > ElementVector; + typedef std::vector > ElementVector; ElementVector _elementVector; SGSharedPtr _alternativeDataElementFactory; diff --git a/simgear/hla/HLADataElementVisitor.hxx b/simgear/hla/HLADataElementVisitor.hxx index 938f7302..538202c4 100644 --- a/simgear/hla/HLADataElementVisitor.hxx +++ b/simgear/hla/HLADataElementVisitor.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2009 - 2011 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 @@ -24,7 +24,7 @@ class HLABasicDataElement; class HLAAbstractEnumeratedDataElement; class HLAAbstractFixedRecordDataElement; class HLAAbstractArrayDataElement; -class HLAAbstractVariantDataElement; +class HLAAbstractVariantRecordDataElement; class HLADataElementVisitor { public: @@ -36,7 +36,7 @@ public: virtual void apply(HLAAbstractEnumeratedDataElement&); virtual void apply(HLAAbstractArrayDataElement&); virtual void apply(HLAAbstractFixedRecordDataElement&); - virtual void apply(HLAAbstractVariantDataElement&); + virtual void apply(HLAAbstractVariantRecordDataElement&); }; class HLAConstDataElementVisitor { @@ -49,7 +49,7 @@ public: virtual void apply(const HLAAbstractEnumeratedDataElement&); virtual void apply(const HLAAbstractArrayDataElement&); virtual void apply(const HLAAbstractFixedRecordDataElement&); - virtual void apply(const HLAAbstractVariantDataElement&); + virtual void apply(const HLAAbstractVariantRecordDataElement&); }; } diff --git a/simgear/hla/HLADataType.cxx b/simgear/hla/HLADataType.cxx index b22fb218..73198534 100644 --- a/simgear/hla/HLADataType.cxx +++ b/simgear/hla/HLADataType.cxx @@ -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 @@ -69,8 +69,8 @@ HLADataType::toFixedRecordDataType() const return 0; } -const HLAVariantDataType* -HLADataType::toVariantDataType() const +const HLAVariantRecordDataType* +HLADataType::toVariantRecordDataType() const { return 0; } diff --git a/simgear/hla/HLADataType.hxx b/simgear/hla/HLADataType.hxx index 23fb5070..7b20dafd 100644 --- a/simgear/hla/HLADataType.hxx +++ b/simgear/hla/HLADataType.hxx @@ -32,7 +32,7 @@ class HLABasicDataType; class HLAArrayDataType; class HLAEnumeratedDataType; class HLAFixedRecordDataType; -class HLAVariantDataType; +class HLAVariantRecordDataType; enum HLAUpdateType { HLAStaticUpdate, @@ -63,7 +63,9 @@ public: virtual const HLAArrayDataType* toArrayDataType() const; virtual const HLAEnumeratedDataType* toEnumeratedDataType() const; virtual const HLAFixedRecordDataType* toFixedRecordDataType() const; - virtual const HLAVariantDataType* toVariantDataType() const; + /// deprecated + const HLAVariantRecordDataType* toVariantDataType() const { return toVariantRecordDataType(); } + virtual const HLAVariantRecordDataType* toVariantRecordDataType() const; protected: HLADataType(const std::string& name, unsigned alignment = 1); diff --git a/simgear/hla/HLADataTypeVisitor.cxx b/simgear/hla/HLADataTypeVisitor.cxx index a13d12a4..5978ac06 100644 --- a/simgear/hla/HLADataTypeVisitor.cxx +++ b/simgear/hla/HLADataTypeVisitor.cxx @@ -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 @@ -22,7 +22,7 @@ #include "HLADataTypeVisitor.hxx" #include "HLAEnumeratedDataElement.hxx" #include "HLAFixedRecordDataElement.hxx" -#include "HLAVariantDataElement.hxx" +#include "HLAVariantRecordDataElement.hxx" namespace simgear { @@ -160,11 +160,11 @@ HLADataElementFactoryVisitor::apply(const HLAFixedRecordDataType& dataType) _dataElement = recordDataElement; } -class HLADataElementFactoryVisitor::VariantDataElementFactory : public HLAVariantDataElement::DataElementFactory { +class HLADataElementFactoryVisitor::VariantRecordDataElementFactory : public HLAVariantRecordDataElement::DataElementFactory { public: - virtual HLADataElement* createElement(const HLAVariantDataElement& element, unsigned index) + virtual HLADataElement* createElement(const HLAVariantRecordDataElement& element, unsigned index) { - const HLAVariantDataType* dataType = element.getDataType(); + const HLAVariantRecordDataType* dataType = element.getDataType(); if (!dataType) return 0; const HLADataType* alternativeDataType = element.getAlternativeDataType(); @@ -177,12 +177,12 @@ public: }; void -HLADataElementFactoryVisitor::apply(const HLAVariantDataType& dataType) +HLADataElementFactoryVisitor::apply(const HLAVariantRecordDataType& dataType) { - SGSharedPtr variantDataElement; - variantDataElement = new HLAVariantDataElement(&dataType); - variantDataElement->setDataElementFactory(new VariantDataElementFactory); - _dataElement = variantDataElement; + SGSharedPtr variantRecordDataElement; + variantRecordDataElement = new HLAVariantRecordDataElement(&dataType); + variantRecordDataElement->setDataElementFactory(new VariantRecordDataElementFactory); + _dataElement = variantRecordDataElement; } } // namespace simgear diff --git a/simgear/hla/HLADataTypeVisitor.hxx b/simgear/hla/HLADataTypeVisitor.hxx index 2af1012c..824b22a3 100644 --- a/simgear/hla/HLADataTypeVisitor.hxx +++ b/simgear/hla/HLADataTypeVisitor.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 @@ -27,7 +27,7 @@ #include "HLADataElement.hxx" #include "HLAEnumeratedDataType.hxx" #include "HLAFixedRecordDataType.hxx" -#include "HLAVariantDataType.hxx" +#include "HLAVariantRecordDataType.hxx" namespace simgear { @@ -84,7 +84,7 @@ public: virtual void apply(const HLAFixedRecordDataType& dataType) { apply(static_cast(dataType)); } - virtual void apply(const HLAVariantDataType& dataType) + virtual void apply(const HLAVariantRecordDataType& dataType) { apply(static_cast(dataType)); } }; @@ -145,7 +145,7 @@ public: } } - virtual void apply(const HLAVariantDataType& dataType) + virtual void apply(const HLAVariantRecordDataType& dataType) { assert(0); } protected: @@ -188,7 +188,7 @@ public: dataType.getFieldDataType(i)->accept(*this); } - virtual void apply(const HLAVariantDataType& dataType) { assert(0); } + virtual void apply(const HLAVariantRecordDataType& dataType) { assert(0); } protected: HLADecodeStream& _stream; @@ -232,7 +232,7 @@ public: dataType.getFieldDataType(i)->accept(*this); } - virtual void apply(const HLAVariantDataType& dataType) { assert(0); } + virtual void apply(const HLAVariantRecordDataType& dataType) { assert(0); } protected: HLAEncodeStream& _stream; @@ -269,7 +269,7 @@ public: HLADataTypeDecodeVisitor::apply(dataType); } - virtual void apply(const HLAVariantDataType& dataType) + virtual void apply(const HLAVariantRecordDataType& dataType) { SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while decodeing scalar value"); HLADataTypeDecodeVisitor::apply(dataType); @@ -305,7 +305,7 @@ public: HLADataTypeEncodeVisitor::apply(dataType); } - virtual void apply(const HLAVariantDataType& dataType) + virtual void apply(const HLAVariantRecordDataType& dataType) { SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while writing scalar value"); HLADataTypeEncodeVisitor::apply(dataType); @@ -386,7 +386,7 @@ public: HLADataTypeDecodeVisitor::apply(dataType); } - virtual void apply(const HLAVariantDataType& dataType) + virtual void apply(const HLAVariantRecordDataType& dataType) { SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while decodeing a fixed record value"); HLADataTypeDecodeVisitor::apply(dataType); @@ -467,7 +467,7 @@ public: HLADataTypeEncodeVisitor::apply(dataType); } - virtual void apply(const HLAVariantDataType& dataType) + virtual void apply(const HLAVariantRecordDataType& dataType) { SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while writing a fixed record value"); HLADataTypeEncodeVisitor::apply(dataType); @@ -654,14 +654,14 @@ public: virtual void apply(const HLAFixedRecordDataType& dataType); - virtual void apply(const HLAVariantDataType& dataType); + virtual void apply(const HLAVariantRecordDataType& dataType); HLADataElement* getDataElement() { return _dataElement.release(); } protected: class ArrayDataElementFactory; - class VariantDataElementFactory; + class VariantRecordDataElementFactory; SGSharedPtr _dataElement; }; diff --git a/simgear/hla/HLAOMTXmlVisitor.cxx b/simgear/hla/HLAOMTXmlVisitor.cxx index fa731eb3..e573f244 100644 --- a/simgear/hla/HLAOMTXmlVisitor.cxx +++ b/simgear/hla/HLAOMTXmlVisitor.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2009 - 2011 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 @@ -28,7 +28,7 @@ #include "HLADataTypeVisitor.hxx" #include "HLAEnumeratedDataType.hxx" #include "HLAFixedRecordDataType.hxx" -#include "HLAVariantDataType.hxx" +#include "HLAVariantRecordDataType.hxx" namespace simgear { @@ -287,7 +287,7 @@ HLAOMTXmlVisitor::getDataType(const std::string& dataTypeName, HLAOMTXmlVisitor: if (dataType.valid()) return dataType; - dataType = getVariantDataType(dataTypeName, dataTypeMap); + dataType = getVariantRecordDataType(dataTypeName, dataTypeMap); if (dataType.valid()) return dataType; @@ -473,13 +473,13 @@ HLAOMTXmlVisitor::getFixedRecordDataType(const std::string& dataTypeName, HLAOMT return dataType; } -SGSharedPtr -HLAOMTXmlVisitor::getVariantDataType(const std::string& dataTypeName, HLAOMTXmlVisitor::StringDataTypeMap& dataTypeMap) const +SGSharedPtr +HLAOMTXmlVisitor::getVariantRecordDataType(const std::string& dataTypeName, HLAOMTXmlVisitor::StringDataTypeMap& dataTypeMap) const { VariantRecordDataMap::const_iterator i = _variantRecordDataMap.find(dataTypeName); if (i == _variantRecordDataMap.end()) return 0; - SGSharedPtr dataType = new HLAVariantDataType(dataTypeName); + SGSharedPtr dataType = new HLAVariantRecordDataType(dataTypeName); dataTypeMap[dataTypeName] = dataType; SGSharedPtr enumeratedDataType = getEnumeratedDataType(i->second._dataType); diff --git a/simgear/hla/HLAOMTXmlVisitor.hxx b/simgear/hla/HLAOMTXmlVisitor.hxx index 32a8cd64..ce52eb1a 100644 --- a/simgear/hla/HLAOMTXmlVisitor.hxx +++ b/simgear/hla/HLAOMTXmlVisitor.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 @@ -153,7 +153,7 @@ private: SGSharedPtr getEnumeratedDataType(const std::string& dataTypeName) const; SGSharedPtr getArrayDataType(const std::string& dataTypeName, StringDataTypeMap& dataTypeMap) const; SGSharedPtr getFixedRecordDataType(const std::string& dataTypeName, StringDataTypeMap& dataTypeMap) const; - SGSharedPtr getVariantDataType(const std::string& dataTypeName, StringDataTypeMap& dataTypeMap) const; + SGSharedPtr getVariantRecordDataType(const std::string& dataTypeName, StringDataTypeMap& dataTypeMap) const; enum Mode { UnknownMode, diff --git a/simgear/hla/HLAObjectInstance.cxx b/simgear/hla/HLAObjectInstance.cxx index 1644d938..22d8309e 100644 --- a/simgear/hla/HLAObjectInstance.cxx +++ b/simgear/hla/HLAObjectInstance.cxx @@ -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 @@ -24,7 +24,7 @@ #include "HLAEnumeratedDataElement.hxx" #include "HLAFixedRecordDataElement.hxx" #include "HLAObjectClass.hxx" -#include "HLAVariantDataElement.hxx" +#include "HLAVariantRecordDataElement.hxx" #include "RTIObjectClass.hxx" #include "RTIObjectInstance.hxx" @@ -312,9 +312,9 @@ public: _dataElement = recordDataElement; } - class VariantDataElementFactory : public HLAVariantDataElement::DataElementFactory { + class VariantRecordDataElementFactory : public HLAVariantRecordDataElement::DataElementFactory { public: - VariantDataElementFactory(const HLADataElement::Path& path, const HLAPathElementMap& pathElementMap) : + VariantRecordDataElementFactory(const HLADataElement::Path& path, const HLAPathElementMap& pathElementMap) : _path(path) { for (HLAPathElementMap::const_iterator i = pathElementMap.lower_bound(path); @@ -325,9 +325,9 @@ public: _pathElementMap.insert(*i); } } - virtual HLADataElement* createElement(const HLAVariantDataElement& element, unsigned index) + virtual HLADataElement* createElement(const HLAVariantRecordDataElement& element, unsigned index) { - const HLAVariantDataType* dataType = element.getDataType(); + const HLAVariantRecordDataType* dataType = element.getDataType(); if (!dataType) return 0; const HLADataType* alternativeDataType = element.getAlternativeDataType(); @@ -344,17 +344,17 @@ public: HLAPathElementMap _pathElementMap; }; - virtual void apply(const HLAVariantDataType& dataType) + virtual void apply(const HLAVariantRecordDataType& dataType) { _dataElement = createDataElement(_path, dataType); if (_dataElement.valid()) return; - SGSharedPtr variantDataElement; - variantDataElement = new HLAVariantDataElement(&dataType); - variantDataElement->setDataElementFactory(new VariantDataElementFactory(_path, _pathElementMap)); + SGSharedPtr variantRecordDataElement; + variantRecordDataElement = new HLAVariantRecordDataElement(&dataType); + variantRecordDataElement->setDataElementFactory(new VariantRecordDataElementFactory(_path, _pathElementMap)); - _dataElement = variantDataElement; + _dataElement = variantRecordDataElement; } private: diff --git a/simgear/hla/HLAPropertyDataElement.cxx b/simgear/hla/HLAPropertyDataElement.cxx index af19ff4d..130d3c14 100644 --- a/simgear/hla/HLAPropertyDataElement.cxx +++ b/simgear/hla/HLAPropertyDataElement.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2009 - 2011 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 @@ -22,7 +22,7 @@ #include "HLADataElementVisitor.hxx" #include "HLADataTypeVisitor.hxx" #include "HLAFixedRecordDataElement.hxx" -#include "HLAVariantDataElement.hxx" +#include "HLAVariantRecordDataElement.hxx" namespace simgear { @@ -373,14 +373,14 @@ public: _dataElement = recordDataElement; } - class VariantDataElementFactory : public HLAVariantDataElement::DataElementFactory { + class VariantRecordDataElementFactory : public HLAVariantRecordDataElement::DataElementFactory { public: - VariantDataElementFactory(SGPropertyNode* propertyNode) : + VariantRecordDataElementFactory(SGPropertyNode* propertyNode) : _propertyNode(propertyNode) { } - virtual HLADataElement* createElement(const HLAVariantDataElement& element, unsigned index) + virtual HLADataElement* createElement(const HLAVariantRecordDataElement& element, unsigned index) { - const HLAVariantDataType* dataType = element.getDataType(); + const HLAVariantRecordDataType* dataType = element.getDataType(); if (!dataType) return 0; const HLADataType* alternativeDataType = element.getAlternativeDataType(); @@ -394,12 +394,12 @@ public: SGSharedPtr _propertyNode; }; - virtual void apply(const HLAVariantDataType& dataType) + virtual void apply(const HLAVariantRecordDataType& dataType) { - SGSharedPtr variantDataElement; - variantDataElement = new HLAVariantDataElement(&dataType); - variantDataElement->setDataElementFactory(new VariantDataElementFactory(_propertyNode.get())); - _dataElement = variantDataElement; + SGSharedPtr variantRecordDataElement; + variantRecordDataElement = new HLAVariantRecordDataElement(&dataType); + variantRecordDataElement->setDataElementFactory(new VariantRecordDataElementFactory(_propertyNode.get())); + _dataElement = variantRecordDataElement; } HLADataElement* getDataElement() diff --git a/simgear/hla/HLAVariantDataElement.cxx b/simgear/hla/HLAVariantDataElement.cxx deleted file mode 100644 index 2eca369a..00000000 --- a/simgear/hla/HLAVariantDataElement.cxx +++ /dev/null @@ -1,169 +0,0 @@ -// Copyright (C) 2009 - 2010 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 -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// - -#include "HLAVariantDataElement.hxx" - -#include - -#include "HLADataElementVisitor.hxx" - -namespace simgear { - -HLAAbstractVariantDataElement::HLAAbstractVariantDataElement(const HLAVariantDataType* dataType) : - _dataType(dataType) -{ -} - -HLAAbstractVariantDataElement::~HLAAbstractVariantDataElement() -{ -} - -void -HLAAbstractVariantDataElement::accept(HLADataElementVisitor& visitor) -{ - visitor.apply(*this); -} - -void -HLAAbstractVariantDataElement::accept(HLAConstDataElementVisitor& visitor) const -{ - visitor.apply(*this); -} - -bool -HLAAbstractVariantDataElement::decode(HLADecodeStream& stream) -{ - if (!_dataType.valid()) - return false; - return _dataType->decode(stream, *this); -} - -bool -HLAAbstractVariantDataElement::encode(HLAEncodeStream& stream) const -{ - if (!_dataType.valid()) - return false; - return _dataType->encode(stream, *this); -} - -const HLAVariantDataType* -HLAAbstractVariantDataElement::getDataType() const -{ - return _dataType.get(); -} - -bool -HLAAbstractVariantDataElement::setDataType(const HLADataType* dataType) -{ - const HLAVariantDataType* variantDataType = dataType->toVariantDataType(); - if (!variantDataType) { - SG_LOG(SG_NETWORK, SG_WARN, "HLAVariantDataType: unable to set data type!"); - return false; - } - setDataType(variantDataType); - return true; -} - -void -HLAAbstractVariantDataElement::setDataType(const HLAVariantDataType* dataType) -{ - _dataType = dataType; -} - -std::string -HLAAbstractVariantDataElement::getAlternativeName() const -{ - if (!_dataType.valid()) - return std::string(); - return _dataType->getAlternativeName(getAlternativeIndex()); -} - -const HLADataType* -HLAAbstractVariantDataElement::getAlternativeDataType() const -{ - if (!_dataType.valid()) - return 0; - return _dataType->getAlternativeDataType(getAlternativeIndex()); -} - - -HLAVariantDataElement::DataElementFactory::~DataElementFactory() -{ -} - -HLAVariantDataElement::HLAVariantDataElement(const HLAVariantDataType* dataType) : - HLAAbstractVariantDataElement(dataType), - _alternativeIndex(~0u) -{ -} - -HLAVariantDataElement::~HLAVariantDataElement() -{ -} - -bool -HLAVariantDataElement::setAlternativeIndex(unsigned index) -{ - if (_alternativeIndex == index) - return true; - SGSharedPtr dataElement = newElement(index); - if (!dataElement.valid()) - return false; - _dataElement.swap(dataElement); - _alternativeIndex = index; - return true; -} - -bool -HLAVariantDataElement::decodeAlternative(HLADecodeStream& stream) -{ - return _dataElement->decode(stream); -} - -unsigned -HLAVariantDataElement::getAlternativeIndex() const -{ - return _alternativeIndex; -} - -bool -HLAVariantDataElement::encodeAlternative(HLAEncodeStream& stream) const -{ - return _dataElement->encode(stream); -} - -void -HLAVariantDataElement::setDataElementFactory(HLAVariantDataElement::DataElementFactory* dataElementFactory) -{ - _dataElementFactory = dataElementFactory; -} - -HLAVariantDataElement::DataElementFactory* -HLAVariantDataElement::getDataElementFactory() -{ - return _dataElementFactory; -} - -HLADataElement* -HLAVariantDataElement::newElement(unsigned index) -{ - if (!_dataElementFactory.valid()) - return 0; - return _dataElementFactory->createElement(*this, index); -} - -} diff --git a/simgear/hla/HLAVariantDataElement.hxx b/simgear/hla/HLAVariantDataElement.hxx index 0b14ef45..34909e20 100644 --- a/simgear/hla/HLAVariantDataElement.hxx +++ b/simgear/hla/HLAVariantDataElement.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 @@ -18,67 +18,13 @@ #ifndef HLAVariantDataElement_hxx #define HLAVariantDataElement_hxx -#include -#include -#include "HLADataElement.hxx" #include "HLAVariantDataType.hxx" +#include "HLAVariantRecordDataElement.hxx" namespace simgear { -class HLAAbstractVariantDataElement : public HLADataElement { -public: - HLAAbstractVariantDataElement(const HLAVariantDataType* dataType); - virtual ~HLAAbstractVariantDataElement(); - - virtual void accept(HLADataElementVisitor& visitor); - virtual void accept(HLAConstDataElementVisitor& visitor) const; - - virtual bool decode(HLADecodeStream& stream); - virtual bool encode(HLAEncodeStream& stream) const; - - virtual const HLAVariantDataType* getDataType() const; - virtual bool setDataType(const HLADataType* dataType); - void setDataType(const HLAVariantDataType* dataType); - - std::string getAlternativeName() const; - const HLADataType* getAlternativeDataType() const; - - virtual bool setAlternativeIndex(unsigned index) = 0; - virtual bool decodeAlternative(HLADecodeStream& stream) = 0; - virtual unsigned getAlternativeIndex() const = 0; - virtual bool encodeAlternative(HLAEncodeStream& stream) const = 0; - -private: - SGSharedPtr _dataType; -}; - -class HLAVariantDataElement : public HLAAbstractVariantDataElement { -public: - HLAVariantDataElement(const HLAVariantDataType* dataType); - virtual ~HLAVariantDataElement(); - - virtual bool setAlternativeIndex(unsigned index); - virtual bool decodeAlternative(HLADecodeStream& stream); - virtual unsigned getAlternativeIndex() const; - virtual bool encodeAlternative(HLAEncodeStream& stream) const; - - class DataElementFactory : public SGReferenced { - public: - virtual ~DataElementFactory(); - virtual HLADataElement* createElement(const HLAVariantDataElement&, unsigned) = 0; - }; - - void setDataElementFactory(DataElementFactory* dataElementFactory); - DataElementFactory* getDataElementFactory(); - -private: - HLADataElement* newElement(unsigned index); - - SGSharedPtr _dataElement; - unsigned _alternativeIndex; - - SGSharedPtr _dataElementFactory; -}; +typedef HLAAbstractVariantRecordDataElement HLAAbstractVariantDataElement; +typedef HLAVariantRecordDataElement HLAVariantDataElement; } diff --git a/simgear/hla/HLAVariantDataType.cxx b/simgear/hla/HLAVariantDataType.cxx deleted file mode 100644 index 45e20dbf..00000000 --- a/simgear/hla/HLAVariantDataType.cxx +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (C) 2009 - 2010 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 -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// - -#include "HLAVariantDataType.hxx" - -#include "HLADataTypeVisitor.hxx" -#include "HLAVariantDataElement.hxx" - -namespace simgear { - -HLAVariantDataType::HLAVariantDataType(const std::string& name) : - HLADataType(name) -{ -} - -HLAVariantDataType::~HLAVariantDataType() -{ -} - -void -HLAVariantDataType::accept(HLADataTypeVisitor& visitor) const -{ - visitor.apply(*this); -} - -const HLAVariantDataType* -HLAVariantDataType::toVariantDataType() const -{ - return this; -} - -bool -HLAVariantDataType::decode(HLADecodeStream& stream, HLAAbstractVariantDataElement& value) const -{ - if (!stream.alignOffsetForSize(getAlignment())) - return false; - if (!_enumeratedDataType.valid()) - return false; - unsigned index = ~0u; - if (!_enumeratedDataType->decode(stream, index)) - return false; - if (!value.setAlternativeIndex(index)) - return false; - if (!value.decodeAlternative(stream)) - return false; - return true; -} - -bool -HLAVariantDataType::encode(HLAEncodeStream& stream, const HLAAbstractVariantDataElement& value) const -{ - if (!stream.alignOffsetForSize(getAlignment())) - return false; - if (!_enumeratedDataType.valid()) - return false; - unsigned index = value.getAlternativeIndex(); - if (!_enumeratedDataType->encode(stream, index)) - return false; - if (!value.encodeAlternative(stream)) - return false; - return true; -} - -void -HLAVariantDataType::setEnumeratedDataType(HLAEnumeratedDataType* dataType) -{ - _enumeratedDataType = dataType; -} - -bool -HLAVariantDataType::addAlternative(const std::string& name, const std::string& enumerator, - const HLADataType* dataType, const std::string& semantics) -{ - if (!_enumeratedDataType.valid()) - return false; - unsigned index = _enumeratedDataType->getIndex(enumerator); - if (_enumeratedDataType->getNumEnumerators() <= index) - return false; - _alternativeList.resize(_enumeratedDataType->getNumEnumerators()); - _alternativeList[index]._name = name; - _alternativeList[index]._dataType = dataType; - _alternativeList[index]._semantics = semantics; - setAlignment(SGMisc::max(getAlignment(), dataType->getAlignment())); - return true; -} - -} // namespace simgear diff --git a/simgear/hla/HLAVariantDataType.hxx b/simgear/hla/HLAVariantDataType.hxx index 59b4aacd..043fe25f 100644 --- a/simgear/hla/HLAVariantDataType.hxx +++ b/simgear/hla/HLAVariantDataType.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 @@ -18,84 +18,11 @@ #ifndef HLAVariantDataType_hxx #define HLAVariantDataType_hxx -#include -#include -#include "simgear/structure/SGSharedPtr.hxx" -#include "HLADataType.hxx" -#include "HLAEnumeratedDataType.hxx" +#include "HLAVariantRecordDataType.hxx" namespace simgear { -class HLAAbstractVariantDataElement; - -class HLAVariantDataType : public HLADataType { -public: - HLAVariantDataType(const std::string& name = "HLAVariantDataType"); - virtual ~HLAVariantDataType(); - - virtual void accept(HLADataTypeVisitor& visitor) const; - - virtual const HLAVariantDataType* toVariantDataType() const; - - virtual bool decode(HLADecodeStream& stream, HLAAbstractVariantDataElement& value) const; - virtual bool encode(HLAEncodeStream& stream, const HLAAbstractVariantDataElement& value) const; - - const HLAEnumeratedDataType* getEnumeratedDataType() const - { return _enumeratedDataType.get(); } - void setEnumeratedDataType(HLAEnumeratedDataType* dataType); - - bool addAlternative(const std::string& name, const std::string& enumerator, - const HLADataType* dataType, const std::string& semantics); - - unsigned getNumAlternatives() const - { return _alternativeList.size(); } - - unsigned getAlternativeIndex(const std::string& enumerator) const - { - if (!_enumeratedDataType.valid()) - return ~unsigned(0); - return _enumeratedDataType->getIndex(enumerator); - } - - const HLADataType* getAlternativeDataType(unsigned index) const - { - if (_alternativeList.size() <= index) - return 0; - return _alternativeList[index]._dataType.get(); - } - const HLADataType* getAlternativeDataType(const std::string& enumerator) const - { return getAlternativeDataType(getAlternativeIndex(enumerator)); } - - std::string getAlternativeName(unsigned index) const - { - if (_alternativeList.size() <= index) - return std::string(); - return _alternativeList[index]._name; - } - std::string getAlternativeName(const std::string& enumerator) const - { return getAlternativeName(getAlternativeIndex(enumerator)); } - - std::string getAlternativeSemantics(unsigned index) const - { - if (_alternativeList.size() <= index) - return std::string(); - return _alternativeList[index]._semantics; - } - std::string getAlternativeSemantics(const std::string& enumerator) const - { return getAlternativeSemantics(getAlternativeIndex(enumerator)); } - -private: - SGSharedPtr _enumeratedDataType; - - struct Alternative { - std::string _name; - SGSharedPtr _dataType; - std::string _semantics; - }; - - typedef std::vector AlternativeList; - AlternativeList _alternativeList; -}; +typedef HLAVariantRecordDataType HLAVariantDataType; } // namespace simgear diff --git a/simgear/hla/HLAVariantRecordDataElement.cxx b/simgear/hla/HLAVariantRecordDataElement.cxx new file mode 100644 index 00000000..db8f1be0 --- /dev/null +++ b/simgear/hla/HLAVariantRecordDataElement.cxx @@ -0,0 +1,169 @@ +// 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 +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// + +#include "HLAVariantRecordDataElement.hxx" + +#include + +#include "HLADataElementVisitor.hxx" + +namespace simgear { + +HLAAbstractVariantRecordDataElement::HLAAbstractVariantRecordDataElement(const HLAVariantRecordDataType* dataType) : + _dataType(dataType) +{ +} + +HLAAbstractVariantRecordDataElement::~HLAAbstractVariantRecordDataElement() +{ +} + +void +HLAAbstractVariantRecordDataElement::accept(HLADataElementVisitor& visitor) +{ + visitor.apply(*this); +} + +void +HLAAbstractVariantRecordDataElement::accept(HLAConstDataElementVisitor& visitor) const +{ + visitor.apply(*this); +} + +bool +HLAAbstractVariantRecordDataElement::decode(HLADecodeStream& stream) +{ + if (!_dataType.valid()) + return false; + return _dataType->decode(stream, *this); +} + +bool +HLAAbstractVariantRecordDataElement::encode(HLAEncodeStream& stream) const +{ + if (!_dataType.valid()) + return false; + return _dataType->encode(stream, *this); +} + +const HLAVariantRecordDataType* +HLAAbstractVariantRecordDataElement::getDataType() const +{ + return _dataType.get(); +} + +bool +HLAAbstractVariantRecordDataElement::setDataType(const HLADataType* dataType) +{ + const HLAVariantRecordDataType* variantRecordDataType = dataType->toVariantRecordDataType(); + if (!variantRecordDataType) { + SG_LOG(SG_NETWORK, SG_WARN, "HLAVariantRecordDataType: unable to set data type!"); + return false; + } + setDataType(variantRecordDataType); + return true; +} + +void +HLAAbstractVariantRecordDataElement::setDataType(const HLAVariantRecordDataType* dataType) +{ + _dataType = dataType; +} + +std::string +HLAAbstractVariantRecordDataElement::getAlternativeName() const +{ + if (!_dataType.valid()) + return std::string(); + return _dataType->getAlternativeName(getAlternativeIndex()); +} + +const HLADataType* +HLAAbstractVariantRecordDataElement::getAlternativeDataType() const +{ + if (!_dataType.valid()) + return 0; + return _dataType->getAlternativeDataType(getAlternativeIndex()); +} + + +HLAVariantRecordDataElement::DataElementFactory::~DataElementFactory() +{ +} + +HLAVariantRecordDataElement::HLAVariantRecordDataElement(const HLAVariantRecordDataType* dataType) : + HLAAbstractVariantRecordDataElement(dataType), + _alternativeIndex(~0u) +{ +} + +HLAVariantRecordDataElement::~HLAVariantRecordDataElement() +{ +} + +bool +HLAVariantRecordDataElement::setAlternativeIndex(unsigned index) +{ + if (_alternativeIndex == index) + return true; + SGSharedPtr dataElement = newElement(index); + if (!dataElement.valid()) + return false; + _dataElement.swap(dataElement); + _alternativeIndex = index; + return true; +} + +bool +HLAVariantRecordDataElement::decodeAlternative(HLADecodeStream& stream) +{ + return _dataElement->decode(stream); +} + +unsigned +HLAVariantRecordDataElement::getAlternativeIndex() const +{ + return _alternativeIndex; +} + +bool +HLAVariantRecordDataElement::encodeAlternative(HLAEncodeStream& stream) const +{ + return _dataElement->encode(stream); +} + +void +HLAVariantRecordDataElement::setDataElementFactory(HLAVariantRecordDataElement::DataElementFactory* dataElementFactory) +{ + _dataElementFactory = dataElementFactory; +} + +HLAVariantRecordDataElement::DataElementFactory* +HLAVariantRecordDataElement::getDataElementFactory() +{ + return _dataElementFactory; +} + +HLADataElement* +HLAVariantRecordDataElement::newElement(unsigned index) +{ + if (!_dataElementFactory.valid()) + return 0; + return _dataElementFactory->createElement(*this, index); +} + +} diff --git a/simgear/hla/HLAVariantRecordDataElement.hxx b/simgear/hla/HLAVariantRecordDataElement.hxx new file mode 100644 index 00000000..0f4f364f --- /dev/null +++ b/simgear/hla/HLAVariantRecordDataElement.hxx @@ -0,0 +1,85 @@ +// 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 +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// + +#ifndef HLAVariantRecordDataElement_hxx +#define HLAVariantRecordDataElement_hxx + +#include +#include +#include "HLADataElement.hxx" +#include "HLAVariantRecordDataType.hxx" + +namespace simgear { + +class HLAAbstractVariantRecordDataElement : public HLADataElement { +public: + HLAAbstractVariantRecordDataElement(const HLAVariantRecordDataType* dataType); + virtual ~HLAAbstractVariantRecordDataElement(); + + virtual void accept(HLADataElementVisitor& visitor); + virtual void accept(HLAConstDataElementVisitor& visitor) const; + + virtual bool decode(HLADecodeStream& stream); + virtual bool encode(HLAEncodeStream& stream) const; + + virtual const HLAVariantRecordDataType* getDataType() const; + virtual bool setDataType(const HLADataType* dataType); + void setDataType(const HLAVariantRecordDataType* dataType); + + std::string getAlternativeName() const; + const HLADataType* getAlternativeDataType() const; + + virtual bool setAlternativeIndex(unsigned index) = 0; + virtual bool decodeAlternative(HLADecodeStream& stream) = 0; + virtual unsigned getAlternativeIndex() const = 0; + virtual bool encodeAlternative(HLAEncodeStream& stream) const = 0; + +private: + SGSharedPtr _dataType; +}; + +class HLAVariantRecordDataElement : public HLAAbstractVariantRecordDataElement { +public: + HLAVariantRecordDataElement(const HLAVariantRecordDataType* dataType); + virtual ~HLAVariantRecordDataElement(); + + virtual bool setAlternativeIndex(unsigned index); + virtual bool decodeAlternative(HLADecodeStream& stream); + virtual unsigned getAlternativeIndex() const; + virtual bool encodeAlternative(HLAEncodeStream& stream) const; + + class DataElementFactory : public SGReferenced { + public: + virtual ~DataElementFactory(); + virtual HLADataElement* createElement(const HLAVariantRecordDataElement&, unsigned) = 0; + }; + + void setDataElementFactory(DataElementFactory* dataElementFactory); + DataElementFactory* getDataElementFactory(); + +private: + HLADataElement* newElement(unsigned index); + + SGSharedPtr _dataElement; + unsigned _alternativeIndex; + + SGSharedPtr _dataElementFactory; +}; + +} + +#endif diff --git a/simgear/hla/HLAVariantRecordDataType.cxx b/simgear/hla/HLAVariantRecordDataType.cxx new file mode 100644 index 00000000..ff7488b9 --- /dev/null +++ b/simgear/hla/HLAVariantRecordDataType.cxx @@ -0,0 +1,101 @@ +// 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 +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// + +#include "HLAVariantRecordDataType.hxx" + +#include "HLADataTypeVisitor.hxx" +#include "HLAVariantRecordDataElement.hxx" + +namespace simgear { + +HLAVariantRecordDataType::HLAVariantRecordDataType(const std::string& name) : + HLADataType(name) +{ +} + +HLAVariantRecordDataType::~HLAVariantRecordDataType() +{ +} + +void +HLAVariantRecordDataType::accept(HLADataTypeVisitor& visitor) const +{ + visitor.apply(*this); +} + +const HLAVariantRecordDataType* +HLAVariantRecordDataType::toVariantRecordDataType() const +{ + return this; +} + +bool +HLAVariantRecordDataType::decode(HLADecodeStream& stream, HLAAbstractVariantRecordDataElement& value) const +{ + if (!stream.alignOffsetForSize(getAlignment())) + return false; + if (!_enumeratedDataType.valid()) + return false; + unsigned index = ~0u; + if (!_enumeratedDataType->decode(stream, index)) + return false; + if (!value.setAlternativeIndex(index)) + return false; + if (!value.decodeAlternative(stream)) + return false; + return true; +} + +bool +HLAVariantRecordDataType::encode(HLAEncodeStream& stream, const HLAAbstractVariantRecordDataElement& value) const +{ + if (!stream.alignOffsetForSize(getAlignment())) + return false; + if (!_enumeratedDataType.valid()) + return false; + unsigned index = value.getAlternativeIndex(); + if (!_enumeratedDataType->encode(stream, index)) + return false; + if (!value.encodeAlternative(stream)) + return false; + return true; +} + +void +HLAVariantRecordDataType::setEnumeratedDataType(HLAEnumeratedDataType* dataType) +{ + _enumeratedDataType = dataType; +} + +bool +HLAVariantRecordDataType::addAlternative(const std::string& name, const std::string& enumerator, + const HLADataType* dataType, const std::string& semantics) +{ + if (!_enumeratedDataType.valid()) + return false; + unsigned index = _enumeratedDataType->getIndex(enumerator); + if (_enumeratedDataType->getNumEnumerators() <= index) + return false; + _alternativeList.resize(_enumeratedDataType->getNumEnumerators()); + _alternativeList[index]._name = name; + _alternativeList[index]._dataType = dataType; + _alternativeList[index]._semantics = semantics; + setAlignment(SGMisc::max(getAlignment(), dataType->getAlignment())); + return true; +} + +} // namespace simgear diff --git a/simgear/hla/HLAVariantRecordDataType.hxx b/simgear/hla/HLAVariantRecordDataType.hxx new file mode 100644 index 00000000..06226da9 --- /dev/null +++ b/simgear/hla/HLAVariantRecordDataType.hxx @@ -0,0 +1,102 @@ +// 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 +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// + +#ifndef HLAVariantRecordDataType_hxx +#define HLAVariantRecordDataType_hxx + +#include +#include +#include "simgear/structure/SGSharedPtr.hxx" +#include "HLADataType.hxx" +#include "HLAEnumeratedDataType.hxx" + +namespace simgear { + +class HLAAbstractVariantRecordDataElement; + +class HLAVariantRecordDataType : public HLADataType { +public: + HLAVariantRecordDataType(const std::string& name = "HLAVariantRecordDataType"); + virtual ~HLAVariantRecordDataType(); + + virtual void accept(HLADataTypeVisitor& visitor) const; + + virtual const HLAVariantRecordDataType* toVariantRecordDataType() const; + + virtual bool decode(HLADecodeStream& stream, HLAAbstractVariantRecordDataElement& value) const; + virtual bool encode(HLAEncodeStream& stream, const HLAAbstractVariantRecordDataElement& value) const; + + const HLAEnumeratedDataType* getEnumeratedDataType() const + { return _enumeratedDataType.get(); } + void setEnumeratedDataType(HLAEnumeratedDataType* dataType); + + bool addAlternative(const std::string& name, const std::string& enumerator, + const HLADataType* dataType, const std::string& semantics); + + unsigned getNumAlternatives() const + { return _alternativeList.size(); } + + unsigned getAlternativeIndex(const std::string& enumerator) const + { + if (!_enumeratedDataType.valid()) + return ~unsigned(0); + return _enumeratedDataType->getIndex(enumerator); + } + + const HLADataType* getAlternativeDataType(unsigned index) const + { + if (_alternativeList.size() <= index) + return 0; + return _alternativeList[index]._dataType.get(); + } + const HLADataType* getAlternativeDataType(const std::string& enumerator) const + { return getAlternativeDataType(getAlternativeIndex(enumerator)); } + + std::string getAlternativeName(unsigned index) const + { + if (_alternativeList.size() <= index) + return std::string(); + return _alternativeList[index]._name; + } + std::string getAlternativeName(const std::string& enumerator) const + { return getAlternativeName(getAlternativeIndex(enumerator)); } + + std::string getAlternativeSemantics(unsigned index) const + { + if (_alternativeList.size() <= index) + return std::string(); + return _alternativeList[index]._semantics; + } + std::string getAlternativeSemantics(const std::string& enumerator) const + { return getAlternativeSemantics(getAlternativeIndex(enumerator)); } + +private: + SGSharedPtr _enumeratedDataType; + + struct Alternative { + std::string _name; + SGSharedPtr _dataType; + std::string _semantics; + }; + + typedef std::vector AlternativeList; + AlternativeList _alternativeList; +}; + +} // namespace simgear + +#endif