diff options
-rw-r--r-- | src/report.cc | 13 | ||||
-rw-r--r-- | src/report.h | 4 | ||||
-rw-r--r-- | src/session.cc | 26 | ||||
-rw-r--r-- | src/session.h | 4 | ||||
-rw-r--r-- | src/xpath.cc | 30 | ||||
-rw-r--r-- | src/xpath.h | 13 |
6 files changed, 37 insertions, 53 deletions
diff --git a/src/report.cc b/src/report.cc index 5f52d37e..04ed2471 100644 --- a/src/report.cc +++ b/src/report.cc @@ -82,27 +82,24 @@ value_t report_t::ftime(xml::xpath_t::scope_t * locals) #endif } -bool report_t::resolve(const string& name, value_t& result, - xml::xpath_t::scope_t * locals) +optional<value_t> +report_t::resolve(const string& name, xml::xpath_t::scope_t * locals) { const char * p = name.c_str(); switch (*p) { case 'a': if (name == "abbrev") { - result = abbrev(locals); - return true; + return abbrev(locals); } break; case 'f': if (name == "ftime") { - result = ftime(locals); - return true; + return ftime(locals); } break; } - - return xml::xpath_t::scope_t::resolve(name, result, locals); + return xml::xpath_t::scope_t::resolve(name, locals); } xml::xpath_t::ptr_op_t report_t::lookup(const string& name) diff --git a/src/report.h b/src/report.h index de5773d1..bf43e927 100644 --- a/src/report.h +++ b/src/report.h @@ -161,8 +161,8 @@ class report_t : public xml::xpath_t::scope_t // Scope members // - virtual bool resolve(const string& name, value_t& result, - xml::xpath_t::scope_t * locals); + virtual optional<value_t> resolve(const string& name, + xml::xpath_t::scope_t * locals); virtual xml::xpath_t::ptr_op_t lookup(const string& name); }; diff --git a/src/session.cc b/src/session.cc index 4bb88e4e..a93fb755 100644 --- a/src/session.cc +++ b/src/session.cc @@ -173,41 +173,35 @@ std::size_t session_t::read_data(xml::builder_t& builder, return entry_count; } -bool session_t::resolve(const string& name, value_t& result, - xml::xpath_t::scope_t * locals) +optional<value_t> +session_t::resolve(const string& name, xml::xpath_t::scope_t * locals) { const char * p = name.c_str(); switch (*p) { case 'd': +#if 0 if (name == "date_format") { // jww (2007-04-18): What to do here? -#if 0 - result.set_string(moment_t::output_format); -#endif - return true; + return value_t(moment_t::output_format, true); } +#endif break; case 'n': switch (*++p) { case 'o': - if (name == "now") { - result = now; - return true; - } + if (name == "now") + return value_t(now); break; } break; case 'r': - if (name == "register_format") { - result = register_format; - return true; - } + if (name == "register_format") + return value_t(register_format, true); break; } - - return xml::xpath_t::scope_t::resolve(name, result, locals); + return xml::xpath_t::scope_t::resolve(name, locals); } xml::xpath_t::ptr_op_t session_t::lookup(const string& name) diff --git a/src/session.h b/src/session.h index 8db9faf1..6f7b5a12 100644 --- a/src/session.h +++ b/src/session.h @@ -180,8 +180,8 @@ class session_t : public xml::xpath_t::scope_t // Scope members // - virtual bool resolve(const string& name, value_t& result, - xml::xpath_t::scope_t * locals = NULL); + virtual optional<value_t> resolve(const string& name, + xml::xpath_t::scope_t * locals = NULL); virtual xml::xpath_t::ptr_op_t lookup(const string& name); // diff --git a/src/xpath.cc b/src/xpath.cc index 80749d72..2a28956d 100644 --- a/src/xpath.cc +++ b/src/xpath.cc @@ -483,33 +483,29 @@ void xpath_t::scope_t::define(const string& name, const function_t& def) { define(name, wrap_functor(def)); } -bool xpath_t::function_scope_t::resolve(const string& name, - value_t& result, - scope_t * locals) +optional<value_t> +xpath_t::function_scope_t::resolve(const string& name, scope_t * locals) { switch (name[0]) { case 'l': if (name == "last") { - result = (long)size; - return true; + return value_t((long)size); } break; case 'p': if (name == "position") { - result = (long)index + 1; - return true; + return value_t((long)index + 1); } break; case 't': if (name == "text") { - result = node.to_value(); - return true; + return node.to_value(); } break; } - return scope_t::resolve(name, result, locals); + return scope_t::resolve(name, locals); } xpath_t::ptr_op_t @@ -1208,9 +1204,8 @@ xpath_t::op_t::compile(const node_t& context, scope_t * scope, bool resolve) case FUNC_NAME: if (scope) { if (resolve) { - value_t temp; - if (scope->resolve(as_string(), temp)) - return wrap_value(temp); + if (optional<value_t> temp = scope->resolve(as_string())) + return wrap_value(*temp); } if (ptr_op_t def = scope->lookup(as_string())) return def->compile(context, scope, resolve); @@ -1543,11 +1538,10 @@ xpath_t::op_t::compile(const node_t& context, scope_t * scope, bool resolve) call_args->args = call_seq; if (left()->kind == FUNC_NAME) { - if (resolve) { - value_t temp; - if (scope && scope->resolve(left()->as_string(), temp, call_args.get())) - return wrap_value(temp); - } + if (resolve && scope) + if (optional<value_t> temp = + scope->resolve(left()->as_string(), call_args.get())) + return wrap_value(*temp); // Don't compile to the left, otherwise the function name may // get resolved before we have a chance to call it diff --git a/src/xpath.h b/src/xpath.h index 5433223d..0bb234a5 100644 --- a/src/xpath.h +++ b/src/xpath.h @@ -84,12 +84,11 @@ public: public: virtual void define(const string& name, ptr_op_t def); - // jww (2007-05-15): ?? - virtual bool resolve(const string& name, value_t& result, - scope_t * locals = NULL) { + virtual optional<value_t> resolve(const string& name, + scope_t * locals = NULL) { if (parent) - return parent->resolve(name, result, locals); - return false; + return parent->resolve(name, locals); + return none; } virtual ptr_op_t lookup(const string& name); @@ -116,8 +115,8 @@ public: : scope_t(_parent, STATIC), node(_node), index(_index), size(_size) {} - virtual bool resolve(const string& name, value_t& result, - scope_t * locals = NULL); + virtual optional<value_t> resolve(const string& name, + scope_t * locals = NULL); }; #define XPATH_PARSE_NORMAL 0x00 |