diff options
author | randomdan <randomdan@localhost> | 2013-07-05 00:01:26 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2013-07-05 00:01:26 +0000 |
commit | 530d921225b019130585667d91bad25194179310 (patch) | |
tree | 6f3a750f79ad26047ff5322522219798d19aa64c /project2/common/variables | |
parent | Move remaining options out of environment (diff) | |
download | project2-530d921225b019130585667d91bad25194179310.tar.bz2 project2-530d921225b019130585667d91bad25194179310.tar.xz project2-530d921225b019130585667d91bad25194179310.zip |
Massive refactor to remove the appEngine and environment complication and instead have an execution context that's passed around from the original call site
Diffstat (limited to 'project2/common/variables')
-rw-r--r-- | project2/common/variables/config.cpp | 13 | ||||
-rw-r--r-- | project2/common/variables/fixed.cpp | 2 | ||||
-rw-r--r-- | project2/common/variables/fixed.h | 2 | ||||
-rw-r--r-- | project2/common/variables/literal.cpp | 22 | ||||
-rw-r--r-- | project2/common/variables/literal.h | 14 | ||||
-rw-r--r-- | project2/common/variables/localparam.cpp | 8 | ||||
-rw-r--r-- | project2/common/variables/lookup.cpp | 18 | ||||
-rw-r--r-- | project2/common/variables/param.cpp | 12 | ||||
-rw-r--r-- | project2/common/variables/session.cpp | 10 |
9 files changed, 51 insertions, 50 deletions
diff --git a/project2/common/variables/config.cpp b/project2/common/variables/config.cpp index 51759d5..9b4cccb 100644 --- a/project2/common/variables/config.cpp +++ b/project2/common/variables/config.cpp @@ -3,7 +3,6 @@ #include "../scriptLoader.h" #include "../scriptStorage.h" #include <boost/algorithm/string/predicate.hpp> -#include "../appEngine.h" typedef std::map<Glib::ustring, VariableType> ConfigOptions; static ConfigOptions cfgOpts; @@ -15,17 +14,17 @@ class VariableConfig : public VariableImplDyn { public: VariableConfig(ScriptNodePtr e) : VariableImplDyn(e), - name(e->value("name").as<Glib::ustring>()) + name(e->value("name", NULL).as<Glib::ustring>()) { } - VariableType value() const + VariableType value(ExecContext * ec) const { const ConfigOptions::const_iterator i = cfgOpts.find(name); if (i != cfgOpts.end()) { return i->second; } if (defaultValue) { - return defaultValue.get()(); + return defaultValue.get()(ec); } throw NoSuchConfigurationValue(name); } @@ -40,17 +39,17 @@ class VariableConfigLoader : public VariableLoader::For<VariableConfig> { void reset() const { cfgOpts.clear(); } - void consume(const Glib::ustring & n, const Glib::ustring & p, const VariableType & v) const { + void consume(const Glib::ustring & n, const Glib::ustring & p, const VariableType & v, const Options::CurrentPlatform & cp) const { if (boost::algorithm::starts_with(n, "application.")) { Glib::ustring k(n.substr(12)); const ConfigOptions::iterator i = cfgOpts.find(k); if (i == cfgOpts.end()) { - if (p.empty() || p == Environment::getCurrent()->platform()) { + if (p.empty() || p == cp) { cfgOpts.insert(ConfigOptions::value_type(k, v)); } } else { - if (p == Environment::getCurrent()->platform()) { + if (p == cp) { i->second = v; } } diff --git a/project2/common/variables/fixed.cpp b/project2/common/variables/fixed.cpp index fdb67ed..4687c6a 100644 --- a/project2/common/variables/fixed.cpp +++ b/project2/common/variables/fixed.cpp @@ -6,7 +6,7 @@ VariableFixed::VariableFixed(VariableType v) : } VariableType -VariableFixed::value() const +VariableFixed::value(ExecContext *) const { return var; } diff --git a/project2/common/variables/fixed.h b/project2/common/variables/fixed.h index ec8be1a..b1380dd 100644 --- a/project2/common/variables/fixed.h +++ b/project2/common/variables/fixed.h @@ -7,7 +7,7 @@ class VariableFixed : public VariableImpl { public: VariableFixed(VariableType v); - VariableType value() const; + VariableType value(ExecContext * ec) const; private: VariableType var; diff --git a/project2/common/variables/literal.cpp b/project2/common/variables/literal.cpp index 11fb78a..3696346 100644 --- a/project2/common/variables/literal.cpp +++ b/project2/common/variables/literal.cpp @@ -19,7 +19,7 @@ append(VariableLiteral::Vals * vals, const Y & y) VariableLiteral::VariableLiteral(ScriptNodePtr s) { try { - val = VariableType::make(s->value("value"), VariableType::getTypeFromName(s->value("type", ""))); + val = VariableType::make(s->value("value", NULL), VariableType::getTypeFromName(s->value("type", "", NULL))); } catch (const ValueNotFound &) { s->composeWithCallbacks( @@ -29,17 +29,17 @@ VariableLiteral::VariableLiteral(ScriptNodePtr s) { } VariableType -VariableLiteral::value() const +VariableLiteral::value(ExecContext * ec) const { if (vals.empty()) { return val; } if (vals.size() == 1) { - return *vals.front(); + return vals.front()->value(ec); } Glib::ustring v; BOOST_FOREACH(PartCPtr p, vals) { - p->appendTo(v); + p->appendTo(ec, v); } return v; } @@ -49,11 +49,12 @@ VariableLiteral::TextPart::TextPart(const Glib::ustring & e) : { } void -VariableLiteral::TextPart::appendTo(Glib::ustring & str) const +VariableLiteral::TextPart::appendTo(ExecContext *, Glib::ustring & str) const { str += txt; } -VariableLiteral::TextPart::operator VariableType() const +VariableType +VariableLiteral::TextPart::value(ExecContext *) const { return txt; } @@ -62,13 +63,14 @@ VariableLiteral::VarPart::VarPart(ScriptNodePtr e) : Variable(e) { } void -VariableLiteral::VarPart::appendTo(Glib::ustring & str) const +VariableLiteral::VarPart::appendTo(ExecContext * ec, Glib::ustring & str) const { - str += (*this)().operator const Glib::ustring &(); + str += (*this)(ec).operator const Glib::ustring &(); } -VariableLiteral::VarPart::operator VariableType() const +VariableType +VariableLiteral::VarPart::value(ExecContext * ec) const { - return (*this)(); + return (*this)(ec); } DECLARE_COMPONENT_LOADER("literal", VariableLiteral, VariableLoader); diff --git a/project2/common/variables/literal.h b/project2/common/variables/literal.h index 4128d1c..8c120b6 100644 --- a/project2/common/variables/literal.h +++ b/project2/common/variables/literal.h @@ -8,28 +8,28 @@ class VariableLiteral : public VariableImpl { public: VariableLiteral(const Glib::ustring & src, const VT_typeID format = DefaultType); VariableLiteral(ScriptNodePtr); - virtual VariableType value() const; + virtual VariableType value(ExecContext * ec) const; class Part; typedef boost::intrusive_ptr<Part> PartCPtr; typedef std::list<PartCPtr> Vals; class Part : public IntrusivePtrBase { public: - virtual void appendTo(Glib::ustring & str) const = 0; - virtual operator VariableType() const = 0; + virtual void appendTo(ExecContext *, Glib::ustring & str) const = 0; + virtual VariableType value(ExecContext *) const = 0; }; class TextPart : public Part { public: TextPart(const Glib::ustring & e); - void appendTo(Glib::ustring & str) const; - operator VariableType() const; + void appendTo(ExecContext *, Glib::ustring & str) const; + VariableType value(ExecContext *) const; const Glib::ustring txt; }; class VarPart : public Part, public Variable { public: VarPart(ScriptNodePtr e); - void appendTo(Glib::ustring & str) const; - operator VariableType() const; + void appendTo(ExecContext *, Glib::ustring & str) const; + VariableType value(ExecContext *) const; }; private: VariableType val; diff --git a/project2/common/variables/localparam.cpp b/project2/common/variables/localparam.cpp index 1b789a7..bb71bde 100644 --- a/project2/common/variables/localparam.cpp +++ b/project2/common/variables/localparam.cpp @@ -9,19 +9,19 @@ class VariableLocalParam : public VariableImplDyn { public: VariableLocalParam(ScriptNodePtr e) : VariableImplDyn(e), - name(e->value("name").as<Glib::ustring>()) + name(e->value("name", NULL).as<Glib::ustring>()) { } - VariableType value() const + VariableType value(ExecContext * ec) const { try { - return IHaveParameters::getScopedParameter(name); + return IHaveParameters::getScopedParameter(name, ec); } catch (ParamNotFound) { if (!defaultValue) { throw; } - return (*defaultValue)(); + return (*defaultValue)(ec); } } private: diff --git a/project2/common/variables/lookup.cpp b/project2/common/variables/lookup.cpp index 2a96338..b3f9002 100644 --- a/project2/common/variables/lookup.cpp +++ b/project2/common/variables/lookup.cpp @@ -33,38 +33,38 @@ class VariableLookup : public VariableImplDyn, public RowProcessor { VariableLookup(ScriptNodePtr e) : VariableImplDyn(e), RowProcessor(e), - name(e->value("name").as<Glib::ustring>()) + name(e->value("name", NULL).as<Glib::ustring>()) { e->script->loader.addLoadTarget(e, Storer::into<ElementLoader>(&rowSets)); } - VariableType value() const + VariableType value(ExecContext * ec) const { if (map.empty()) { - fillCache(); + fillCache(ec); } Key k; k.reserve(parameters.size()); BOOST_FOREACH(const Parameters::value_type & p, parameters) { - k.push_back(p.second); + k.push_back(p.second(ec)); } return safeMapLookup<NotFound>(map, k); } private: - void fillCache() const + void fillCache(ExecContext * ec) const { BOOST_FOREACH(const RowSets::value_type & rs, rowSets) { - rs->execute(filter, this); + rs->execute(filter, boost::bind(&VariableLookup::rowReady, this, _1, ec), ec); } Logger()->messagef(LOG_DEBUG, "%s: %s has filled cached with %zu items", __PRETTY_FUNCTION__, name.c_str(), map.size()); } - void rowReady(const RowState * rs) const + void rowReady(const RowState * rs, ExecContext * ec) const { Key k; BOOST_FOREACH(const Parameters::value_type & p, parameters) { - k.push_back(rs->getCurrentValue(p.first)); + k.push_back(rs->getCurrentValue(ec, p.first)); } - map[k] = rs->getCurrentValue(name); + map[k] = rs->getCurrentValue(ec, name); } mutable Map map; typedef ANONSTORAGEOF(RowSet) RowSets; diff --git a/project2/common/variables/param.cpp b/project2/common/variables/param.cpp index 7292b0a..a1ef9b7 100644 --- a/project2/common/variables/param.cpp +++ b/project2/common/variables/param.cpp @@ -1,31 +1,31 @@ #include <pch.hpp> +#include "../execContext.h" #include "../variables.h" #include "../scriptLoader.h" #include "../scriptStorage.h" -#include "../appEngine.h" /// Variable implementation to access call parameters class VariableParam : public VariableImplDyn { public: VariableParam(ScriptNodePtr e) : VariableImplDyn(e), - name(e->value("name").as<Glib::ustring>()) + name(e->value("name", NULL)) { } - VariableType value() const + VariableType value(ExecContext * ec) const { try { - return ApplicationEngine::getCurrent()->env()->getParamQuery(name); + return ec->getParameter(name); } catch (ParamNotFound) { if (!defaultValue) { throw; } - return (*defaultValue)(); + return (*defaultValue)(ec); } } private: - const Glib::ustring name; + const VariableType name; }; DECLARE_COMPONENT_LOADER("param", VariableParam, VariableLoader); diff --git a/project2/common/variables/session.cpp b/project2/common/variables/session.cpp index fc33d8e..ed2077d 100644 --- a/project2/common/variables/session.cpp +++ b/project2/common/variables/session.cpp @@ -1,27 +1,27 @@ #include <pch.hpp> #include "../variables.h" +#include "../execContext.h" #include "../scriptLoader.h" #include "../scriptStorage.h" -#include "../appEngine.h" /// Variable implementation to access session contents class VariableSession : public VariableImplDyn { public: VariableSession(ScriptNodePtr e) : VariableImplDyn(e), - name(e->value("name").as<Glib::ustring>()) + name(e->value("name", NULL).as<Glib::ustring>()) { } - VariableType value() const + VariableType value(ExecContext * ec) const { try { - return ApplicationEngine::getCurrent()->session()->GetValue(name); + return ec->getSession()->GetValue(name); } catch (Session::VariableNotFound) { if (!defaultValue) { throw; } - return (*defaultValue)(); + return (*defaultValue)(ec); } } private: |