summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2014-04-11 18:39:25 +0000
committerrandomdan <randomdan@localhost>2014-04-11 18:39:25 +0000
commit4bd27475881331578fd4ee18837d503b3bc93db6 (patch)
tree6695c7f3cfdcb863ca61cd5052725cb57d0015bd
parentSupport create a variable directly from a script node instance (diff)
downloadproject2-4bd27475881331578fd4ee18837d503b3bc93db6.tar.bz2
project2-4bd27475881331578fd4ee18837d503b3bc93db6.tar.xz
project2-4bd27475881331578fd4ee18837d503b3bc93db6.zip
Support getting all script nodes of a given name
-rw-r--r--project2/common/scripts.cpp9
-rw-r--r--project2/common/scripts.h1
2 files changed, 10 insertions, 0 deletions
diff --git a/project2/common/scripts.cpp b/project2/common/scripts.cpp
index a7a6c23..2b52db5 100644
--- a/project2/common/scripts.cpp
+++ b/project2/common/scripts.cpp
@@ -1,4 +1,5 @@
#include "scripts.h"
+#include <algorithm>
#include "variables/fixed.h"
#include <boost/filesystem/convenience.hpp>
#include <boost/tuple/tuple_comparison.hpp>
@@ -32,6 +33,14 @@ ScriptNode::variable(const Glib::ustring & n, const VariableType & def) const
}
}
+ScriptNode::ScriptNodes
+ScriptNode::children(const Glib::ustring & name) const
+{
+ auto nodes = children();
+ nodes.erase(std::remove_if(nodes.begin(), nodes.end(), [&name](const ScriptNodePtr & n) { return n->get_name() != name; }), nodes.end());
+ return nodes;
+}
+
VariableType
ScriptNode::value(const Glib::ustring & n, const VariableType & def, ExecContext * ec) const
{
diff --git a/project2/common/scripts.h b/project2/common/scripts.h
index 92151f6..7d43a01 100644
--- a/project2/common/scripts.h
+++ b/project2/common/scripts.h
@@ -43,6 +43,7 @@ class ScriptNode : public IntrusivePtrBase {
virtual ScriptNodePtr child(const Glib::ustring & name, bool required = true) const = 0;
// All children
virtual ScriptNodes children() const = 0;
+ virtual ScriptNodes children(const Glib::ustring & name) const;
// All children in sub
virtual ScriptNodes childrenIn(const Glib::ustring & sub) const = 0;