diff options
author | randomdan <randomdan@localhost> | 2011-02-10 22:00:22 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2011-02-10 22:00:22 +0000 |
commit | d3c7ac5b0574a79863aa7c148af29ca369457964 (patch) | |
tree | 5be6eabd541bf8df2de403335ad5c79f65a94358 | |
parent | Rename OdbcVariableBinder, it's not (anymore) ODBC specific (diff) | |
download | project2-d3c7ac5b0574a79863aa7c148af29ca369457964.tar.bz2 project2-d3c7ac5b0574a79863aa7c148af29ca369457964.tar.xz project2-d3c7ac5b0574a79863aa7c148af29ca369457964.zip |
Add an 'if' component that works with views and iterators
Give some control to the behaviour of unsupported items when loading from XML
Make regexcheck's regex a variable
-rw-r--r-- | project2/Jamfile.jam | 2 | ||||
-rw-r--r-- | project2/if.cpp | 71 | ||||
-rw-r--r-- | project2/if.h | 29 | ||||
-rw-r--r-- | project2/iterate.cpp | 2 | ||||
-rw-r--r-- | project2/regexCheck.cpp | 4 | ||||
-rw-r--r-- | project2/regexCheck.h | 3 | ||||
-rw-r--r-- | project2/rowView.cpp | 2 | ||||
-rw-r--r-- | project2/xmlObjectLoader.cpp | 16 | ||||
-rw-r--r-- | project2/xmlObjectLoader.h | 6 |
9 files changed, 121 insertions, 14 deletions
diff --git a/project2/Jamfile.jam b/project2/Jamfile.jam index cdba0d3..3b8e1e8 100644 --- a/project2/Jamfile.jam +++ b/project2/Jamfile.jam @@ -48,7 +48,7 @@ lib p2uuid : lib p2common : appEngine.cpp dataSource.cpp environment.cpp fileStarGlibIoChannel.cpp iHaveParameters.cpp - iterate.cpp paramChecker.cpp presenter.cpp rawView.cpp dumpTask.cpp logger.cpp + iterate.cpp paramChecker.cpp presenter.cpp rawView.cpp dumpTask.cpp logger.cpp if.cpp sourceObject.cpp task.cpp variables.cpp variableConvert.cpp view.cpp xmlObjectLoader.cpp exceptions.cpp sessionClearTask.cpp session.cpp sessionSetTask.cpp commonObjects.cpp xmlPresenter.cpp rowView.cpp rowSet.cpp rowUser.cpp rowProcessor.cpp config.cpp 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(); + } + } +} + + diff --git a/project2/if.h b/project2/if.h new file mode 100644 index 0000000..403f4b0 --- /dev/null +++ b/project2/if.h @@ -0,0 +1,29 @@ +#ifndef IF_H +#define IF_H + +#include "iterate.h" +#include "rowView.h" +#include "paramChecker.h" + +class IfSet : public virtual IntrusivePtrBase { + public: + IfSet(const xmlpp::Element *); + bool passes() const; + + private: + enum Mode { And, Or }; + Mode mode; + OrderedParamCheckers checks; +}; + +class If : public Iterate, public RowView, public IfSet { + public: + If(const xmlpp::Element *); + + virtual void loadComplete(const CommonObjects*); + virtual void execute(const Presenter*) const; + virtual void execute() const; +}; + +#endif + diff --git a/project2/iterate.cpp b/project2/iterate.cpp index d56fd31..cdb0cc6 100644 --- a/project2/iterate.cpp +++ b/project2/iterate.cpp @@ -11,7 +11,7 @@ Iterate::Iterate(const xmlpp::Element * p) : { LoaderBase loader("http://project2.randomdan.homeip.net", true); loader.supportedStorers.insert(Storer::into(&subNOEs)); - loader.collectAll(p, true); + loader.collectAll(p, true, IgnoreUnsupported); } Iterate::~Iterate() diff --git a/project2/regexCheck.cpp b/project2/regexCheck.cpp index 0412145..08b1e75 100644 --- a/project2/regexCheck.cpp +++ b/project2/regexCheck.cpp @@ -9,7 +9,7 @@ RegexCheck::RegexCheck(const xmlpp::Element * p) : SourceObject(p), ParamChecker(p), applyTo(p, "apply-to"), - regex(xmlChildText(p, "regex").raw()) + regex(p, "regex") { } @@ -31,6 +31,6 @@ RegexCheck::performCheck() const bool RegexCheck::checkString(const Glib::ustring & str) const { - return boost::regex_match(str.begin(), str.end(), regex); + return boost::regex_match(str.begin(), str.end(), boost::regex(regex())); } diff --git a/project2/regexCheck.h b/project2/regexCheck.h index e2d5bc1..be55e9b 100644 --- a/project2/regexCheck.h +++ b/project2/regexCheck.h @@ -2,7 +2,6 @@ #define REGEXCHECK_H #include "paramChecker.h" -#include <boost/regex.hpp> class RegexCheck : public ParamChecker { public: @@ -13,7 +12,7 @@ class RegexCheck : public ParamChecker { bool performCheck() const; const Variable applyTo; - const boost::regex regex; + const Variable regex; private: bool checkString(const Glib::ustring & str) const; }; diff --git a/project2/rowView.cpp b/project2/rowView.cpp index 2306474..9d69e9a 100644 --- a/project2/rowView.cpp +++ b/project2/rowView.cpp @@ -20,7 +20,7 @@ RowView::RowView(const xmlpp::Element * p) : } LoaderBase loader("http://project2.randomdan.homeip.net", true); loader.supportedStorers.insert(Storer::into(&subViews)); - loader.collectAll(p, true); + loader.collectAll(p, true, IgnoreUnsupported); } RowView::~RowView() diff --git a/project2/xmlObjectLoader.cpp b/project2/xmlObjectLoader.cpp index aa1873b..4b291da 100644 --- a/project2/xmlObjectLoader.cpp +++ b/project2/xmlObjectLoader.cpp @@ -1,5 +1,6 @@ #include "xmlObjectLoader.h" #include "exceptions.h" +#include "logger.h" #include <stdio.h> unsigned int LoaderBase::depth = 0; @@ -23,7 +24,7 @@ LoaderBase::~LoaderBase() } void -LoaderBase::collectAll(const xmlpp::Element * node, bool childrenOnly) const +LoaderBase::collectAll(const xmlpp::Element * node, bool childrenOnly, UnsupportedHandling uh) const { if (!node) { return; @@ -47,24 +48,29 @@ LoaderBase::collectAll(const xmlpp::Element * node, bool childrenOnly) const throw NotSupported(name); } if (stored < created) { - throw NotSupported(name); + if (uh == ErrorOnUnsupported) { + throw NotSupported(name); + } + else if (uh == WarnOnUnsupported) { + Logger()->messagef(LOG_WARNING, "'%s' unsupported in this location", name.c_str()); + } } } if (created == 0 && (recursive || childrenOnly)) { BOOST_FOREACH(const xmlpp::Node * child, node->get_children()) { - collectAll(dynamic_cast<const xmlpp::Element *>(child), false); + collectAll(dynamic_cast<const xmlpp::Element *>(child), false, uh); } } depth -= 1; } void -LoaderBase::collectAll(const CommonObjects * co, const xmlpp::Element * node, bool childrenOnly) const +LoaderBase::collectAll(const CommonObjects * co, const xmlpp::Element * node, bool childrenOnly, UnsupportedHandling uh) const { if (depth != 0) { throw std::logic_error("Cannot set CommonObjects in subloader"); } - collectAll(node, childrenOnly); + collectAll(node, childrenOnly, uh); BOOST_FOREACH(SourceObjectPtr o, loadedObjects) { o->loadComplete(co); } diff --git a/project2/xmlObjectLoader.h b/project2/xmlObjectLoader.h index 1ebc154..aaab310 100644 --- a/project2/xmlObjectLoader.h +++ b/project2/xmlObjectLoader.h @@ -82,14 +82,16 @@ Storer::into(std::map<Key, boost::intrusive_ptr<X> > * map) return new StorerImpl<X, Key>(map); } +enum UnsupportedHandling { ErrorOnUnsupported, WarnOnUnsupported, IgnoreUnsupported }; + class LoaderBase { public: typedef std::map<std::string, ElementLoader *> ElementLoaderMap; LoaderBase(const Glib::ustring & ns, bool recursive); virtual ~LoaderBase(); - void collectAll(const CommonObjects * co, const xmlpp::Element * node, bool childrenOnly) const; - void collectAll(const xmlpp::Element * node, bool childrenOnly) const; + void collectAll(const CommonObjects * co, const xmlpp::Element * node, bool childrenOnly, UnsupportedHandling uh = ErrorOnUnsupported) const; + void collectAll(const xmlpp::Element * node, bool childrenOnly, UnsupportedHandling uh = ErrorOnUnsupported) const; static ElementLoaderMap & getMap(); template<class Y> |