summaryrefslogtreecommitdiff
path: root/project2/basics
diff options
context:
space:
mode:
Diffstat (limited to 'project2/basics')
-rw-r--r--project2/basics/Jamfile.jam2
-rw-r--r--project2/basics/if.cpp49
-rw-r--r--project2/basics/if.h25
-rw-r--r--project2/basics/tasks/iterate.cpp41
-rw-r--r--project2/basics/tasks/iterate.h26
5 files changed, 142 insertions, 1 deletions
diff --git a/project2/basics/Jamfile.jam b/project2/basics/Jamfile.jam
index 19726d9..c540c68 100644
--- a/project2/basics/Jamfile.jam
+++ b/project2/basics/Jamfile.jam
@@ -9,7 +9,7 @@ build-project unittests ;
cpp-pch pch : pch.hpp :
<include>../../libmisc
- <library>glibmm
+ <library>glibmm
<library>../common//p2common
;
diff --git a/project2/basics/if.cpp b/project2/basics/if.cpp
new file mode 100644
index 0000000..bdd9835
--- /dev/null
+++ b/project2/basics/if.cpp
@@ -0,0 +1,49 @@
+#include <pch.hpp>
+#include "if.h"
+#include "logger.h"
+#include "scriptLoader.h"
+#include <boost/bind.hpp>
+#include <algorithm>
+
+DECLARE_LOADER("if", If);
+StaticMessageException(NoTestsToPerform, "No tests to perform");
+
+If::If(ScriptNodePtr e) :
+ SourceObject(e),
+ IHaveSubTasks(e),
+ View(e)
+{
+ e->script->loader.addLoadTarget(e, Storer::into<ElementLoader>(&normal));
+ e->script->loader.addLoadTarget(e, Storer::into<ElementLoader>(&subViews));
+ e->script->loader.addLoadTarget(e, Storer::into<ElementLoader>(&test));
+}
+
+bool
+If::passes(ExecContext * ec) const
+{
+ if (!test) {
+ throw NoTestsToPerform();
+ }
+ return test->passes(ec);
+}
+
+void
+If::execute(const MultiRowSetPresenter * presenter, ExecContext * ec) const
+{
+ if (passes(ec)) {
+ Logger()->messagef(LOG_DEBUG, "Test passed; showing %zu views", subViews.size());
+ for (const SubViews::value_type & sq : subViews) {
+ sq->execute(presenter, ec);
+ }
+ }
+}
+
+void
+If::execute(ExecContext * ec) const
+{
+ if (passes(ec)) {
+ Logger()->messagef(LOG_DEBUG, "Test passed; executing %zu tasks", normal.size());
+ run(normal, ec);
+ }
+}
+
diff --git a/project2/basics/if.h b/project2/basics/if.h
new file mode 100644
index 0000000..64f885b
--- /dev/null
+++ b/project2/basics/if.h
@@ -0,0 +1,25 @@
+#ifndef IF_H
+#define IF_H
+
+#include "iHaveSubTasks.h"
+#include "view.h"
+#include "test.h"
+
+/// Project2 component to conditionally execute its children
+class If : public IHaveSubTasks, public View {
+ public:
+ If(ScriptNodePtr);
+
+ virtual void execute(const MultiRowSetPresenter *, ExecContext *) const;
+ virtual void execute(ExecContext *) const;
+
+ private:
+ bool passes(ExecContext *) const;
+
+ typedef ANONSTORAGEOF(View) SubViews;
+ SubViews subViews;
+ TestPtr test;
+};
+
+#endif
+
diff --git a/project2/basics/tasks/iterate.cpp b/project2/basics/tasks/iterate.cpp
new file mode 100644
index 0000000..ae73cdb
--- /dev/null
+++ b/project2/basics/tasks/iterate.cpp
@@ -0,0 +1,41 @@
+#include <pch.hpp>
+#include "iterate.h"
+#include "logger.h"
+#include <boost/bind.hpp>
+#include "scriptLoader.h"
+#include "scopeObject.h"
+
+DECLARE_LOADER("iterate", Iterate);
+
+Iterate::Iterate(ScriptNodePtr p) :
+ SourceObject(p),
+ IHaveSubTasks(p),
+ RowProcessor(p)
+{
+ p->script->loader.addLoadTarget(p, Storer::into<ElementLoader>(&normal));
+}
+
+Iterate::~Iterate()
+{
+}
+
+void
+Iterate::loadComplete(const CommonObjects * co)
+{
+ RowProcessor::loadComplete(co);
+}
+
+void
+Iterate::execute(ExecContext * ec) const
+{
+ RowProcessor::execute(ec, boost::bind(&Iterate::executeChildren, this, ec));
+}
+
+void
+Iterate::executeChildren(ExecContext * ec) const
+{
+ for (const Tasks::value_type & sq : normal) {
+ sq->execute(ec);
+ }
+}
+
diff --git a/project2/basics/tasks/iterate.h b/project2/basics/tasks/iterate.h
new file mode 100644
index 0000000..2afbe98
--- /dev/null
+++ b/project2/basics/tasks/iterate.h
@@ -0,0 +1,26 @@
+#ifndef ITERATE_H
+#define ITERATE_H
+
+#include "rowProcessor.h"
+#include "iHaveSubTasks.h"
+#include "scriptStorage.h"
+
+class Iterate;
+typedef boost::intrusive_ptr<Iterate> IteratePtr;
+
+/// Project2 component to iterate over a row set, executing its children for each record
+class Iterate : public IHaveSubTasks, public RowProcessor {
+ public:
+ Iterate(ScriptNodePtr p);
+ virtual ~Iterate();
+
+ void loadComplete(const CommonObjects *);
+ void execute(ExecContext *) const;
+
+ protected:
+ void executeChildren(ExecContext *) const;
+};
+
+#endif
+
+