]> git.mxchange.org Git - simgear.git/blobdiff - simgear/props/props.cxx
cppbind.Ghost: clean up a bit
[simgear.git] / simgear / props / props.cxx
index f5484568f984e2449bcda499b2a4b8dac3563e31..d9c90a33c814a09815703588b42ed6ae5d2033f4 100644 (file)
@@ -11,6 +11,7 @@
 #endif
 
 #include "props.hxx"
+#include "PropertyInterpolationMgr.hxx"
 #include "vectorPropTemplates.hxx"
 
 #include <algorithm>
@@ -236,33 +237,19 @@ first_unused_index( const char * name,
 
 template<typename Itr>
 inline SGPropertyNode*
-SGPropertyNode::getExistingChild (Itr begin, Itr end, int index, bool create)
+SGPropertyNode::getExistingChild (Itr begin, Itr end, int index)
 {
   int pos = find_child(begin, end, index, _children);
-  if (pos >= 0) {
+  if (pos >= 0)
     return _children[pos];
-  } else if (create) {
-    SGPropertyNode_ptr node;
-    pos = find_child(begin, end, index, _removedChildren);
-    if (pos >= 0) {
-      PropertyList::iterator it = _removedChildren.begin();
-      it += pos;
-      node = _removedChildren[pos];
-      _removedChildren.erase(it);
-      node->setAttribute(REMOVED, false);
-      _children.push_back(node);
-      fireChildAdded(node);
-      return node;      
-    }
-  }
   return 0;
 }
-    
+
 template<typename Itr>
 SGPropertyNode *
 SGPropertyNode::getChildImpl (Itr begin, Itr end, int index, bool create)
 {
-    SGPropertyNode* node = getExistingChild(begin, end, index, create);
+    SGPropertyNode* node = getExistingChild(begin, end, index);
 
     if (node) {
       return node;
@@ -774,8 +761,6 @@ SGPropertyNode::~SGPropertyNode ()
   // zero out all parent pointers, else they might be dangling
   for (unsigned i = 0; i < _children.size(); ++i)
     _children[i]->_parent = 0;
-  for (unsigned i = 0; i < _removedChildren.size(); ++i)
-    _removedChildren[i]->_parent = 0;
   clearValue();
 
   if (_listeners) {
@@ -973,8 +958,7 @@ SGPropertyNode::getChild (const char * name, int index, bool create)
 SGPropertyNode *
 SGPropertyNode::getChild (const string& name, int index, bool create)
 {
-  SGPropertyNode* node = getExistingChild(name.begin(), name.end(), index,
-                                          create);
+  SGPropertyNode* node = getExistingChild(name.begin(), name.end(), index);
   if (node) {
       return node;
     } else if (create) {
@@ -1023,7 +1007,7 @@ SGPropertyNode::getChildren (const char * name) const
  * Remove child by position.
  */
 SGPropertyNode_ptr
-SGPropertyNode::removeChild (int pos, bool keep)
+SGPropertyNode::removeChild(int pos)
 {
   SGPropertyNode_ptr node;
   if (pos < 0 || pos >= (int)_children.size())
@@ -1033,9 +1017,6 @@ SGPropertyNode::removeChild (int pos, bool keep)
   it += pos;
   node = _children[pos];
   _children.erase(it);
-  if (keep) {
-    _removedChildren.push_back(node);
-  }
 
   node->setAttribute(REMOVED, true);
   node->clearValue();
@@ -1048,12 +1029,12 @@ SGPropertyNode::removeChild (int pos, bool keep)
  * Remove a child node
  */
 SGPropertyNode_ptr
-SGPropertyNode::removeChild (const char * name, int index, bool keep)
+SGPropertyNode::removeChild(const char * name, int index)
 {
   SGPropertyNode_ptr ret;
   int pos = find_child(name, name + strlen(name), index, _children);
   if (pos >= 0)
-    ret = removeChild(pos, keep);
+    ret = removeChild(pos);
   return ret;
 }
 
@@ -1062,18 +1043,33 @@ SGPropertyNode::removeChild (const char * name, int index, bool keep)
   * Remove all children with the specified name.
   */
 PropertyList
-SGPropertyNode::removeChildren (const char * name, bool keep)
+SGPropertyNode::removeChildren(const char * name)
 {
   PropertyList children;
 
   for (int pos = static_cast<int>(_children.size() - 1); pos >= 0; pos--)
     if (compare_strings(_children[pos]->getName(), name))
-      children.push_back(removeChild(pos, keep));
+      children.push_back(removeChild(pos));
 
   sort(children.begin(), children.end(), CompareIndices());
   return children;
 }
 
+void
+SGPropertyNode::removeAllChildren()
+{
+  for(unsigned i = 0; i < _children.size(); ++i)
+  {
+    SGPropertyNode_ptr& node = _children[i];
+    node->_parent = 0;
+    node->setAttribute(REMOVED, true);
+    node->clearValue();
+    fireChildRemoved(node);
+  }
+
+  _children.clear();
+}
+
 string
 SGPropertyNode::getDisplayName (bool simplify) const
 {
@@ -1654,6 +1650,52 @@ SGPropertyNode::setUnspecifiedValue (const char * value)
   return result;
 }
 
+//------------------------------------------------------------------------------
+bool SGPropertyNode::interpolate( const std::string& type,
+                                  const SGPropertyNode& target,
+                                  double duration,
+                                  const std::string& easing )
+{
+  if( !_interpolation_mgr )
+  {
+    SG_LOG(SG_GENERAL, SG_WARN, "No property interpolator available");
+
+    // no interpolation possible -> set to target immediately
+    setUnspecifiedValue( target.getStringValue() );
+    return false;
+  }
+
+  return _interpolation_mgr->interpolate(this, type, target, duration, easing);
+}
+
+//------------------------------------------------------------------------------
+bool SGPropertyNode::interpolate( const std::string& type,
+                                  const PropertyList& values,
+                                  const double_list& deltas,
+                                  const std::string& easing )
+{
+  if( !_interpolation_mgr )
+  {
+    SG_LOG(SG_GENERAL, SG_WARN, "No property interpolator available");
+
+    // no interpolation possible -> set to last value immediately
+    if( !values.empty() )
+      setUnspecifiedValue(values.back()->getStringValue());
+    return false;
+  }
+
+  return _interpolation_mgr->interpolate(this, type, values, deltas, easing);
+}
+
+//------------------------------------------------------------------------------
+void SGPropertyNode::setInterpolationMgr(simgear::PropertyInterpolationMgr* mgr)
+{
+  _interpolation_mgr = mgr;
+}
+
+simgear::PropertyInterpolationMgr* SGPropertyNode::_interpolation_mgr = 0;
+
+//------------------------------------------------------------------------------
 std::ostream& SGPropertyNode::printOn(std::ostream& stream) const
 {
     if (!getAttribute(READ))