diff options
-rw-r--r-- | project2/cgi/cgiAppEngine.cpp | 24 | ||||
-rw-r--r-- | project2/cgi/cgiAppEngine.h | 2 | ||||
-rw-r--r-- | project2/commonObjects.cpp | 6 | ||||
-rw-r--r-- | project2/commonObjects.h | 6 | ||||
-rw-r--r-- | project2/console/consoleAppEngine.cpp | 20 | ||||
-rw-r--r-- | project2/console/consoleAppEngine.h | 2 | ||||
-rw-r--r-- | project2/dataSource.h | 2 | ||||
-rw-r--r-- | project2/if.cpp | 16 | ||||
-rw-r--r-- | project2/if.h | 2 | ||||
-rw-r--r-- | project2/iterate.cpp | 8 | ||||
-rw-r--r-- | project2/iterate.h | 2 | ||||
-rw-r--r-- | project2/noOutputExecute.h | 3 | ||||
-rw-r--r-- | project2/paramChecker.h | 3 | ||||
-rw-r--r-- | project2/presenter.cpp | 4 | ||||
-rw-r--r-- | project2/rowSet.cpp | 1 | ||||
-rw-r--r-- | project2/rowSet.h | 8 | ||||
-rw-r--r-- | project2/rowView.cpp | 2 | ||||
-rw-r--r-- | project2/sqlMergeTask.cpp | 11 | ||||
-rw-r--r-- | project2/streamRows.h | 1 | ||||
-rw-r--r-- | project2/view.h | 6 | ||||
-rw-r--r-- | project2/xmlObjectLoader.cpp | 2 | ||||
-rw-r--r-- | project2/xmlObjectLoader.h | 97 | ||||
-rw-r--r-- | project2/xmlPresenter.h | 2 | ||||
-rw-r--r-- | project2/xslRows.h | 1 |
24 files changed, 110 insertions, 121 deletions
diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp index 1d00c18..f3f8d56 100644 --- a/project2/cgi/cgiAppEngine.cpp +++ b/project2/cgi/cgiAppEngine.cpp @@ -96,9 +96,9 @@ CgiApplicationEngine::PresentStage::~PresentStage() CgiApplicationEngine::StagePtr CgiApplicationEngine::PresentStage::run() { - BOOST_FOREACH(OrderedParamCheckers::value_type pc, parameterChecks) { - if (!pc.second->performCheck()) { - return new PresentStage(appEngine, pc.second->present); + BOOST_FOREACH(ParamCheckers::value_type pc, parameterChecks.get<bySOOrder>()) { + if (!pc->performCheck()) { + return new PresentStage(appEngine, pc->present); } } execute(); @@ -164,25 +164,25 @@ CgiApplicationEngine::RequestStage::~RequestStage() CgiApplicationEngine::StagePtr CgiApplicationEngine::RequestStage::run() { - BOOST_FOREACH(OrderedParamCheckers::value_type pc, parameterChecks) { - if (!pc.second->performCheck()) { - return new PresentStage(appEngine, pc.second->present); + BOOST_FOREACH(const ParamCheckers::value_type & pc, parameterChecks.get<bySOOrder>()) { + if (!pc->performCheck()) { + return new PresentStage(appEngine, pc->present); } } try { - BOOST_FOREACH(NoOutputExecutes::value_type t, tasks) { - t.second->execute(); + BOOST_FOREACH(const NoOutputExecutes::value_type & t, tasks.get<bySOOrder>()) { + t->execute(); } // Commit data source transactions (without invoking a connection) - BOOST_FOREACH(DataSources::value_type ds, datasources) { - ds.second->commit(); + BOOST_FOREACH(const DataSources::value_type & ds, datasources) { + ds->commit(); } return new PresentStage(appEngine, present); } catch (...) { // Do something about the error - BOOST_FOREACH(DataSources::value_type ds, datasources) { - ds.second->rollback(); + BOOST_FOREACH(const DataSources::value_type & ds, datasources) { + ds->rollback(); } throw; } diff --git a/project2/cgi/cgiAppEngine.h b/project2/cgi/cgiAppEngine.h index 25c6537..2bef0f6 100644 --- a/project2/cgi/cgiAppEngine.h +++ b/project2/cgi/cgiAppEngine.h @@ -65,7 +65,7 @@ class CgiApplicationEngine : public ApplicationEngine { virtual StagePtr run(); std::string present; protected: - OrderedParamCheckers parameterChecks; + ParamCheckers parameterChecks; NoOutputExecutes tasks; }; diff --git a/project2/commonObjects.cpp b/project2/commonObjects.cpp index 90c8bdc..6d8fc08 100644 --- a/project2/commonObjects.cpp +++ b/project2/commonObjects.cpp @@ -3,9 +3,9 @@ RowSetPtr CommonObjects::getSource(const std::string & name) const { - RowSets::const_iterator i = rowSets.find(name); - if (i != rowSets.end()) { - return i->second; + RowSets::index<bySOName>::type::const_iterator i = rowSets.get<bySOName>().find(name); + if (i != rowSets.get<bySOName>().end()) { + return *i; } throw CommonObjects::DataSourceNotFound(); } diff --git a/project2/commonObjects.h b/project2/commonObjects.h index dc522ba..12b1f2b 100644 --- a/project2/commonObjects.h +++ b/project2/commonObjects.h @@ -13,11 +13,11 @@ class CommonObjects : public virtual IntrusivePtrBase { template <class DataSourceType> const DataSourceType * dataSource(const std::string & name) const { - DataSources::const_iterator i = datasources.find(name); - if (i == datasources.end()) { + DataSources::index<bySOName>::type::const_iterator i = datasources.get<bySOName>().find(name); + if (i == datasources.get<bySOName>().end()) { throw DataSourceNotFound(); } - const DataSourceType * s = dynamic_cast<const DataSourceType *>(i->second.get()); + const DataSourceType * s = dynamic_cast<const DataSourceType *>(i->get()); if (!s) { throw DataSourceNotCompatible(); } diff --git a/project2/console/consoleAppEngine.cpp b/project2/console/consoleAppEngine.cpp index 6053ca9..0d0c71d 100644 --- a/project2/console/consoleAppEngine.cpp +++ b/project2/console/consoleAppEngine.cpp @@ -77,29 +77,29 @@ ConsoleApplicationEngine::~ConsoleApplicationEngine() void ConsoleApplicationEngine::process() const { - BOOST_FOREACH(OrderedParamCheckers::value_type pc, parameterChecks) { - if (!pc.second->performCheck()) { + BOOST_FOREACH(const ParamCheckers::value_type & pc, parameterChecks.get<bySOOrder>()) { + if (!pc->performCheck()) { throw std::runtime_error("Check failed"); } } try { - BOOST_FOREACH(NoOutputExecutes::value_type t, tasks) { - t.second->execute(); + BOOST_FOREACH(const NoOutputExecutes::value_type & t, tasks.get<bySOOrder>()) { + t->execute(); } // Commit data source transactions (without invoking a connection) - BOOST_FOREACH(DataSources::value_type ds, this->datasources) { - ds.second->commit(); + BOOST_FOREACH(const DataSources::value_type & ds, this->datasources) { + ds->commit(); } } catch (...) { // Do something about the error - BOOST_FOREACH(DataSources::value_type ds, this->datasources) { - ds.second->rollback(); + BOOST_FOREACH(const DataSources::value_type & ds, this->datasources) { + ds->rollback(); } throw; } - BOOST_FOREACH(Views::value_type v, views) { - v.second->execute(this); + BOOST_FOREACH(const Views::value_type & v, views) { + v->execute(this); } } diff --git a/project2/console/consoleAppEngine.h b/project2/console/consoleAppEngine.h index c18956f..44d90bd 100644 --- a/project2/console/consoleAppEngine.h +++ b/project2/console/consoleAppEngine.h @@ -44,7 +44,7 @@ class ConsoleApplicationEngine : public ApplicationEngine, public Presenter { private: mutable unsigned int indent; - OrderedParamCheckers parameterChecks; + ParamCheckers parameterChecks; NoOutputExecutes tasks; Views views; SessionPtr runtime; diff --git a/project2/dataSource.h b/project2/dataSource.h index 478feb6..890dc9a 100644 --- a/project2/dataSource.h +++ b/project2/dataSource.h @@ -8,7 +8,7 @@ class DataSource; typedef boost::intrusive_ptr<DataSource> DataSourcePtr; -typedef std::map<std::string, DataSourcePtr> DataSources; +typedef Storage<DataSource>::Objects DataSources; class DataSource : public virtual SourceObject { public: diff --git a/project2/if.cpp b/project2/if.cpp index 9d367bf..8fc210d 100644 --- a/project2/if.cpp +++ b/project2/if.cpp @@ -18,16 +18,16 @@ bool IfSet::passes() const { if (mode == And) { - BOOST_FOREACH(OrderedParamCheckers::value_type pc, checks) { - if (!pc.second->performCheck()) { + BOOST_FOREACH(const ParamCheckers::value_type & pc, checks.get<bySOOrder>()) { + if (!pc->performCheck()) { return false; } } return true; } else { - BOOST_FOREACH(OrderedParamCheckers::value_type pc, checks) { - if (pc.second->performCheck()) { + BOOST_FOREACH(const ParamCheckers::value_type & pc, checks.get<bySOOrder>()) { + if (pc->performCheck()) { return true; } } @@ -52,8 +52,8 @@ 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); + BOOST_FOREACH(const Views::value_type & sq, subViews) { + sq->execute(presenter); } } } @@ -62,8 +62,8 @@ void If::execute() const { if (passes()) { Logger()->message(LOG_DEBUG, "IfSet passed"); - BOOST_FOREACH(NoOutputExecutes::value_type sq, subNOEs) { - sq.second->execute(); + BOOST_FOREACH(const NoOutputExecutes::value_type & sq, subNOEs.get<bySOOrder>()) { + sq->execute(); } } } diff --git a/project2/if.h b/project2/if.h index 403f4b0..8ce08fb 100644 --- a/project2/if.h +++ b/project2/if.h @@ -13,7 +13,7 @@ class IfSet : public virtual IntrusivePtrBase { private: enum Mode { And, Or }; Mode mode; - OrderedParamCheckers checks; + ParamCheckers checks; }; class If : public Iterate, public RowView, public IfSet { diff --git a/project2/iterate.cpp b/project2/iterate.cpp index fa0bd77..fc24ed7 100644 --- a/project2/iterate.cpp +++ b/project2/iterate.cpp @@ -51,14 +51,14 @@ Iterate::execute() const void Iterate::executeChildren() const { - BOOST_FOREACH(NoOutputExecutes::value_type sq, subNOEs) { - if (dynamic_cast<const RowProcessor *>(sq.second.get())) { - sq.second->execute(); + BOOST_FOREACH(const NoOutputExecutes::value_type & sq, subNOEs.get<bySOOrder>()) { + if (dynamic_cast<const RowProcessor *>(sq.get())) { + sq->execute(); } else { RowSet::beginRow(NULL); try { - sq.second->execute(); + sq->execute(); RowSet::endRow(NULL); } catch (...) { diff --git a/project2/iterate.h b/project2/iterate.h index 58b4944..0152ffc 100644 --- a/project2/iterate.h +++ b/project2/iterate.h @@ -11,7 +11,7 @@ class Iterate; typedef boost::intrusive_ptr<Iterate> IteratePtr; -typedef std::map<std::string, IteratePtr> Iterates; +typedef Storage<Iterate>::Objects Iterates; class Iterate : public NoOutputExecute, public RowProcessor { public: diff --git a/project2/noOutputExecute.h b/project2/noOutputExecute.h index 9c476eb..4795ae6 100644 --- a/project2/noOutputExecute.h +++ b/project2/noOutputExecute.h @@ -2,13 +2,14 @@ #define NOOUTPUTEXECUTE_H #include "sourceObject.h" +#include "xmlObjectLoader.h" class ApplicationEngine; class PerRowValues; class NoOutputExecute; typedef boost::intrusive_ptr<NoOutputExecute> NoOutputExecutePtr; -typedef std::map<unsigned int, NoOutputExecutePtr> NoOutputExecutes; +typedef Storage<NoOutputExecute>::Objects NoOutputExecutes; class NoOutputExecute : public virtual SourceObject { public: diff --git a/project2/paramChecker.h b/project2/paramChecker.h index 7d14346..179ff37 100644 --- a/project2/paramChecker.h +++ b/project2/paramChecker.h @@ -11,8 +11,7 @@ class ApplicationEngine; class ParamChecker; typedef boost::intrusive_ptr<ParamChecker> ParamCheckerPtr; -typedef std::map<std::string, ParamCheckerPtr> ParamCheckers; -typedef std::map<unsigned int, ParamCheckerPtr> OrderedParamCheckers; +typedef Storage<ParamChecker>::Objects ParamCheckers; class ParamChecker : public virtual SourceObject { public: diff --git a/project2/presenter.cpp b/project2/presenter.cpp index 888a577..37ae223 100644 --- a/project2/presenter.cpp +++ b/project2/presenter.cpp @@ -13,8 +13,8 @@ Presenter::~Presenter() void Presenter::execute() const { - BOOST_FOREACH(Views::value_type s, views) { - s.second->execute(this); + BOOST_FOREACH(const Views::value_type & s, views) { + s->execute(this); } // These were for debug... but why not pass them on? ApplicationEngine * appEngine = ApplicationEngine::getCurrent(); diff --git a/project2/rowSet.cpp b/project2/rowSet.cpp index 2e4b3f7..2dd4663 100644 --- a/project2/rowSet.cpp +++ b/project2/rowSet.cpp @@ -2,6 +2,7 @@ #include "rowUser.h" #include "commonObjects.h" #include "logger.h" +#include "variables.h" #include <boost/foreach.hpp> #include <boost/bind.hpp> diff --git a/project2/rowSet.h b/project2/rowSet.h index b0bb668..bd17412 100644 --- a/project2/rowSet.h +++ b/project2/rowSet.h @@ -4,18 +4,18 @@ #include <glibmm/ustring.h> #include <vector> #include <set> -#include <map> #include <boost/intrusive_ptr.hpp> #include "sourceObject.h" -#include "iHaveParameters.h" -#include "variables.h" +#include "xmlObjectLoader.h" #include <boost/function.hpp> class RowProcessor; class RowSet; +class RowUser; +class VariableType; typedef boost::intrusive_ptr<RowSet> RowSetPtr; typedef boost::intrusive_ptr<const RowSet> ConstRowSetPtr; -typedef std::map<std::string, RowSetPtr> RowSets; +typedef Storage<RowSet>::Objects RowSets; class RowSet : public virtual SourceObject { public: diff --git a/project2/rowView.cpp b/project2/rowView.cpp index f6e7b67..be1800c 100644 --- a/project2/rowView.cpp +++ b/project2/rowView.cpp @@ -82,7 +82,7 @@ void RowView::executeChildren() const { BOOST_FOREACH(Views::value_type sq, subViews) { - sq.second->execute(presenter); + sq->execute(presenter); } } diff --git a/project2/sqlMergeTask.cpp b/project2/sqlMergeTask.cpp index b37cbf6..8847913 100644 --- a/project2/sqlMergeTask.cpp +++ b/project2/sqlMergeTask.cpp @@ -3,6 +3,7 @@ #include "rdbmsDataSource.h" #include "exceptions.h" #include "sqlVariableBinder.h" +#include "xmlObjectLoader.h" #include <misc.h> #include <stdio.h> #include <stdexcept> @@ -91,7 +92,7 @@ SqlMergeTask::loadComplete(const CommonObjects * co) destdb = &co->dataSource<RdbmsDataSource>(dataSource())->getWritable(); insCmd = insertCommand(); BOOST_FOREACH(const Iterates::value_type & i, sources) { - attach(i.second, insCmd); + attach(i, insCmd); } } @@ -287,9 +288,9 @@ attach(IteratePtr i, ModifyCommand * insert) i->subNOEs.insert(NoOutputExecutes::value_type(0, new Populate(insert))); } else { - BOOST_FOREACH(const NoOutputExecutes::value_type & n, i->subNOEs) { - attach(boost::dynamic_pointer_cast<Iterate>(n.second), insert); - attach(boost::dynamic_pointer_cast<SqlMergeInsert>(n.second), insert); + BOOST_FOREACH(const NoOutputExecutes::value_type & n, i->subNOEs.get<bySOOrder>()) { + attach(boost::dynamic_pointer_cast<Iterate>(n), insert); + attach(boost::dynamic_pointer_cast<SqlMergeInsert>(n), insert); } } } @@ -299,7 +300,7 @@ SqlMergeTask::copyToTempTable() const { if (useView) return; BOOST_FOREACH(const Iterates::value_type & i, sources) { - i.second->execute(); + i->execute(); } BOOST_FOREACH(const std::string & sql, sqls) { Buffer ins; diff --git a/project2/streamRows.h b/project2/streamRows.h index 473a0d8..ffe2dc6 100644 --- a/project2/streamRows.h +++ b/project2/streamRows.h @@ -2,6 +2,7 @@ #define STREAMROWS_H #include "rowSet.h" +#include "variables.h" #include <boost/multi_index_container.hpp> #include <boost/multi_index/member.hpp> #include <boost/multi_index/ordered_index.hpp> diff --git a/project2/view.h b/project2/view.h index 8080824..cfee85b 100644 --- a/project2/view.h +++ b/project2/view.h @@ -1,15 +1,13 @@ #ifndef VIEW_H #define VIEW_H -#include <libxml++/nodes/element.h> -#include <boost/intrusive_ptr.hpp> -#include <map> #include "sourceObject.h" +#include "xmlObjectLoader.h" class Presenter; class View; typedef boost::intrusive_ptr<View> ViewPtr; -typedef std::map<std::string, ViewPtr> Views; +typedef Storage<View>::Objects Views; class View : public virtual SourceObject { public: diff --git a/project2/xmlObjectLoader.cpp b/project2/xmlObjectLoader.cpp index f14f773..17e59d4 100644 --- a/project2/xmlObjectLoader.cpp +++ b/project2/xmlObjectLoader.cpp @@ -1,7 +1,7 @@ #include "xmlObjectLoader.h" #include "exceptions.h" #include "logger.h" -#include <stdio.h> +#include <boost/shared_ptr.hpp> unsigned int LoaderBase::depth = 0; std::set<SourceObjectPtr> LoaderBase::loadedObjects; diff --git a/project2/xmlObjectLoader.h b/project2/xmlObjectLoader.h index 7dec077..4d0346e 100644 --- a/project2/xmlObjectLoader.h +++ b/project2/xmlObjectLoader.h @@ -1,85 +1,73 @@ #ifndef XMLOBJECTLOADER_H #define XMLOBJECTLOADER_H -#include <map> #include <set> #include <string> #include <libxml++/nodes/element.h> #include <boost/intrusive_ptr.hpp> -#include <boost/shared_ptr.hpp> #include <libxml++/nodes/textnode.h> #include <boost/foreach.hpp> #include "intrusivePtrBase.h" #include "sourceObject.h" +#include <boost/multi_index_container.hpp> +#include <boost/multi_index/member.hpp> +#include <boost/multi_index/ordered_index.hpp> Glib::ustring xmlChildText(const xmlpp::Node * p, const Glib::ustring & n); +class StoreFailed : public std::exception { }; + +struct bySOName { }; +struct bySOOrder { }; + class ElementLoader; class CommonObjects; +template <class X> +class Storage { + public: + typedef boost::multi_index::multi_index_container< + boost::intrusive_ptr<X>, + boost::multi_index::indexed_by< + boost::multi_index::ordered_unique< + boost::multi_index::tag<bySOOrder>, BOOST_MULTI_INDEX_MEMBER(SourceObject, const unsigned int, order)>, + boost::multi_index::ordered_unique< + boost::multi_index::tag<bySOName>, BOOST_MULTI_INDEX_MEMBER(SourceObject, const std::string, name)> + > > Objects; + typedef Objects * ObjectsPtr; +}; +class Storer; +typedef boost::intrusive_ptr<Storer> StorerPtr; class Storer : public virtual IntrusivePtrBase { public: - template <class X, class Key> - static boost::intrusive_ptr<Storer> into(std::map<Key, boost::intrusive_ptr<X> > * map); + template <class X> + static StorerPtr into(X * map); virtual bool save(SourceObjectPtr o) const = 0; }; -template <class X, class K> -class StorerImplBase : public Storer { - public: - typedef K Key; - StorerImplBase(std::map<Key, boost::intrusive_ptr<X> > * m) : map(m) - { - } - std::map<Key, boost::intrusive_ptr<X> > * map; -}; -template <class X, class K> -class StorerImpl; - -template <typename X> -class StorerImpl<X, unsigned int> : public StorerImplBase<X, unsigned int> { +template <class X> +class StorerImpl : public Storer { public: - typedef unsigned int Key; - typedef boost::intrusive_ptr<X> Ptr; - StorerImpl(std::map<Key, Ptr> * m) : StorerImplBase<X, Key>(m) - { - } - bool save(SourceObjectPtr obj) const + StorerImpl(typename Storage<X>::ObjectsPtr m) : map(m) { - Ptr O = boost::dynamic_pointer_cast<X>(obj); - if (O) { - StorerImplBase<X, Key>::map->insert(std::pair<Key, Ptr>(O->order, O)); - return true; - } - return false; } -}; -template <typename X> -class StorerImpl<X, std::string> : public StorerImplBase<X, std::string> { - public: - typedef std::string Key; - typedef boost::intrusive_ptr<X> Ptr; - StorerImpl(std::map<Key, Ptr> * m) : StorerImplBase<X, Key>(m) - { - } - bool save(SourceObjectPtr obj) const - { - Ptr O = boost::dynamic_pointer_cast<X>(obj); + bool save(SourceObjectPtr obj) const { + boost::intrusive_ptr<X> O = boost::dynamic_pointer_cast<X>(obj); if (O) { - StorerImplBase<X, Key>::map->insert(std::pair<Key, Ptr>(O->name, O)); + map->insert(O); return true; } return false; } + typename Storage<X>::ObjectsPtr map; }; -template <class X, class Key> -boost::intrusive_ptr<Storer> -Storer::into(std::map<Key, boost::intrusive_ptr<X> > * map) -{ - return new StorerImpl<X, Key>(map); +template <class X> +StorerPtr +Storer::into(X * map) { + return new StorerImpl<typename X::value_type::element_type>(map); } enum UnsupportedHandling { ErrorOnUnsupported, WarnOnUnsupported, IgnoreUnsupported }; @@ -88,15 +76,13 @@ class LoaderBase { public: LoaderBase(const Glib::ustring & ns, bool recursive); virtual ~LoaderBase(); - 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; - - template<class Y> - static void save(std::map<unsigned int, boost::intrusive_ptr<Y> > * map, boost::intrusive_ptr<Y> obj); - template<class Y> - static void save(std::map<std::string, boost::intrusive_ptr<Y> > * map, boost::intrusive_ptr<Y> obj); + 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; std::set<boost::intrusive_ptr<Storer> > supportedStorers; + static void onIdle(); static void onIteration(); static void onPeriodic(); @@ -109,6 +95,7 @@ class LoaderBase { static std::set<SourceObjectPtr> loadedObjects; const bool recursive; + public: const Glib::ustring ns; }; diff --git a/project2/xmlPresenter.h b/project2/xmlPresenter.h index 72fc3aa..1c520a8 100644 --- a/project2/xmlPresenter.h +++ b/project2/xmlPresenter.h @@ -25,7 +25,7 @@ class XmlPresenter : public Presenter { const Glib::ustring contentType; protected: - OrderedParamCheckers parameterChecks; + ParamCheckers parameterChecks; private: XmlDocumentPtr responseDoc; diff --git a/project2/xslRows.h b/project2/xslRows.h index e3aae63..8f13c89 100644 --- a/project2/xslRows.h +++ b/project2/xslRows.h @@ -6,6 +6,7 @@ #include <boost/intrusive_ptr.hpp> #include <map> #include "rowSet.h" +#include "variables.h" class XslRows : public RowSet { public: |