From 201cb61f842ef50a19438e3872ba22e588fa1afc Mon Sep 17 00:00:00 2001 From: Mathias Froehlich Date: Sun, 11 Nov 2012 16:54:43 +0100 Subject: [PATCH] hla: Use HLADataElementIndices for HLAInteractionClass. --- simgear/hla/HLAInteractionClass.cxx | 38 +++++++++++++++++++++++++++++ simgear/hla/HLAInteractionClass.hxx | 4 +++ 2 files changed, 42 insertions(+) diff --git a/simgear/hla/HLAInteractionClass.cxx b/simgear/hla/HLAInteractionClass.cxx index afe9bd9f..a9693d98 100644 --- a/simgear/hla/HLAInteractionClass.cxx +++ b/simgear/hla/HLAInteractionClass.cxx @@ -159,6 +159,44 @@ HLAInteractionClass::getIndexPathPair(const std::string& path) const return getIndexPathPair(HLADataElement::toStringPathPair(path)); } +bool +HLAInteractionClass::getDataElementIndex(HLADataElementIndex& dataElementIndex, const std::string& path) const +{ + if (path.empty()) { + SG_LOG(SG_NETWORK, SG_ALERT, "HLAObjectClass: failed to parse empty element path!"); + return false; + } + std::string::size_type len = std::min(path.find_first_of("[."), path.size()); + unsigned index = 0; + while (index < getNumParameters()) { + if (path.compare(0, len, getParameterName(index)) == 0) + break; + ++index; + } + if (getNumParameters() <= index) { + SG_LOG(SG_NETWORK, SG_ALERT, "HLAObjectClass: faild to parse data element index \"" << path << "\":\n" + << "Parameter \"" << path.substr(0, len) << "\" not found in object class \"" + << getName() << "\"!"); + return false; + } + if (!getParameterDataType(index)) { + SG_LOG(SG_NETWORK, SG_ALERT, "HLAObjectClass: faild to parse data element index \"" << path << "\":\n" + << "Undefined parameter data type in variant record data type \"" + << getParameterName(index) << "\"!"); + return false; + } + dataElementIndex.push_back(index); + return getParameterDataType(index)->getDataElementIndex(dataElementIndex, path, len); +} + +HLADataElementIndex +HLAInteractionClass::getDataElementIndex(const std::string& path) const +{ + HLADataElementIndex dataElementIndex; + getDataElementIndex(dataElementIndex, path); + return dataElementIndex; +} + bool HLAInteractionClass::subscribe() { diff --git a/simgear/hla/HLAInteractionClass.hxx b/simgear/hla/HLAInteractionClass.hxx index 34a25c7e..211f3dea 100644 --- a/simgear/hla/HLAInteractionClass.hxx +++ b/simgear/hla/HLAInteractionClass.hxx @@ -62,6 +62,10 @@ public: HLADataElement::IndexPathPair getIndexPathPair(const HLADataElement::StringPathPair& stringPathPair) const; HLADataElement::IndexPathPair getIndexPathPair(const std::string& path) const; + /// Get the attribute data element index for the given path, return true if successful + bool getDataElementIndex(HLADataElementIndex& dataElementIndex, const std::string& path) const; + HLADataElementIndex getDataElementIndex(const std::string& path) const; + virtual bool subscribe(); virtual bool unsubscribe(); -- 2.39.5