summaryrefslogtreecommitdiff
path: root/project2/if.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'project2/if.cpp')
-rw-r--r--project2/if.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/project2/if.cpp b/project2/if.cpp
new file mode 100644
index 0000000..647c0d0
--- /dev/null
+++ b/project2/if.cpp
@@ -0,0 +1,71 @@
+#include "if.h"
+#include "logger.h"
+#include "xmlObjectLoader.h"
+
+ElementLoaderImpl<If> ifLoader("if");
+
+class IfModeIsNonsense : public std::exception { };
+
+IfSet::IfSet(const xmlpp::Element * e) :
+ mode(e->get_attribute_value("mode") == "or" ? Or : And)
+{
+ LoaderBase loader("http://project2.randomdan.homeip.net", true);
+ loader.supportedStorers.insert(Storer::into(&checks));
+ loader.collectAll(e, true, IgnoreUnsupported);
+}
+
+bool
+IfSet::passes() const
+{
+ if (mode == And) {
+ BOOST_FOREACH(OrderedParamCheckers::value_type pc, checks) {
+ if (!pc.second->performCheck()) {
+ return false;
+ }
+ }
+ return true;
+ }
+ else {
+ BOOST_FOREACH(OrderedParamCheckers::value_type pc, checks) {
+ if (pc.second->performCheck()) {
+ return true;
+ }
+ }
+ return false;
+ }
+ throw IfModeIsNonsense();
+}
+
+If::If(const xmlpp::Element * e) :
+ SourceObject(e),
+ Iterate(e),
+ RowView(e),
+ IfSet(e)
+{
+}
+
+void If::loadComplete(const CommonObjects*)
+{
+}
+
+void If::execute(const Presenter * presenter) const
+{
+ if (passes()) {
+ Logger()->messagef(LOG_DEBUG, "IfSet passed, showing %zu views", subViews.size());
+ BOOST_FOREACH(Views::value_type sq, subViews) {
+ sq.second->execute(presenter);
+ }
+ }
+}
+
+void If::execute() const
+{
+ if (passes()) {
+ Logger()->message(LOG_DEBUG, "IfSet passed");
+ BOOST_FOREACH(NoOutputExecutes::value_type sq, subNOEs) {
+ sq.second->execute();
+ }
+ }
+}
+
+