]> git.mxchange.org Git - simgear.git/blobdiff - simgear/hla/HLAObjectClass.cxx
Windows versionhelpers.h support.
[simgear.git] / simgear / hla / HLAObjectClass.cxx
index 3385f6952ad0c7c9a217377106c81a3b91fa2d7b..2740eb029d461ad6e573cf90331d9d3dbcb0e8a8 100644 (file)
@@ -28,6 +28,7 @@
 #include "RTIObjectClass.hxx"
 #include "RTIObjectInstance.hxx"
 #include "HLADataType.hxx"
+#include "HLADataTypeVisitor.hxx"
 #include "HLAFederate.hxx"
 #include "HLAObjectInstance.hxx"
 
@@ -190,23 +191,42 @@ HLAObjectClass::setAttributePublicationType(unsigned index, HLAPublicationType p
     _attributeVector[index]._publicationType = publicationType;
 }
 
-HLADataElement::IndexPathPair
-HLAObjectClass::getIndexPathPair(const HLADataElement::StringPathPair& stringPathPair) const
+bool
+HLAObjectClass::getDataElementIndex(HLADataElementIndex& dataElementIndex, const std::string& path) const
 {
-    unsigned index = getAttributeIndex(stringPathPair.first);
+    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 < getNumAttributes()) {
+        if (path.compare(0, len, getAttributeName(index)) == 0)
+            break;
+        ++index;
+    }
     if (getNumAttributes() <= index) {
-        SG_LOG(SG_NETWORK, SG_ALERT, "HLAObjectClass::getIndexPathPair(\""
-               << HLADataElement::toString(stringPathPair)
-               << "\"): Could not resolve attribute \"" << stringPathPair.first
-               << "\" for object class \"" << getName() << "\"!");
+        SG_LOG(SG_NETWORK, SG_ALERT, "HLAObjectClass: faild to parse data element index \"" << path << "\":\n"
+               << "Attribute \"" << path.substr(0, len) << "\" not found in object class \""
+               << getName() << "\"!");
+        return false;
     }
-    return HLADataElement::IndexPathPair(index, stringPathPair.second);
+    if (!getAttributeDataType(index)) {
+        SG_LOG(SG_NETWORK, SG_ALERT, "HLAObjectClass: faild to parse data element index \"" << path << "\":\n"
+               << "Undefined attribute data type in variant record data type \""
+               << getAttributeName(index) << "\"!");
+        return false;
+    }
+    dataElementIndex.push_back(index);
+    return getAttributeDataType(index)->getDataElementIndex(dataElementIndex, path, len);
 }
 
-HLADataElement::IndexPathPair
-HLAObjectClass::getIndexPathPair(const std::string& path) const
+HLADataElementIndex
+HLAObjectClass::getDataElementIndex(const std::string& path) const
 {
-    return getIndexPathPair(HLADataElement::toStringPathPair(path));
+    HLADataElementIndex dataElementIndex;
+    getDataElementIndex(dataElementIndex, path);
+    return dataElementIndex;
 }
 
 bool
@@ -286,6 +306,34 @@ HLAObjectClass::unpublish()
     return _rtiObjectClass->unpublish();
 }
 
+void
+HLAObjectClass::discoverInstance(HLAObjectInstance& objectInstance, const RTIData& tag)
+{
+    if (_instanceCallback.valid())
+        _instanceCallback->discoverInstance(*this, objectInstance, tag);
+}
+
+void
+HLAObjectClass::removeInstance(HLAObjectInstance& objectInstance, const RTIData& tag)
+{
+    if (_instanceCallback.valid())
+        _instanceCallback->removeInstance(*this, objectInstance, tag);
+}
+
+void
+HLAObjectClass::registerInstance(HLAObjectInstance& objectInstance)
+{
+    if (_instanceCallback.valid())
+        _instanceCallback->registerInstance(*this, objectInstance);
+}
+
+void
+HLAObjectClass::deleteInstance(HLAObjectInstance& objectInstance)
+{
+    if (_instanceCallback.valid())
+        _instanceCallback->deleteInstance(*this, objectInstance);
+}
+
 void
 HLAObjectClass::startRegistration() const
 {
@@ -305,6 +353,26 @@ HLAObjectClass::createObjectInstance(const std::string& name)
     return federate->createObjectInstance(this, name);
 }
 
+void
+HLAObjectClass::createAttributeDataElements(HLAObjectInstance& objectInstance)
+{
+    unsigned numAttributes = getNumAttributes();
+    for (unsigned i = 0; i < numAttributes; ++i)
+        objectInstance.createAndSetAttributeDataElement(i);
+}
+
+HLADataElement*
+HLAObjectClass::createAttributeDataElement(HLAObjectInstance& objectInstance, unsigned index)
+{
+    // FIXME here we want to have a vector of factories and if this fails do the following
+    const HLADataType* dataType = getAttributeDataType(index);
+    if (!dataType)
+        return 0;
+    HLADataElementFactoryVisitor dataElementFactoryVisitor;
+    dataType->accept(dataElementFactoryVisitor);
+    return dataElementFactoryVisitor.getDataElement();
+}
+
 void
 HLAObjectClass::_setRTIObjectClass(RTIObjectClass* objectClass)
 {
@@ -363,8 +431,8 @@ HLAObjectClass::_discoverInstance(RTIObjectInstance* rtiObjectInstance, const RT
                << rtiObjectInstance->getName() << "\" object");
         return;
     }
-    if (_instanceCallback.valid())
-        _instanceCallback->discoverInstance(*this, *objectInstance, tag);
+    objectInstance->discoverInstance(tag);
+    objectInstance->createAttributeDataElements();
 }
 
 void
@@ -376,8 +444,7 @@ HLAObjectClass::_removeInstance(HLAObjectInstance& objectInstance, const RTIData
         return;
     }
     SG_LOG(SG_NETWORK, SG_INFO, "RTI: remove object instance \"" << objectInstance.getName() << "\"");
-    if (_instanceCallback.valid())
-        _instanceCallback->removeInstance(*this, objectInstance, tag);
+    objectInstance.removeInstance(tag);
     federate->_eraseObjectInstance(objectInstance.getName());
 }
 
@@ -398,8 +465,8 @@ HLAObjectClass::_registerInstance(HLAObjectInstance* objectInstance)
                << objectInstance->getName() << "\" object");
         return;
     }
-    if (_instanceCallback.valid())
-        _instanceCallback->registerInstance(*this, *objectInstance);
+    registerInstance(*objectInstance);
+    objectInstance->createAttributeDataElements();
 }
 
 void
@@ -410,8 +477,7 @@ HLAObjectClass::_deleteInstance(HLAObjectInstance& objectInstance)
         SG_LOG(SG_NETWORK, SG_ALERT, "RTI: could not find parent federate while deleting object instance");
         return;
     }
-    if (_instanceCallback.valid())
-        _instanceCallback->deleteInstance(*this, objectInstance);
+    deleteInstance(objectInstance);
     federate->_eraseObjectInstance(objectInstance.getName());
 }