summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--project2/common/scripts.cpp23
-rw-r--r--project2/common/scripts.h4
-rw-r--r--project2/xml/xmlScriptParser.cpp12
-rw-r--r--project2/xml/xmlScriptParser.h2
4 files changed, 20 insertions, 21 deletions
diff --git a/project2/common/scripts.cpp b/project2/common/scripts.cpp
index 4e9f18b..997f558 100644
--- a/project2/common/scripts.cpp
+++ b/project2/common/scripts.cpp
@@ -20,24 +20,21 @@ ScriptNode::variable(const Glib::ustring & n, const VariableType & def) const
VariableType
ScriptNode::value(const Glib::ustring & n, const VariableType & def) const
{
- try {
- return value(n);
- }
- catch (const ValueNotFound &) {
- return def;
+ VariableType r;
+ if (applyValue(n, r)) {
+ return r;
}
+ return def;
}
-bool
-ScriptNode::applyValue(const Glib::ustring & n, VariableType & target) const
+VariableType
+ScriptNode::value(const Glib::ustring & n) const
{
- try {
- target = value(n);
- return true;
- }
- catch (const ValueNotFound &) {
- return false;
+ VariableType r;
+ if (applyValue(n, r)) {
+ return r;
}
+ throw ValueNotFound(n);
}
void
diff --git a/project2/common/scripts.h b/project2/common/scripts.h
index b7fdec9..405056e 100644
--- a/project2/common/scripts.h
+++ b/project2/common/scripts.h
@@ -38,11 +38,11 @@ class ScriptNode : public IntrusivePtrBase {
virtual ScriptNodes childrenIn(const Glib::ustring & sub) const = 0;
virtual bool valueExists(const Glib::ustring & name) const = 0;
- bool applyValue(const Glib::ustring & name, VariableType & target) const;
+ virtual bool applyValue(const Glib::ustring & name, VariableType & target) const = 0;
virtual VariableImpl * variable(const boost::optional<Glib::ustring> & defaultSource = boost::optional<Glib::ustring>()) const = 0;
virtual VariableImpl * variable(const Glib::ustring & name) const = 0;
VariableImpl * variable(const Glib::ustring & name, const VariableType & def) const;
- virtual VariableType value(const Glib::ustring & name) const = 0;
+ VariableType value(const Glib::ustring & name) const;
VariableType value(const Glib::ustring & name, const VariableType & def) const;
virtual void composeWithCallbacks(const LiteralCallback &, const NodeCallback &) const = 0;
diff --git a/project2/xml/xmlScriptParser.cpp b/project2/xml/xmlScriptParser.cpp
index 5091f31..af69566 100644
--- a/project2/xml/xmlScriptParser.cpp
+++ b/project2/xml/xmlScriptParser.cpp
@@ -194,11 +194,12 @@ XmlScriptNode::variable(const boost::optional<Glib::ustring> & defaultSource) co
}
}
-VariableType
-XmlScriptNode::value(const Glib::ustring & n) const
+bool
+XmlScriptNode::applyValue(const Glib::ustring & n, VariableType & val) const
{
if (const xmlpp::Attribute * a = element->get_attribute(n)) {
- return a->get_value();
+ val = a->get_value();
+ return true;
}
const xmlpp::Element::NodeList cs = element->get_children(n);
if (cs.size() == 1) {
@@ -210,10 +211,11 @@ XmlScriptNode::value(const Glib::ustring & n) const
else {
v = new VariableLiteral(new XmlScriptNode(c, script));
}
- return v->value();
+ val = v->value();
+ return false;
}
}
- throw ValueNotFound(n);
+ return false;
}
void
diff --git a/project2/xml/xmlScriptParser.h b/project2/xml/xmlScriptParser.h
index 2d2d5db..9862f49 100644
--- a/project2/xml/xmlScriptParser.h
+++ b/project2/xml/xmlScriptParser.h
@@ -24,7 +24,7 @@ class XmlScriptNode : public ScriptNode {
bool valueExists(const Glib::ustring&) const;
VariableImpl * variable(const boost::optional<Glib::ustring> & defaultSource) const;
VariableImpl * variable(const Glib::ustring&) const;
- VariableType value(const Glib::ustring&) const;
+ bool applyValue(const Glib::ustring & name, VariableType & target) const;
void composeWithCallbacks(const ScriptNode::LiteralCallback&, const ScriptNode::NodeCallback&) const;
private: