From 92a59b6138ec870ba17108a0cf29ba1199414fd5 Mon Sep 17 00:00:00 2001 From: randomdan Date: Wed, 28 Mar 2012 00:45:18 +0000 Subject: Remove lots of specific implementations and replace them with our new generic loader --- project2/cgi/cgiAppEngine.cpp | 2 +- project2/cgi/cgiOutputOptions.cpp | 2 +- project2/cgi/cgiOutputOptions.h | 2 +- project2/cgi/cgiStagePresent.cpp | 2 +- project2/common/genericLoader.h | 27 ---------------------- project2/common/library.cpp | 2 +- project2/common/memoryCache.cpp | 2 +- project2/common/optionsSource.h | 15 +----------- project2/common/presenter.h | 16 +------------ project2/common/scriptLoader.h | 39 ++++++++++++++++++++------------ project2/common/scriptStorage.h | 8 +++---- project2/common/scripts.h | 6 +---- project2/common/scripts_fwd.h | 11 +++++++++ project2/common/sessionContainer.h | 17 +------------- project2/common/sourceObject.cpp | 2 ++ project2/common/sourceObject.h | 6 ++--- project2/common/transform.cpp | 2 +- project2/common/transform.h | 26 ++------------------- project2/common/variables-modconfig.cpp | 2 +- project2/common/variables-modliteral.cpp | 2 +- project2/common/variables.h | 14 +----------- project2/compression/Jamfile.jam | 2 +- project2/compression/decompressor.h | 1 - project2/files/fsRows.cpp | 2 +- project2/files/fsRows.h | 28 ++++++++++++----------- project2/files/presenterCache.cpp | 2 +- project2/json/couchSession.cpp | 2 +- project2/json/presenter.cpp | 2 +- project2/mail/sendmailTask.cpp | 2 +- project2/sql/connectionLoader.h | 16 +------------ project2/sql/rdbmsDataSource.cpp | 4 ++-- project2/sql/rdbmsDataSource.h | 3 +-- project2/sql/sql-modODBC.cpp | 2 +- project2/sql/sql-modPQ.cpp | 2 +- project2/sql/sqlCache.cpp | 2 +- project2/xml/sessionXml.cpp | 2 +- project2/xml/transformText.cpp | 2 +- project2/xml/xmlCache.cpp | 2 +- project2/xml/xmlPresenter.cpp | 2 +- 39 files changed, 91 insertions(+), 192 deletions(-) delete mode 100644 project2/common/genericLoader.h create mode 100644 project2/common/scripts_fwd.h diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp index a503f3d..c7ee3e6 100644 --- a/project2/cgi/cgiAppEngine.cpp +++ b/project2/cgi/cgiAppEngine.cpp @@ -18,7 +18,7 @@ SimpleMessageException(UnknownDomain); CgiApplicationEngine::CgiApplicationEngine(const CgiEnvironment * e, std::ostream & io) : _env(e), - sessionsContainer(LoaderBase::getLoader(e->sessionModule)->open()), + sessionsContainer(SessionContainerLoader::getFor(e->sessionModule)->create()), IO(io), outputCachingActive(false) { diff --git a/project2/cgi/cgiOutputOptions.cpp b/project2/cgi/cgiOutputOptions.cpp index e18a0b8..ba4d621 100644 --- a/project2/cgi/cgiOutputOptions.cpp +++ b/project2/cgi/cgiOutputOptions.cpp @@ -32,7 +32,7 @@ OutputOptionsLoader::OutputOptionsLoader() : } OutputOptionsPtr -OutputOptionsLoader::createFrom(ScriptNodePtr e) const { +OutputOptionsLoader::create(ScriptNodePtr e) const { return new OutputOptions(e); } diff --git a/project2/cgi/cgiOutputOptions.h b/project2/cgi/cgiOutputOptions.h index 4a4f1c8..faace67 100644 --- a/project2/cgi/cgiOutputOptions.h +++ b/project2/cgi/cgiOutputOptions.h @@ -31,7 +31,7 @@ typedef boost::intrusive_ptr OutputOptionsPtr; class OutputOptionsLoader : public ComponentLoader { public: OutputOptionsLoader(); - OutputOptionsPtr createFrom(ScriptNodePtr e) const; + OutputOptionsPtr create(ScriptNodePtr e) const; const Options * options() const; private: diff --git a/project2/cgi/cgiStagePresent.cpp b/project2/cgi/cgiStagePresent.cpp index 9c7ab7f..98031e4 100644 --- a/project2/cgi/cgiStagePresent.cpp +++ b/project2/cgi/cgiStagePresent.cpp @@ -52,7 +52,7 @@ MultiRowSetPresenterPtr CgiApplicationEngine::PresentStage::getPresenter() const { if (!presenter) { - presenter = LoaderBase::getLoader(env()->defaultPresenter)->createFrom(root); + presenter = PresenterLoader::getFor(env()->defaultPresenter)->create(root); } return presenter; } diff --git a/project2/common/genericLoader.h b/project2/common/genericLoader.h deleted file mode 100644 index cd129f0..0000000 --- a/project2/common/genericLoader.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef GENERICLOADER_H -#define GENERICLOADER_H - -#include "scriptLoader.h" - -template -class GenLoader : public ComponentLoader { - public: - template - class For : public GenLoader { - public: - inline Impl * create(const Params & ... p) const - { - return new T(p...); - } - }; - virtual Impl * create(const Params & ...) const = 0; - inline static boost::shared_ptr> getFor(const char * n) - { - return LoaderBase::getLoader, NotSupported>(n); - } -}; -#define DECLARE_GENERIC_LOADER(N, B, T) \ - DECLARE_CUSTOM_COMPONENT_LOADER(N, T, B::For, B); - -#endif - diff --git a/project2/common/library.cpp b/project2/common/library.cpp index f7cc51c..b53a6b0 100644 --- a/project2/common/library.cpp +++ b/project2/common/library.cpp @@ -25,7 +25,7 @@ Library::~Library() } STORAGEOF(Library) libraries; -class LibraryLoader : public ElementLoaderImpl { +class LibraryLoader : public ElementLoader::For { public: void onIteration() { diff --git a/project2/common/memoryCache.cpp b/project2/common/memoryCache.cpp index a24abb3..cd13930 100644 --- a/project2/common/memoryCache.cpp +++ b/project2/common/memoryCache.cpp @@ -145,7 +145,7 @@ class MemoryCache : public Cache { time_t MemoryCache::CacheLife; MemoryCache::CacheStore MemoryCache::Store; -class CustomMemoryCacheLoader : public ElementLoaderImpl { +class CustomMemoryCacheLoader : public ElementLoader::For { public: CustomMemoryCacheLoader() : opts("Memory Cache options") diff --git a/project2/common/optionsSource.h b/project2/common/optionsSource.h index f238a66..208e5ff 100644 --- a/project2/common/optionsSource.h +++ b/project2/common/optionsSource.h @@ -22,20 +22,7 @@ class OptionsSource : public IntrusivePtrBase { typedef boost::intrusive_ptr OptionsSourcePtr; /// Base class to implement presenter modules -class OptionsSourceLoader : public ComponentLoader { - public: - virtual OptionsSourcePtr create() const = 0; -}; - -/// Helper implemention for specific presenters -template -class OptionsSourceLoaderImpl : public OptionsSourceLoader { - public: - virtual OptionsSourcePtr create() const - { - return new OptionsSourceType(); - } -}; +typedef GenLoader OptionsSourceLoader; #endif diff --git a/project2/common/presenter.h b/project2/common/presenter.h index a16b32b..e1a78dd 100644 --- a/project2/common/presenter.h +++ b/project2/common/presenter.h @@ -76,21 +76,7 @@ typedef boost::intrusive_ptr RowSetPresenterPtr; typedef boost::intrusive_ptr MultiRowSetPresenterPtr; typedef boost::intrusive_ptr NameValuePairPresenterPtr; -/// Base class to implement presenter modules -class PresenterLoader : public ComponentLoader { - public: - virtual MultiRowSetPresenterPtr createFrom(ScriptNodePtr e) const = 0; -}; - -/// Helper implemention for specific presenters -template -class PresenterLoaderImpl : public PresenterLoader { - public: - virtual MultiRowSetPresenterPtr createFrom(ScriptNodePtr e) const - { - return new PresenterType(e); - } -}; +typedef GenLoader PresenterLoader; #endif diff --git a/project2/common/scriptLoader.h b/project2/common/scriptLoader.h index b2faecd..ccc7afb 100644 --- a/project2/common/scriptLoader.h +++ b/project2/common/scriptLoader.h @@ -8,16 +8,18 @@ #include #include "intrusivePtrBase.h" #include "sourceObject.h" +#include "scripts_fwd.h" #include "exceptions.h" #include #include #include -class ElementLoader; class ComponentLoader; class CommonObjects; class Storer; class ScriptReader; +class SourceObject; +typedef boost::intrusive_ptr SourceObjectPtr; class LoaderBase { public: @@ -90,7 +92,7 @@ class LoaderBase { static ScriptNodePtr getSub(ScriptNodePtr root, const Glib::ustring & name, bool required); Targets targets; static unsigned int depth; - template friend class ElementLoaderImpl; + friend class SourceObject; static std::set loadedObjects; const bool recursive; @@ -107,9 +109,11 @@ class LoaderBase { #define DECLARE_CUSTOM_LOADER(N, T) \ DECLARE_CUSTOM_COMPONENT_LOADER(N, T, T, ElementLoader) #define DECLARE_COMPONENT_LOADER(N, T, B) \ - DECLARE_CUSTOM_COMPONENT_LOADER(N, T, B##Impl, B) + DECLARE_CUSTOM_COMPONENT_LOADER(N, T, B::For, B) #define DECLARE_LOADER(N, T) \ DECLARE_COMPONENT_LOADER(N, T, ElementLoader) +#define DECLARE_GENERIC_LOADER(N, B, T) \ + DECLARE_CUSTOM_COMPONENT_LOADER(N, T, B::For, B); /// Helper for loading and maintaining Project2 components class Options; @@ -123,22 +127,27 @@ class ComponentLoader { virtual void onPeriodic(); // When the app engine feels like it virtual const Options * options() const; // Options to be populated from the common config file/env/etc }; -/// Helper for loading and maintaining Project2 script components -class ElementLoader : public ComponentLoader { - public: - virtual SourceObjectPtr createFrom(ScriptNodePtr) const = 0; -}; -/// Helper for loading and maintaining Project2 script components (typed implementation) -template -class ElementLoaderImpl : public ElementLoader { +template +class GenLoader : public ComponentLoader { public: - SourceObjectPtr createFrom(ScriptNodePtr sn) const + template + class For : public GenLoader { + public: + inline Impl * create(const Params & ... p) const + { + return new T(p...); + } + }; + virtual Impl * create(const Params & ...) const = 0; + inline static boost::shared_ptr> getFor(const std::string & n) { - SourceObjectPtr sop = new X(sn); - LoaderBase::loadedObjects.insert(sop); - return sop; + return LoaderBase::getLoader, NotSupported>(n); } }; + +/// Helper for loading and maintaining Project2 script components +typedef GenLoader ElementLoader; + #endif diff --git a/project2/common/scriptStorage.h b/project2/common/scriptStorage.h index c58711b..63ee71c 100644 --- a/project2/common/scriptStorage.h +++ b/project2/common/scriptStorage.h @@ -132,25 +132,25 @@ class StorerImpl : public StorerBase { template boost::intrusive_ptr > Storer::into(SINGLE(X) * obj, const C & ... c) { - return new StorerImpl(obj, boost::bind(&L::createFrom, _1, _2, c...)); + return new StorerImpl(obj, boost::bind(&L::create, _1, _2, c...)); } template boost::intrusive_ptr > Storer::into(STORAGEOF(X) * map, const C & ... c) { - return new StorerImpl(map, boost::bind(&L::createFrom, _1, _2, c...)); + return new StorerImpl(map, boost::bind(&L::create, _1, _2, c...)); } template boost::intrusive_ptr > Storer::into(ANONSTORAGEOF(X) * set, const C & ... c) { - return new StorerImpl(set, boost::bind(&L::createFrom, _1, _2, c...)); + return new StorerImpl(set, boost::bind(&L::create, _1, _2, c...)); } template boost::intrusive_ptr > Storer::into(ANONORDEREDSTORAGEOF(X) * list, const C & ... c) { - return new StorerImpl(list, boost::bind(&L::createFrom, _1, _2, c...)); + return new StorerImpl(list, boost::bind(&L::create, _1, _2, c...)); } #endif diff --git a/project2/common/scripts.h b/project2/common/scripts.h index 972c23f..ba5a8e9 100644 --- a/project2/common/scripts.h +++ b/project2/common/scripts.h @@ -6,6 +6,7 @@ #include #include #include "scriptLoader.h" +#include "scripts_fwd.h" #include "exceptions.h" #include "variables.h" #include @@ -14,11 +15,6 @@ SimpleMessageException(ValueNotFound); SimpleMessage2Exception(ScriptNotFound); SimpleMessage2Exception(DependencyNotFound); -class ScriptNode; -class ScriptReader; -typedef boost::intrusive_ptr ScriptNodePtr; -typedef boost::intrusive_ptr ScriptReaderPtr; - class ScriptNode : public IntrusivePtrBase { public: ScriptNode(ScriptReaderPtr); diff --git a/project2/common/scripts_fwd.h b/project2/common/scripts_fwd.h new file mode 100644 index 0000000..7d5ed00 --- /dev/null +++ b/project2/common/scripts_fwd.h @@ -0,0 +1,11 @@ +#ifndef SCRIPTS_FWD_H +#define SCRIPTS_FWD_H + +#include + +class ScriptNode; +class ScriptReader; +typedef boost::intrusive_ptr ScriptNodePtr; +typedef boost::intrusive_ptr ScriptReaderPtr; + +#endif diff --git a/project2/common/sessionContainer.h b/project2/common/sessionContainer.h index ffbc5ed..2a20085 100644 --- a/project2/common/sessionContainer.h +++ b/project2/common/sessionContainer.h @@ -17,22 +17,7 @@ class SessionContainer : public IntrusivePtrBase { virtual SessionPtr getSession(const UUID & sid) const = 0; }; typedef boost::intrusive_ptr SessionContainerPtr; - -/// Base class to implement session container imlpementations -class SessionContainerLoader : public ComponentLoader { - public: - virtual SessionContainerPtr open() const = 0; -}; - -/// Helper implemention for specific container types -template -class SessionContainerLoaderImpl : public SessionContainerLoader { - public: - virtual SessionContainerPtr open() const - { - return new SCType(); - } -}; +typedef GenLoader SessionContainerLoader; #endif diff --git a/project2/common/sourceObject.cpp b/project2/common/sourceObject.cpp index ccc1034..e66e9ee 100644 --- a/project2/common/sourceObject.cpp +++ b/project2/common/sourceObject.cpp @@ -7,12 +7,14 @@ SourceObject::SourceObject(ScriptNodePtr p) : name(p ? p->value("name", "anon").as() : "anon"), order(loadOrder++) { + LoaderBase::loadedObjects.insert(this); } SourceObject::SourceObject(const std::string & n) : name(n), order(loadOrder++) { + LoaderBase::loadedObjects.insert(this); } SourceObject::~SourceObject() diff --git a/project2/common/sourceObject.h b/project2/common/sourceObject.h index 4d10dd4..8cf75ad 100644 --- a/project2/common/sourceObject.h +++ b/project2/common/sourceObject.h @@ -4,12 +4,10 @@ #include #include #include "intrusivePtrBase.h" +#include "scriptLoader.h" +#include "scripts_fwd.h" class CommonObjects; -class SourceObject; -class ScriptNode; -typedef boost::intrusive_ptr SourceObjectPtr; -typedef boost::intrusive_ptr ScriptNodePtr; /// Base class for all Project2 components that can be placed in a Project2 script class SourceObject : public virtual IntrusivePtrBase { public: diff --git a/project2/common/transform.cpp b/project2/common/transform.cpp index 9a53107..874ced3 100644 --- a/project2/common/transform.cpp +++ b/project2/common/transform.cpp @@ -12,7 +12,7 @@ class TransformTargetStorer : public Storer { } boost::intrusive_ptr create(ScriptNodePtr p) const { - return LoaderBase::getLoader(p->get_name())->createFrom(p); + return LoaderBase::getLoader(p->get_name())->create(p); } bool save(boost::intrusive_ptr o, ScriptNodePtr s) { diff --git a/project2/common/transform.h b/project2/common/transform.h index e2216d7..2355195 100644 --- a/project2/common/transform.h +++ b/project2/common/transform.h @@ -45,32 +45,10 @@ class Transform : public virtual IntrusivePtrBase { virtual void configure(ScriptNodePtr) { }; }; -class TransformLoader : public ComponentLoader { - public: - virtual boost::intrusive_ptr create() const = 0; -}; - -template -class TransformLoaderImpl : public TransformLoader { - public: - boost::intrusive_ptr create() const { - return new T(); - } -}; +typedef GenLoader TransformLoader; #define DECLARE_TRANSFORM(T) DECLARE_COMPONENT_LOADER(#T, T, TransformLoader) -class TransformTargetLoader : public ComponentLoader { - public: - virtual boost::intrusive_ptr createFrom(ScriptNodePtr) const = 0; -}; - -template -class TransformTargetLoaderImpl : public TransformTargetLoader { - public: - boost::intrusive_ptr createFrom(ScriptNodePtr s) const { - return new T(s); - } -}; +typedef GenLoader TransformTargetLoader; #define DECLARE_TRANSFORMTARGET(N, T) DECLARE_COMPONENT_LOADER(N, T, TransformTargetLoader) template diff --git a/project2/common/variables-modconfig.cpp b/project2/common/variables-modconfig.cpp index 3f5e25a..4d9553a 100644 --- a/project2/common/variables-modconfig.cpp +++ b/project2/common/variables-modconfig.cpp @@ -33,7 +33,7 @@ class VariableConfig : public VariableImplDyn { const Glib::ustring name; }; -class VariableConfigLoader : public VariableLoaderImpl { +class VariableConfigLoader : public VariableLoader::For { public: class AppSettings : public Options::Option { public: diff --git a/project2/common/variables-modliteral.cpp b/project2/common/variables-modliteral.cpp index 8c165ee..33c9ad5 100644 --- a/project2/common/variables-modliteral.cpp +++ b/project2/common/variables-modliteral.cpp @@ -73,6 +73,6 @@ VariableLiteral::VarPart::operator VariableType() const } DECLARE_COMPONENT_LOADER("literal", VariableLiteral, VariableLoader); -DECLARE_CUSTOM_COMPONENT_LOADER("", VariableLiteralDef, VariableLoaderImpl, VariableLoader); +DECLARE_CUSTOM_COMPONENT_LOADER("", VariableLiteralDef, VariableLoader::For, VariableLoader); diff --git a/project2/common/variables.h b/project2/common/variables.h index ca2cdc7..932da90 100644 --- a/project2/common/variables.h +++ b/project2/common/variables.h @@ -136,19 +136,7 @@ class VariableImplDyn : public VariableImpl { }; /// Base class to create variables -class VariableLoader : public ComponentLoader { - public: - virtual VariableImpl * create(ScriptNodePtr) const = 0; -}; -/// Helper implementation of VariableLoader for specific variable types -template -class VariableLoaderImpl : public VariableLoader { - public: - virtual VariableImpl * create(ScriptNodePtr e) const - { - return new VarType(e); - } -}; +typedef GenLoader VariableLoader; #endif diff --git a/project2/compression/Jamfile.jam b/project2/compression/Jamfile.jam index 99d3b75..b1715cb 100644 --- a/project2/compression/Jamfile.jam +++ b/project2/compression/Jamfile.jam @@ -12,6 +12,6 @@ lib p2compression : glibmm libz ../common//p2common - ../files//p2files + ../streams//p2streams ; diff --git a/project2/compression/decompressor.h b/project2/compression/decompressor.h index dfa1db7..32be53a 100644 --- a/project2/compression/decompressor.h +++ b/project2/compression/decompressor.h @@ -2,7 +2,6 @@ #define DECOMPRESSOR #include "stream.h" -#include "genericLoader.h" #include "intrusivePtrBase.h" class Decompressor : public IntrusivePtrBase { diff --git a/project2/files/fsRows.cpp b/project2/files/fsRows.cpp index 9dfa3f8..72a2055 100644 --- a/project2/files/fsRows.cpp +++ b/project2/files/fsRows.cpp @@ -80,7 +80,7 @@ FsRows::execute(const Glib::ustring &, const RowProcessor * rp) const for (SpecSpec::const_iterator sf = s.begin(); sf != s.end(); ) { const Glib::ustring & name = (*sf++); if (name[0] == '-') { - ss.specs.insert(LoaderBase::getLoader(name.substr(1))->create(*sf++)); + ss.specs.insert(LoaderBase::getLoader(name.substr(1))->createWith(*sf++)); } else { throw NotSupported(name); diff --git a/project2/files/fsRows.h b/project2/files/fsRows.h index acbce0d..6b689d3 100644 --- a/project2/files/fsRows.h +++ b/project2/files/fsRows.h @@ -7,6 +7,7 @@ #include "variables.h" #include "rowSet.h" #include "scriptStorage.h" +#include "scriptLoader.h" class CommonObjects; @@ -24,21 +25,22 @@ class FsRows : public RowSet { const struct stat & curStat(const SearchState * fs) const; }; typedef boost::intrusive_ptr SpecBasePtr; - class SpecBaseLoader : public ComponentLoader { + template + class SpecBaseLoaderX : public GenLoader { public: - virtual SpecBasePtr createFrom(ScriptNodePtr) const = 0; - virtual SpecBasePtr create(const Glib::ustring &) const = 0; - }; - template - class SpecBaseLoaderImpl : public SpecBaseLoader { - public: - SpecBasePtr createFrom(ScriptNodePtr s) const { - return new T(s); - } - SpecBasePtr create(const Glib::ustring & v) const { - return new T(v); - } + virtual SpecBase * createWith(const Glib::ustring &) const = 0; + template + class For : public SpecBaseLoaderX { + public: + SpecBase * create(const ScriptNodePtr & v) const { + return new T(v); + } + SpecBase * createWith(const Glib::ustring & v) const { + return new T(v); + } + }; }; + typedef SpecBaseLoaderX SpecBaseLoader; typedef ANONSTORAGEOF(SpecBase) SpecBases; typedef std::list SpecSpec; typedef boost::filesystem::path Path; diff --git a/project2/files/presenterCache.cpp b/project2/files/presenterCache.cpp index 789dd95..8d189b5 100644 --- a/project2/files/presenterCache.cpp +++ b/project2/files/presenterCache.cpp @@ -139,7 +139,7 @@ boost::filesystem::path FilePresenterCache::Store; std::string FilePresenterCache::FileName; time_t FilePresenterCache::CacheLife; -class FilePresenterCacheLoader : public ElementLoaderImpl { +class FilePresenterCacheLoader : public ElementLoader::For { public: FilePresenterCacheLoader() : opts("XML Cache options") diff --git a/project2/json/couchSession.cpp b/project2/json/couchSession.cpp index 5d964aa..a6c49e9 100644 --- a/project2/json/couchSession.cpp +++ b/project2/json/couchSession.cpp @@ -105,7 +105,7 @@ class CouchSessionContainer : public SessionContainer { std::vector CouchSessionContainer::baseUrls; const Glib::ustring CouchSessionContainer::ExpiryKey("project2:expires"); -class CustomCouchSessionLoader : public SessionContainerLoaderImpl { +class CustomCouchSessionLoader : public SessionContainerLoader::For { public: CustomCouchSessionLoader() : opts("Session CouchDB options") diff --git a/project2/json/presenter.cpp b/project2/json/presenter.cpp index 0eb484b..b76f232 100644 --- a/project2/json/presenter.cpp +++ b/project2/json/presenter.cpp @@ -97,4 +97,4 @@ class JsonPresenter : public MultiRowSetPresenter, public ContentPresenter, publ mutable std::stack curRowSet; mutable std::stack curRowArray; }; -DECLARE_COMPONENT_LOADER("json", JsonPresenter, PresenterLoader) +DECLARE_GENERIC_LOADER("json", PresenterLoader, JsonPresenter) diff --git a/project2/mail/sendmailTask.cpp b/project2/mail/sendmailTask.cpp index f8bc879..f70fe64 100644 --- a/project2/mail/sendmailTask.cpp +++ b/project2/mail/sendmailTask.cpp @@ -14,7 +14,7 @@ std::string SendMailTask::defaultMailServer; std::string SendMailTask::defaultMailEncoding; -class CustomSendMailTaskLoader : public ElementLoaderImpl { +class CustomSendMailTaskLoader : public ElementLoader::For { public: CustomSendMailTaskLoader() : opts("Send Email Task options") diff --git a/project2/sql/connectionLoader.h b/project2/sql/connectionLoader.h index 3dc5f93..89de76b 100644 --- a/project2/sql/connectionLoader.h +++ b/project2/sql/connectionLoader.h @@ -4,21 +4,7 @@ #include "scriptLoader.h" #include "../libdbpp/connection.h" -/// Base class to implement DB connection type modules -class ConnectionLoader : public ComponentLoader { - public: - virtual DB::Connection * connect(const std::string & dsn) const = 0; -}; - -/// Helper implemention for specific DB types -template -class ConnectionLoaderImpl : public ConnectionLoader { - public: - virtual DB::Connection * connect(const std::string & dsn) const - { - return new DBType(dsn); - } -}; +typedef GenLoader ConnectionLoader; #endif diff --git a/project2/sql/rdbmsDataSource.cpp b/project2/sql/rdbmsDataSource.cpp index 6f3cedb..8bdacdf 100644 --- a/project2/sql/rdbmsDataSource.cpp +++ b/project2/sql/rdbmsDataSource.cpp @@ -9,7 +9,7 @@ SimpleMessageException(UnknownConnectionProvider); /// Specialized ElementLoader for instances of RdbmsDataSource; handles persistent DB connections -class RdbmsDataSourceLoader : public ElementLoaderImpl { +class RdbmsDataSourceLoader : public ElementLoader::For { public: void onIdle() { @@ -201,7 +201,7 @@ RdbmsDataSource::ConnectionInfo::ConnectionInfo(ScriptNodePtr node) : DB::Connection * RdbmsDataSource::ConnectionInfo::connect() const { - return typeId->connect(dsn); + return typeId->create(dsn); } bool diff --git a/project2/sql/rdbmsDataSource.h b/project2/sql/rdbmsDataSource.h index c0345a0..6d3b184 100644 --- a/project2/sql/rdbmsDataSource.h +++ b/project2/sql/rdbmsDataSource.h @@ -8,8 +8,7 @@ #include "../libdbpp/connection.h" #include "../libdbpp/error.h" #include "scriptLoader.h" - -class ConnectionLoader; +#include "connectionLoader.h" /// Project2 component to provide access to transactional RDBMS data sources class RdbmsDataSource : public DataSource { diff --git a/project2/sql/sql-modODBC.cpp b/project2/sql/sql-modODBC.cpp index 1703cb6..284d02e 100644 --- a/project2/sql/sql-modODBC.cpp +++ b/project2/sql/sql-modODBC.cpp @@ -1,4 +1,4 @@ #include "connectionLoader.h" #include "../libodbcpp/connection.h" typedef ODBC::Connection ODBCConnection; -DECLARE_COMPONENT_LOADER("odbc", ODBCConnection, ConnectionLoader) +DECLARE_GENERIC_LOADER("odbc", ConnectionLoader, ODBCConnection) diff --git a/project2/sql/sql-modPQ.cpp b/project2/sql/sql-modPQ.cpp index 5991754..cb753e0 100644 --- a/project2/sql/sql-modPQ.cpp +++ b/project2/sql/sql-modPQ.cpp @@ -1,4 +1,4 @@ #include "connectionLoader.h" #include "../libpqpp/connection.h" typedef PQ::Connection PQConnection; -DECLARE_COMPONENT_LOADER("postgresql", PQConnection, ConnectionLoader) +DECLARE_GENERIC_LOADER("postgresql", ConnectionLoader, PQConnection) diff --git a/project2/sql/sqlCache.cpp b/project2/sql/sqlCache.cpp index e94e345..08d2831 100644 --- a/project2/sql/sqlCache.cpp +++ b/project2/sql/sqlCache.cpp @@ -257,7 +257,7 @@ std::string SqlCache::DataSource; std::string SqlCache::HeaderTable; time_t SqlCache::CacheLife; -class CustomSqlCacheLoader : public ElementLoaderImpl { +class CustomSqlCacheLoader : public ElementLoader::For { public: CustomSqlCacheLoader() : opts("SQL Cache options") diff --git a/project2/xml/sessionXml.cpp b/project2/xml/sessionXml.cpp index a3455f6..db34b52 100644 --- a/project2/xml/sessionXml.cpp +++ b/project2/xml/sessionXml.cpp @@ -8,7 +8,7 @@ #include #include "options.h" -class CustomSessionContainerLoaderXml : public SessionContainerLoaderImpl { +class CustomSessionContainerLoaderXml : public SessionContainerLoader::For { public: CustomSessionContainerLoaderXml() : opts("SessionXML options") diff --git a/project2/xml/transformText.cpp b/project2/xml/transformText.cpp index efe0c0b..02c12e3 100644 --- a/project2/xml/transformText.cpp +++ b/project2/xml/transformText.cpp @@ -35,7 +35,7 @@ TextDocument::getContentClass() const { } class TransformHtmlToText; -class TransformHtmlToTextLoader : public TransformLoaderImpl { +class TransformHtmlToTextLoader : public TransformLoader::For { public: TransformHtmlToTextLoader() : opts("Transform HTML to text options") diff --git a/project2/xml/xmlCache.cpp b/project2/xml/xmlCache.cpp index 0ec745b..abe56ab 100644 --- a/project2/xml/xmlCache.cpp +++ b/project2/xml/xmlCache.cpp @@ -84,7 +84,7 @@ boost::filesystem::path XmlCache::Store; std::string XmlCache::FileName; time_t XmlCache::CacheLife; -class CustomXmlCacheLoader : public ElementLoaderImpl { +class CustomXmlCacheLoader : public ElementLoader::For { public: CustomXmlCacheLoader() : opts("XML Cache options") diff --git a/project2/xml/xmlPresenter.cpp b/project2/xml/xmlPresenter.cpp index 02ec82d..a6d6f40 100644 --- a/project2/xml/xmlPresenter.cpp +++ b/project2/xml/xmlPresenter.cpp @@ -7,7 +7,7 @@ #include #include -class XmlPresenterLoader : public PresenterLoaderImpl { +class XmlPresenterLoader : public PresenterLoader::For { public: XmlPresenterLoader() : opts("XML Cache options") -- cgit v1.2.3