From e0c9c1b5dd0ed1236615a9284d7a9dbbebaa868c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 6 Jun 2015 22:07:48 +0100 Subject: Move the parameter stack into ExecContext too --- project2/common/execContext.cpp | 24 ++++++++++++++++++++++++ project2/common/execContext.h | 7 +++++++ project2/common/iHaveParameters.cpp | 26 -------------------------- project2/common/iHaveParameters.h | 7 ------- project2/common/rowProcessor.cpp | 5 +++-- project2/common/variables/localparam.cpp | 3 ++- 6 files changed, 36 insertions(+), 36 deletions(-) diff --git a/project2/common/execContext.cpp b/project2/common/execContext.cpp index 1349ab0..462de8b 100644 --- a/project2/common/execContext.cpp +++ b/project2/common/execContext.cpp @@ -2,6 +2,7 @@ #include "logger.h" #include "presenter.h" #include "rowSet.h" +#include "iHaveParameters.h" void ExecContext::logMessage(bool writeLog, const Glib::ustring & g, const Glib::ustring & m) @@ -55,4 +56,27 @@ ExecContext::RowValues(size_t depth) const return rowValuesStack.at(rowValuesStack.size() - depth); } +void +ExecContext::ParametersPush(const IHaveParameters * p) +{ + parameterStack.push_back(p); +} + +void +ExecContext::ParametersPop() +{ + parameterStack.pop_back(); +} + +VariableType +ExecContext::getScopedParameter(const Glib::ustring & name) +{ + for(auto ihp = parameterStack.rbegin(); ihp != parameterStack.rend(); ++ihp) { + auto i = (*ihp)->allParameters().find(name); + if (i != (*ihp)->allParameters().end()) { + return i->second(this); + } + } + throw ParamNotFound(name); +} diff --git a/project2/common/execContext.h b/project2/common/execContext.h index 5bce0d7..86438bd 100644 --- a/project2/common/execContext.h +++ b/project2/common/execContext.h @@ -9,6 +9,7 @@ class MultiRowSetPresenter; class RowState; +class IHaveParameters; class ExecContext { public: @@ -22,6 +23,7 @@ class ExecContext { typedef boost::intrusive_ptr MessagePtr; typedef std::list Messages; typedef std::vector RowValuesStack; + typedef std::vector ParameterStack; virtual VariableType getParameter(const VariableType & key) const = 0; virtual SessionPtr getSession() const = 0; @@ -35,9 +37,14 @@ class ExecContext { void RowValuesPop(); const RowState * RowValues(size_t depth) const; + void ParametersPush(const IHaveParameters *); + void ParametersPop(); + VariableType getScopedParameter(const Glib::ustring &); + private: Messages messages; RowValuesStack rowValuesStack; + ParameterStack parameterStack; }; #endif diff --git a/project2/common/iHaveParameters.cpp b/project2/common/iHaveParameters.cpp index c3effdf..cb9241a 100644 --- a/project2/common/iHaveParameters.cpp +++ b/project2/common/iHaveParameters.cpp @@ -3,8 +3,6 @@ #include "exceptions.h" #include "safeMapFind.h" -IHaveParameters::Stack IHaveParameters::scope; - IHaveParameters::IHaveParameters(ScriptNodePtr p) { for (ScriptNodePtr node : p->childrenIn("parameters")) { @@ -22,30 +20,6 @@ IHaveParameters::getParameter(const Glib::ustring & name, ExecContext * ec) cons return safeMapLookup(parameters, name)(ec); } -void -IHaveParameters::push(const IHaveParameters * p) -{ - scope.push_back(p); -} - -void -IHaveParameters::pop() -{ - scope.pop_back(); -} - -VariableType -IHaveParameters::getScopedParameter(const Glib::ustring & name, ExecContext * ec) -{ - for(Stack::const_reverse_iterator ihp = scope.rbegin(); ihp != scope.rend(); ++ihp) { - Parameters::const_iterator i = (*ihp)->parameters.find(name); - if (i != (*ihp)->parameters.end()) { - return i->second(ec); - } - } - throw ParamNotFound(name); -} - const IHaveParameters::Parameters & IHaveParameters::allParameters() const { diff --git a/project2/common/iHaveParameters.h b/project2/common/iHaveParameters.h index 7b15289..bab4592 100644 --- a/project2/common/iHaveParameters.h +++ b/project2/common/iHaveParameters.h @@ -16,16 +16,9 @@ class IHaveParameters { const Parameters & allParameters() const; VariableType getParameter(const Glib::ustring &, ExecContext *) const; - static VariableType getScopedParameter(const Glib::ustring &, ExecContext *); protected: Parameters parameters; - - static void push(const IHaveParameters *); - static void pop(); - private: - typedef std::vector Stack; - static Stack scope; }; #endif diff --git a/project2/common/rowProcessor.cpp b/project2/common/rowProcessor.cpp index 2e695cf..5156f62 100644 --- a/project2/common/rowProcessor.cpp +++ b/project2/common/rowProcessor.cpp @@ -4,6 +4,7 @@ #include "commonObjects.h" #include "scopeObject.h" #include +#include "execContext.h" RowProcessor::RowProcessor(ScriptNodePtr p) : IHaveParameters(p), @@ -25,9 +26,9 @@ RowProcessor::loadComplete(const CommonObjects * co) void RowProcessor::execute(ExecContext * ec, const RowProcessorCallback & cb) const { - IHaveParameters::push(this); + ec->ParametersPush(this); ScopeObject _ihp( - boost::bind(&IHaveParameters::pop), + boost::bind(&ExecContext::ParametersPop, ec), boost::bind(&RowProcessor::saveCaches, this, ec), boost::bind((CROE ? &RowProcessor::saveCaches : &RowProcessor::discardCaches), this, ec), boost::bind(&TargetCaches::clear, &tc)); diff --git a/project2/common/variables/localparam.cpp b/project2/common/variables/localparam.cpp index bb71bde..cf2f165 100644 --- a/project2/common/variables/localparam.cpp +++ b/project2/common/variables/localparam.cpp @@ -3,6 +3,7 @@ #include "../scriptLoader.h" #include "../scriptStorage.h" #include "../iHaveParameters.h" +#include "../execContext.h" /// Variable implementation to access call parameters class VariableLocalParam : public VariableImplDyn { @@ -15,7 +16,7 @@ class VariableLocalParam : public VariableImplDyn { VariableType value(ExecContext * ec) const { try { - return IHaveParameters::getScopedParameter(name, ec); + return ec->getScopedParameter(name); } catch (ParamNotFound) { if (!defaultValue) { -- cgit v1.2.3