]> git.mxchange.org Git - simgear.git/blobdiff - simgear/hla/HLADataElement.cxx
hla: Use HLADataElementIndices for HLAInteractionClass.
[simgear.git] / simgear / hla / HLADataElement.cxx
index ae981128543722ed91837ab955ef1ae2021750a4..69a32d1e0b674beb3cabcb6b3a21141922d80acd 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 "HLADataElement.hxx"
 
 #include <simgear/debug/logstream.hxx>
 
+#include "HLADataElementVisitor.hxx"
+
 namespace simgear {
 
 HLADataElement::PathElement::Data::~Data()
@@ -129,6 +137,85 @@ HLADataElement::~HLADataElement()
 {
 }
 
+bool
+HLADataElement::setDataElement(HLADataElementIndex::const_iterator begin, HLADataElementIndex::const_iterator end, HLADataElement* dataElement)
+{
+    return false;
+}
+
+HLADataElement*
+HLADataElement::getDataElement(HLADataElementIndex::const_iterator begin, HLADataElementIndex::const_iterator end)
+{
+    if (begin != end)
+        return 0;
+    return this;
+}
+
+const HLADataElement*
+HLADataElement::getDataElement(HLADataElementIndex::const_iterator begin, HLADataElementIndex::const_iterator end) const
+{
+    if (begin != end)
+        return 0;
+    return this;
+}
+
+void
+HLADataElement::setTimeStamp(const SGTimeStamp& timeStamp)
+{
+    if (!_stamp.valid())
+        return;
+    _stamp->setTimeStamp(timeStamp);
+}
+
+void
+HLADataElement::setTimeStampValid(bool timeStampValid)
+{
+    if (!_stamp.valid())
+        return;
+    _stamp->setTimeStampValid(timeStampValid);
+}
+
+double
+HLADataElement::getTimeDifference(const SGTimeStamp& timeStamp) const
+{
+    if (!_stamp.valid())
+        return 0;
+    if (!_stamp->getTimeStampValid())
+        return 0;
+    return (timeStamp - _stamp->getTimeStamp()).toSecs();
+}
+
+void
+HLADataElement::createStamp()
+{
+    _setStamp(new Stamp);
+    setDirty(true);
+}
+
+void
+HLADataElement::attachStamp(HLADataElement& dataElement)
+{
+    _setStamp(dataElement._getStamp());
+}
+
+void
+HLADataElement::clearStamp()
+{
+    _setStamp(0);
+}
+
+void
+HLADataElement::accept(HLADataElementVisitor& visitor)
+{
+    visitor.apply(*this);
+}
+
+void
+HLADataElement::accept(HLAConstDataElementVisitor& visitor) const
+{
+    visitor.apply(*this);
+}
+
 std::string
 HLADataElement::toString(const Path& path)
 {
@@ -138,11 +225,11 @@ HLADataElement::toString(const Path& path)
     return s;
 }
 
-HLADataElement::AttributePathPair
-HLADataElement::toAttributePathPair(const std::string& s)
+HLADataElement::StringPathPair
+HLADataElement::toStringPathPair(const std::string& s)
 {
     Path path;
-    // Skip the initial attribute name if given
+    // Skip the initial attribute/parameter name if given
     std::string::size_type i = s.find_first_of("[.");
     std::string attribute = s.substr(0, i);
     while (i < s.size()) {
@@ -157,7 +244,7 @@ HLADataElement::toAttributePathPair(const std::string& s)
                 if (10 <= v) {
                     SG_LOG(SG_NETWORK, SG_WARN, "HLADataElement: invalid character in array subscript for \""
                            << s << "\" at \"" << attribute << toString(path) << "\"!");
-                    return AttributePathPair();
+                    return StringPathPair();
                 }
                 index *= 10;
                 index += v;
@@ -172,7 +259,7 @@ HLADataElement::toAttributePathPair(const std::string& s)
             if (s.size() <= ++i) {
                 SG_LOG(SG_NETWORK, SG_WARN, "HLADataElement: invalid terminating '.' for \""
                        << s << "\"!");
-                return AttributePathPair();
+                return StringPathPair();
             }
             std::string::size_type e = s.find_first_of("[.", i);
             path.push_back(s.substr(i, e - i));
@@ -181,7 +268,13 @@ HLADataElement::toAttributePathPair(const std::string& s)
         }
     }
 
-    return AttributePathPair(attribute, path);
+    return StringPathPair(attribute, path);
+}
+
+void
+HLADataElement::_setStamp(HLADataElement::Stamp* stamp)
+{
+    _stamp = stamp;
 }
 
 }