summaryrefslogtreecommitdiff
path: root/project2/if.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'project2/if.cpp')
-rw-r--r--project2/if.cpp33
1 files changed, 17 insertions, 16 deletions
diff --git a/project2/if.cpp b/project2/if.cpp
index 3474815..5fa7a8c 100644
--- a/project2/if.cpp
+++ b/project2/if.cpp
@@ -1,8 +1,8 @@
#include "if.h"
-#include "appEngine.h"
#include "logger.h"
#include "xmlObjectLoader.h"
#include <boost/foreach.hpp>
+#include <algorithm>
DECLARE_LOADER("if", If);
@@ -11,29 +11,30 @@ SimpleMessageException(IfModeIsNonsense);
IfSet::IfSet(const xmlpp::Element * e) :
mode(e->get_attribute_value("mode") == "or" ? Or : And)
{
- LoaderBase loader(ApplicationEngine::getCurrent()->env()->getXmlNamespace(), true);
+ LoaderBase loader(true);
loader.supportedStorers.insert(Storer::into(&checks));
loader.collectAll(e, true, IgnoreUnsupported);
}
+template <class Range, class Pred>
+bool all(const Range & c, const Pred & p)
+{
+ return (std::find_if(c.begin(), c.end(), !p) == c.end());
+}
+template <class Range, class Pred>
+bool any(const Range & c, const Pred & p)
+{
+ return (std::find_if(c.begin(), c.end(), p) != c.end());
+}
+
bool
IfSet::passes() const
{
if (mode == And) {
- BOOST_FOREACH(const ParamCheckers::value_type & pc, checks.get<bySOOrder>()) {
- if (!pc->performCheck()) {
- return false;
- }
- }
- return true;
+ return all(checks.get<bySOOrder>(), boost::bind(&ParamChecker::performCheck, _1));
}
- else {
- BOOST_FOREACH(const ParamCheckers::value_type & pc, checks.get<bySOOrder>()) {
- if (pc->performCheck()) {
- return true;
- }
- }
- return false;
+ else if (mode == Or) {
+ return any(checks.get<bySOOrder>(), boost::bind(&ParamChecker::performCheck, _1));
}
throw IfModeIsNonsense(getName());
}
@@ -45,7 +46,7 @@ If::If(const xmlpp::Element * e) :
IfSet(e),
localErrorHandling(e->get_attribute_value("errorHandling") == "local")
{
- LoaderBase loader(ApplicationEngine::getCurrent()->env()->getXmlNamespace(), true);
+ LoaderBase loader(true);
loader.supportedStorers.insert(new NOEErrorStorer(&normNOEs, &errorNOEs));
loader.supportedStorers.insert(Storer::into(&subViews));
loader.collectAll(e, true, IgnoreUnsupported);