]> git.mxchange.org Git - simgear.git/blobdiff - simgear/hla/HLAInteractionClass.cxx
hla: Use HLADataElementIndices for HLAInteractionClass.
[simgear.git] / simgear / hla / HLAInteractionClass.cxx
index b56aec4437583da63ee7ac154b22da4832abedaa..a9693d9822067c4c75dc2e70094ce57ca307011e 100644 (file)
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 
+#ifdef HAVE_CONFIG_H
+#  include <simgear_config.h>
+#endif
+
+#include <simgear/compiler.h>
+
 #include "HLAInteractionClass.hxx"
 
 #include <simgear/debug/logstream.hxx>
@@ -55,6 +61,12 @@ HLAInteractionClass::getName() const
     return _name;
 }
 
+const SGWeakPtr<HLAFederate>&
+HLAInteractionClass::getFederate() const
+{
+    return _federate;
+}
+
 HLASubscriptionType
 HLAInteractionClass::getSubscriptionType() const
 {
@@ -147,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()
 {