]> git.mxchange.org Git - simgear.git/commitdiff
hla: Use HLADataElementIndices for HLAInteractionClass.
authorMathias Froehlich <Mathias.Froehlich@web.de>
Sun, 11 Nov 2012 15:54:43 +0000 (16:54 +0100)
committerMathias Froehlich <Mathias.Froehlich@web.de>
Sun, 11 Nov 2012 16:09:31 +0000 (17:09 +0100)
simgear/hla/HLAInteractionClass.cxx
simgear/hla/HLAInteractionClass.hxx

index afe9bd9f5ef0c06308b4a582d3a112f2761c059a..a9693d9822067c4c75dc2e70094ce57ca307011e 100644 (file)
@@ -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()
 {
index 34a25c7e95db506aba602b33f9eaab37c8b2f88f..211f3deab5f8710f2f19c24d1c6dc3c38f1cc6e4 100644 (file)
@@ -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();