From 4bd27475881331578fd4ee18837d503b3bc93db6 Mon Sep 17 00:00:00 2001 From: randomdan Date: Fri, 11 Apr 2014 18:39:25 +0000 Subject: Support getting all script nodes of a given name --- project2/common/scripts.cpp | 9 +++++++++ project2/common/scripts.h | 1 + 2 files changed, 10 insertions(+) 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 #include "variables/fixed.h" #include #include @@ -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; -- cgit v1.2.3