diff options
author | randomdan <randomdan@localhost> | 2010-08-24 20:41:54 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2010-08-24 20:41:54 +0000 |
commit | 64992fdf169c55f8575e9d3926a66d8bb90f39d2 (patch) | |
tree | e24f74a9b227d13ee91c55d65e47d983cb0cd179 | |
parent | Add option to use a temporary view instead of a table to reduce WAL churn dur... (diff) | |
download | project2-64992fdf169c55f8575e9d3926a66d8bb90f39d2.tar.bz2 project2-64992fdf169c55f8575e9d3926a66d8bb90f39d2.tar.xz project2-64992fdf169c55f8575e9d3926a66d8bb90f39d2.zip |
Whole new low dependency object loader
Switch to using intrusive_ptr in cases where the class is mine
Remove deps of funtional type base cpp files on implementation headers
General tidy up in places
Post load event and removal of mutable things initialised on first run
53 files changed, 464 insertions, 294 deletions
diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp index 98cb397..f37172e 100644 --- a/project2/cgi/cgiAppEngine.cpp +++ b/project2/cgi/cgiAppEngine.cpp @@ -87,7 +87,7 @@ CgiApplicationEngine::Stage * CgiApplicationEngine::PresentStage::run() { BOOST_FOREACH(OrderedParamCheckers::value_type pc, parameterChecks) { - if (!pc.second->performCheck(appEngine)) { + if (!pc.second->performCheck()) { return new PresentStage(appEngine, pc.second->present); } } @@ -147,12 +147,11 @@ CgiApplicationEngine::RequestStage::RequestStage(const CgiApplicationEngine * e, xmlpp::Element * requestRoot = request.get_document()->get_root_node(); present = requestRoot->get_attribute_value("present"); - Loaders loaders; - _DataSource::AddLoaders(loaders, appEngine->datasources); - _ParamChecker::AddLoaders(loaders, parameterChecks); - _Task::AddLoaders(loaders, tasks); - _Iterate::AddLoaders(loaders, tasks); - _LoaderBase::collectAll(loaders, "project2", requestRoot, true, true); + LoaderBase loader; + loader.supportedStorers.insert(Storer::into(&appEngine->datasources)); + loader.supportedStorers.insert(Storer::into(¶meterChecks)); + loader.supportedStorers.insert(Storer::into(&tasks)); + loader.collectAll("project2", requestRoot, true, true); } CgiApplicationEngine::RequestStage::~RequestStage() { @@ -161,7 +160,7 @@ CgiApplicationEngine::Stage * CgiApplicationEngine::RequestStage::run() { BOOST_FOREACH(OrderedParamCheckers::value_type pc, parameterChecks) { - if (!pc.second->performCheck(appEngine)) { + if (!pc.second->performCheck()) { return new PresentStage(appEngine, pc.second->present); } } diff --git a/project2/cgi/cgiAppEngine.h b/project2/cgi/cgiAppEngine.h index 112e672..cebb294 100644 --- a/project2/cgi/cgiAppEngine.h +++ b/project2/cgi/cgiAppEngine.h @@ -5,7 +5,7 @@ #include "../task.h" #include "../paramChecker.h" #include "../presenter.h" -#include <boost/shared_ptr.hpp> +#include <boost/intrusive_ptr.hpp> #include <boost/uuid/uuid.hpp> #include <libxml++/document.h> #include <libxml++/parsers/domparser.h> diff --git a/project2/console/consoleAppEngine.cpp b/project2/console/consoleAppEngine.cpp index 5955538..035f60a 100644 --- a/project2/console/consoleAppEngine.cpp +++ b/project2/console/consoleAppEngine.cpp @@ -11,12 +11,11 @@ ConsoleApplicationEngine::ConsoleApplicationEngine(const ConsoleEnvironment * en while (xmlXIncludeProcessFlags(request.get_document()->cobj(), XML_PARSE_NOXINCNODE) > 0); xmlpp::Element * requestRoot = request.get_document()->get_root_node(); - Loaders loaders; - _DataSource::AddLoaders(loaders, this->datasources); - _ParamChecker::AddLoaders(loaders, parameterChecks); - _Task::AddLoaders(loaders, tasks); - _Iterate::AddLoaders(loaders, tasks); - _LoaderBase::collectAll(loaders, "project2", requestRoot, true, true); + LoaderBase loader; + loader.supportedStorers.insert(Storer::into(&this->datasources)); + loader.supportedStorers.insert(Storer::into(¶meterChecks)); + loader.supportedStorers.insert(Storer::into(&tasks)); + loader.collectAll("project2", requestRoot, true, true); } ConsoleApplicationEngine::~ConsoleApplicationEngine() @@ -27,7 +26,7 @@ void ConsoleApplicationEngine::process() const { BOOST_FOREACH(OrderedParamCheckers::value_type pc, parameterChecks) { - if (!pc.second->performCheck(this)) { + if (!pc.second->performCheck()) { throw std::runtime_error("Check failed"); } } diff --git a/project2/console/consoleAppEngine.h b/project2/console/consoleAppEngine.h index 7ff1059..fb9597e 100644 --- a/project2/console/consoleAppEngine.h +++ b/project2/console/consoleAppEngine.h @@ -5,7 +5,7 @@ #include "../task.h" #include "../paramChecker.h" #include "../presenter.h" -#include <boost/shared_ptr.hpp> +#include <boost/intrusive_ptr.hpp> #include <boost/uuid/uuid.hpp> #include <boost/filesystem/path.hpp> #include <libxml++/document.h> diff --git a/project2/dataSource.cpp b/project2/dataSource.cpp index 9b6bd18..6da997e 100644 --- a/project2/dataSource.cpp +++ b/project2/dataSource.cpp @@ -1,7 +1,4 @@ #include "dataSource.h" -#include "xmlObjectLoader.h" -#include <libxml++/nodes/textnode.h> -#include "rdbmsDataSource.h" _DataSource::_DataSource(const xmlpp::Element * p) : _SourceObject(p) @@ -12,8 +9,3 @@ _DataSource::~_DataSource() { } -void -_DataSource::AddLoaders(Loaders & l, DataSources & dss) -{ - l.insert(LoadersVT("rdbmsdatasource", _LoaderBase::Make<_RdbmsDataSource, _DataSource, std::string, _SourceObject, &_SourceObject::name>(&dss))); -} diff --git a/project2/dataSource.h b/project2/dataSource.h index 0cc0124..297f048 100644 --- a/project2/dataSource.h +++ b/project2/dataSource.h @@ -2,13 +2,13 @@ #define DATASOURCE_H #include <libxml/tree.h> -#include <boost/shared_ptr.hpp> +#include <boost/intrusive_ptr.hpp> #include <map> #include "sourceObject.h" #include "xmlObjectLoader.h" class _DataSource; -typedef boost::shared_ptr<_DataSource> DataSource; +typedef boost::intrusive_ptr<_DataSource> DataSource; typedef std::map<std::string, DataSource> DataSources; class _DataSource : public virtual _SourceObject { @@ -18,8 +18,6 @@ class _DataSource : public virtual _SourceObject { virtual void commit() { }; virtual void rollback() { }; - - static void AddLoaders(Loaders & l, DataSources & dss); }; #endif diff --git a/project2/fileRows.cpp b/project2/fileRows.cpp index 5c499ff..9c6a5fe 100644 --- a/project2/fileRows.cpp +++ b/project2/fileRows.cpp @@ -1,6 +1,9 @@ #include "fileRows.h" #include <stdexcept> +ElementLoaderImpl<_FileIterate> fileiterateLoader("fileiterate"); +ElementLoaderImpl<_FileView> fileviewLoader("fileview"); + _FileRows::_FileRows(const xmlpp::Element * p) : path(p->get_attribute_value("path")), fieldSep(p->get_attribute_value("fieldSep")[0]), @@ -20,6 +23,11 @@ _FileRows::~_FileRows() { } +void +_FileRows::loadComplete() +{ +} + unsigned int _FileRows::columnCount() const { diff --git a/project2/fileRows.h b/project2/fileRows.h index ca94510..f083ecb 100644 --- a/project2/fileRows.h +++ b/project2/fileRows.h @@ -2,6 +2,7 @@ #define FILEROWS_H #include <libxml++/nodes/element.h> +#include <boost/intrusive_ptr.hpp> #include <boost/shared_ptr.hpp> #include <map> #include "view.h" @@ -15,6 +16,7 @@ class _FileRows : public PerRowValues { ~_FileRows(); void execute() const; + virtual void loadComplete(); unsigned int columnCount() const; const Glib::ustring & getColumnName(unsigned int col) const; const Glib::ustring & getCurrentValue(const Glib::ustring & id) const; @@ -39,14 +41,14 @@ class _FileRows : public PerRowValues { typedef std::vector<Glib::ustring> Columns; mutable Columns columns; }; -typedef boost::shared_ptr<_FileRows> FileRows; +typedef boost::intrusive_ptr<_FileRows> FileRows; typedef _GenericView<_FileRows> _FileView; -typedef boost::shared_ptr<_FileView> FileView; +typedef boost::intrusive_ptr<_FileView> FileView; typedef std::map<std::string, FileView> FileViews; typedef _GenericIterate<_FileRows> _FileIterate; -typedef boost::shared_ptr<_FileIterate> FileIterate; +typedef boost::intrusive_ptr<_FileIterate> FileIterate; typedef std::map<std::string, FileIterate> FileIterates; #endif diff --git a/project2/fileStarGlibIoChannel.h b/project2/fileStarGlibIoChannel.h index b11ffe7..77b6282 100644 --- a/project2/fileStarGlibIoChannel.h +++ b/project2/fileStarGlibIoChannel.h @@ -3,9 +3,11 @@ #include <stdio.h> #include <glibmm/iochannel.h> +#include <boost/intrusive_ptr.hpp> #include <boost/shared_ptr.hpp> +#include "intrusivePtrBase.h" -class FileStarChannel : public Glib::IOChannel { +class FileStarChannel : public Glib::IOChannel, public virtual IntrusivePtrBase { public: FileStarChannel(FILE * f, bool seekable, int (*closer)(FILE *) = fclose); virtual ~FileStarChannel(); diff --git a/project2/iHaveParameters.cpp b/project2/iHaveParameters.cpp index 0f1084e..c4006b9 100644 --- a/project2/iHaveParameters.cpp +++ b/project2/iHaveParameters.cpp @@ -5,21 +5,29 @@ IHaveParameters::IHaveParameters(const xmlpp::Element * p) { xmlpp::NodeSet ps = p->find("parameters"); - Loaders loaders; - loaders.insert(LoadersVT("param", - _LoaderBase::Make<_Parameter, _Parameter, unsigned int, _Parameter, &_Parameter::bind>(¶meters))); BOOST_FOREACH(xmlpp::Node * psi, ps) { - _LoaderBase::collectAll(loaders, "", dynamic_cast<const xmlpp::Element *>(psi), false, true); + LoaderBase loader; + loader.supportedStorers.insert(Storer::into(¶meters)); + loader.collectAll("", dynamic_cast<const xmlpp::Element *>(psi), false, true); } } +ElementLoaderImpl<IHaveParameters::_Parameter> paramLoader("param"); + IHaveParameters::~IHaveParameters() { } IHaveParameters::_Parameter::_Parameter(const xmlpp::Element * p) : + _SourceObject(p), value(p->get_attribute("value")), bind(atoi(p->get_attribute_value("bind").c_str())) { } +void +IHaveParameters::_Parameter::loadComplete() +{ +} + + diff --git a/project2/iHaveParameters.h b/project2/iHaveParameters.h index 329e341..14c1639 100644 --- a/project2/iHaveParameters.h +++ b/project2/iHaveParameters.h @@ -2,20 +2,24 @@ #define IHAVEPARAMETERS #include <libxml++/nodes/element.h> -#include <boost/shared_ptr.hpp> +#include <boost/intrusive_ptr.hpp> #include "variables.h" +#include "intrusivePtrBase.h" +#include "sourceObject.h" -class IHaveParameters { +class IHaveParameters : public virtual IntrusivePtrBase { public: - class _Parameter { + class _Parameter : public _SourceObject { public: _Parameter(const xmlpp::Element * p); + void loadComplete(); const Variable value; const unsigned int bind; }; IHaveParameters(const xmlpp::Element * p); virtual ~IHaveParameters() = 0; - typedef boost::shared_ptr<_Parameter> Parameter; + + typedef boost::intrusive_ptr<_Parameter> Parameter; typedef std::map<unsigned int, Parameter> Parameters; protected: Parameters parameters; diff --git a/project2/iterate.cpp b/project2/iterate.cpp index f29328b..d245536 100644 --- a/project2/iterate.cpp +++ b/project2/iterate.cpp @@ -2,20 +2,14 @@ #include <boost/foreach.hpp> #include <syslog.h> #include "xmlObjectLoader.h" -#include "sqlRows.h" -#include "fileRows.h" -#include "urlRows.h" -#include "procRows.h" -#include "task.h" _Iterate::_Iterate(const xmlpp::Element * p) : _SourceObject(p), _NoOutputExecute(p) { - Loaders loaders; - _Iterate::AddLoaders(loaders, subNOEs); - _Task::AddLoaders(loaders, subNOEs); - _LoaderBase::collectAll(loaders, "project2", p, true, true); + LoaderBase loader; + loader.supportedStorers.insert(Storer::into(&subNOEs)); + loader.collectAll("project2", p, true, true); } _Iterate::~_Iterate() @@ -23,24 +17,6 @@ _Iterate::~_Iterate() } void -_Iterate::AddLoaders(Loaders & l, NoOutputExecutes & iterates) -{ - l.insert(LoadersVT("sqliterate", _LoaderBase::Make<_SqlIterate, _NoOutputExecute, unsigned int, _SourceObject, &_SourceObject::order>(&iterates))); - l.insert(LoadersVT("fileiterate", _LoaderBase::Make<_FileIterate, _NoOutputExecute, unsigned int, _SourceObject, &_SourceObject::order>(&iterates))); - l.insert(LoadersVT("prociterate", _LoaderBase::Make<_ProcIterate, _NoOutputExecute, unsigned int, _SourceObject, &_SourceObject::order>(&iterates))); - l.insert(LoadersVT("urliterate", _LoaderBase::Make<_UrlIterate, _NoOutputExecute, unsigned int, _SourceObject, &_SourceObject::order>(&iterates))); -} - -void -_Iterate::AddLoaders(Loaders & l, Iterates & iterates) -{ - l.insert(LoadersVT("sqliterate", _LoaderBase::Make<_SqlIterate, _Iterate, std::string, _SourceObject, &_SourceObject::name>(&iterates))); - l.insert(LoadersVT("fileiterate", _LoaderBase::Make<_FileIterate, _Iterate, std::string, _SourceObject, &_SourceObject::name>(&iterates))); - l.insert(LoadersVT("prociterate", _LoaderBase::Make<_ProcIterate, _Iterate, std::string, _SourceObject, &_SourceObject::name>(&iterates))); - l.insert(LoadersVT("urliterate", _LoaderBase::Make<_UrlIterate, _Iterate, std::string, _SourceObject, &_SourceObject::name>(&iterates))); -} - -void _Iterate::executeChildren() const { try { diff --git a/project2/iterate.h b/project2/iterate.h index 17a046c..502c24a 100644 --- a/project2/iterate.h +++ b/project2/iterate.h @@ -2,7 +2,7 @@ #define ITERATE_H #include <libxml++/nodes/element.h> -#include <boost/shared_ptr.hpp> +#include <boost/intrusive_ptr.hpp> #include <map> #include "sourceObject.h" #include "xmlObjectLoader.h" @@ -11,7 +11,7 @@ class ApplicationEngine; class _Iterate; -typedef boost::shared_ptr<_Iterate> Iterate; +typedef boost::intrusive_ptr<_Iterate> Iterate; typedef std::map<std::string, Iterate> Iterates; class _Iterate : public virtual _SourceObject, public PerRowValues, public _NoOutputExecute { @@ -19,9 +19,6 @@ class _Iterate : public virtual _SourceObject, public PerRowValues, public _NoOu _Iterate(const xmlpp::Element * p); virtual ~_Iterate(); - static void AddLoaders(Loaders & l, NoOutputExecutes & vs); - static void AddLoaders(Loaders & l, Iterates & vs); - NoOutputExecutes subNOEs; protected: @@ -33,22 +30,11 @@ class _GenericIterate : public _Iterate, public Driver { public: _GenericIterate(const xmlpp::Element * p); - virtual unsigned int columnCount() const - { - return Driver::columnCount(); - } - virtual const Glib::ustring & getCurrentValue(const unsigned int id) const - { - return Driver::getCurrentValue(id); - } - virtual const Glib::ustring & getCurrentValue(const Glib::ustring & id) const - { - return Driver::getCurrentValue(id); - } - virtual const Glib::ustring & getColumnName(const unsigned int id) const - { - return Driver::getColumnName(id); - } + virtual void loadComplete(); + virtual unsigned int columnCount() const; + virtual const Glib::ustring & getCurrentValue(const unsigned int id) const; + virtual const Glib::ustring & getCurrentValue(const Glib::ustring & id) const; + virtual const Glib::ustring & getColumnName(const unsigned int id) const; virtual void executeChildren() const; virtual void execute() const; virtual void rowReady() const; diff --git a/project2/iterate.hpp b/project2/iterate.hpp index 87701cc..07925ad 100644 --- a/project2/iterate.hpp +++ b/project2/iterate.hpp @@ -10,6 +10,13 @@ _GenericIterate<Driver>::_GenericIterate(const xmlpp::Element * p) : template <class Driver> void +_GenericIterate<Driver>::loadComplete() +{ + Driver::loadComplete(); +} + +template <class Driver> +void _GenericIterate<Driver>::execute() const { Driver::execute(); @@ -29,3 +36,31 @@ _GenericIterate<Driver>::executeChildren() const _Iterate::executeChildren(); } +template <class Driver> +unsigned int +_GenericIterate<Driver>::columnCount() const +{ + return Driver::columnCount(); +} + +template <class Driver> +const Glib::ustring & +_GenericIterate<Driver>::getCurrentValue(const unsigned int id) const +{ + return Driver::getCurrentValue(id); +} + +template <class Driver> +const Glib::ustring & +_GenericIterate<Driver>::getCurrentValue(const Glib::ustring & id) const +{ + return Driver::getCurrentValue(id); +} + +template <class Driver> +const Glib::ustring & +_GenericIterate<Driver>::getColumnName(const unsigned int id) const +{ + return Driver::getColumnName(id); +} + diff --git a/project2/noOutputExecute.h b/project2/noOutputExecute.h index 01abb5c..55fdf7a 100644 --- a/project2/noOutputExecute.h +++ b/project2/noOutputExecute.h @@ -7,7 +7,7 @@ class ApplicationEngine; class PerRowValues; class _NoOutputExecute; -typedef boost::shared_ptr<_NoOutputExecute> NoOutputExecute; +typedef boost::intrusive_ptr<_NoOutputExecute> NoOutputExecute; typedef std::map<unsigned int, NoOutputExecute> NoOutputExecutes; class _NoOutputExecute : public virtual _SourceObject { diff --git a/project2/paramChecker.cpp b/project2/paramChecker.cpp index 5455f22..7d2f68a 100644 --- a/project2/paramChecker.cpp +++ b/project2/paramChecker.cpp @@ -1,8 +1,4 @@ #include "paramChecker.h" -#include "xmlObjectLoader.h" -#include <libxml++/nodes/textnode.h> -#include "regexCheck.h" -#include "sqlCheck.h" _ParamChecker::_ParamChecker(const xmlpp::Element * p) : _SourceObject(p), @@ -15,10 +11,3 @@ _ParamChecker::~_ParamChecker() { } -void -_ParamChecker::AddLoaders(Loaders & l, OrderedParamCheckers & checks) -{ - l.insert(LoadersVT("regexcheck", _LoaderBase::Make<_RegexCheck, _ParamChecker, unsigned int, _SourceObject, &_SourceObject::order>(&checks))); - l.insert(LoadersVT("sqlcheck", _LoaderBase::Make<_SqlCheck, _ParamChecker, unsigned int, _SourceObject, &_SourceObject::order>(&checks))); -} - diff --git a/project2/paramChecker.h b/project2/paramChecker.h index b22a1f9..d2ccbfc 100644 --- a/project2/paramChecker.h +++ b/project2/paramChecker.h @@ -2,7 +2,7 @@ #define PARAMCHECKER_H #include <libxml/tree.h> -#include <boost/shared_ptr.hpp> +#include <boost/intrusive_ptr.hpp> #include <map> #include "sourceObject.h" #include "xmlObjectLoader.h" @@ -10,7 +10,7 @@ class ApplicationEngine; class _ParamChecker; -typedef boost::shared_ptr<_ParamChecker> ParamChecker; +typedef boost::intrusive_ptr<_ParamChecker> ParamChecker; typedef std::map<std::string, ParamChecker> ParamCheckers; typedef std::map<unsigned int, ParamChecker> OrderedParamCheckers; @@ -19,12 +19,10 @@ class _ParamChecker : public virtual _SourceObject { _ParamChecker(const xmlpp::Element * p); virtual ~_ParamChecker(); - virtual bool performCheck(const ApplicationEngine *) const = 0; + virtual bool performCheck() const = 0; const Glib::ustring message; const std::string present; - - static void AddLoaders(Loaders & l, OrderedParamCheckers & vs); }; #endif diff --git a/project2/presenter.cpp b/project2/presenter.cpp index ee529ba..3743e68 100644 --- a/project2/presenter.cpp +++ b/project2/presenter.cpp @@ -10,11 +10,11 @@ Presenter::Presenter(const std::string & group, const std::string & file) : { while (xmlXIncludeProcessFlags(present.get_document()->cobj(), XML_PARSE_NOXINCNODE) > 0); - Loaders loaders; - _DataSource::AddLoaders(loaders, ApplicationEngine::getCurrent()->datasources); - _View::AddLoaders(loaders, views); - _ParamChecker::AddLoaders(loaders, parameterChecks); - _LoaderBase::collectAll(loaders, "project2", present.get_document()->get_root_node(), true, true); + LoaderBase loader; + loader.supportedStorers.insert(Storer::into(&ApplicationEngine::getCurrent()->datasources)); + loader.supportedStorers.insert(Storer::into(&views)); + loader.supportedStorers.insert(Storer::into(¶meterChecks)); + loader.collectAll("project2", present.get_document()->get_root_node(), true, true); } Presenter::~Presenter() diff --git a/project2/presenter.h b/project2/presenter.h index ae0a12b..977aa4d 100644 --- a/project2/presenter.h +++ b/project2/presenter.h @@ -1,13 +1,14 @@ #ifndef PRESENTER_H #define PRESENTER_H +#include <boost/intrusive_ptr.hpp> #include <boost/shared_ptr.hpp> #include <glibmm/ustring.h> #include <libxml++/parsers/domparser.h> #include "view.h" #include "paramChecker.h" -class Presenter { +class Presenter : public virtual IntrusivePtrBase { public: typedef boost::shared_ptr<xmlpp::Document> XmlDocumentPtr; Presenter(const std::string & group, const std::string & file); @@ -23,7 +24,7 @@ class Presenter { const Glib::ustring responseRootNodeName; const Glib::ustring responseStyle; }; -typedef boost::shared_ptr<Presenter> PresenterPtr; +typedef boost::intrusive_ptr<Presenter> PresenterPtr; #endif diff --git a/project2/procRows.cpp b/project2/procRows.cpp index fdeca88..f4d0f50 100644 --- a/project2/procRows.cpp +++ b/project2/procRows.cpp @@ -1,6 +1,9 @@ #include "procRows.h" #include <stdexcept> +ElementLoaderImpl<_ProcIterate> prociterateLoader("prociterate"); +ElementLoaderImpl<_ProcView> procviewLoader("procview"); + _ProcRows::_ProcRows(const xmlpp::Element * p) : _FileRows(p) { @@ -10,6 +13,11 @@ _ProcRows::~_ProcRows() { } +void +_ProcRows::loadComplete() +{ +} + FileStarChannel _ProcRows::doOpen() const { diff --git a/project2/procRows.h b/project2/procRows.h index aaac430..02add07 100644 --- a/project2/procRows.h +++ b/project2/procRows.h @@ -8,6 +8,7 @@ class _ProcRows : public _FileRows { _ProcRows(const xmlpp::Element * p); ~_ProcRows(); + virtual void loadComplete(); virtual FileStarChannel doOpen() const; }; typedef _GenericView<_ProcRows> _ProcView; diff --git a/project2/rawView.cpp b/project2/rawView.cpp index 4d41e63..e0691a7 100644 --- a/project2/rawView.cpp +++ b/project2/rawView.cpp @@ -5,6 +5,8 @@ #include "environment.h" #include "appEngine.h" +ElementLoaderImpl<_RawView> rawviewLoader("rawview"); + _RawView::_RawView(const xmlpp::Element * p) : _SourceObject(p), _View(p), @@ -12,6 +14,11 @@ _RawView::_RawView(const xmlpp::Element * p) : { } +void +_RawView::loadComplete() +{ +} + unsigned int _RawView::columnCount() const { diff --git a/project2/rawView.h b/project2/rawView.h index 33d0d1d..116d395 100644 --- a/project2/rawView.h +++ b/project2/rawView.h @@ -2,7 +2,7 @@ #define RAWVIEW_H #include <libxml++/nodes/element.h> -#include <boost/shared_ptr.hpp> +#include <boost/intrusive_ptr.hpp> #include <map> #include "view.h" @@ -12,6 +12,7 @@ class _RawView : public _View { public: _RawView(const xmlpp::Element * p); void execute(xmlpp::Element *) const; + virtual void loadComplete(); virtual unsigned int columnCount() const; virtual const Glib::ustring & getColumnName(unsigned int col) const; virtual const Glib::ustring & getCurrentValue(const Glib::ustring & id) const; @@ -19,7 +20,7 @@ class _RawView : public _View { private: const xmlpp::Element * copyRoot; }; -typedef boost::shared_ptr<_RawView> RawView; +typedef boost::intrusive_ptr<_RawView> RawView; typedef std::map<std::string, RawView> RawViews; #endif diff --git a/project2/rdbmsDataSource.cpp b/project2/rdbmsDataSource.cpp index 6f3fc92..ef1c694 100644 --- a/project2/rdbmsDataSource.cpp +++ b/project2/rdbmsDataSource.cpp @@ -6,6 +6,8 @@ #include <errno.h> #include <sqlext.h> +ElementLoaderImpl<_RdbmsDataSource> rdbmsLoader("rdbmsdatasource"); + _RdbmsDataSource::DBHosts _RdbmsDataSource::dbhosts; _RdbmsDataSource::FailedHosts _RdbmsDataSource::failedhosts; @@ -24,6 +26,11 @@ _RdbmsDataSource::_RdbmsDataSource(const xmlpp::Element * p) : } } +void +_RdbmsDataSource::loadComplete() +{ +} + ODBC::Connection & _RdbmsDataSource::getWritable() const { diff --git a/project2/rdbmsDataSource.h b/project2/rdbmsDataSource.h index a9dad6c..d360529 100644 --- a/project2/rdbmsDataSource.h +++ b/project2/rdbmsDataSource.h @@ -16,6 +16,7 @@ class _RdbmsDataSource : public _DataSource { _RdbmsDataSource(const xmlpp::Element * p); ODBC::Connection & getReadonly() const; ODBC::Connection & getWritable() const; + virtual void loadComplete(); virtual void commit(); virtual void rollback(); const std::string masterDsn; diff --git a/project2/regexCheck.cpp b/project2/regexCheck.cpp index d6e1bb0..62be6b1 100644 --- a/project2/regexCheck.cpp +++ b/project2/regexCheck.cpp @@ -3,6 +3,8 @@ #include "appEngine.h" #include <boost/regex.hpp> +ElementLoaderImpl<_RegexCheck> regexCheckLoader("regexcheck"); + _RegexCheck::_RegexCheck(const xmlpp::Element * p) : _SourceObject(p), _ParamChecker(p), @@ -15,8 +17,13 @@ _RegexCheck::~_RegexCheck() { } +void +_RegexCheck::loadComplete() +{ +} + bool -_RegexCheck::performCheck(const ApplicationEngine * ep) const +_RegexCheck::performCheck() const { const Glib::ustring & param(applyTo); return boost::regex_match(param.begin(), param.end(), regex); diff --git a/project2/regexCheck.h b/project2/regexCheck.h index b515d54..e848ef0 100644 --- a/project2/regexCheck.h +++ b/project2/regexCheck.h @@ -9,12 +9,13 @@ class _RegexCheck : public _ParamChecker { _RegexCheck(const xmlpp::Element * p); virtual ~_RegexCheck(); - bool performCheck(const ApplicationEngine *) const; + virtual void loadComplete(); + bool performCheck() const; const Variable applyTo; const boost::regex regex; }; -typedef boost::shared_ptr<_RegexCheck> RegexCheck; +typedef boost::intrusive_ptr<_RegexCheck> RegexCheck; typedef std::map<std::string, RegexCheck> RegexChecks; #endif diff --git a/project2/sendmailTask.cpp b/project2/sendmailTask.cpp index 0cbc88b..fdc298d 100644 --- a/project2/sendmailTask.cpp +++ b/project2/sendmailTask.cpp @@ -9,6 +9,9 @@ #include <libxslt/transform.h> #include <libesmtp.h> #include <libxslt/xsltutils.h> + +ElementLoaderImpl<_SendMailTask> sendmailLoader("sendmail"); + _SendMailTask::_SendMailTask(const xmlpp::Element * p) : _SourceObject(p), _Task(p), @@ -28,6 +31,11 @@ _SendMailTask::~_SendMailTask() } } +void +_SendMailTask::loadComplete() +{ +} + const char * _SendMailTask::writeMailWrapper(void ** buf, int * len, void * arg) { diff --git a/project2/sendmailTask.h b/project2/sendmailTask.h index 7783816..ef66c3f 100644 --- a/project2/sendmailTask.h +++ b/project2/sendmailTask.h @@ -2,6 +2,7 @@ #define SENDMAILTASK_H #include <libxml++/nodes/element.h> +#include <boost/intrusive_ptr.hpp> #include <boost/shared_ptr.hpp> #include <map> #include "task.h" @@ -15,6 +16,7 @@ class _SendMailTask : public _Task { public: _SendMailTask(const xmlpp::Element * p); virtual ~_SendMailTask(); + virtual void loadComplete(); virtual void execute() const; protected: @@ -36,7 +38,7 @@ class _SendMailTask : public _Task { mutable int bodyLength; mutable int position; }; -typedef boost::shared_ptr<_SendMailTask> SendMailTask; +typedef boost::intrusive_ptr<_SendMailTask> SendMailTask; typedef std::map<std::string, SendMailTask> SendMailTasks; #endif diff --git a/project2/session.h b/project2/session.h index 8dc1b8b..c0101fe 100644 --- a/project2/session.h +++ b/project2/session.h @@ -4,9 +4,10 @@ #include <map> #include <glibmm/ustring.h> #include <boost/uuid/uuid.hpp> -#include <boost/shared_ptr.hpp> +#include <boost/intrusive_ptr.hpp> +#include "intrusivePtrBase.h" -class Session { +class Session : public virtual IntrusivePtrBase { public: class VariableNotFound : public std::exception { }; typedef std::map<Glib::ustring, Glib::ustring> Values; @@ -24,7 +25,7 @@ class Session { virtual void ExpiryTime(time_t) = 0; friend class SessionContainer; }; -typedef boost::shared_ptr<Session> SessionPtr; +typedef boost::intrusive_ptr<Session> SessionPtr; class SessionContainer { public: diff --git a/project2/sessionClearTask.cpp b/project2/sessionClearTask.cpp index 146c85b..95b1145 100644 --- a/project2/sessionClearTask.cpp +++ b/project2/sessionClearTask.cpp @@ -4,6 +4,8 @@ #include "appEngine.h" #include "session.h" +ElementLoaderImpl<_SessionClearTask> sessionclearLoader("sessionclear"); + _SessionClearTask::_SessionClearTask(const xmlpp::Element * p) : _SourceObject(p), _Task(p), @@ -16,6 +18,11 @@ _SessionClearTask::~_SessionClearTask() } void +_SessionClearTask::loadComplete() +{ +} + +void _SessionClearTask::execute() const { ApplicationEngine::getCurrent()->session()->ClearValue(key); diff --git a/project2/sessionClearTask.h b/project2/sessionClearTask.h index 0f15fef..ab602b1 100644 --- a/project2/sessionClearTask.h +++ b/project2/sessionClearTask.h @@ -2,7 +2,7 @@ #define SESSIONCLEARTASK_H #include <libxml++/nodes/element.h> -#include <boost/shared_ptr.hpp> +#include <boost/intrusive_ptr.hpp> #include <map> #include "sourceObject.h" #include "xmlObjectLoader.h" @@ -10,12 +10,13 @@ class ApplicationEngine; class _SessionClearTask; -typedef boost::shared_ptr<_SessionClearTask> SessionClearTask; +typedef boost::intrusive_ptr<_SessionClearTask> SessionClearTask; class _SessionClearTask : public virtual _Task { public: _SessionClearTask(const xmlpp::Element * p); virtual ~_SessionClearTask(); + virtual void loadComplete(); void execute() const; const Glib::ustring key; diff --git a/project2/sessionSetTask.cpp b/project2/sessionSetTask.cpp index 7d937f0..2340468 100644 --- a/project2/sessionSetTask.cpp +++ b/project2/sessionSetTask.cpp @@ -5,6 +5,8 @@ #include "appEngine.h" #include "session.h" +ElementLoaderImpl<_SessionSetTask> sessionsetLoader("sessionset"); + _SessionSetTask::_SessionSetTask(const xmlpp::Element * p) : _SourceObject(p), _Task(p), @@ -18,6 +20,11 @@ _SessionSetTask::~_SessionSetTask() } void +_SessionSetTask::loadComplete() +{ +} + +void _SessionSetTask::execute() const { ApplicationEngine::getCurrent()->session()->SetValue(key, value); diff --git a/project2/sessionSetTask.h b/project2/sessionSetTask.h index c1a7432..164b562 100644 --- a/project2/sessionSetTask.h +++ b/project2/sessionSetTask.h @@ -2,7 +2,7 @@ #define SESSIONSETTASK_H #include <libxml++/nodes/element.h> -#include <boost/shared_ptr.hpp> +#include <boost/intrusive_ptr.hpp> #include <map> #include "sourceObject.h" #include "xmlObjectLoader.h" @@ -11,12 +11,13 @@ class ApplicationEngine; class _SessionSetTask; -typedef boost::shared_ptr<_SessionSetTask> SessionSetTask; +typedef boost::intrusive_ptr<_SessionSetTask> SessionSetTask; class _SessionSetTask : public virtual _Task { public: _SessionSetTask(const xmlpp::Element * p); virtual ~_SessionSetTask(); + virtual void loadComplete(); void execute() const; const Glib::ustring key; diff --git a/project2/sourceObject.h b/project2/sourceObject.h index da94614..b37aad1 100644 --- a/project2/sourceObject.h +++ b/project2/sourceObject.h @@ -2,18 +2,22 @@ #define SOURCEOBJECT_H #include <libxml++/nodes/element.h> -#include <boost/shared_ptr.hpp> +#include <boost/intrusive_ptr.hpp> +#include "intrusivePtrBase.h" -class _SourceObject { +class _SourceObject; +typedef boost::intrusive_ptr<_SourceObject> Project2SourceObject; +class _SourceObject : public virtual IntrusivePtrBase { public: _SourceObject(const xmlpp::Element * p); _SourceObject(const std::string & name); virtual ~_SourceObject() = 0; + virtual void loadComplete() = 0; + const std::string name; const unsigned int order; private: static unsigned int loadOrder; }; -typedef boost::shared_ptr<_SourceObject> Project2SourceObject; #endif diff --git a/project2/sqlCheck.cpp b/project2/sqlCheck.cpp index 65cf0e3..8d48d24 100644 --- a/project2/sqlCheck.cpp +++ b/project2/sqlCheck.cpp @@ -6,6 +6,8 @@ #include "rdbmsDataSource.h" #include <boost/regex.hpp> +ElementLoaderImpl<_SqlCheck> sqlCheckLoader("sqlcheck"); + _SqlCheck::_SqlCheck(const xmlpp::Element * p) : _SourceObject(p), IHaveParameters(p), @@ -13,18 +15,26 @@ _SqlCheck::_SqlCheck(const xmlpp::Element * p) : dataSource(p->get_attribute_value("datasource")), sql(xmlChildText(p, "sql")), testOp(p->get_attribute_value("testOp")), - testValue(atof(p->get_attribute_value("testValue").c_str())) + testValue(atof(p->get_attribute_value("testValue").c_str())), + query(NULL) { } _SqlCheck::~_SqlCheck() { + delete query; +} + +void +_SqlCheck::loadComplete() +{ + query = new ODBC::SelectCommand(ApplicationEngine::getCurrent()->dataSource<_RdbmsDataSource>( + dataSource)->getReadonly(), sql); } bool -_SqlCheck::performCheck(const ApplicationEngine * ep) const +_SqlCheck::performCheck() const { - ODBC::SelectCommand * query = new ODBC::SelectCommand(ep->dataSource<_RdbmsDataSource>(dataSource)->getReadonly(), sql); BOOST_FOREACH(Parameters::value_type p, parameters) { query->bindParamS(p.second->bind, p.second->value); } @@ -50,7 +60,6 @@ _SqlCheck::performCheck(const ApplicationEngine * ep) const retVal = true; } } - delete query; return retVal; } diff --git a/project2/sqlCheck.h b/project2/sqlCheck.h index a5a5ae0..0c5efcc 100644 --- a/project2/sqlCheck.h +++ b/project2/sqlCheck.h @@ -4,19 +4,24 @@ #include "paramChecker.h" #include "iHaveParameters.h" +namespace ODBC { class SelectCommand; } + class _SqlCheck : public IHaveParameters, public _ParamChecker { public: _SqlCheck(const xmlpp::Element * p); virtual ~_SqlCheck(); - bool performCheck(const ApplicationEngine *) const; + virtual void loadComplete(); + bool performCheck() const; const std::string dataSource; const Glib::ustring sql; const std::string testOp; const double testValue; + private: + ODBC::SelectCommand * query; }; -typedef boost::shared_ptr<_SqlCheck> SqlCheck; +typedef boost::intrusive_ptr<_SqlCheck> SqlCheck; typedef std::map<std::string, SqlCheck> SqlChecks; #endif diff --git a/project2/sqlMergeTask.cpp b/project2/sqlMergeTask.cpp index d59d356..2863b7c 100644 --- a/project2/sqlMergeTask.cpp +++ b/project2/sqlMergeTask.cpp @@ -9,6 +9,8 @@ bool _SqlMergeTask::defaultUseTempTable = true; static void attach(Iterate i, ModifyCommand * insert); +ElementLoaderImpl<_SqlMergeTask> sqlmergeLoader("sqlmerge"); + // Conversion logic _SqlMergeTask::_SqlMergeTask(const xmlpp::Element * p) : _SourceObject(p), @@ -24,9 +26,10 @@ _SqlMergeTask::_SqlMergeTask(const xmlpp::Element * p) : dtable(p->get_attribute_value("targettable")), dtablet(stringf("tmp_%s_%d", dtable.c_str(), getpid())) { - Loaders loaders; - _Iterate::AddLoaders(loaders, sources); - _LoaderBase::collectAll(loaders, "project2", p, true, true); + LoaderBase loader; + loader.supportedStorers.insert(Storer::into(&sources)); + loader.collectAll("project2", p, true, true); + if (!sources.empty() && useView) { throw std::runtime_error("useview not supported with iterate fillers"); } @@ -56,6 +59,16 @@ _SqlMergeTask::~_SqlMergeTask() delete insCmd; } +void +_SqlMergeTask::loadComplete() +{ + destdb = &ApplicationEngine::getCurrent()->dataSource<_RdbmsDataSource>(dataSource)->getWritable(); + insCmd = insertCommand(); + BOOST_FOREACH(const Iterates::value_type & i, sources) { + attach(i.second, insCmd); + } +} + _SqlMergeTask::TargetColumn::TargetColumn(const Column & c) : column(c), mapcolumn(c) @@ -71,13 +84,6 @@ _SqlMergeTask::TargetColumn::Sort::operator()(const TargetColumnPtr & a, const T void _SqlMergeTask::execute() const { - destdb = &ApplicationEngine::getCurrent()->dataSource<_RdbmsDataSource>(dataSource)->getWritable(); - if (!insCmd) { - insCmd = insertCommand(); - BOOST_FOREACH(const Iterates::value_type & i, sources) { - attach(i.second, insCmd); - } - } createTempTable(); if (earlyKeys) { createTempKey(); @@ -189,9 +195,11 @@ class _Populate : public _NoOutputExecute { _NoOutputExecute(__FUNCTION__), iter(i), cmd(c) - { - } - + { + } + virtual void loadComplete() + { + } void execute() const { if (idxs.empty()) { @@ -219,7 +227,7 @@ class _Populate : public _NoOutputExecute { Iterate iter; ModifyCommand * cmd; }; -typedef boost::shared_ptr<_Populate> Populate; +typedef boost::intrusive_ptr<_Populate> Populate; static void attach(Iterate i, ModifyCommand * insert) { diff --git a/project2/sqlMergeTask.h b/project2/sqlMergeTask.h index ce10f70..633dc2a 100644 --- a/project2/sqlMergeTask.h +++ b/project2/sqlMergeTask.h @@ -19,8 +19,8 @@ class _SqlMergeTask : public _Task { typedef std::string Table; typedef std::string Column; class TargetColumn; - typedef boost::shared_ptr<TargetColumn> TargetColumnPtr; - class TargetColumn { + typedef boost::intrusive_ptr<TargetColumn> TargetColumnPtr; + class TargetColumn : public virtual IntrusivePtrBase { public: class Sort { public: @@ -40,6 +40,7 @@ class _SqlMergeTask : public _Task { _SqlMergeTask(const xmlpp::Element * p); virtual ~_SqlMergeTask(); + virtual void loadComplete(); void execute() const; Columns cols; Keys keys; @@ -60,10 +61,10 @@ class _SqlMergeTask : public _Task { std::list<std::string> sqls; protected: ModifyCommand * insertCommand() const; - mutable ModifyCommand * insCmd; + ModifyCommand * insCmd; public: - mutable ODBC::Connection * destdb; + ODBC::Connection * destdb; const std::string dataSource; const Table dtable; const Table dtablet; diff --git a/project2/sqlRows.cpp b/project2/sqlRows.cpp index ca814f7..922d785 100644 --- a/project2/sqlRows.cpp +++ b/project2/sqlRows.cpp @@ -8,6 +8,9 @@ #include "xmlObjectLoader.h" #include "appEngine.h" +ElementLoaderImpl<_SqlIterate> sqliterateLoader("sqliterate"); +ElementLoaderImpl<_SqlView> sqlviewLoader("sqlview"); + _SqlRows::_SqlRows(const xmlpp::Element * p) : IHaveParameters(p), dataSource(p->get_attribute_value("datasource")), @@ -21,6 +24,13 @@ _SqlRows::~_SqlRows() delete query; } +void +_SqlRows::loadComplete() +{ + query = new ODBC::SelectCommand(ApplicationEngine::getCurrent()->dataSource<_RdbmsDataSource>( + dataSource)->getReadonly(), sql); +} + const Glib::ustring & _SqlRows::getCurrentValue(const Glib::ustring & id) const { @@ -48,10 +58,6 @@ _SqlRows::getColumnName(unsigned int col) const void _SqlRows::execute() const { - if (!query) { - query = new ODBC::SelectCommand(ApplicationEngine::getCurrent()->dataSource<_RdbmsDataSource>( - dataSource)->getReadonly(), sql); - } BOOST_FOREACH(Parameters::value_type p, parameters) { query->bindParamS(p.second->bind, p.second->value); } diff --git a/project2/sqlRows.h b/project2/sqlRows.h index eff32bc..d084b4b 100644 --- a/project2/sqlRows.h +++ b/project2/sqlRows.h @@ -2,7 +2,7 @@ #define SQLITERATE_H #include <libxml++/nodes/element.h> -#include <boost/shared_ptr.hpp> +#include <boost/intrusive_ptr.hpp> #include <map> #include "selectcommand.h" #include "iterate.h" @@ -17,6 +17,7 @@ class _SqlRows : public IHaveParameters, public PerRowValues { ~_SqlRows(); void execute() const; + virtual void loadComplete(); unsigned int columnCount() const; const Glib::ustring & getColumnName(unsigned int col) const; const Glib::ustring & getCurrentValue(const Glib::ustring & id) const; @@ -29,14 +30,14 @@ class _SqlRows : public IHaveParameters, public PerRowValues { private: mutable ODBC::SelectCommand * query; }; -typedef boost::shared_ptr<_SqlRows> SqlRows; +typedef boost::intrusive_ptr<_SqlRows> SqlRows; typedef _GenericView<_SqlRows> _SqlView; -typedef boost::shared_ptr<_SqlView> SqlView; +typedef boost::intrusive_ptr<_SqlView> SqlView; typedef std::map<std::string, SqlView> SqlViews; typedef _GenericIterate<_SqlRows> _SqlIterate; -typedef boost::shared_ptr<_SqlIterate> SqlIterate; +typedef boost::intrusive_ptr<_SqlIterate> SqlIterate; typedef std::map<std::string, SqlIterate> SqlIterates; #endif diff --git a/project2/sqlTask.cpp b/project2/sqlTask.cpp index b21c6c0..7ff5f40 100644 --- a/project2/sqlTask.cpp +++ b/project2/sqlTask.cpp @@ -5,26 +5,32 @@ #include "appEngine.h" #include "rdbmsDataSource.h" +ElementLoaderImpl<_SqlTask> sqltaskLoader("sqltask"); + _SqlTask::_SqlTask(const xmlpp::Element * p) : _SourceObject(p), _Task(p), IHaveParameters(p), dataSource(p->get_attribute_value("datasource")), - sql(xmlChildText(p, "sql")) + sql(xmlChildText(p, "sql")), + modify(NULL) { } _SqlTask::~_SqlTask() { + delete modify; +} + +void +_SqlTask::loadComplete() +{ + modify = new ODBC::ModifyCommand(ApplicationEngine::getCurrent()->dataSource<_RdbmsDataSource>(dataSource)->getWritable(), sql); } void _SqlTask::execute() const { - if (!modify) { - modify = CommandPtr(new ODBC::ModifyCommand(ApplicationEngine::getCurrent()->dataSource<_RdbmsDataSource>( - dataSource)->getWritable(), sql)); - } BOOST_FOREACH(Parameters::value_type p, parameters) { modify->bindParamS(p.second->bind, p.second->value); } diff --git a/project2/sqlTask.h b/project2/sqlTask.h index f079bb8..e24fe24 100644 --- a/project2/sqlTask.h +++ b/project2/sqlTask.h @@ -2,7 +2,7 @@ #define SQLTASK_H #include <libxml++/nodes/element.h> -#include <boost/shared_ptr.hpp> +#include <boost/intrusive_ptr.hpp> #include <map> #include "task.h" #include "iHaveParameters.h" @@ -16,15 +16,15 @@ class _SqlTask : public _Task, public IHaveParameters { public: _SqlTask(const xmlpp::Element * p); virtual ~_SqlTask(); + virtual void loadComplete(); virtual void execute() const; const std::string dataSource; const std::string sql; protected: - typedef boost::shared_ptr<ODBC::ModifyCommand> CommandPtr; - mutable CommandPtr modify; + mutable ODBC::ModifyCommand * modify; }; -typedef boost::shared_ptr<_SqlTask> SqlTask; +typedef boost::intrusive_ptr<_SqlTask> SqlTask; typedef std::map<std::string, SqlTask> SqlTasks; #endif diff --git a/project2/task.cpp b/project2/task.cpp index ee5bb18..70cf03b 100644 --- a/project2/task.cpp +++ b/project2/task.cpp @@ -1,11 +1,5 @@ #include "task.h" #include <boost/foreach.hpp> -#include "xmlObjectLoader.h" -#include "sqlTask.h" -#include "sqlMergeTask.h" -#include "sessionClearTask.h" -#include "sessionSetTask.h" -#include "sendmailTask.h" _Task::_Task(const xmlpp::Element * p) : _SourceObject(p), @@ -17,23 +11,3 @@ _Task::~_Task() { } -void -_Task::AddLoaders(Loaders & l, OrderedTasks & tasks) -{ - l.insert(LoadersVT("sqltask", _LoaderBase::Make<_SqlTask, _Task, unsigned int, _SourceObject, &_SourceObject::order>(&tasks))); - l.insert(LoadersVT("sqlmerge", _LoaderBase::Make<_SqlMergeTask, _Task, unsigned int, _SourceObject, &_SourceObject::order>(&tasks))); - l.insert(LoadersVT("sessionclear", _LoaderBase::Make<_SessionClearTask, _Task, unsigned int, _SourceObject, &_SourceObject::order>(&tasks))); - l.insert(LoadersVT("sessionset", _LoaderBase::Make<_SessionSetTask, _Task, unsigned int, _SourceObject, &_SourceObject::order>(&tasks))); - l.insert(LoadersVT("sendmail", _LoaderBase::Make<_SendMailTask, _Task, unsigned int, _SourceObject, &_SourceObject::order>(&tasks))); -} - -void -_Task::AddLoaders(Loaders & l, NoOutputExecutes & tasks) -{ - l.insert(LoadersVT("sqltask", _LoaderBase::Make<_SqlTask, _NoOutputExecute, unsigned int, _SourceObject, &_SourceObject::order>(&tasks))); - l.insert(LoadersVT("sqlmerge", _LoaderBase::Make<_SqlMergeTask, _NoOutputExecute, unsigned int, _SourceObject, &_SourceObject::order>(&tasks))); - l.insert(LoadersVT("sessionclear", _LoaderBase::Make<_SessionClearTask, _NoOutputExecute, unsigned int, _SourceObject, &_SourceObject::order>(&tasks))); - l.insert(LoadersVT("sessionset", _LoaderBase::Make<_SessionSetTask, _NoOutputExecute, unsigned int, _SourceObject, &_SourceObject::order>(&tasks))); - l.insert(LoadersVT("sendmail", _LoaderBase::Make<_SendMailTask, _NoOutputExecute, unsigned int, _SourceObject, &_SourceObject::order>(&tasks))); -} - diff --git a/project2/task.h b/project2/task.h index 6cc8c3e..d100042 100644 --- a/project2/task.h +++ b/project2/task.h @@ -2,7 +2,7 @@ #define TASK_H #include <libxml++/nodes/element.h> -#include <boost/shared_ptr.hpp> +#include <boost/intrusive_ptr.hpp> #include <map> #include "sourceObject.h" #include "xmlObjectLoader.h" @@ -11,7 +11,7 @@ class ApplicationEngine; class _Task; -typedef boost::shared_ptr<_Task> Task; +typedef boost::intrusive_ptr<_Task> Task; typedef std::map<std::string, Task> Tasks; typedef std::map<unsigned int, Task> OrderedTasks; @@ -20,9 +20,6 @@ class _Task : public virtual _SourceObject, public _NoOutputExecute { _Task(const xmlpp::Element * p); virtual ~_Task(); virtual void execute() const = 0; - - static void AddLoaders(Loaders & l, OrderedTasks & vs); - static void AddLoaders(Loaders & l, NoOutputExecutes & vs); }; #endif diff --git a/project2/urlRows.cpp b/project2/urlRows.cpp index ddae45c..7be904c 100644 --- a/project2/urlRows.cpp +++ b/project2/urlRows.cpp @@ -3,6 +3,9 @@ #include <stdexcept> #include <queue> +ElementLoaderImpl<_UrlIterate> urliterateLoader("urliterate"); +ElementLoaderImpl<_UrlView> urlviewLoader("urlview"); + _UrlRows::_UrlRows(const xmlpp::Element * p) : url(p->get_attribute_value("url")), fieldSep(p->get_attribute_value("fieldSep")[0]), @@ -26,6 +29,11 @@ _UrlRows::~_UrlRows() { } +void +_UrlRows::loadComplete() +{ +} + unsigned int _UrlRows::columnCount() const { diff --git a/project2/urlRows.h b/project2/urlRows.h index f94e149..d9eb413 100644 --- a/project2/urlRows.h +++ b/project2/urlRows.h @@ -2,6 +2,7 @@ #define URLROWS_H #include <libxml++/nodes/element.h> +#include <boost/intrusive_ptr.hpp> #include <boost/shared_ptr.hpp> #include <map> #include "view.h" @@ -12,6 +13,7 @@ class _UrlRows : public PerRowValues { _UrlRows(const xmlpp::Element * p); ~_UrlRows(); + virtual void loadComplete(); void execute() const; unsigned int columnCount() const; const Glib::ustring & getColumnName(unsigned int col) const; @@ -45,14 +47,14 @@ class _UrlRows : public PerRowValues { mutable bool prevWasQuote; mutable Glib::ustring tok; }; -typedef boost::shared_ptr<_UrlRows> UrlRows; +typedef boost::intrusive_ptr<_UrlRows> UrlRows; typedef _GenericView<_UrlRows> _UrlView; -typedef boost::shared_ptr<_UrlView> UrlView; +typedef boost::intrusive_ptr<_UrlView> UrlView; typedef std::map<std::string, UrlView> UrlViews; typedef _GenericIterate<_UrlRows> _UrlIterate; -typedef boost::shared_ptr<_UrlIterate> UrlIterate; +typedef boost::intrusive_ptr<_UrlIterate> UrlIterate; typedef std::map<std::string, UrlIterate> UrlIterates; #endif diff --git a/project2/variables.h b/project2/variables.h index f3f8668..1d4b4ba 100644 --- a/project2/variables.h +++ b/project2/variables.h @@ -1,15 +1,16 @@ #ifndef VARIABLES_H #define VARIABLES_H -#include <boost/shared_ptr.hpp> +#include <boost/intrusive_ptr.hpp> #include <boost/optional.hpp> #include <glibmm/ustring.h> #include <libxml++/nodes/element.h> #include <libxml++/attribute.h> +#include "intrusivePtrBase.h" class RowUser; -class VariableImpl { +class VariableImpl : public virtual IntrusivePtrBase { public: virtual const Glib::ustring & value() const = 0; @@ -22,7 +23,7 @@ class VariableImpl { class Variable { public: - typedef boost::shared_ptr<VariableImpl> VariableImplPtr; + typedef boost::intrusive_ptr<VariableImpl> VariableImplPtr; Variable(xmlpp::Attribute *); Variable(xmlpp::Element *); diff --git a/project2/view.cpp b/project2/view.cpp index 217424f..8ed5f65 100644 --- a/project2/view.cpp +++ b/project2/view.cpp @@ -1,19 +1,13 @@ #include "view.h" #include <boost/foreach.hpp> -#include "xmlObjectLoader.h" -#include "rawView.h" -#include "fileRows.h" -#include "urlRows.h" -#include "sqlRows.h" -#include "procRows.h" _View::_View(const xmlpp::Element * p) : _SourceObject(p), recordName(p->get_attribute_value("recordname")) { - Loaders loaders; - _View::AddLoaders(loaders, subViews); - _LoaderBase::collectAll(loaders, "project2", p, true, true); + LoaderBase loader; + loader.supportedStorers.insert(Storer::into(&subViews)); + loader.collectAll("project2", p, true, true); } _View::~_View() @@ -21,16 +15,6 @@ _View::~_View() } void -_View::AddLoaders(Loaders & l, Views & views) -{ - l.insert(LoadersVT("sqlview", _LoaderBase::Make<_SqlView, _View, std::string, _SourceObject, &_SourceObject::name>(&views))); - l.insert(LoadersVT("rawview", _LoaderBase::Make<_RawView, _View, std::string, _SourceObject, &_SourceObject::name>(&views))); - l.insert(LoadersVT("fileview", _LoaderBase::Make<_FileView, _View, std::string, _SourceObject, &_SourceObject::name>(&views))); - l.insert(LoadersVT("procview", _LoaderBase::Make<_ProcView, _View, std::string, _SourceObject, &_SourceObject::name>(&views))); - l.insert(LoadersVT("urlview", _LoaderBase::Make<_UrlView, _View, std::string, _SourceObject, &_SourceObject::name>(&views))); -} - -void _View::executeChildren(xmlpp::Element * record) const { try { diff --git a/project2/view.h b/project2/view.h index 23b7464..ff0335e 100644 --- a/project2/view.h +++ b/project2/view.h @@ -2,7 +2,7 @@ #define VIEW_H #include <libxml++/nodes/element.h> -#include <boost/shared_ptr.hpp> +#include <boost/intrusive_ptr.hpp> #include <map> #include "sourceObject.h" #include "xmlObjectLoader.h" @@ -11,7 +11,7 @@ class ApplicationEngine; class _View; -typedef boost::shared_ptr<_View> View; +typedef boost::intrusive_ptr<_View> View; typedef std::map<std::string, View> Views; class _View : public virtual _SourceObject, public PerRowValues { @@ -22,7 +22,6 @@ class _View : public virtual _SourceObject, public PerRowValues { virtual const Glib::ustring & getCurrentValue(const Glib::ustring & id) const = 0; const Glib::ustring recordName; - static void AddLoaders(Loaders & l, Views & vs); protected: void executeChildren(xmlpp::Element *) const; Views subViews; @@ -33,22 +32,11 @@ class _GenericView : public _View, public Driver { public: _GenericView(const xmlpp::Element * p); - virtual unsigned int columnCount() const - { - return Driver::columnCount(); - } - virtual const Glib::ustring & getCurrentValue(const unsigned int id) const - { - return Driver::getCurrentValue(id); - } - virtual const Glib::ustring & getCurrentValue(const Glib::ustring & id) const - { - return Driver::getCurrentValue(id); - } - virtual const Glib::ustring & getColumnName(const unsigned int id) const - { - return Driver::getColumnName(id); - } + virtual unsigned int columnCount() const; + virtual void loadComplete(); + virtual const Glib::ustring & getCurrentValue(const unsigned int id) const; + virtual const Glib::ustring & getCurrentValue(const Glib::ustring & id) const; + virtual const Glib::ustring & getColumnName(const unsigned int id) const; virtual void execute(xmlpp::Element * e) const; virtual void rowReady() const; private: diff --git a/project2/view.hpp b/project2/view.hpp index be15eb5..820360f 100644 --- a/project2/view.hpp +++ b/project2/view.hpp @@ -30,3 +30,38 @@ _GenericView<Driver>::rowReady() const executeChildren(record); } +template <class Driver> +unsigned int +_GenericView<Driver>:: columnCount() const +{ + return Driver::columnCount(); +} + +template <class Driver> +void +_GenericView<Driver>:: loadComplete() +{ + Driver::loadComplete(); +} + +template <class Driver> +const Glib::ustring & +_GenericView<Driver>:: getCurrentValue(const unsigned int id) const +{ + return Driver::getCurrentValue(id); +} + +template <class Driver> +const Glib::ustring & +_GenericView<Driver>:: getCurrentValue(const Glib::ustring & id) const +{ + return Driver::getCurrentValue(id); +} + +template <class Driver> +const Glib::ustring & +_GenericView<Driver>:: getColumnName(const unsigned int id) const +{ + return Driver::getColumnName(id); +} + diff --git a/project2/xmlObjectLoader.cpp b/project2/xmlObjectLoader.cpp index 1eb85f9..71f1b53 100644 --- a/project2/xmlObjectLoader.cpp +++ b/project2/xmlObjectLoader.cpp @@ -1,32 +1,57 @@ #include "xmlObjectLoader.h" +#include <stdexcept> +#include <stdio.h> -_LoaderBase::_LoaderBase() -{ -} -_LoaderBase::~_LoaderBase() +unsigned int LoaderBase::depth = 0; +std::set<Project2SourceObject> LoaderBase::loadedObjects; + +LoaderBase::ElementLoaderMap & +LoaderBase::getMap() { + static ElementLoaderMap loaders; + return loaders; } void -_LoaderBase::collectAll(const Loaders & ls, const Glib::ustring & ns, const xmlpp::Element * node, bool recursive, bool childrenOnly) +LoaderBase::collectAll(const Glib::ustring & ns, const xmlpp::Element * node, bool recursive, bool childrenOnly) const { if (!node) { return; } + depth += 1; if (!childrenOnly && ns == node->get_namespace_prefix()) { Glib::ustring name = node->get_name(); unsigned int created = 0; - for(Loaders::const_iterator i = ls.lower_bound(name); i != ls.upper_bound(name); i++) { - i->second->go(node); + unsigned int stored = 0; + for(ElementLoaderMap::const_iterator i = getMap().lower_bound(name); i != getMap().upper_bound(name); i++) { + Project2SourceObject o = i->second->go(node); created += 1; + loadedObjects.insert(o); + BOOST_FOREACH(std::set<boost::intrusive_ptr<Storer> >::value_type s, supportedStorers) { + if (s->save(o)) { + stored += 1; + } + } } if (created < 1) { fprintf(stderr, "Didn't create any objects for %s:%s\n", ns.c_str(), name.c_str()); + throw std::runtime_error("Unknown object"); + } + if (stored < 1) { + throw std::runtime_error("Unsupported object"); } } else if (recursive || childrenOnly) { BOOST_FOREACH(xmlpp::Node * child, node->get_children()) { - collectAll(ls, ns, dynamic_cast<const xmlpp::Element *>(child), recursive, false); + collectAll(ns, dynamic_cast<const xmlpp::Element *>(child), recursive, false); } } + depth -= 1; + if (depth == 0) { + BOOST_FOREACH(Project2SourceObject o, loadedObjects) { + o->loadComplete(); + } + loadedObjects.clear(); + } } + diff --git a/project2/xmlObjectLoader.h b/project2/xmlObjectLoader.h index e68a7d8..0be5eeb 100644 --- a/project2/xmlObjectLoader.h +++ b/project2/xmlObjectLoader.h @@ -2,70 +2,129 @@ #define XMLOBJECTLOADER_H #include <map> +#include <set> #include <string> -#include <stdio.h> #include <libxml++/nodes/element.h> +#include <boost/intrusive_ptr.hpp> #include <boost/shared_ptr.hpp> -#include <boost/foreach.hpp> -#include <boost/bind.hpp> #include <libxml++/nodes/textnode.h> +#include <boost/foreach.hpp> +#include "intrusivePtrBase.h" +#include "sourceObject.h" #define xmlChildText(p, t) dynamic_cast<const xmlpp::Element&>(*p->get_children(t).front()).get_child_text()->get_content() -class _LoaderBase; -template <class T, class IT, class Key> -class _Loader; -typedef boost::shared_ptr<_LoaderBase> Loader; -typedef std::multimap<std::string, Loader> Loaders; +class ElementLoader; + +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); + + virtual bool save(Project2SourceObject o) const = 0; +}; -class _LoaderBase { +template <class X, class K> +class StorerImplBase : public Storer { public: - _LoaderBase(); - virtual ~_LoaderBase() = 0; - virtual void go(const xmlpp::Element * e) const = 0; - - template <class T, typename KeyT, class IdT, const KeyT IdT::*Var> - static - void - storeByX(std::map<KeyT, boost::shared_ptr<T> > * m, boost::shared_ptr<T> o) + typedef K Key; + StorerImplBase(std::map<Key, boost::intrusive_ptr<X> > * m) : map(m) { - if (o && m->find(o.get()->*Var) == m->end()) { - (*m)[o.get()->*Var] = o; - } } - template <class CT, class BaseT, class KeyT, class IdT, const KeyT IdT::*Var> - static - Loader Make(std::map<KeyT, boost::shared_ptr<BaseT> > * m); - static void collectAll(const Loaders & ls, const Glib::ustring & ns, const xmlpp::Element * node, bool recursive, bool childrenOnly); + std::map<Key, boost::intrusive_ptr<X> > * map; }; +template <class X, class K> +class StorerImpl; -template <class T, class IT, class Key> -class _Loader : public _LoaderBase { +template <typename X> +class StorerImpl<X, unsigned int> : public StorerImplBase<X, unsigned int> { public: - typedef boost::shared_ptr<T> ptr; - typedef std::map<Key, ptr> ptrmap; - typedef void (*S)(ptrmap *, ptr); - - _Loader(S s, ptrmap * m) : _LoaderBase(), storer(s), map(m) + typedef unsigned int Key; + typedef boost::intrusive_ptr<X> Ptr; + StorerImpl(std::map<Key, Ptr> * m) : StorerImplBase<X, Key>(m) { } - - void go(const xmlpp::Element * e) const + bool save(Project2SourceObject obj) const { - storer(map, ptr(new IT(e))); + 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; } - const S storer; - ptrmap * map; }; -typedef Loaders::value_type LoadersVT; +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(Project2SourceObject obj) const + { + Ptr O = boost::dynamic_pointer_cast<X>(obj); + if (O) { + StorerImplBase<X, Key>::map->insert(std::pair<Key, Ptr>(O->name, O)); + return true; + } + return false; + } +}; -template <class CT, class BaseT, class KeyT, class IdT, const KeyT IdT::*Var> -Loader -_LoaderBase::Make(std::map<KeyT, boost::shared_ptr<BaseT> > * m) +template <class X, class Key> +boost::intrusive_ptr<Storer> +Storer::into(std::map<Key, boost::intrusive_ptr<X> > * map) { - return Loader(new _Loader<BaseT, CT, KeyT>(&storeByX<BaseT, KeyT, IdT, Var>, m)); + return new StorerImpl<X, Key>(map); } +class LoaderBase { + public: + typedef std::map<std::string, const ElementLoader *> ElementLoaderMap; + + void collectAll(const Glib::ustring & ns, const xmlpp::Element * node, bool recursive, bool childrenOnly) const; + static ElementLoaderMap & getMap(); + + 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); + + std::set<boost::intrusive_ptr<Storer> > supportedStorers; + private: + static unsigned int depth; + static std::set<Project2SourceObject> loadedObjects; +}; + +class ElementLoader { + public: + virtual Project2SourceObject go(const xmlpp::Element * xml) const = 0; +}; + +template <class X> +class ElementLoaderImpl : ElementLoader { + public: + ElementLoaderImpl(const std::string & x) : + xmlName(x) + { + LoaderBase::getMap()[xmlName] = this; + } + ~ElementLoaderImpl() + { + LoaderBase::getMap().erase(xmlName); + } + Project2SourceObject go(const xmlpp::Element * xml) const + { + return new X(xml); + } + + const std::string xmlName; + + private: +}; + #endif |