From db5559c6175ffba57a7c4d946be9adff4e66e2e3 Mon Sep 17 00:00:00 2001 From: randomdan Date: Sat, 19 Feb 2011 17:19:49 +0000 Subject: Tidy up the class hierarchy and reduce header dependencies --- project2/cgi/cgiAppEngine.cpp | 3 +- project2/cgi/cgiAppEngine.h | 4 ++- project2/commonObjects.cpp | 3 +- project2/commonObjects.h | 6 +++- project2/console/consoleAppEngine.cpp | 5 +-- project2/console/consoleAppEngine.h | 5 ++- project2/console/p2consoleMain.cpp | 2 ++ project2/dataSource.h | 3 -- project2/if.cpp | 5 +-- project2/if.h | 1 + project2/iterate.cpp | 2 +- project2/iterate.h | 9 ++--- project2/noOutputExecute.h | 2 -- project2/paramChecker.cpp | 1 + project2/paramChecker.h | 5 --- project2/presenter.cpp | 3 +- project2/presenter.h | 1 + project2/rawView.cpp | 2 ++ project2/rdbmsDataSource.cpp | 1 + project2/rdbmsDataSource.h | 1 + project2/regexCheck.h | 1 + project2/rowProcessor.h | 2 +- project2/rowSet.h | 5 +-- project2/rowView.cpp | 4 ++- project2/rowView.h | 4 +-- project2/sqlCheck.cpp | 1 + project2/sqlMergeTask.cpp | 10 +++--- project2/sqlMergeTask.h | 3 +- project2/sqlRows.cpp | 1 + project2/task.h | 2 +- project2/view.h | 5 +-- project2/xmlObjectLoader.cpp | 3 ++ project2/xmlObjectLoader.h | 65 +++------------------------------- project2/xmlPresenter.cpp | 2 ++ project2/xmlPresenter.h | 1 + project2/xmlRows.cpp | 1 + project2/xmlStorage.h | 66 +++++++++++++++++++++++++++++++++++ project2/xslRows.cpp | 1 + 38 files changed, 135 insertions(+), 106 deletions(-) create mode 100644 project2/xmlStorage.h diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp index 345932a..40d1431 100644 --- a/project2/cgi/cgiAppEngine.cpp +++ b/project2/cgi/cgiAppEngine.cpp @@ -7,6 +7,7 @@ #include "../iterate.h" #include #include +#include #include "../sessionXml.h" const std::string SESSIONID = "sessionID"; @@ -169,7 +170,7 @@ CgiApplicationEngine::RequestStage::run() } } try { - BOOST_FOREACH(const NoOutputExecutes::value_type & t, tasks.get()) { + BOOST_FOREACH(const Tasks::value_type & t, tasks.get()) { t->execute(); } // Commit data source transactions (without invoking a connection) diff --git a/project2/cgi/cgiAppEngine.h b/project2/cgi/cgiAppEngine.h index 2bef0f6..1425207 100644 --- a/project2/cgi/cgiAppEngine.h +++ b/project2/cgi/cgiAppEngine.h @@ -65,8 +65,10 @@ class CgiApplicationEngine : public ApplicationEngine { virtual StagePtr run(); std::string present; protected: + typedef Storage::Objects ParamCheckers; ParamCheckers parameterChecks; - NoOutputExecutes tasks; + typedef Storage::Objects Tasks; + Tasks tasks; }; class PresentStage : public Stage, public XmlPresenter { diff --git a/project2/commonObjects.cpp b/project2/commonObjects.cpp index 89eb913..fcf479c 100644 --- a/project2/commonObjects.cpp +++ b/project2/commonObjects.cpp @@ -1,4 +1,5 @@ #include "commonObjects.h" +#include "xmlObjectLoader.h" #include #include @@ -18,7 +19,7 @@ CommonObjects::getSource(const std::string & name) const throw CommonObjects::DataSourceNotFound(name); } -DataSources::index::type::const_iterator +CommonObjects::DataSources::index::type::const_iterator CommonObjects::loadDataSource(const std::string & name) const { xmlpp::DomParser xml("datasources/" + name + ".xml"); diff --git a/project2/commonObjects.h b/project2/commonObjects.h index 32be835..dccdb20 100644 --- a/project2/commonObjects.h +++ b/project2/commonObjects.h @@ -3,9 +3,13 @@ #include "dataSource.h" #include "rowSet.h" +#include "xmlStorage.h" class CommonObjects : public virtual IntrusivePtrBase { public: + typedef Storage::Objects RowSets; + typedef Storage::Objects DataSources; + SimpleMessageException(DataSourceNotFound); SimpleMessageException(DataSourceNotCompatible); @@ -15,7 +19,7 @@ class CommonObjects : public virtual IntrusivePtrBase { template const DataSourceType * dataSource(const std::string & name) const { - DataSources::index::type::const_iterator i = datasources.get().find(name); + Storage::Objects::index::type::const_iterator i = datasources.get().find(name); if (i == datasources.get().end()) { i = loadDataSource(name); } diff --git a/project2/console/consoleAppEngine.cpp b/project2/console/consoleAppEngine.cpp index c0eac5e..7ef1ad0 100644 --- a/project2/console/consoleAppEngine.cpp +++ b/project2/console/consoleAppEngine.cpp @@ -1,9 +1,10 @@ #include "consoleAppEngine.h" #include "consoleEnvironment.h" #include "../iterate.h" -#include +#include "../xmlObjectLoader.h" #include #include +#include SimpleMessageException(UnknownPlatformAlias); @@ -82,7 +83,7 @@ ConsoleApplicationEngine::process() const } } try { - BOOST_FOREACH(const NoOutputExecutes::value_type & t, tasks.get()) { + BOOST_FOREACH(const Tasks::value_type & t, tasks.get()) { t->execute(); } // Commit data source transactions (without invoking a connection) diff --git a/project2/console/consoleAppEngine.h b/project2/console/consoleAppEngine.h index 44d90bd..d8cdca5 100644 --- a/project2/console/consoleAppEngine.h +++ b/project2/console/consoleAppEngine.h @@ -44,8 +44,11 @@ class ConsoleApplicationEngine : public ApplicationEngine, public Presenter { private: mutable unsigned int indent; + typedef Storage::Objects ParamCheckers; ParamCheckers parameterChecks; - NoOutputExecutes tasks; + typedef Storage::Objects Tasks; + Tasks tasks; + typedef Storage::Objects Views; Views views; SessionPtr runtime; FileStreamVariableWriter out; diff --git a/project2/console/p2consoleMain.cpp b/project2/console/p2consoleMain.cpp index eee7603..4584126 100644 --- a/project2/console/p2consoleMain.cpp +++ b/project2/console/p2consoleMain.cpp @@ -1,7 +1,9 @@ #include #include "consoleEnvironment.h" #include "consoleAppEngine.h" +#include "../xmlObjectLoader.h" #include "../logger.h" +#include int main(int argc, char ** argv) diff --git a/project2/dataSource.h b/project2/dataSource.h index 890dc9a..81a59ad 100644 --- a/project2/dataSource.h +++ b/project2/dataSource.h @@ -2,13 +2,10 @@ #define DATASOURCE_H #include -#include #include "sourceObject.h" -#include "xmlObjectLoader.h" class DataSource; typedef boost::intrusive_ptr DataSourcePtr; -typedef Storage::Objects DataSources; class DataSource : public virtual SourceObject { public: diff --git a/project2/if.cpp b/project2/if.cpp index 4531b89..fe47059 100644 --- a/project2/if.cpp +++ b/project2/if.cpp @@ -1,6 +1,7 @@ #include "if.h" #include "logger.h" #include "xmlObjectLoader.h" +#include DECLARE_LOADER("if", If); @@ -54,7 +55,7 @@ If::execute(const Presenter * presenter) const { if (passes()) { Logger()->messagef(LOG_DEBUG, "IfSet passed, showing %zu views", subViews.size()); - BOOST_FOREACH(const Views::value_type & sq, subViews) { + BOOST_FOREACH(const SubViews::value_type & sq, subViews) { sq->execute(presenter); } } @@ -65,7 +66,7 @@ If::execute() const { if (passes()) { Logger()->message(LOG_DEBUG, "IfSet passed"); - BOOST_FOREACH(const NoOutputExecutes::value_type & sq, subNOEs.get()) { + BOOST_FOREACH(const SubNOEs::value_type & sq, subNOEs.get()) { sq->execute(); } } diff --git a/project2/if.h b/project2/if.h index 26aef1a..87fc1ee 100644 --- a/project2/if.h +++ b/project2/if.h @@ -14,6 +14,7 @@ class IfSet : public virtual IntrusivePtrBase { virtual const std::string & getName() const = 0; enum Mode { And, Or }; Mode mode; + typedef Storage::Objects ParamCheckers; ParamCheckers checks; }; diff --git a/project2/iterate.cpp b/project2/iterate.cpp index fc24ed7..f0097c8 100644 --- a/project2/iterate.cpp +++ b/project2/iterate.cpp @@ -51,7 +51,7 @@ Iterate::execute() const void Iterate::executeChildren() const { - BOOST_FOREACH(const NoOutputExecutes::value_type & sq, subNOEs.get()) { + BOOST_FOREACH(const SubNOEs::value_type & sq, subNOEs.get()) { if (dynamic_cast(sq.get())) { sq->execute(); } diff --git a/project2/iterate.h b/project2/iterate.h index 0152ffc..2c7eeba 100644 --- a/project2/iterate.h +++ b/project2/iterate.h @@ -2,16 +2,12 @@ #define ITERATE_H #include -#include -#include -#include "sourceObject.h" -#include "xmlObjectLoader.h" #include "rowProcessor.h" #include "noOutputExecute.h" +#include "xmlStorage.h" class Iterate; typedef boost::intrusive_ptr IteratePtr; -typedef Storage::Objects Iterates; class Iterate : public NoOutputExecute, public RowProcessor { public: @@ -22,7 +18,8 @@ class Iterate : public NoOutputExecute, public RowProcessor { void rowReady() const; void execute() const; - NoOutputExecutes subNOEs; + typedef Storage::Objects SubNOEs; + SubNOEs subNOEs; protected: void executeChildren() const; diff --git a/project2/noOutputExecute.h b/project2/noOutputExecute.h index 4795ae6..ec73ce1 100644 --- a/project2/noOutputExecute.h +++ b/project2/noOutputExecute.h @@ -2,14 +2,12 @@ #define NOOUTPUTEXECUTE_H #include "sourceObject.h" -#include "xmlObjectLoader.h" class ApplicationEngine; class PerRowValues; class NoOutputExecute; typedef boost::intrusive_ptr NoOutputExecutePtr; -typedef Storage::Objects NoOutputExecutes; class NoOutputExecute : public virtual SourceObject { public: diff --git a/project2/paramChecker.cpp b/project2/paramChecker.cpp index 71b5a74..aa1dbff 100644 --- a/project2/paramChecker.cpp +++ b/project2/paramChecker.cpp @@ -1,4 +1,5 @@ #include "paramChecker.h" +#include "xmlObjectLoader.h" ParamChecker::ParamChecker(const xmlpp::Element * p) : SourceObject(p), diff --git a/project2/paramChecker.h b/project2/paramChecker.h index 179ff37..219396c 100644 --- a/project2/paramChecker.h +++ b/project2/paramChecker.h @@ -2,16 +2,11 @@ #define PARAMCHECKER_H #include -#include -#include #include "sourceObject.h" -#include "xmlObjectLoader.h" -#include "variables.h" class ApplicationEngine; class ParamChecker; typedef boost::intrusive_ptr ParamCheckerPtr; -typedef Storage::Objects ParamCheckers; class ParamChecker : public virtual SourceObject { public: diff --git a/project2/presenter.cpp b/project2/presenter.cpp index 37ae223..11f2996 100644 --- a/project2/presenter.cpp +++ b/project2/presenter.cpp @@ -1,6 +1,7 @@ #include "presenter.h" #include "dataSource.h" #include "appEngine.h" +#include Presenter::Presenter() { @@ -13,7 +14,7 @@ Presenter::~Presenter() void Presenter::execute() const { - BOOST_FOREACH(const Views::value_type & s, views) { + BOOST_FOREACH(const Storage::Objects::value_type & s, views) { s->execute(this); } // These were for debug... but why not pass them on? diff --git a/project2/presenter.h b/project2/presenter.h index 4c54a7b..6b75c5a 100644 --- a/project2/presenter.h +++ b/project2/presenter.h @@ -25,6 +25,7 @@ class Presenter : public virtual CommonObjects, public virtual IntrusivePtrBase void execute() const; protected: + typedef Storage::Objects Views; Views views; }; diff --git a/project2/rawView.cpp b/project2/rawView.cpp index 325460a..d9ca15b 100644 --- a/project2/rawView.cpp +++ b/project2/rawView.cpp @@ -4,6 +4,8 @@ #include "xmlObjectLoader.h" #include "environment.h" #include "appEngine.h" +#include +#include DECLARE_LOADER("rawview", RawView); diff --git a/project2/rdbmsDataSource.cpp b/project2/rdbmsDataSource.cpp index 9ffcc93..7ff4408 100644 --- a/project2/rdbmsDataSource.cpp +++ b/project2/rdbmsDataSource.cpp @@ -5,6 +5,7 @@ #include "logger.h" #include #include +#include static const int NOTSET = 0; #ifdef WITH_PQ diff --git a/project2/rdbmsDataSource.h b/project2/rdbmsDataSource.h index f105eed..4026f48 100644 --- a/project2/rdbmsDataSource.h +++ b/project2/rdbmsDataSource.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "dataSource.h" #include "../libdbpp/connection.h" #include "../libdbpp/error.h" diff --git a/project2/regexCheck.h b/project2/regexCheck.h index be55e9b..41bb2c8 100644 --- a/project2/regexCheck.h +++ b/project2/regexCheck.h @@ -2,6 +2,7 @@ #define REGEXCHECK_H #include "paramChecker.h" +#include "variables.h" class RegexCheck : public ParamChecker { public: diff --git a/project2/rowProcessor.h b/project2/rowProcessor.h index f47d04e..e4377bd 100644 --- a/project2/rowProcessor.h +++ b/project2/rowProcessor.h @@ -16,7 +16,7 @@ class RowProcessor : public IHaveParameters, public virtual SourceObject { const Glib::ustring filter; protected: - RowSetPtr source; + boost::intrusive_ptr source; }; #endif diff --git a/project2/rowSet.h b/project2/rowSet.h index 9a74719..d2e4b1f 100644 --- a/project2/rowSet.h +++ b/project2/rowSet.h @@ -1,12 +1,10 @@ #ifndef ROWSET_H #define ROWSET_H -#include #include #include -#include #include "sourceObject.h" -#include "xmlObjectLoader.h" +#include "exceptions.h" #include class RowProcessor; @@ -15,7 +13,6 @@ class RowUser; class VariableType; typedef boost::intrusive_ptr RowSetPtr; typedef boost::intrusive_ptr ConstRowSetPtr; -typedef Storage::Objects RowSets; class RowSet : public virtual SourceObject { public: diff --git a/project2/rowView.cpp b/project2/rowView.cpp index 864580a..e036dd7 100644 --- a/project2/rowView.cpp +++ b/project2/rowView.cpp @@ -1,6 +1,8 @@ #include "rowView.h" #include "presenter.h" +#include "xmlObjectLoader.h" #include +#include DECLARE_LOADER("view", RowView); @@ -77,7 +79,7 @@ RowView::execute(const Presenter * p) const void RowView::executeChildren() const { - BOOST_FOREACH(Views::value_type sq, subViews) { + BOOST_FOREACH(const SubViews::value_type & sq, subViews) { sq->execute(presenter); } } diff --git a/project2/rowView.h b/project2/rowView.h index fb22b2b..a866558 100644 --- a/project2/rowView.h +++ b/project2/rowView.h @@ -3,7 +3,6 @@ #include #include -#include "sourceObject.h" #include "rowProcessor.h" #include "view.h" @@ -24,7 +23,8 @@ class RowView : public View, public RowProcessor { Columns viewColumns; void executeChildren() const; - Views subViews; + typedef Storage::Objects SubViews; + SubViews subViews; mutable const Presenter * presenter; }; diff --git a/project2/sqlCheck.cpp b/project2/sqlCheck.cpp index a6e71a1..766f16d 100644 --- a/project2/sqlCheck.cpp +++ b/project2/sqlCheck.cpp @@ -6,6 +6,7 @@ #include #include "commonObjects.h" #include "sqlVariableBinder.h" +#include DECLARE_LOADER("sqlcheck", SqlCheck); diff --git a/project2/sqlMergeTask.cpp b/project2/sqlMergeTask.cpp index e3a28f1..a2dfe72 100644 --- a/project2/sqlMergeTask.cpp +++ b/project2/sqlMergeTask.cpp @@ -8,13 +8,15 @@ #include #include #include +#include +#include bool SqlMergeTask::defaultUseTempTable = true; static void attach(IteratePtr i, ModifyCommand * insert); class SqlMergeInsert; typedef boost::intrusive_ptr SqlMergeInsertPtr; -class SqlMergeInsert : public IHaveParameters, public virtual SourceObject, public Task { +class SqlMergeInsert : public IHaveParameters, public Task { public: SqlMergeInsert(const xmlpp::Element * p) : SourceObject(p), @@ -91,7 +93,7 @@ SqlMergeTask::loadComplete(const CommonObjects * co) { destdb = &co->dataSource(dataSource())->getWritable(); insCmd = insertCommand(); - BOOST_FOREACH(const Iterates::value_type & i, sources) { + BOOST_FOREACH(const Sources::value_type & i, sources) { attach(i, insCmd); } } @@ -288,7 +290,7 @@ attach(IteratePtr i, ModifyCommand * insert) i->subNOEs.insert(new Populate(insert)); } else { - BOOST_FOREACH(const NoOutputExecutes::value_type & n, i->subNOEs.get()) { + BOOST_FOREACH(const Iterate::SubNOEs::value_type & n, i->subNOEs.get()) { attach(boost::dynamic_pointer_cast(n), insert); attach(boost::dynamic_pointer_cast(n), insert); } @@ -299,7 +301,7 @@ void SqlMergeTask::copyToTempTable() const { if (useView) return; - BOOST_FOREACH(const Iterates::value_type & i, sources) { + BOOST_FOREACH(const Sources::value_type & i, sources) { i->execute(); } BOOST_FOREACH(const std::string & sql, sqls) { diff --git a/project2/sqlMergeTask.h b/project2/sqlMergeTask.h index 85a6b4e..fc33bc5 100644 --- a/project2/sqlMergeTask.h +++ b/project2/sqlMergeTask.h @@ -57,7 +57,8 @@ class SqlMergeTask : public Task { void createTempKey() const; mutable bool tempTableCreated; - Iterates sources; + typedef Storage::Objects Sources; + Sources sources; std::list sqls; protected: ModifyCommand * insertCommand() const; diff --git a/project2/sqlRows.cpp b/project2/sqlRows.cpp index 5a57fc7..14bdd41 100644 --- a/project2/sqlRows.cpp +++ b/project2/sqlRows.cpp @@ -11,6 +11,7 @@ #include "sqlVariableBinder.h" #include #include +#include DECLARE_LOADER("sqlrows", SqlRows); diff --git a/project2/task.h b/project2/task.h index dc47b07..f9fd1ff 100644 --- a/project2/task.h +++ b/project2/task.h @@ -5,7 +5,7 @@ #include "sourceObject.h" #include "noOutputExecute.h" -class Task : public virtual SourceObject, public NoOutputExecute { +class Task : public NoOutputExecute { public: Task(const xmlpp::Element * p); virtual ~Task(); diff --git a/project2/view.h b/project2/view.h index cfee85b..a6ae565 100644 --- a/project2/view.h +++ b/project2/view.h @@ -2,12 +2,9 @@ #define VIEW_H #include "sourceObject.h" -#include "xmlObjectLoader.h" +#include "xmlStorage.h" class Presenter; -class View; -typedef boost::intrusive_ptr ViewPtr; -typedef Storage::Objects Views; class View : public virtual SourceObject { public: diff --git a/project2/xmlObjectLoader.cpp b/project2/xmlObjectLoader.cpp index 17e59d4..e16c9e1 100644 --- a/project2/xmlObjectLoader.cpp +++ b/project2/xmlObjectLoader.cpp @@ -1,7 +1,10 @@ #include "xmlObjectLoader.h" +#include "xmlStorage.h" #include "exceptions.h" #include "logger.h" #include +#include +#include unsigned int LoaderBase::depth = 0; std::set LoaderBase::loadedObjects; diff --git a/project2/xmlObjectLoader.h b/project2/xmlObjectLoader.h index 4568124..9fba5bd 100644 --- a/project2/xmlObjectLoader.h +++ b/project2/xmlObjectLoader.h @@ -3,77 +3,20 @@ #include #include -#include #include -#include -#include #include "intrusivePtrBase.h" #include "sourceObject.h" #include "exceptions.h" -#include -#include -#include +namespace xmlpp { + class Element; +} Glib::ustring xmlChildText(const xmlpp::Node * p, const Glib::ustring & n); -SimpleMessageException(StoreFailed); - -struct bySOName { }; -struct bySOOrder { }; - +enum UnsupportedHandling { ErrorOnUnsupported, WarnOnUnsupported, IgnoreUnsupported }; class ElementLoader; class CommonObjects; - -template -class Storage { - public: - typedef boost::multi_index::multi_index_container< - boost::intrusive_ptr, - boost::multi_index::indexed_by< - boost::multi_index::ordered_unique< - boost::multi_index::tag, BOOST_MULTI_INDEX_MEMBER(SourceObject, const unsigned int, order)>, - boost::multi_index::ordered_unique< - boost::multi_index::tag, BOOST_MULTI_INDEX_MEMBER(SourceObject, const std::string, name)> - > > Objects; - typedef Objects * ObjectsPtr; -}; class Storer; -typedef boost::intrusive_ptr StorerPtr; -class Storer : public virtual IntrusivePtrBase { - public: - template - static StorerPtr into(X * map); - - virtual bool save(SourceObjectPtr o) const = 0; -}; - -template -class StorerImpl : public Storer { - public: - StorerImpl(typename Storage::ObjectsPtr m) : map(m) - { - } - - bool save(SourceObjectPtr obj) const { - boost::intrusive_ptr O = boost::dynamic_pointer_cast(obj); - if (O) { - if (map->insert(O).second) { - return true; - } - throw StoreFailed(obj->name); - } - return false; - } - typename Storage::ObjectsPtr map; -}; - -template -StorerPtr -Storer::into(X * map) { - return new StorerImpl(map); -} - -enum UnsupportedHandling { ErrorOnUnsupported, WarnOnUnsupported, IgnoreUnsupported }; class LoaderBase { public: diff --git a/project2/xmlPresenter.cpp b/project2/xmlPresenter.cpp index a8db552..906d2c9 100644 --- a/project2/xmlPresenter.cpp +++ b/project2/xmlPresenter.cpp @@ -1,5 +1,7 @@ #include "xmlPresenter.h" +#include "xmlObjectLoader.h" #include +#include "variables.h" XmlPresenter::~XmlPresenter() { diff --git a/project2/xmlPresenter.h b/project2/xmlPresenter.h index 1c520a8..effa713 100644 --- a/project2/xmlPresenter.h +++ b/project2/xmlPresenter.h @@ -25,6 +25,7 @@ class XmlPresenter : public Presenter { const Glib::ustring contentType; protected: + typedef Storage::Objects ParamCheckers; ParamCheckers parameterChecks; private: diff --git a/project2/xmlRows.cpp b/project2/xmlRows.cpp index 0056084..6cf7da0 100644 --- a/project2/xmlRows.cpp +++ b/project2/xmlRows.cpp @@ -9,6 +9,7 @@ #include #include #include +#include DECLARE_LOADER("xmlrows", XmlRows); diff --git a/project2/xmlStorage.h b/project2/xmlStorage.h new file mode 100644 index 0000000..d35a182 --- /dev/null +++ b/project2/xmlStorage.h @@ -0,0 +1,66 @@ +#ifndef XMLSTORAGE_H +#define XMLSTORAGE_H + +#include "sourceObject.h" +#include "exceptions.h" +#include +#include +#include +#include + +SimpleMessageException(StoreFailed); + +struct bySOName { }; +struct bySOOrder { }; + +template +class Storage { + public: + typedef boost::multi_index::multi_index_container< + boost::intrusive_ptr, + boost::multi_index::indexed_by< + boost::multi_index::ordered_unique< + boost::multi_index::tag, BOOST_MULTI_INDEX_MEMBER(SourceObject, const unsigned int, order)>, + boost::multi_index::ordered_unique< + boost::multi_index::tag, BOOST_MULTI_INDEX_MEMBER(SourceObject, const std::string, name)> + > > Objects; + typedef Objects * ObjectsPtr; +}; +class Storer; +typedef boost::intrusive_ptr StorerPtr; +class Storer : public virtual IntrusivePtrBase { + public: + template + static StorerPtr into(X * map); + + virtual bool save(SourceObjectPtr o) const = 0; +}; + +template +class StorerImpl : public Storer { + public: + StorerImpl(typename Storage::ObjectsPtr m) : map(m) + { + } + + bool save(SourceObjectPtr obj) const { + boost::intrusive_ptr O = boost::dynamic_pointer_cast(obj); + if (O) { + if (map->insert(O).second) { + return true; + } + throw StoreFailed(obj->name); + } + return false; + } + typename Storage::ObjectsPtr map; +}; + +template +StorerPtr +Storer::into(X * map) { + return new StorerImpl(map); +} + +#endif + diff --git a/project2/xslRows.cpp b/project2/xslRows.cpp index 7f53e91..e00d8b7 100644 --- a/project2/xslRows.cpp +++ b/project2/xslRows.cpp @@ -9,6 +9,7 @@ #include #include #include "../libmisc/curlsup.h" +#include DECLARE_LOADER("xslrows", XslRows); -- cgit v1.2.3