summaryrefslogtreecommitdiff
path: root/project2/common
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2013-07-05 00:01:26 +0000
committerrandomdan <randomdan@localhost>2013-07-05 00:01:26 +0000
commit530d921225b019130585667d91bad25194179310 (patch)
tree6f3a750f79ad26047ff5322522219798d19aa64c /project2/common
parentMove remaining options out of environment (diff)
downloadproject2-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')
-rw-r--r--project2/common/aggregate.cpp4
-rw-r--r--project2/common/aggregate.h4
-rw-r--r--project2/common/appEngine.cpp53
-rw-r--r--project2/common/appEngine.h42
-rw-r--r--project2/common/cache.cpp14
-rw-r--r--project2/common/cache.h15
-rw-r--r--project2/common/check.cpp4
-rw-r--r--project2/common/check.h4
-rw-r--r--project2/common/checkHost.cpp8
-rw-r--r--project2/common/checkHost.h2
-rw-r--r--project2/common/commonObjects.cpp1
-rw-r--r--project2/common/environment.cpp22
-rw-r--r--project2/common/environment.h28
-rw-r--r--project2/common/exceptions.h1
-rw-r--r--project2/common/execContext.cpp36
-rw-r--r--project2/common/execContext.h37
-rw-r--r--project2/common/iHaveParameters.cpp9
-rw-r--r--project2/common/iHaveParameters.h4
-rw-r--r--project2/common/iHaveSubTasks.cpp4
-rw-r--r--project2/common/iHaveSubTasks.h4
-rw-r--r--project2/common/if.cpp16
-rw-r--r--project2/common/if.h6
-rw-r--r--project2/common/iterate.cpp14
-rw-r--r--project2/common/iterate.h5
-rw-r--r--project2/common/library.cpp2
-rw-r--r--project2/common/memoryCache.cpp18
-rw-r--r--project2/common/noOutputExecute.h3
-rw-r--r--project2/common/options.cpp17
-rw-r--r--project2/common/options.h10
-rw-r--r--project2/common/optionsSource.cpp8
-rw-r--r--project2/common/optionsSource.h6
-rw-r--r--project2/common/presenter.cpp1
-rw-r--r--project2/common/presenter.h4
-rw-r--r--project2/common/presenterCache.cpp6
-rw-r--r--project2/common/presenterCache.h4
-rw-r--r--project2/common/rowProcessor.cpp38
-rw-r--r--project2/common/rowProcessor.h10
-rw-r--r--project2/common/rowSet.cpp13
-rw-r--r--project2/common/rowSet.h14
-rw-r--r--project2/common/rowView.cpp47
-rw-r--r--project2/common/rowView.h9
-rw-r--r--project2/common/scriptLoader.cpp1
-rw-r--r--project2/common/scripts.cpp8
-rw-r--r--project2/common/scripts.h7
-rw-r--r--project2/common/sessionClearTask.cpp8
-rw-r--r--project2/common/sessionClearTask.h2
-rw-r--r--project2/common/sessionContainer.cpp1
-rw-r--r--project2/common/sessionSetTask.cpp8
-rw-r--r--project2/common/sessionSetTask.h2
-rw-r--r--project2/common/singleton.cpp16
-rw-r--r--project2/common/sourceObject.cpp2
-rw-r--r--project2/common/stream.h4
-rw-r--r--project2/common/structExceptHandling.cpp12
-rw-r--r--project2/common/structExceptHandling.h2
-rw-r--r--project2/common/task.h2
-rw-r--r--project2/common/taskHost.cpp4
-rw-r--r--project2/common/taskHost.h2
-rw-r--r--project2/common/test.h4
-rw-r--r--project2/common/transform.cpp18
-rw-r--r--project2/common/transform.h18
-rw-r--r--project2/common/variables.cpp17
-rw-r--r--project2/common/variables.h9
-rw-r--r--project2/common/variables/config.cpp13
-rw-r--r--project2/common/variables/fixed.cpp2
-rw-r--r--project2/common/variables/fixed.h2
-rw-r--r--project2/common/variables/literal.cpp22
-rw-r--r--project2/common/variables/literal.h14
-rw-r--r--project2/common/variables/localparam.cpp8
-rw-r--r--project2/common/variables/lookup.cpp18
-rw-r--r--project2/common/variables/param.cpp12
-rw-r--r--project2/common/variables/session.cpp10
-rw-r--r--project2/common/view.h3
-rw-r--r--project2/common/viewGroup.cpp4
-rw-r--r--project2/common/viewHost.cpp14
-rw-r--r--project2/common/viewHost.h6
75 files changed, 372 insertions, 450 deletions
diff --git a/project2/common/aggregate.cpp b/project2/common/aggregate.cpp
index 1bb453b..ee7c871 100644
--- a/project2/common/aggregate.cpp
+++ b/project2/common/aggregate.cpp
@@ -17,8 +17,8 @@ SetAggregate::SetAggregate(ScriptNodePtr s) :
}
void
-Aggregate::pushValue() const
+Aggregate::pushValue(ExecContext * ec) const
{
- pushValue(value());
+ pushValue(value(ec), ec);
}
diff --git a/project2/common/aggregate.h b/project2/common/aggregate.h
index 0641c6e..7f33b6b 100644
--- a/project2/common/aggregate.h
+++ b/project2/common/aggregate.h
@@ -10,9 +10,9 @@ class Aggregate : public SourceObject {
Aggregate(ScriptNodePtr);
virtual void reset() const = 0;
- void pushValue() const;
+ void pushValue(ExecContext * ec) const;
protected:
- virtual void pushValue(const VariableType &) const = 0;
+ virtual void pushValue(const VariableType &, ExecContext *) const = 0;
private:
Variable value;
};
diff --git a/project2/common/appEngine.cpp b/project2/common/appEngine.cpp
deleted file mode 100644
index ce71153..0000000
--- a/project2/common/appEngine.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-#include <pch.hpp>
-#include "appEngine.h"
-#include "logger.h"
-#include "presenter.h"
-#include <stdexcept>
-#include <boost/foreach.hpp>
-
-ApplicationEngine * ApplicationEngine::currentEngine = NULL;
-
-ApplicationEngine::ApplicationEngine()
-{
- if (currentEngine) {
- throw std::runtime_error("One application at a time, please");
- }
- currentEngine = this;
-}
-
-ApplicationEngine::~ApplicationEngine()
-{
- currentEngine = NULL;
-}
-
-void
-ApplicationEngine::logMessage(bool writeLog, const Glib::ustring & g, const Glib::ustring & m)
-{
- if (writeLog) {
- Logger()->messagebf(LOG_NOTICE, "%s: %s: %s", __PRETTY_FUNCTION__, g, m);
- }
- appMessages.push_back(new Message(g, m));
-}
-
-void
-ApplicationEngine::addCoreAppData(const MultiRowSetPresenter * p) const
-{
- // Message log
- p->addNewRowSet("messages", Scripts::scriptNamespacePrefix);
- p->addNewArray("message", true);
- BOOST_FOREACH(const Messages::value_type & m, appMessages) {
- p->addNewRow("message");
- p->addAttribute("group", m->group);
- p->addAttribute("text", m->message);
- p->finishRow();
- }
- p->finishArray(true);
- p->finishRowSet();
-}
-
-ApplicationEngine::Message::Message(const Glib::ustring & g, const Glib::ustring & m) :
- group(g),
- message(m)
-{
-}
-
diff --git a/project2/common/appEngine.h b/project2/common/appEngine.h
deleted file mode 100644
index 6de21e1..0000000
--- a/project2/common/appEngine.h
+++ /dev/null
@@ -1,42 +0,0 @@
-#ifndef APPENGINE_H
-#define APPENGINE_H
-
-#include "environment.h"
-#include "session.h"
-
-class MultiRowSetPresenter;
-
-class ApplicationEngine {
- public:
- class Message : public IntrusivePtrBase {
- public:
- Message(const Glib::ustring & g, const Glib::ustring & m);
-
- const Glib::ustring group;
- const Glib::ustring message;
- };
- typedef boost::intrusive_ptr<Message> MessagePtr;
- typedef std::list<MessagePtr> Messages;
-
- ApplicationEngine();
- virtual ~ApplicationEngine() = 0;
-
- void logMessage(bool writeLog, const Glib::ustring & g, const Glib::ustring & m);
-
- virtual void process() const = 0;
- virtual const Environment * env() const = 0;
- virtual SessionPtr session() const = 0;
-
- static ApplicationEngine * getCurrent() { return currentEngine; }
-
- protected:
- void addCoreAppData(const MultiRowSetPresenter * p) const;
-
- Messages appMessages;
-
- private:
- static ApplicationEngine * currentEngine;
-};
-
-#endif
-
diff --git a/project2/common/cache.cpp b/project2/common/cache.cpp
index 9be5845..2a1d410 100644
--- a/project2/common/cache.cpp
+++ b/project2/common/cache.cpp
@@ -9,17 +9,17 @@
Cache::Cache(ScriptNodePtr p) :
IHaveParameters(p),
SourceObject(p),
- inherit(p->value("inherit", true).as<bool>())
+ inherit(p->value("inherit", true, NULL).as<bool>())
{
}
-bool Cache::checkAndExecute(const Glib::ustring & n, const Glib::ustring & f, const RowProcessor * rp)
+bool Cache::checkAndExecute(ExecContext * ec, const Glib::ustring & n, const Glib::ustring & f, const IHaveParameters * p, const RowProcessorCallback & rp)
{
- RowSetCPtr cached = getCachedRowSet(n, f, rp);
+ RowSetCPtr cached = getCachedRowSet(ec, n, f, p);
if (cached) {
try {
Logger()->messagebf(LOG_DEBUG, "Executing from cache '%s'", name);
- cached->execute(f, rp);
+ cached->execute(f, rp, ec);
return true;
}
catch (const Glib::Exception & e) {
@@ -36,14 +36,14 @@ bool Cache::checkAndExecute(const Glib::ustring & n, const Glib::ustring & f, co
}
void
-Cache::applyKeys(const boost::function2<void, const std::string &, const VariableType &> & f, const IHaveParameters * ps) const
+Cache::applyKeys(ExecContext * ec, const KeyApplier & f, const IHaveParameters * ps) const
{
BOOST_FOREACH(const IHaveParameters::Parameters::value_type & p, allParameters()) {
- f(p.first, p.second);
+ f(p.first, p.second(ec));
}
if (inherit) {
BOOST_FOREACH(const IHaveParameters::Parameters::value_type & p, ps->allParameters()) {
- f(p.first, p.second);
+ f(p.first, p.second(ec));
}
}
}
diff --git a/project2/common/cache.h b/project2/common/cache.h
index 2c438b8..0806c6f 100644
--- a/project2/common/cache.h
+++ b/project2/common/cache.h
@@ -4,8 +4,8 @@
#include "sourceObject.h"
#include "presenter.h"
#include "iHaveParameters.h"
+#include "rowSet.h"
-class RowProcessor;
class RowSet;
class RowState;
typedef boost::intrusive_ptr<const RowSet> RowSetCPtr;
@@ -14,14 +14,15 @@ class Cache : public IHaveParameters, public SourceObject {
public:
Cache(ScriptNodePtr p);
- bool checkAndExecute(const Glib::ustring &, const Glib::ustring &, const RowProcessor *);
- virtual RowSetPresenterPtr openFor(const Glib::ustring &, const Glib::ustring &, const IHaveParameters *) = 0;
- virtual void save(const Glib::ustring &, const Glib::ustring &, const IHaveParameters *) = 0;
- virtual void discard(const Glib::ustring &, const Glib::ustring &, const IHaveParameters *) = 0;
+ bool checkAndExecute(ExecContext *, const Glib::ustring &, const Glib::ustring &, const IHaveParameters *, const RowProcessorCallback &);
+ virtual RowSetPresenterPtr openFor(ExecContext *, const Glib::ustring &, const Glib::ustring &, const IHaveParameters *) = 0;
+ virtual void save(ExecContext *, const Glib::ustring &, const Glib::ustring &, const IHaveParameters *) = 0;
+ virtual void discard(ExecContext *, const Glib::ustring &, const Glib::ustring &, const IHaveParameters *) = 0;
protected:
- virtual RowSetCPtr getCachedRowSet(const Glib::ustring &, const Glib::ustring &, const IHaveParameters *) const = 0;
- void applyKeys(const boost::function2<void, const std::string &, const VariableType &> & f, const IHaveParameters *) const;
+ virtual RowSetCPtr getCachedRowSet(ExecContext *, const Glib::ustring &, const Glib::ustring &, const IHaveParameters *) const = 0;
+ typedef boost::function<void (const std::string &, const VariableType &)> KeyApplier;
+ void applyKeys(ExecContext * ec, const KeyApplier & f, const IHaveParameters * ps) const;
const bool inherit;
};
typedef boost::intrusive_ptr<Cache> CachePtr;
diff --git a/project2/common/check.cpp b/project2/common/check.cpp
index 21d17cf..d288e2f 100644
--- a/project2/common/check.cpp
+++ b/project2/common/check.cpp
@@ -20,11 +20,11 @@ Check::~Check()
}
bool
-Check::performCheck() const
+Check::performCheck(ExecContext * ec) const
{
if (!test) {
throw NoTestsToPerform();
}
- return test->passes();
+ return test->passes(ec);
}
diff --git a/project2/common/check.h b/project2/common/check.h
index e9f44b5..dc97f8f 100644
--- a/project2/common/check.h
+++ b/project2/common/check.h
@@ -5,13 +5,15 @@
#include "variables.h"
#include "test.h"
+class ExecContext;
+
/// Base class for Project2 compoments that perform checks
class Check : public SourceObject {
public:
Check(ScriptNodePtr p);
virtual ~Check();
- bool performCheck() const;
+ bool performCheck(ExecContext *) const;
const Variable message;
const Variable group;
diff --git a/project2/common/checkHost.cpp b/project2/common/checkHost.cpp
index 49533a9..dedea85 100644
--- a/project2/common/checkHost.cpp
+++ b/project2/common/checkHost.cpp
@@ -1,6 +1,6 @@
#include <pch.hpp>
#include "checkHost.h"
-#include "appEngine.h"
+#include "execContext.h"
#include <boost/foreach.hpp>
CheckHost::CheckHost(ScriptNodePtr s) :
@@ -14,12 +14,12 @@ CheckHost::~CheckHost()
}
void
-CheckHost::runChecks() const
+CheckHost::runChecks(ExecContext * ec) const
{
loadScriptComponents();
BOOST_FOREACH(const Checks::value_type & pc, checks) {
- if (!pc->performCheck()) {
- ApplicationEngine::getCurrent()->logMessage(false, pc->group(), pc->message());
+ if (!pc->performCheck(ec)) {
+ ec->logMessage(false, pc->group(ec), pc->message(ec));
throw CheckFailure(pc);
}
}
diff --git a/project2/common/checkHost.h b/project2/common/checkHost.h
index edc2cd8..f404d9e 100644
--- a/project2/common/checkHost.h
+++ b/project2/common/checkHost.h
@@ -18,7 +18,7 @@ class CheckHost : virtual public CommonObjects {
CheckHost(ScriptNodePtr script);
~CheckHost();
- void runChecks() const;
+ void runChecks(ExecContext *) const;
typedef ANONORDEREDSTORAGEOF(Check) Checks;
Checks checks;
diff --git a/project2/common/commonObjects.cpp b/project2/common/commonObjects.cpp
index 23f2edb..a25bb9f 100644
--- a/project2/common/commonObjects.cpp
+++ b/project2/common/commonObjects.cpp
@@ -1,7 +1,6 @@
#include <pch.hpp>
#include "commonObjects.h"
#include "safeMapFind.h"
-#include "appEngine.h"
#include "scriptLoader.h"
CommonObjects::CommonObjects() :
diff --git a/project2/common/environment.cpp b/project2/common/environment.cpp
deleted file mode 100644
index 69f853c..0000000
--- a/project2/common/environment.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-#include <pch.hpp>
-#include "environment.h"
-#include "optionsSource.h"
-
-const Environment * Environment::currentEnv(NULL);
-
-Environment::Environment()
-{
- currentEnv = this;
-}
-
-Environment::~Environment()
-{
- currentEnv = NULL;
-}
-
-const Environment *
-Environment::getCurrent()
-{
- return currentEnv;
-}
-
diff --git a/project2/common/environment.h b/project2/common/environment.h
deleted file mode 100644
index a97255f..0000000
--- a/project2/common/environment.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef ENVIRONMENT_H
-#define ENVIRONMENT_H
-
-#include <string>
-#include <glibmm/ustring.h>
-#include "exceptions.h"
-#include "scripts.h"
-
-SimpleMessageException(NoSuchPlatform);
-
-class Environment {
- public:
- Environment();
- virtual ~Environment() = 0;
-
- static const Environment * getCurrent();
-
- virtual Glib::ustring getParamQuery(const std::string & idx) const = 0;
-
- virtual std::string getServerName() const = 0;
- virtual const Glib::ustring & platform() const = 0;
-
- private:
- static const Environment * currentEnv;
-};
-
-#endif
-
diff --git a/project2/common/exceptions.h b/project2/common/exceptions.h
index 38f0efa..9cdf6f0 100644
--- a/project2/common/exceptions.h
+++ b/project2/common/exceptions.h
@@ -67,6 +67,7 @@ SimpleMessageException(NotSupported);
SimpleMessageException(FileNotReadable);
SimpleMessageException(FileNotWritable);
SimpleMessageException(FilterNotFound);
+SimpleMessageException(NoSuchPlatform);
#endif
diff --git a/project2/common/execContext.cpp b/project2/common/execContext.cpp
new file mode 100644
index 0000000..571b5f0
--- /dev/null
+++ b/project2/common/execContext.cpp
@@ -0,0 +1,36 @@
+#include "execContext.h"
+#include "logger.h"
+#include "presenter.h"
+#include <boost/foreach.hpp>
+
+void
+ExecContext::logMessage(bool writeLog, const Glib::ustring & g, const Glib::ustring & m)
+{
+ if (writeLog) {
+ Logger()->messagebf(LOG_NOTICE, "%s: %s: %s", __PRETTY_FUNCTION__, g, m);
+ }
+ messages.push_back(new Message(g, m));
+}
+
+void
+ExecContext::addContextData(const MultiRowSetPresenter * p) const
+{
+ // Message log
+ p->addNewRowSet("messages", Scripts::scriptNamespacePrefix);
+ p->addNewArray("message", true);
+ BOOST_FOREACH(const Messages::value_type & m, messages) {
+ p->addNewRow("message");
+ p->addAttribute("group", m->group);
+ p->addAttribute("text", m->message);
+ p->finishRow();
+ }
+ p->finishArray(true);
+ p->finishRowSet();
+}
+
+ExecContext::Message::Message(const Glib::ustring & g, const Glib::ustring & m) :
+ group(g),
+ message(m)
+{
+}
+
diff --git a/project2/common/execContext.h b/project2/common/execContext.h
new file mode 100644
index 0000000..6018058
--- /dev/null
+++ b/project2/common/execContext.h
@@ -0,0 +1,37 @@
+#ifndef EXECCONTEXT_H
+#define EXECCONTEXT_H
+
+#include <glibmm/ustring.h>
+#include <boost/intrusive_ptr.hpp>
+#include <list>
+#include "variableType.h"
+#include "session.h"
+
+class MultiRowSetPresenter;
+
+class ExecContext {
+ public:
+ class Message : public IntrusivePtrBase {
+ public:
+ Message(const Glib::ustring & g, const Glib::ustring & m);
+
+ const Glib::ustring group;
+ const Glib::ustring message;
+ };
+ typedef boost::intrusive_ptr<Message> MessagePtr;
+ typedef std::list<MessagePtr> Messages;
+
+ virtual VariableType getParameter(const VariableType & key) const = 0;
+ virtual SessionPtr getSession() const = 0;
+
+ void logMessage(bool writeLog, const Glib::ustring & g, const Glib::ustring & m);
+ const Messages & getMessages() const;
+
+ void addContextData(const MultiRowSetPresenter * p) const;
+
+ private:
+ Messages messages;
+};
+
+#endif
+
diff --git a/project2/common/iHaveParameters.cpp b/project2/common/iHaveParameters.cpp
index f880944..1bf1362 100644
--- a/project2/common/iHaveParameters.cpp
+++ b/project2/common/iHaveParameters.cpp
@@ -2,7 +2,6 @@
#include "iHaveParameters.h"
#include "exceptions.h"
#include "safeMapFind.h"
-#include "appEngine.h"
#include <boost/foreach.hpp>
IHaveParameters::Stack IHaveParameters::scope;
@@ -19,9 +18,9 @@ IHaveParameters::~IHaveParameters()
}
VariableType
-IHaveParameters::getParameter(const Glib::ustring & name) const
+IHaveParameters::getParameter(const Glib::ustring & name, ExecContext * ec) const
{
- return safeMapLookup<ParamNotFound>(parameters, name);
+ return safeMapLookup<ParamNotFound>(parameters, name)(ec);
}
void
@@ -37,12 +36,12 @@ IHaveParameters::pop()
}
VariableType
-IHaveParameters::getScopedParameter(const Glib::ustring & name)
+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;
+ return i->second(ec);
}
}
throw ParamNotFound(name);
diff --git a/project2/common/iHaveParameters.h b/project2/common/iHaveParameters.h
index 2b7ed2a..7b15289 100644
--- a/project2/common/iHaveParameters.h
+++ b/project2/common/iHaveParameters.h
@@ -15,8 +15,8 @@ class IHaveParameters {
virtual ~IHaveParameters() = 0;
const Parameters & allParameters() const;
- VariableType getParameter(const Glib::ustring &) const;
- static VariableType getScopedParameter(const Glib::ustring &);
+ VariableType getParameter(const Glib::ustring &, ExecContext *) const;
+ static VariableType getScopedParameter(const Glib::ustring &, ExecContext *);
protected:
Parameters parameters;
diff --git a/project2/common/iHaveSubTasks.cpp b/project2/common/iHaveSubTasks.cpp
index 78868aa..92248fb 100644
--- a/project2/common/iHaveSubTasks.cpp
+++ b/project2/common/iHaveSubTasks.cpp
@@ -13,10 +13,10 @@ IHaveSubTasks::~IHaveSubTasks()
}
void
-IHaveSubTasks::run(const Tasks & tlist) const
+IHaveSubTasks::run(const Tasks & tlist, ExecContext * ec) const
{
BOOST_FOREACH(const Tasks::value_type & t, tlist) {
- t->execute();
+ t->execute(ec);
}
}
diff --git a/project2/common/iHaveSubTasks.h b/project2/common/iHaveSubTasks.h
index e52a9be..d13a890 100644
--- a/project2/common/iHaveSubTasks.h
+++ b/project2/common/iHaveSubTasks.h
@@ -12,11 +12,11 @@ class IHaveSubTasks : public NoOutputExecute {
IHaveSubTasks(const std::string & n);
virtual ~IHaveSubTasks();
- virtual void execute() const = 0;
+ virtual void execute(ExecContext * ec) const = 0;
Tasks normal;
protected:
- void run(const Tasks &) const;
+ void run(const Tasks &, ExecContext * ec) const;
};
#endif
diff --git a/project2/common/if.cpp b/project2/common/if.cpp
index c7f790e..ed2abf6 100644
--- a/project2/common/if.cpp
+++ b/project2/common/if.cpp
@@ -20,31 +20,31 @@ If::If(ScriptNodePtr e) :
}
bool
-If::passes() const
+If::passes(ExecContext * ec) const
{
if (!test) {
throw NoTestsToPerform();
}
- return test->passes();
+ return test->passes(ec);
}
void
-If::execute(const MultiRowSetPresenter * presenter) const
+If::execute(const MultiRowSetPresenter * presenter, ExecContext * ec) const
{
- if (passes()) {
+ if (passes(ec)) {
Logger()->messagef(LOG_DEBUG, "Test passed; showing %zu views", subViews.size());
BOOST_FOREACH(const SubViews::value_type & sq, subViews) {
- sq->execute(presenter);
+ sq->execute(presenter, ec);
}
}
}
void
-If::execute() const
+If::execute(ExecContext * ec) const
{
- if (passes()) {
+ if (passes(ec)) {
Logger()->messagef(LOG_DEBUG, "Test passed; executing %zu tasks", normal.size());
- run(normal);
+ run(normal, ec);
}
}
diff --git a/project2/common/if.h b/project2/common/if.h
index 2496dc4..64f885b 100644
--- a/project2/common/if.h
+++ b/project2/common/if.h
@@ -10,11 +10,11 @@ class If : public IHaveSubTasks, public View {
public:
If(ScriptNodePtr);
- virtual void execute(const MultiRowSetPresenter*) const;
- virtual void execute() const;
+ virtual void execute(const MultiRowSetPresenter *, ExecContext *) const;
+ virtual void execute(ExecContext *) const;
private:
- bool passes() const;
+ bool passes(ExecContext *) const;
typedef ANONSTORAGEOF(View) SubViews;
SubViews subViews;
diff --git a/project2/common/iterate.cpp b/project2/common/iterate.cpp
index 037261d..4473885 100644
--- a/project2/common/iterate.cpp
+++ b/project2/common/iterate.cpp
@@ -27,22 +27,16 @@ Iterate::loadComplete(const CommonObjects * co)
}
void
-Iterate::rowReady(const RowState *) const
+Iterate::execute(ExecContext * ec) const
{
- executeChildren();
+ RowProcessor::execute(ec, boost::bind(&Iterate::executeChildren, this, ec));
}
void
-Iterate::execute() const
-{
- RowProcessor::execute();
-}
-
-void
-Iterate::executeChildren() const
+Iterate::executeChildren(ExecContext * ec) const
{
BOOST_FOREACH(const Tasks::value_type & sq, normal) {
- sq->execute();
+ sq->execute(ec);
}
}
diff --git a/project2/common/iterate.h b/project2/common/iterate.h
index 540cec6..2afbe98 100644
--- a/project2/common/iterate.h
+++ b/project2/common/iterate.h
@@ -15,11 +15,10 @@ class Iterate : public IHaveSubTasks, public RowProcessor {
virtual ~Iterate();
void loadComplete(const CommonObjects *);
- void rowReady(const RowState *) const;
- void execute() const;
+ void execute(ExecContext *) const;
protected:
- void executeChildren() const;
+ void executeChildren(ExecContext *) const;
};
#endif
diff --git a/project2/common/library.cpp b/project2/common/library.cpp
index 4762211..738803f 100644
--- a/project2/common/library.cpp
+++ b/project2/common/library.cpp
@@ -11,7 +11,7 @@ SimpleMessageException(UnloadLibraryFailed);
Library::Library(ScriptNodePtr p) :
SourceObject(p),
- handle(dlopen(Variable(p, "path")(), RTLD_NOW))
+ handle(dlopen(Variable(p, "path")(NULL), RTLD_NOW))
{
if (!handle) {
throw LoadLibraryFailed(dlerror());
diff --git a/project2/common/memoryCache.cpp b/project2/common/memoryCache.cpp
index 0a4f53f..7ab271e 100644
--- a/project2/common/memoryCache.cpp
+++ b/project2/common/memoryCache.cpp
@@ -43,7 +43,7 @@ class MemoryCache : public Cache {
{
}
- void execute(const Glib::ustring&, const RowProcessor * rp) const {
+ void execute(const Glib::ustring&, const RowProcessorCallback & rp, ExecContext *) const {
BOOST_FOREACH(const DataCache::value_type & mcr, dataCache) {
mcr->process(rp, false);
}
@@ -100,8 +100,8 @@ class MemoryCache : public Cache {
{
}
- RowSetCPtr getCachedRowSet(const Glib::ustring & n, const Glib::ustring & f, const IHaveParameters * ps) const {
- Key key(makeKey(n, f, ps));
+ RowSetCPtr getCachedRowSet(ExecContext * ec, const Glib::ustring & n, const Glib::ustring & f, const IHaveParameters * ps) const {
+ Key key(makeKey(ec, n, f, ps));
CacheStore::index<IndexByKey>::type::const_iterator i = Store.get<IndexByKey>().find(key);
if (i == Store.get<IndexByKey>().end()) {
return NULL;
@@ -113,27 +113,27 @@ class MemoryCache : public Cache {
return *i;
}
- RowSetPresenterPtr openFor(const Glib::ustring & n, const Glib::ustring & f, const IHaveParameters * ps) {
- return (cur = new CachedRowSet(makeKey(n, f, ps)));
+ RowSetPresenterPtr openFor(ExecContext * ec, const Glib::ustring & n, const Glib::ustring & f, const IHaveParameters * ps) {
+ return (cur = new CachedRowSet(makeKey(ec, n, f, ps)));
}
- void save(const Glib::ustring & , const Glib::ustring & , const IHaveParameters * ) {
+ void save(ExecContext *, const Glib::ustring & , const Glib::ustring & , const IHaveParameters * ) {
if (cur) {
Store.insert(cur);
cur.reset();
}
}
- void discard(const Glib::ustring & , const Glib::ustring & , const IHaveParameters * ) {
+ void discard(ExecContext *, const Glib::ustring & , const Glib::ustring & , const IHaveParameters * ) {
cur.reset();
}
private:
- Key makeKey(const Glib::ustring & n, const Glib::ustring & f, const IHaveParameters * ps) const {
+ Key makeKey(ExecContext * ec, const Glib::ustring & n, const Glib::ustring & f, const IHaveParameters * ps) const {
Key key;
key.push_back(n);
key.push_back(f);
- applyKeys([&key](const std::string &, const VariableType & v) { key.push_back(v); }, ps);
+ applyKeys(ec, [&key](const std::string &, const VariableType & v) { key.push_back(v); }, ps);
return key;
}
diff --git a/project2/common/noOutputExecute.h b/project2/common/noOutputExecute.h
index 67f6b00..61d03b5 100644
--- a/project2/common/noOutputExecute.h
+++ b/project2/common/noOutputExecute.h
@@ -5,6 +5,7 @@
#include "scriptStorage.h"
class NoOutputExecute;
+class ExecContext;
typedef boost::intrusive_ptr<NoOutputExecute> NoOutputExecutePtr;
/// Base class for Project2 compoments that perform actions, but product no output
@@ -15,7 +16,7 @@ class NoOutputExecute : public virtual SourceObject {
virtual ~NoOutputExecute();
- virtual void execute() const = 0;
+ virtual void execute(ExecContext *) const = 0;
};
#endif
diff --git a/project2/common/options.cpp b/project2/common/options.cpp
index 5c79163..fd93576 100644
--- a/project2/common/options.cpp
+++ b/project2/common/options.cpp
@@ -1,6 +1,5 @@
#include <pch.hpp>
#include "options.h"
-#include "environment.h"
#include <boost/foreach.hpp>
class NamedOption : public Options::Option {
@@ -11,9 +10,9 @@ class NamedOption : public Options::Option {
desc(d)
{
}
- 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 (n == id) {
- target->consume(p, v);
+ target->consume(p, v, cp);
}
}
void reset() const {
@@ -44,9 +43,9 @@ class OptionAlias : public Options::Option {
target(t)
{
}
- void consume(const Glib::ustring & a, const Glib::ustring & p, const VariableType & v) const {
+ void consume(const Glib::ustring & a, const Glib::ustring & p, const VariableType & v, const Options::CurrentPlatform & cp) const {
if (a == alias) {
- target->target->consume(p, v);
+ target->target->consume(p, v, cp);
}
}
void reset() const {
@@ -108,10 +107,10 @@ Options::reset() const
}
void
-Options::consume(const Glib::ustring & n, const Glib::ustring & p, const VariableType & v) const
+Options::consume(const Glib::ustring & n, const Glib::ustring & p, const VariableType & v, const Options::CurrentPlatform & cp) const
{
BOOST_FOREACH(const OptionPtr & o, options) {
- o->consume(n, p, v);
+ o->consume(n, p, v, cp);
}
}
@@ -145,13 +144,13 @@ Options::InstanceTarget::paramRequired() const
}
void
-Options::InstanceTarget::consume(const Glib::ustring & p, const VariableType & v) const
+Options::InstanceTarget::consume(const Glib::ustring & p, const VariableType & v, const Options::CurrentPlatform & cp) const
{
if (ts != Platform && p.empty()) {
assign(v);
ts = Global;
}
- else if (!p.empty() && p == Environment::getCurrent()->platform()) {
+ else if (!p.empty() && p == cp) {
assign(v);
ts = Platform;
}
diff --git a/project2/common/options.h b/project2/common/options.h
index e92e69b..c2416ef 100644
--- a/project2/common/options.h
+++ b/project2/common/options.h
@@ -15,11 +15,13 @@ class Options {
class Target;
enum TargetState { Default = 1, Global = 2, Platform = 3 };
+ typedef boost::function<const Glib::ustring &()> CurrentPlatform;
+
class Target : public IntrusivePtrBase {
public:
virtual void reset() const = 0;
virtual bool paramRequired() const = 0;
- virtual void consume(const Glib::ustring & platform, const VariableType & value) const = 0;
+ virtual void consume(const Glib::ustring & platform, const VariableType & value, const CurrentPlatform & currentPlatform) const = 0;
};
typedef boost::intrusive_ptr<Target> TargetPtr;
typedef boost::function<void(const VariableType &)> Assigner;
@@ -29,7 +31,7 @@ class Options {
public:
InstanceTarget(const Assigner &, const Resetter &);
bool paramRequired() const;
- void consume(const Glib::ustring & platform, const VariableType & value) const;
+ void consume(const Glib::ustring & platform, const VariableType & value, const CurrentPlatform & currentPlatform) const;
protected:
void reset() const;
void assign(const VariableType & value) const;
@@ -45,7 +47,7 @@ class Options {
virtual Glib::ustring name() const = 0;
virtual Glib::ustring description() const = 0;
virtual bool accepts(const Glib::ustring & name) const = 0;
- virtual void consume(const Glib::ustring & name, const Glib::ustring & platform, const VariableType & value) const = 0;
+ virtual void consume(const Glib::ustring & name, const Glib::ustring & platform, const VariableType & value, const CurrentPlatform & currentPlatform) const = 0;
};
typedef boost::intrusive_ptr<Option> OptionPtr;
typedef std::list<OptionPtr> OptionList;
@@ -86,7 +88,7 @@ class Options {
}
void reset() const;
- void consume(const Glib::ustring & name, const Glib::ustring & platform, const VariableType & value) const;
+ void consume(const Glib::ustring & name, const Glib::ustring & platform, const VariableType & value, const CurrentPlatform & currentPlatform) const;
const Option * find(const Glib::ustring & name) const;
const Glib::ustring name;
diff --git a/project2/common/optionsSource.cpp b/project2/common/optionsSource.cpp
index ed40df9..702b852 100644
--- a/project2/common/optionsSource.cpp
+++ b/project2/common/optionsSource.cpp
@@ -3,8 +3,8 @@
class DefaultConfigConsumer : public ConfigConsumer {
public:
- void operator()(const Glib::ustring & n, const Glib::ustring & p, const Glib::ustring & v) const {
- Plugable::onAll<Options>(boost::bind(&Options::consume, _1, n, p, v));
+ void operator()(const Glib::ustring & n, const Glib::ustring & p, const Glib::ustring & v, const Options::CurrentPlatform & cp) const {
+ Plugable::onAll<Options>(boost::bind(&Options::consume, _1, n, p, v, cp));
}
const Options::Option * get(const Glib::ustring & n) const {
const Options::Option * rtn = NULL;
@@ -19,7 +19,7 @@ class DefaultConfigConsumer : public ConfigConsumer {
};
void
-OptionsSource::loadSources()
+OptionsSource::loadSources(const Options::CurrentPlatform & platform)
{
const auto & configs = Plugable::ComponentType<OptionsSource>::components();
if (std::find_if(configs->begin(), configs->end(), boost::bind(&OptionsSource::needReload, _1)) != configs->end()) {
@@ -27,7 +27,7 @@ OptionsSource::loadSources()
DefaultConfigConsumer dcc;
BOOST_FOREACH(const auto & c, *configs) {
- c->loadInto(dcc);
+ c->loadInto(dcc, platform);
}
Plugable::onAllComponents(boost::bind(&ComponentLoader::onConfigLoad, _1));
diff --git a/project2/common/optionsSource.h b/project2/common/optionsSource.h
index 49bb876..d6f41ab 100644
--- a/project2/common/optionsSource.h
+++ b/project2/common/optionsSource.h
@@ -9,17 +9,17 @@
class ConfigConsumer {
public:
- virtual void operator()(const Glib::ustring &, const Glib::ustring &, const Glib::ustring &) const = 0;
+ virtual void operator()(const Glib::ustring &, const Glib::ustring &, const Glib::ustring &, const Options::CurrentPlatform &) const = 0;
virtual const Options::Option * get(const Glib::ustring & name) const = 0;
};
/// Base class of things that load options
class OptionsSource {
public:
- virtual void loadInto(const ConfigConsumer &) const = 0;
+ virtual void loadInto(const ConfigConsumer &, const Options::CurrentPlatform & platform) const = 0;
virtual bool needReload() const = 0;
- static void loadSources();
+ static void loadSources(const Options::CurrentPlatform & platform);
};
typedef boost::intrusive_ptr<OptionsSource> OptionsSourcePtr;
diff --git a/project2/common/presenter.cpp b/project2/common/presenter.cpp
index 1e5bbf2..4e12307 100644
--- a/project2/common/presenter.cpp
+++ b/project2/common/presenter.cpp
@@ -1,7 +1,6 @@
#include <pch.hpp>
#include "presenter.h"
#include "dataSource.h"
-#include "appEngine.h"
#include <boost/foreach.hpp>
NameValuePairPresenter::NameValuePairPresenter()
diff --git a/project2/common/presenter.h b/project2/common/presenter.h
index f9069de..3ea56e7 100644
--- a/project2/common/presenter.h
+++ b/project2/common/presenter.h
@@ -39,7 +39,7 @@ class MultiRowSetPresenter : public RowSetPresenter {
virtual void finishRowSet() const = 0;
virtual void addNewArray(const Glib::ustring & name, bool objects) const = 0;
virtual void finishArray(bool objects) const = 0;
- virtual void init() = 0;
+ virtual void init(ExecContext *) = 0;
virtual void finalizeContent() const;
};
@@ -77,7 +77,7 @@ typedef boost::intrusive_ptr<RowSetPresenter> RowSetPresenterPtr;
typedef boost::intrusive_ptr<MultiRowSetPresenter> MultiRowSetPresenterPtr;
typedef boost::intrusive_ptr<NameValuePairPresenter> NameValuePairPresenterPtr;
-typedef GenLoader<MultiRowSetPresenter, ScriptNodePtr, ObjectSource> PresenterLoader;
+typedef GenLoader<MultiRowSetPresenter, ScriptNodePtr, ObjectSource, ExecContext *> PresenterLoader;
#endif
diff --git a/project2/common/presenterCache.cpp b/project2/common/presenterCache.cpp
index 6ca3661..31fdc8f 100644
--- a/project2/common/presenterCache.cpp
+++ b/project2/common/presenterCache.cpp
@@ -4,7 +4,7 @@
PresenterCache::PresenterCache(ScriptNodePtr s) :
SourceObject(s),
IHaveParameters(s),
- encoding(s->value("encoding", "utf-8").as<std::string>())
+ encoding(s->value("encoding", "utf-8", NULL).as<std::string>())
{
}
@@ -15,8 +15,8 @@ PresenterCache::flushCache()
class WriteToCache : public TransformImpl<WritableContent, PresenterCache> {
public:
- void transform(const WritableContent * wc, PresenterCache * pc) const {
- wc->writeTo(pc->writeCache(wc->getContentType(), pc->encoding), pc->encoding);
+ void transform(const WritableContent * wc, PresenterCache * pc, ExecContext * ec) const {
+ wc->writeTo(pc->writeCache(wc->getContentType(), pc->encoding, ec), pc->encoding, ec);
}
};
DECLARE_TRANSFORM(WriteToCache);
diff --git a/project2/common/presenterCache.h b/project2/common/presenterCache.h
index 799181b..b0adab8 100644
--- a/project2/common/presenterCache.h
+++ b/project2/common/presenterCache.h
@@ -8,9 +8,9 @@
class PresenterCache : public SourceObject, public virtual TransformSource, public StaticContent, public SourceOf<StaticContent>, public IHaveParameters {
public:
PresenterCache(ScriptNodePtr);
- virtual bool check(time_t scriptMtime) const = 0;
+ virtual bool check(time_t scriptMtime, ExecContext *) const = 0;
- virtual std::ostream & writeCache(const std::string & ct, const std::string & encoding) = 0;
+ virtual std::ostream & writeCache(const std::string & ct, const std::string & encoding, ExecContext *) = 0;
virtual void flushCache();
const std::string encoding;
};
diff --git a/project2/common/rowProcessor.cpp b/project2/common/rowProcessor.cpp
index 4e3bf1d..26ca433 100644
--- a/project2/common/rowProcessor.cpp
+++ b/project2/common/rowProcessor.cpp
@@ -8,10 +8,10 @@
RowProcessor::RowProcessor(ScriptNodePtr p) :
IHaveParameters(p),
- recordSource(p->value("source").as<std::string>()),
- filter(p->value("filter", "").as<Glib::ustring>()),
- CROE(p->value("cacheRowsOnError", false)),
- IRSE(p->value("ignoreRowSourceError", false))
+ recordSource(p->value("source", NULL).as<std::string>()),
+ filter(p->value("filter", "", NULL).as<Glib::ustring>()),
+ CROE(p->value("cacheRowsOnError", false, NULL)),
+ IRSE(p->value("ignoreRowSourceError", false, NULL))
{
p->script->loader.addLoadTarget(p, Storer::into<ElementLoader>(&caches));
p->script->loader.addLoadTarget(p, Storer::into<ElementLoader>(&tests));
@@ -24,19 +24,19 @@ RowProcessor::loadComplete(const CommonObjects * co)
}
void
-RowProcessor::execute() const
+RowProcessor::execute(ExecContext * ec, const RowProcessorCallback & cb) const
{
IHaveParameters::push(this);
ScopeObject _ihp(
boost::bind(&IHaveParameters::pop),
- boost::bind(&RowProcessor::saveCaches, this),
- boost::bind((CROE ? &RowProcessor::saveCaches : &RowProcessor::discardCaches), this),
+ boost::bind(&RowProcessor::saveCaches, this, ec),
+ boost::bind((CROE ? &RowProcessor::saveCaches : &RowProcessor::discardCaches), this, ec),
boost::bind(&TargetCaches::clear, &tc));
BOOST_FOREACH(const CachePtr & c, caches) {
- if (c->checkAndExecute(source->name, filter, this)) {
+ if (c->checkAndExecute(ec, source->name, filter, this, cb)) {
return;
}
- RowSetPresenterPtr p = c->openFor(source->name, filter, this);
+ RowSetPresenterPtr p = c->openFor(ec, source->name, filter, this);
if (p) {
tc.insert(TargetCachePtr(new TargetCache(p, c)));
}
@@ -47,44 +47,44 @@ RowProcessor::execute() const
}
if (IRSE) {
try {
- source->execute(filter, this);
+ source->execute(filter, cb, ec);
}
catch (const std::exception & e) {
Logger()->messagebf(LOG_WARNING, "Source '%s' failed with '%s'", source->name, e.what());
}
}
else {
- source->execute(filter, this);
+ source->execute(filter, cb, ec);
}
}
void
-RowProcessor::saveCaches() const
+RowProcessor::saveCaches(ExecContext * ec) const
{
BOOST_FOREACH(const TargetCaches::value_type & c, tc) {
- c->get<1>()->save(source->name, filter, this);
+ c->get<1>()->save(ec, source->name, filter, this);
}
}
void
-RowProcessor::discardCaches() const
+RowProcessor::discardCaches(ExecContext * ec) const
{
BOOST_FOREACH(const TargetCaches::value_type & c, tc) {
- c->get<1>()->discard(source->name, filter, this);
+ c->get<1>()->discard(ec, source->name, filter, this);
}
}
void
-RowProcessor::rowReadyInternal(const RowState * rs) const
+RowProcessor::rowReadyInternal(const RowState * rs, const RowProcessorCallback & cb, ExecContext * ec) const
{
BOOST_FOREACH(const TargetCaches::value_type & c, tc) {
c->get<0>()->addNewRow(filter.empty() ? "row" : filter);
- rs->foreachColumn(boost::bind(&RowSetPresenter::addNamedValue, c->get<0>(), _2, _3));
+ rs->foreachColumn(ec, boost::bind(&RowSetPresenter::addNamedValue, c->get<0>(), _2, _3));
rs->foreachAttr(boost::bind(&RowSetPresenter::addAttribute, c->get<0>(), _1, _2));
c->get<0>()->finishRow();
}
- if (boost::algorithm::all(tests, boost::bind(&Test::passes, _1))) {
- rowReady(rs);
+ if (boost::algorithm::all(tests, boost::bind(&Test::passes, _1, ec))) {
+ cb(rs);
}
}
diff --git a/project2/common/rowProcessor.h b/project2/common/rowProcessor.h
index 04a61bf..70f453c 100644
--- a/project2/common/rowProcessor.h
+++ b/project2/common/rowProcessor.h
@@ -10,6 +10,7 @@
#include "scriptStorage.h"
class Presenter;
+class ExecContext;
/// Base class for Project2 components that work with row sets
class RowProcessor : public IHaveParameters {
@@ -25,12 +26,11 @@ class RowProcessor : public IHaveParameters {
protected:
boost::intrusive_ptr<RowSet> source;
- void execute() const;
+ void execute(ExecContext *, const RowProcessorCallback &) const;
private:
friend class RowState;
- void rowReadyInternal(const RowState *) const;
- virtual void rowReady(const RowState *) const = 0;
+ void rowReadyInternal(const RowState *, const RowProcessorCallback &, ExecContext *) const;
typedef ANONSTORAGEOF(Test) Tests;
Tests tests;
typedef ANONORDEREDSTORAGEOF(Cache) Caches;
@@ -40,8 +40,8 @@ class RowProcessor : public IHaveParameters {
typedef std::set<TargetCachePtr> TargetCaches;
mutable TargetCaches tc;
- void saveCaches() const;
- void discardCaches() const;
+ void saveCaches(ExecContext *) const;
+ void discardCaches(ExecContext *) const;
};
#endif
diff --git a/project2/common/rowSet.cpp b/project2/common/rowSet.cpp
index 0378b51..daa81b3 100644
--- a/project2/common/rowSet.cpp
+++ b/project2/common/rowSet.cpp
@@ -4,7 +4,6 @@
#include "scopeObject.h"
#include "logger.h"
#include "variables.h"
-#include "rowProcessor.h"
#include <boost/foreach.hpp>
#include <boost/bind.hpp>
@@ -29,12 +28,12 @@ RowState::~RowState()
}
void
-RowState::process(const RowProcessor * rp, bool r)
+RowState::process(const RowProcessorCallback & rp, bool r)
{
rowNum += 1;
stack.push_back(this);
ScopeObject s(boost::bind(&RowState::RowValuesStack::pop_back, &stack));
- rp->rowReadyInternal(this);
+ rp(this);
if (r) {
reset();
}
@@ -70,13 +69,13 @@ RowState::resolveAttr(const Glib::ustring & attrName) const
}
VariableType
-RowState::getCurrentValue(const Glib::ustring & col) const
+RowState::getCurrentValue(ExecContext * ec, const Glib::ustring & col) const
{
const Columns & columns = getColumns();
Columns::index<byColName>::type::iterator di = columns.get<byColName>().find(col);
if (di != columns.get<byColName>().end()) {
if (fields[(*di)->idx].isNull()) {
- return (*di)->defValue;
+ return (*di)->defValue(ec);
}
return fields[(*di)->idx];
}
@@ -84,11 +83,11 @@ RowState::getCurrentValue(const Glib::ustring & col) const
}
void
-RowState::foreachColumn(const ColumnAction & action) const
+RowState::foreachColumn(ExecContext * ec, const ColumnAction & action) const
{
const Columns & columns = getColumns();
BOOST_FOREACH(const Columns::value_type & col, columns.get<byColName>()) {
- action(col->idx, col->name, (!boost::get<Null>(&fields[col->idx])) ? fields[col->idx] : col->defValue());
+ action(col->idx, col->name, (!boost::get<Null>(&fields[col->idx])) ? fields[col->idx] : col->defValue(ec));
}
}
diff --git a/project2/common/rowSet.h b/project2/common/rowSet.h
index 2845983..50dd3fd 100644
--- a/project2/common/rowSet.h
+++ b/project2/common/rowSet.h
@@ -8,13 +8,13 @@
#include "columns.h"
#include <boost/function.hpp>
-class RowProcessor;
class RowSet;
class VariableType;
+class RowState;
+
typedef boost::intrusive_ptr<RowSet> RowSetPtr;
typedef boost::intrusive_ptr<const RowSet> ConstRowSetPtr;
-
-class RowState;
+typedef boost::function<void(const RowState *)> RowProcessorCallback;
/// Base class for Project2 components that provide a row set representation of data
class RowSet : public SourceObject {
@@ -26,7 +26,7 @@ class RowSet : public SourceObject {
RowSet(ScriptNodePtr);
virtual ~RowSet() = 0;
- virtual void execute(const Glib::ustring &, const RowProcessor *) const = 0;
+ virtual void execute(const Glib::ustring &, const RowProcessorCallback &, ExecContext *) const = 0;
};
class RowState {
@@ -40,12 +40,12 @@ class RowState {
SimpleMessageException(AttributeDoesNotExist);
VariableType getRowNum() const;
- void process(const RowProcessor *, bool reset = true);
+ void process(const RowProcessorCallback &, bool reset = true);
void blankRow();
void reset();
- virtual VariableType getCurrentValue(const Glib::ustring & id) const;
+ virtual VariableType getCurrentValue(ExecContext *, const Glib::ustring & id) const;
virtual RowAttribute resolveAttr(const Glib::ustring & attrName) const;
- void foreachColumn(const ColumnAction & action) const;
+ void foreachColumn(ExecContext * ec, const ColumnAction & action) const;
virtual void foreachAttr(const AttrAction & action) const;
virtual const Columns & getColumns() const = 0;
diff --git a/project2/common/rowView.cpp b/project2/common/rowView.cpp
index c0e5cae..b9508bd 100644
--- a/project2/common/rowView.cpp
+++ b/project2/common/rowView.cpp
@@ -16,9 +16,7 @@ RowView::RowView(ScriptNodePtr p) :
rootName(p, "rootname", Null()),
recordName(p, "recordname"),
required(p, "required", false),
- isObject(p, "isobject", true),
- presenter(NULL),
- rowsFound(false)
+ isObject(p, "isobject", true)
{
BOOST_FOREACH(ScriptNodePtr node, p->childrenIn("columns")) {
viewColumns.insert(Columns::value_type(node->get_name(), Variable(node)));
@@ -39,67 +37,66 @@ RowView::loadComplete(const CommonObjects * co)
}
void
-RowView::rowReady(const RowState * rs) const
+RowView::rowReady(const RowState * rs, const MultiRowSetPresenter * presenter, ExecContext * ec, bool & rowsFound) const
{
rowsFound = true;
- if (isObject()) {
- presenter->addNewRow(recordName());
+ if (isObject(ec)) {
+ presenter->addNewRow(recordName(ec));
}
if (viewColumns.empty()) {
- rs->foreachColumn(boost::bind(&RowSetPresenter::addNamedValue, presenter, _2, _3));
+ rs->foreachColumn(ec, boost::bind(&RowSetPresenter::addNamedValue, presenter, _2, _3));
}
else {
BOOST_FOREACH(const Columns::value_type & col, viewColumns) {
- presenter->addNamedValue(col.first, col.second);
+ presenter->addNamedValue(col.first, col.second(ec));
}
}
- if (isObject()) {
- executeChildren();
+ if (isObject(ec)) {
+ executeChildren(presenter, ec);
presenter->finishRow();
}
BOOST_FOREACH(SetAggregateCPtr s, setAggregates) {
- s->pushValue();
+ s->pushValue(ec);
}
BOOST_FOREACH(ValueAggregateCPtr a, valueAggregates) {
- a->pushValue();
+ a->pushValue(ec);
}
}
void
-RowView::execute(const MultiRowSetPresenter * p) const
+RowView::execute(const MultiRowSetPresenter * p, ExecContext * ec) const
{
- rowsFound = false;
- presenter = p;
- if (!rootName().isNull()) {
- presenter->addNewRowSet(rootName());
+ if (!rootName(ec).isNull()) {
+ p->addNewRowSet(rootName(ec));
}
- ScopeObject pres(rootName().isNull() ? ScopeObject::Event() : boost::bind(&MultiRowSetPresenter::finishRowSet, p));
+ bool rowsFound = false;
+ ScopeObject pres(rootName(ec).isNull() ? ScopeObject::Event() : boost::bind(&MultiRowSetPresenter::finishRowSet, p));
{
- presenter->addNewArray(recordName(), true);
+ p->addNewArray(recordName(ec), true);
ScopeObject pres(boost::bind(&MultiRowSetPresenter::finishArray, p, true));
- RowProcessor::execute();
+ RowProcessor::execute(ec, boost::bind(&RowView::rowReady, this, _1, p, ec, boost::ref(rowsFound)));
}
- if (required() && !rowsFound) {
+ if (required(ec) && !rowsFound) {
throw EmptyRequiredRows(name);
}
BOOST_FOREACH(SetAggregateCPtr s, setAggregates) {
- presenter->addNewArray(s->name, false);
+ p->addNewArray(s->name, false);
ScopeObject pres(boost::bind(&MultiRowSetPresenter::finishArray, p, false));
s->onResultValues(boost::bind(&MultiRowSetPresenter::addNamedValue, p, "value", _1));
s->reset();
}
BOOST_FOREACH(ValueAggregateCPtr a, valueAggregates) {
- presenter->addNamedValue(a->name, a->resultValue());
+ p->addNamedValue(a->name, a->resultValue());
a->reset();
}
}
void
-RowView::executeChildren() const
+RowView::executeChildren(const MultiRowSetPresenter * presenter, ExecContext * ec) const
{
BOOST_FOREACH(const SubViews::value_type & sq, subViews) {
- sq->execute(presenter);
+ sq->execute(presenter, ec);
}
}
diff --git a/project2/common/rowView.h b/project2/common/rowView.h
index 534a06f..d2745db 100644
--- a/project2/common/rowView.h
+++ b/project2/common/rowView.h
@@ -13,8 +13,8 @@ class RowView : public View, public RowProcessor {
virtual ~RowView();
void loadComplete(const CommonObjects *);
- void execute(const MultiRowSetPresenter *) const;
- void rowReady(const RowState *) const;
+ void execute(const MultiRowSetPresenter *, ExecContext *) const;
+ void rowReady(const RowState *, const MultiRowSetPresenter *, ExecContext *, bool & found) const;
const Variable rootName;
const Variable recordName;
@@ -25,16 +25,13 @@ class RowView : public View, public RowProcessor {
typedef std::map<Glib::ustring, Variable> Columns;
Columns viewColumns;
- void executeChildren() const;
+ void executeChildren(const MultiRowSetPresenter * presenter, ExecContext *) const;
typedef ANONORDEREDSTORAGEOF(View) SubViews;
SubViews subViews;
typedef ANONSTORAGEOF(ValueAggregate) ValueAggregates;
ValueAggregates valueAggregates;
typedef ANONSTORAGEOF(SetAggregate) SetAggregates;
SetAggregates setAggregates;
- mutable const MultiRowSetPresenter * presenter;
-
- mutable bool rowsFound;
};
#endif
diff --git a/project2/common/scriptLoader.cpp b/project2/common/scriptLoader.cpp
index ab02f02..fe8799b 100644
--- a/project2/common/scriptLoader.cpp
+++ b/project2/common/scriptLoader.cpp
@@ -3,7 +3,6 @@
#include "scriptLoader.h"
#include "scriptStorage.h"
#include "library.h"
-#include "appEngine.h"
#include <boost/shared_ptr.hpp>
#include <boost/foreach.hpp>
#include <boost/function.hpp>
diff --git a/project2/common/scripts.cpp b/project2/common/scripts.cpp
index 767ff0d..f065e4b 100644
--- a/project2/common/scripts.cpp
+++ b/project2/common/scripts.cpp
@@ -32,20 +32,20 @@ ScriptNode::variable(const Glib::ustring & n, const VariableType & def) const
}
VariableType
-ScriptNode::value(const Glib::ustring & n, const VariableType & def) const
+ScriptNode::value(const Glib::ustring & n, const VariableType & def, ExecContext * ec) const
{
VariableType r;
- if (applyValue(n, r)) {
+ if (applyValue(n, r, ec)) {
return r;
}
return def;
}
VariableType
-ScriptNode::value(const Glib::ustring & n) const
+ScriptNode::value(const Glib::ustring & n, ExecContext * ec) const
{
VariableType r;
- if (applyValue(n, r)) {
+ if (applyValue(n, r, ec)) {
return r;
}
throw ValueNotFound(n);
diff --git a/project2/common/scripts.h b/project2/common/scripts.h
index 0cb478c..7bf6326 100644
--- a/project2/common/scripts.h
+++ b/project2/common/scripts.h
@@ -18,6 +18,7 @@ SimpleMessage2Exception(ScriptNotFound);
SimpleMessage2Exception(DependencyNotFound);
class VariableImpl;
+class ExecContext;
class Scripts {
public:
@@ -45,12 +46,12 @@ class ScriptNode : public IntrusivePtrBase {
virtual ScriptNodes childrenIn(const Glib::ustring & sub) const = 0;
virtual bool valueExists(const Glib::ustring & name) const = 0;
- virtual bool applyValue(const Glib::ustring & name, VariableType & target) const = 0;
+ virtual bool applyValue(const Glib::ustring & name, VariableType & target, ExecContext *) 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;
- VariableType value(const Glib::ustring & name) const;
- VariableType value(const Glib::ustring & name, const VariableType & def) const;
+ VariableType value(const Glib::ustring & name, ExecContext *) const;
+ VariableType value(const Glib::ustring & name, const VariableType & def, ExecContext *) const;
virtual void composeWithCallbacks(const LiteralCallback &, const NodeCallback &) const = 0;
const ScriptReaderPtr script;
diff --git a/project2/common/sessionClearTask.cpp b/project2/common/sessionClearTask.cpp
index b3b1000..265bb1c 100644
--- a/project2/common/sessionClearTask.cpp
+++ b/project2/common/sessionClearTask.cpp
@@ -2,15 +2,15 @@
#include <boost/foreach.hpp>
#include "scriptLoader.h"
#include "sessionClearTask.h"
-#include "appEngine.h"
#include "session.h"
+#include "execContext.h"
DECLARE_LOADER("sessionclear", SessionClearTask);
SessionClearTask::SessionClearTask(ScriptNodePtr p) :
SourceObject(p),
Task(p),
- key(p->value("key").as<Glib::ustring>())
+ key(p->value("key", NULL).as<Glib::ustring>())
{
}
@@ -19,8 +19,8 @@ SessionClearTask::~SessionClearTask()
}
void
-SessionClearTask::execute() const
+SessionClearTask::execute(ExecContext * ec) const
{
- ApplicationEngine::getCurrent()->session()->ClearValue(key);
+ ec->getSession()->ClearValue(key);
}
diff --git a/project2/common/sessionClearTask.h b/project2/common/sessionClearTask.h
index c7def60..ead88bf 100644
--- a/project2/common/sessionClearTask.h
+++ b/project2/common/sessionClearTask.h
@@ -15,7 +15,7 @@ class SessionClearTask : public Task {
SessionClearTask(ScriptNodePtr p);
virtual ~SessionClearTask();
- void execute() const;
+ void execute(ExecContext *) const;
const Glib::ustring key;
};
diff --git a/project2/common/sessionContainer.cpp b/project2/common/sessionContainer.cpp
index e9c76c9..41c3f98 100644
--- a/project2/common/sessionContainer.cpp
+++ b/project2/common/sessionContainer.cpp
@@ -1,6 +1,5 @@
#include <pch.hpp>
#include "sessionContainer.h"
-#include "environment.h"
SessionContainer::SessionContainer()
{
diff --git a/project2/common/sessionSetTask.cpp b/project2/common/sessionSetTask.cpp
index aca5b26..f46571b 100644
--- a/project2/common/sessionSetTask.cpp
+++ b/project2/common/sessionSetTask.cpp
@@ -2,15 +2,15 @@
#include <boost/foreach.hpp>
#include "scriptLoader.h"
#include "sessionSetTask.h"
-#include "appEngine.h"
#include "session.h"
+#include "execContext.h"
DECLARE_LOADER("sessionset", SessionSetTask);
SessionSetTask::SessionSetTask(ScriptNodePtr p) :
SourceObject(p),
Task(p),
- key(p->value("key").as<Glib::ustring>()),
+ key(p->value("key", NULL).as<Glib::ustring>()),
value(p, "value")
{
}
@@ -20,8 +20,8 @@ SessionSetTask::~SessionSetTask()
}
void
-SessionSetTask::execute() const
+SessionSetTask::execute(ExecContext * ec) const
{
- ApplicationEngine::getCurrent()->session()->SetValue(key, value);
+ ec->getSession()->SetValue(key, value(ec));
}
diff --git a/project2/common/sessionSetTask.h b/project2/common/sessionSetTask.h
index 8e88837..d38c216 100644
--- a/project2/common/sessionSetTask.h
+++ b/project2/common/sessionSetTask.h
@@ -16,7 +16,7 @@ class SessionSetTask : public Task {
SessionSetTask(ScriptNodePtr p);
virtual ~SessionSetTask();
- void execute() const;
+ void execute(ExecContext *) const;
const Glib::ustring key;
const Variable value;
diff --git a/project2/common/singleton.cpp b/project2/common/singleton.cpp
index 0aaf5f7..eff3f94 100644
--- a/project2/common/singleton.cpp
+++ b/project2/common/singleton.cpp
@@ -10,29 +10,28 @@ class Singleton : public View {
Singleton(ScriptNodePtr p) :
SourceObject(p),
View(p),
- rootName(p, "rootname"),
- presenter(NULL) {
+ rootName(p, "rootname")
+ {
BOOST_FOREACH(ScriptNodePtr node, p->childrenIn("columns")) {
viewColumns.insert(Columns::value_type(node->get_name(), Variable(node)));
}
p->script->loader.addLoadTarget(p, Storer::into<ElementLoader>(&subViews));
}
- void execute(const MultiRowSetPresenter * p) const
+ void execute(const MultiRowSetPresenter * p, ExecContext * ec) const
{
- presenter = p;
- presenter->addNewRowSet(rootName());
+ p->addNewRowSet(rootName(ec));
ScopeObject pres(boost::bind(&MultiRowSetPresenter::finishRowSet, p));
BOOST_FOREACH(const Columns::value_type & col, viewColumns) {
- p->addNamedValue(col.first, col.second);
+ p->addNamedValue(col.first, col.second(ec));
}
}
const Variable rootName;
private:
- void executeChildren() const
+ void executeChildren(const MultiRowSetPresenter * p, ExecContext * ec) const
{
BOOST_FOREACH(const SubViews::value_type & sq, subViews) {
- sq->execute(presenter);
+ sq->execute(p, ec);
}
}
@@ -41,7 +40,6 @@ class Singleton : public View {
typedef ANONSTORAGEOF(View) SubViews;
SubViews subViews;
- mutable const MultiRowSetPresenter * presenter;
};
DECLARE_LOADER("singleton", Singleton);
diff --git a/project2/common/sourceObject.cpp b/project2/common/sourceObject.cpp
index 03f06b5..b451919 100644
--- a/project2/common/sourceObject.cpp
+++ b/project2/common/sourceObject.cpp
@@ -8,7 +8,7 @@ unsigned int SourceObject::loadOrder = 1;
SimpleMessageException(ComponentNotFound);
SourceObject::SourceObject(ScriptNodePtr p) :
- name(p ? p->value("name", "anon").as<std::string>() : "anon"),
+ name(p ? p->value("name", "anon", NULL).as<std::string>() : "anon"),
order(loadOrder++),
script(p->script.get())
{
diff --git a/project2/common/stream.h b/project2/common/stream.h
index eebefab..ad3ee79 100644
--- a/project2/common/stream.h
+++ b/project2/common/stream.h
@@ -4,12 +4,14 @@
#include "sourceObject.h"
#include <boost/function.hpp>
+class ExecContext;
+
class Stream : public SourceObject {
public:
template<typename... X> Stream(const X &... x) : SourceObject(x...) { }
typedef boost::function<size_t(const char *, size_t)> Sink;
- virtual void runStream(const Sink &) const = 0;
+ virtual void runStream(const Sink &, ExecContext *) const = 0;
};
typedef boost::intrusive_ptr<Stream> StreamPtr;
diff --git a/project2/common/structExceptHandling.cpp b/project2/common/structExceptHandling.cpp
index 0881d6d..917f030 100644
--- a/project2/common/structExceptHandling.cpp
+++ b/project2/common/structExceptHandling.cpp
@@ -23,22 +23,22 @@ StructuredExceptionHandler::loadComplete(const CommonObjects * co)
}
void
-StructuredExceptionHandler::execute() const
+StructuredExceptionHandler::execute(ExecContext * ec) const
{
try {
- run(normal);
+ run(normal, ec);
}
catch (...) {
try {
- run(catches);
- run(finallies);
+ run(catches, ec);
+ run(finallies, ec);
return;
}
catch (...) {
}
- run(finallies);
+ run(finallies, ec);
throw;
}
- run(finallies);
+ run(finallies, ec);
}
diff --git a/project2/common/structExceptHandling.h b/project2/common/structExceptHandling.h
index 067c389..b6702f1 100644
--- a/project2/common/structExceptHandling.h
+++ b/project2/common/structExceptHandling.h
@@ -8,7 +8,7 @@ class StructuredExceptionHandler : public IHaveSubTasks {
StructuredExceptionHandler(ScriptNodePtr);
void loadComplete(const CommonObjects*);
- void execute() const;
+ void execute(ExecContext * ec) const;
private:
Tasks catches, finallies;
diff --git a/project2/common/task.h b/project2/common/task.h
index 5303f15..15ccfbd 100644
--- a/project2/common/task.h
+++ b/project2/common/task.h
@@ -9,7 +9,7 @@ class Task : public NoOutputExecute {
public:
Task(ScriptNodePtr p);
virtual ~Task();
- virtual void execute() const = 0;
+ virtual void execute(ExecContext *) const = 0;
};
#endif
diff --git a/project2/common/taskHost.cpp b/project2/common/taskHost.cpp
index cbfe7c3..07f7601 100644
--- a/project2/common/taskHost.cpp
+++ b/project2/common/taskHost.cpp
@@ -27,11 +27,11 @@ TaskHost::loadComplete(const CommonObjects * co)
}
void
-TaskHost::execute() const
+TaskHost::execute(ExecContext * ec) const
{
loadScriptComponents();
ScopeObject txHandler(ScopeObject::Event(), boost::bind(&TaskHost::commitAll, this), boost::bind(&TaskHost::rollbackAll, this));
- run(tasks);
+ run(tasks, ec);
}
void
diff --git a/project2/common/taskHost.h b/project2/common/taskHost.h
index edecda6..e4b8b3a 100644
--- a/project2/common/taskHost.h
+++ b/project2/common/taskHost.h
@@ -15,7 +15,7 @@ class TaskHost : public IHaveSubTasks, virtual public CheckHost, virtual public
virtual ~TaskHost();
void loadComplete(const CommonObjects *);
- void execute() const;
+ void execute(ExecContext *) const;
Tasks tasks;
diff --git a/project2/common/test.h b/project2/common/test.h
index 4f87c10..7cf563c 100644
--- a/project2/common/test.h
+++ b/project2/common/test.h
@@ -4,10 +4,12 @@
#include "sourceObject.h"
#include "scripts.h"
+class ExecContext;
+
class Test : public virtual SourceObject {
public:
Test(ScriptNodePtr);
- virtual bool passes() const = 0;
+ virtual bool passes(ExecContext *) const = 0;
virtual void reset() const;
};
typedef boost::intrusive_ptr<const Test> TestPtr;
diff --git a/project2/common/transform.cpp b/project2/common/transform.cpp
index fb92486..efe9bf6 100644
--- a/project2/common/transform.cpp
+++ b/project2/common/transform.cpp
@@ -19,7 +19,7 @@ class TransformTargetStorer : public Storer {
{
TransformChainLinkPtr O = boost::dynamic_pointer_cast<TransformChainLink>(o);
if (O) {
- transformSource->addTarget(O, s);
+ transformSource->addTarget(O, NULL, s);
}
return O;
}
@@ -44,13 +44,13 @@ TransformChainLink::~TransformChainLink()
typedef std::map<std::string, boost::shared_ptr<TransformLoader> > TransformLoaderMap;
void
-TransformSource::addTarget(TransformChainLinkPtr tcl, ScriptNodePtr e)
+TransformSource::addTarget(TransformChainLinkPtr tcl, ExecContext * ec, ScriptNodePtr e)
{
BOOST_FOREACH(const TransformLoaderMap::value_type & tl, *Plugable::objLoaders<TransformLoader>()) {
TransformPtr t = tl.second->create();
if (t->canTransform(this, tcl.get())) {
if (e) {
- t->configure(e);
+ t->configure(e, ec);
}
targets[tcl] = t;
return;
@@ -72,12 +72,12 @@ TransformSource::removeTarget(TransformChainLinkPtr tcl)
}
void
-TransformSource::doTransforms() const
+TransformSource::doTransforms(ExecContext * ec) const
{
BOOST_FOREACH(const Targets::value_type & t, targets) {
- t.second->transform(this, t.first.get());
+ t.second->transform(this, t.first.get(), ec);
if (const TransformSource * tr = dynamic_cast<const TransformSource *>(t.first.get())) {
- tr->doTransforms();
+ tr->doTransforms(ec);
}
}
}
@@ -90,16 +90,16 @@ TransformSource::getTargets() const
class TransformWritableContentToStdStream : public TransformImpl<WritableContent, ostreamWrapper> {
public:
- void transform(const WritableContent * wc, ostreamWrapper * o) const
+ void transform(const WritableContent * wc, ostreamWrapper * o, ExecContext * ec) const
{
- wc->writeTo(o->strm, "UTF-8");
+ wc->writeTo(o->strm, "UTF-8", ec);
}
};
DECLARE_TRANSFORM(TransformWritableContentToStdStream);
class TransformStaticContentToStdStream : public TransformImpl<StaticContent, ostreamWrapper> {
public:
- void transform(const StaticContent * wc, ostreamWrapper * o) const
+ void transform(const StaticContent * wc, ostreamWrapper * o, ExecContext *) const
{
wc->writeTo(o->strm);
}
diff --git a/project2/common/transform.h b/project2/common/transform.h
index 3ae1063..34e91b7 100644
--- a/project2/common/transform.h
+++ b/project2/common/transform.h
@@ -6,6 +6,8 @@
#include "scriptLoader.h"
#include <map>
+class ExecContext;
+
class TransformChainLink : public virtual IntrusivePtrBase {
public:
virtual ~TransformChainLink() = 0;
@@ -22,8 +24,8 @@ class TransformSource : public TransformChainLink {
TransformSource(ScriptNodePtr, ObjectSource);
void clearTargets();
void removeTarget(TransformChainLinkPtr);
- void addTarget(TransformChainLinkPtr, ScriptNodePtr e = NULL);
- void doTransforms() const;
+ void addTarget(TransformChainLinkPtr, ExecContext *, ScriptNodePtr e);
+ void doTransforms(ExecContext *) const;
const Targets & getTargets() const;
private:
virtual const TransformChainLink * object() const { return this; }
@@ -41,9 +43,9 @@ class SourceOf : public virtual TransformSource {
class Transform : public virtual IntrusivePtrBase {
public:
- virtual void transform(const TransformSource * src, TransformChainLink * dest) const = 0;
+ virtual void transform(const TransformSource * src, TransformChainLink * dest, ExecContext *) const = 0;
virtual bool canTransform(const TransformSource * src, TransformChainLink * dest) const = 0;
- virtual void configure(ScriptNodePtr) { };
+ virtual void configure(ScriptNodePtr, ExecContext *) { };
};
typedef GenLoader<Transform> TransformLoader;
@@ -55,10 +57,10 @@ typedef GenLoader<TransformChainLink, ScriptNodePtr, ObjectSource> TransformTarg
template <class Source, class Destination>
class TransformImpl : public Transform {
public:
- virtual void transform(const Source *, Destination *) const = 0;
- void transform(const TransformSource * src, TransformChainLink * dest) const
+ virtual void transform(const Source *, Destination *, ExecContext *) const = 0;
+ void transform(const TransformSource * src, TransformChainLink * dest, ExecContext * ec) const
{
- transform(dynamic_cast<const SourceOf<Source> *>(src)->operator const Source *(), dynamic_cast<Destination *>(dest));
+ transform(dynamic_cast<const SourceOf<Source> *>(src)->operator const Source *(), dynamic_cast<Destination *>(dest), ec);
}
bool canTransform(const TransformSource * src, TransformChainLink * dest) const
{
@@ -75,7 +77,7 @@ class WritableContent {
};
virtual Class getContentClass() const = 0;
virtual Glib::ustring getContentType() const = 0;
- virtual void writeTo(std::ostream &, const std::string & encoding) const = 0;
+ virtual void writeTo(std::ostream &, const std::string & encoding, ExecContext *) const = 0;
};
class StaticContent {
diff --git a/project2/common/variables.cpp b/project2/common/variables.cpp
index 6f62dc1..a8ca808 100644
--- a/project2/common/variables.cpp
+++ b/project2/common/variables.cpp
@@ -5,7 +5,6 @@
#include "iHaveParameters.h"
#include "scriptLoader.h"
#include "exceptions.h"
-#include "appEngine.h"
#include "session.h"
#include "rowSet.h"
#include <stdexcept>
@@ -31,9 +30,9 @@ class VariableParent : public VariableImplDyn {
public:
VariableParent(ScriptNodePtr e) :
VariableImplDyn(e),
- depth(e->value("depth", 1).as<int32_t>()),
+ depth(e->value("depth", 1, NULL).as<int32_t>()),
attr(e->valueExists("attribute")),
- name((attr ? e->value("attribute") : e->value("name")).as<Glib::ustring>())
+ name((attr ? e->value("attribute", NULL) : e->value("name", NULL)).as<Glib::ustring>())
{
}
VariableParent(const Glib::ustring & n, bool a, unsigned int d) :
@@ -43,14 +42,14 @@ class VariableParent : public VariableImplDyn {
name(n)
{
}
- VariableType value() const
+ VariableType value(ExecContext * ec) const
{
try {
if (!getValue) {
if (depth > RowState::Stack().size()) {
throw RowSet::ParentOutOfRange(depth);
}
- bind(RowState::Stack()[RowState::Stack().size() - depth]);
+ bind(ec, RowState::Stack()[RowState::Stack().size() - depth]);
}
return getValue();
}
@@ -58,23 +57,23 @@ class VariableParent : public VariableImplDyn {
if (!defaultValue) {
throw;
}
- return (*defaultValue)();
+ return (*defaultValue)(ec);
}
catch (RowSet::FieldDoesNotExist) {
if (!defaultValue) {
throw;
}
- return (*defaultValue)();
+ return (*defaultValue)(ec);
}
}
protected:
- void bind(const RowState * row) const
+ void bind(ExecContext * ec, const RowState * row) const
{
if (attr) {
getValue = boost::bind(row->resolveAttr(name));
}
else {
- getValue = boost::bind(&RowState::getCurrentValue, row, name);
+ getValue = boost::bind(&RowState::getCurrentValue, row, ec, name);
}
}
const size_t depth;
diff --git a/project2/common/variables.h b/project2/common/variables.h
index 948f2d2..7713667 100644
--- a/project2/common/variables.h
+++ b/project2/common/variables.h
@@ -10,12 +10,14 @@
#include "variableType.h"
#include <boost/shared_ptr.hpp>
+class ExecContext;
+
SimpleMessageException(UnknownVariableSource);
/// Base class for Project2 variable accessors
class VariableImpl : public IntrusivePtrBase {
public:
- virtual VariableType value() const = 0;
+ virtual VariableType value(ExecContext *) const = 0;
protected:
virtual ~VariableImpl() = 0;
@@ -32,8 +34,7 @@ class Variable {
static Variable makeParent(const Glib::ustring & name, bool attr, unsigned int depth);
- operator VariableType () const { return var->value(); }
- VariableType operator()() const { return var->value(); }
+ VariableType operator()(ExecContext * ec) const { return var->value(ec); }
private:
Variable(VariableImpl *);
@@ -45,7 +46,7 @@ class Variable {
class VariableImplDyn : public VariableImpl {
public:
VariableImplDyn(ScriptNodePtr e);
- virtual VariableType value() const = 0;
+ virtual VariableType value(ExecContext *) const = 0;
protected:
boost::optional<Variable> defaultValue;
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:
diff --git a/project2/common/view.h b/project2/common/view.h
index 75a0f3c..52a4130 100644
--- a/project2/common/view.h
+++ b/project2/common/view.h
@@ -5,6 +5,7 @@
#include "scriptStorage.h"
class MultiRowSetPresenter;
+class ExecContext;
SimpleMessageException(EmptyRequiredRows);
/// Base class for Project2 components that output data
@@ -13,7 +14,7 @@ class View : public virtual SourceObject {
View(ScriptNodePtr);
virtual ~View();
- virtual void execute(const MultiRowSetPresenter *) const = 0;
+ virtual void execute(const MultiRowSetPresenter *, ExecContext *) const = 0;
};
#endif
diff --git a/project2/common/viewGroup.cpp b/project2/common/viewGroup.cpp
index b01f6c8..e6e84d0 100644
--- a/project2/common/viewGroup.cpp
+++ b/project2/common/viewGroup.cpp
@@ -11,11 +11,11 @@ class ViewGroup : public View {
s->script->loader.addLoadTarget(s, Storer::into<ElementLoader>(&subViews));
}
- void execute(const MultiRowSetPresenter * presenter) const
+ void execute(const MultiRowSetPresenter * presenter, ExecContext * ec) const
{
presenter->addNewRowSet(name);
BOOST_FOREACH(const SubViews::value_type & sq, subViews) {
- sq->execute(presenter);
+ sq->execute(presenter, ec);
}
presenter->finishRowSet();
}
diff --git a/project2/common/viewHost.cpp b/project2/common/viewHost.cpp
index 04e0d88..320e86d 100644
--- a/project2/common/viewHost.cpp
+++ b/project2/common/viewHost.cpp
@@ -17,14 +17,14 @@ ViewHost::~ViewHost()
}
void
-ViewHost::executeViews() const
+ViewHost::executeViews(ExecContext * ec) const
{
loadScriptComponents();
- MultiRowSetPresenterPtr presenter = getPresenter();
- presenter->init();
+ MultiRowSetPresenterPtr presenter = getPresenter(ec);
+ presenter->init(ec);
BOOST_FOREACH(const Views::value_type & s, views) {
- s->execute(presenter.get());
+ s->execute(presenter.get(), ec);
}
// Caches might open transactions
BOOST_FOREACH(const CommonObjects::DataSources::value_type & ds, CommonObjects::datasources) {
@@ -34,12 +34,12 @@ ViewHost::executeViews() const
}
void
-ViewHost::doTransforms() const
+ViewHost::doTransforms(ExecContext * ec) const
{
- MultiRowSetPresenterPtr presenter = getPresenter();
+ MultiRowSetPresenterPtr presenter = getPresenter(ec);
TransformSourcePtr ts = boost::dynamic_pointer_cast<TransformSource>(presenter);
if (ts) {
- ts->doTransforms();
+ ts->doTransforms(ec);
}
}
diff --git a/project2/common/viewHost.h b/project2/common/viewHost.h
index d09f1af..5ede3e4 100644
--- a/project2/common/viewHost.h
+++ b/project2/common/viewHost.h
@@ -13,11 +13,11 @@ class ViewHost : virtual public CheckHost, virtual public CommonObjects {
ViewHost(ScriptNodePtr script);
~ViewHost();
- void executeViews() const;
- void doTransforms() const;
+ void executeViews(ExecContext *) const;
+ void doTransforms(ExecContext *) const;
protected:
- virtual MultiRowSetPresenterPtr getPresenter() const = 0;
+ virtual MultiRowSetPresenterPtr getPresenter(ExecContext *) const = 0;
private:
typedef ANONORDEREDSTORAGEOF(View) Views;