summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2013-09-15 12:43:27 +0000
committerrandomdan <randomdan@localhost>2013-09-15 12:43:27 +0000
commitd022256a4136234d742e3178d31948b5f88bc0f6 (patch)
tree34182eca80cc6a92a7a4a4c9d19836f0da2e0981
parentAdd a module for preloading libraries, which supersedes that in daemon (diff)
downloadproject2-d022256a4136234d742e3178d31948b5f88bc0f6.tar.bz2
project2-d022256a4136234d742e3178d31948b5f88bc0f6.tar.xz
project2-d022256a4136234d742e3178d31948b5f88bc0f6.zip
Allow instance registration to occur with different key types
-rw-r--r--project2/basics/preload.cpp6
-rw-r--r--project2/cgi/cgiOutputOptions.h2
-rw-r--r--project2/cgi/cgiRouter.h2
-rw-r--r--project2/cgi/testCgi.cpp6
-rw-r--r--project2/common/Jamfile.jam1
-rw-r--r--project2/common/genLoader.h18
-rw-r--r--project2/common/instanceStore.h103
-rw-r--r--project2/common/logger.cpp6
-rw-r--r--project2/common/logger.h2
-rw-r--r--project2/common/options.h5
-rw-r--r--project2/common/optionsSource.cpp12
-rw-r--r--project2/common/optionsSource.h5
-rw-r--r--project2/common/plugable.h144
-rw-r--r--project2/common/presenter.h2
-rw-r--r--project2/common/scriptLoader.h2
-rw-r--r--project2/common/scriptStorage.h4
-rw-r--r--project2/common/scripts.cpp4
-rw-r--r--project2/common/scripts.h2
-rw-r--r--project2/common/sessionContainer.h2
-rw-r--r--project2/common/transform.cpp6
-rw-r--r--project2/common/transform.h4
-rw-r--r--project2/common/variables.h2
-rw-r--r--project2/compression/decompressor.h2
-rw-r--r--project2/console/consoleAppEngine.cpp2
-rw-r--r--project2/console/p2consoleMain.cpp2
-rw-r--r--project2/daemon/lib/daemon.h2
-rw-r--r--project2/daemon/p2daemonMain.cpp2
-rw-r--r--project2/files/fsRows.cpp2
-rw-r--r--project2/files/fsRows.h2
-rw-r--r--project2/sql/Jamfile.jam6
-rw-r--r--project2/sql/connectionLoader.h2
-rw-r--r--project2/sql/rdbmsDataSource.cpp2
-rw-r--r--project2/xml/xmlDocumentCache.cpp4
-rw-r--r--project2/xml/xmlPresenter.h2
-rw-r--r--project2/xml/xmlScriptParser.cpp8
35 files changed, 233 insertions, 145 deletions
diff --git a/project2/basics/preload.cpp b/project2/basics/preload.cpp
index e8aa6e9..b701d8d 100644
--- a/project2/basics/preload.cpp
+++ b/project2/basics/preload.cpp
@@ -16,7 +16,7 @@ class Preload {
static void LoadLibrary(const VariableType & librarypath)
{
- const auto beforeOpts = *Plugable::ComponentType<Options>::components();
+ const auto beforeOpts = InstanceSet<Options>::GetAll();
void * handle = dlopen(librarypath, RTLD_NOW);
if (handle) {
@@ -28,8 +28,8 @@ class Preload {
}
libs[librarypath.as<std::string>()] = boost::shared_ptr<void>(handle, &dlclose);
- const auto afterOpts = Plugable::ComponentType<Options>::components();
- BOOST_FOREACH(const auto & opt, *afterOpts) {
+ const auto afterOpts = InstanceSet<Options>::GetAll();
+ BOOST_FOREACH(const auto & opt, afterOpts) {
if (std::find(beforeOpts.begin(), beforeOpts.end(), opt) == beforeOpts.end()) {
opt->reset();
}
diff --git a/project2/cgi/cgiOutputOptions.h b/project2/cgi/cgiOutputOptions.h
index bb214ea..be2c452 100644
--- a/project2/cgi/cgiOutputOptions.h
+++ b/project2/cgi/cgiOutputOptions.h
@@ -32,6 +32,8 @@ typedef boost::intrusive_ptr<OutputOptions> OutputOptionsPtr;
class OutputOptionsLoader : public ComponentLoader {
public:
+ typedef std::string KeyType;
+
OutputOptionsPtr create(ScriptNodePtr e) const;
INITOPTIONS;
};
diff --git a/project2/cgi/cgiRouter.h b/project2/cgi/cgiRouter.h
index 4a88b19..9e9c621 100644
--- a/project2/cgi/cgiRouter.h
+++ b/project2/cgi/cgiRouter.h
@@ -15,7 +15,7 @@ class Router : public IntrusivePtrBase {
virtual void present(const MultiRowSetPresenter * p) const = 0;
};
typedef boost::intrusive_ptr<Router> RouterPtr;
-typedef GenLoader<Router, const std::string &> RouterLoader;
+typedef GenLoader<Router, std::string, const std::string &> RouterLoader;
#endif
diff --git a/project2/cgi/testCgi.cpp b/project2/cgi/testCgi.cpp
index 6648cd3..e842958 100644
--- a/project2/cgi/testCgi.cpp
+++ b/project2/cgi/testCgi.cpp
@@ -15,7 +15,7 @@ class TestInput : public cgicc::CgiInput, public CgiEnvInput {
class TestConfigConsumer : public ConfigConsumer {
public:
void operator()(const Glib::ustring & n, const Glib::ustring & p, const Glib::ustring & v, const Options::CurrentPlatform & cp) const {
- Plugable::onAll<Options>(boost::bind(&Options::consume, _1, n, p, v, cp));
+ InstanceSet<Options>::OnAll(boost::bind(&Options::consume, _1, n, p, v, cp));
}
const Options::Option * get(const Glib::ustring &) const {
return NULL;
@@ -26,8 +26,8 @@ class TestInput : public cgicc::CgiInput, public CgiEnvInput {
typedef std::map<std::string, StrPtr> OptStore;
TestInput(int argc, char ** argv)
{
- Plugable::newLoader<OptionsSource, OptionsSource>("_1", new FileOptions(".testCgi.settings"));
- Plugable::newLoader<OptionsSource, OptionsSource>("_2", new CommandLineArguments(argc, argv,
+ OptionsSources::Add("_1", new FileOptions(".testCgi.settings"));
+ OptionsSources::Add("_2", new CommandLineArguments(argc, argv,
[](const char * url) { urls.push_back(url); }));
}
diff --git a/project2/common/Jamfile.jam b/project2/common/Jamfile.jam
index 2b58409..541e714 100644
--- a/project2/common/Jamfile.jam
+++ b/project2/common/Jamfile.jam
@@ -9,6 +9,7 @@ lib boost_date_time : : <name>boost_date_time ;
cpp-pch pch : pch.hpp :
<include>../../libmisc
+ <library>../lib//p2lib
<library>glibmm
;
diff --git a/project2/common/genLoader.h b/project2/common/genLoader.h
index 4208f40..e5ff43e 100644
--- a/project2/common/genLoader.h
+++ b/project2/common/genLoader.h
@@ -4,10 +4,13 @@
#include "componentLoader.h"
#include "plugable.h"
-template <class Impl, typename... Params>
+template <class Impl, class Key, typename... Params>
class GenLoader : public ComponentLoader {
public:
- template <class T, class BaseLoader = GenLoader<Impl, Params...>>
+ typedef Key KeyType;
+ typedef GenLoader<Impl, KeyType, Params...> Self;
+
+ template <class T, class BaseLoader = Self>
class For : public BaseLoader {
public:
inline Impl * create(const Params & ... p) const
@@ -15,14 +18,17 @@ class GenLoader : public ComponentLoader {
return new T(p...);
}
};
+
virtual Impl * create(const Params & ...) const = 0;
- inline static Impl * createNew(const std::string & n, const Params & ... p)
+
+ inline static Impl * createNew(const KeyType & n, const Params & ... p)
{
- return Plugable::getLoader<GenLoader<Impl, Params...>, NotSupported>(n)->create(p...);
+ return InstanceMap<Self, KeyType>::template Get<NotSupported>(n)->create(p...);
}
- inline static boost::shared_ptr<GenLoader<Impl, Params...>> getFor(const std::string & n)
+
+ inline static boost::shared_ptr<Self> getFor(const KeyType & n)
{
- return Plugable::getLoader<GenLoader<Impl, Params...>, NotSupported>(n);
+ return InstanceMap<Self, KeyType>::template Get<NotSupported>(n);
}
};
diff --git a/project2/common/instanceStore.h b/project2/common/instanceStore.h
new file mode 100644
index 0000000..c61ccfe
--- /dev/null
+++ b/project2/common/instanceStore.h
@@ -0,0 +1,103 @@
+#ifndef INSTANCESTORE_H
+#define INSTANCESTORE_H
+
+#include <boost/foreach.hpp>
+#include <boost/function.hpp>
+#include <set>
+#include <map>
+#include <safeMapFind.h>
+
+/// A static collection of any type, specifically with automatically cleaned up storage of a function static variable
+// which makes it safe to use in constructor functions.
+template <class Type, class StoreType>
+class InstanceStore {
+ public:
+ static const StoreType & GetAll()
+ {
+ return *getInstances();
+ }
+
+ static void Add(const typename StoreType::value_type & p)
+ {
+ getInstances()->insert(p);
+ }
+
+ template <typename EraseByType>
+ static void Remove(const EraseByType & p)
+ {
+ getInstances()->erase(p);
+ prune();
+ }
+
+ static void OnEach(const boost::function<void(typename StoreType::value_type &)> & func)
+ {
+ BOOST_FOREACH(const auto & l, GetAll()) {
+ try {
+ func(l.get());
+ }
+ catch (...) {
+ }
+ }
+ prune();
+ }
+
+ static void OnAll(const boost::function<void(Type *)> & func)
+ {
+ BOOST_FOREACH(const auto & l, GetAll()) {
+ try {
+ func(l.get());
+ }
+ catch (...) {
+ }
+ }
+ prune();
+ }
+
+ private:
+ static void prune()
+ {
+ auto & ps = getInstances();
+ if (ps->empty()) {
+ delete ps;
+ ps = NULL;
+ }
+ }
+
+ static StoreType * & getInstances()
+ {
+ static StoreType * instances = NULL;
+ if (!instances) {
+ instances = new StoreType();
+ }
+ return instances;
+ }
+};
+
+/// Keyed collection of instances
+template <class Type, class KeyType>
+class InstanceMap : public InstanceStore<Type, std::map<KeyType, boost::shared_ptr<Type>>> {
+ public:
+ typedef std::map<KeyType, boost::shared_ptr<Type>> Store;
+ typedef typename Store::value_type Value;
+
+ static void Add(const KeyType & k, Type * p) {
+ InstanceStore<Type, Store>::Add(Value(k, boost::shared_ptr<Type>(p)));
+ }
+
+ static void Add(const KeyType & k, const boost::shared_ptr<Type> & p) {
+ InstanceStore<Type, Store>::Add(Value(k, p));
+ }
+
+ template <class E> static boost::shared_ptr<Type> Get(const KeyType & n)
+ {
+ return safeMapLookup<E>(InstanceStore<Type, Store>::GetAll(), n);
+ }
+};
+
+/// Anonymous collection of instances
+template <class Type>
+class InstanceSet : public InstanceStore<Type, std::set<boost::shared_ptr<Type>>> {
+};
+
+#endif
+
diff --git a/project2/common/logger.cpp b/project2/common/logger.cpp
index 5ce82f9..781b44a 100644
--- a/project2/common/logger.cpp
+++ b/project2/common/logger.cpp
@@ -27,9 +27,9 @@ Log::setLoggerAt(LogDriverLoader * ldr, int level)
logs[ldr] = ldr->create();
}
lowestLevel = -1;
- BOOST_FOREACH(const auto & log, *Plugable::objLoaders<LogDriverLoader>()) {
- if (log.second->loggerLevel() > lowestLevel) {
- lowestLevel = log.second->loggerLevel();
+ BOOST_FOREACH(const auto & log, InstanceSet<LogDriverLoader>::GetAll()) {
+ if (log->loggerLevel() > lowestLevel) {
+ lowestLevel = log->loggerLevel();
}
}
}
diff --git a/project2/common/logger.h b/project2/common/logger.h
index d16aefb..8e81bdc 100644
--- a/project2/common/logger.h
+++ b/project2/common/logger.h
@@ -19,7 +19,7 @@ class LogDriverBase : public virtual IntrusivePtrBase {
virtual void message(int priority, const char * msg) const = 0;
};
-class LogDriverLoader : public GenLoader<LogDriverBase> {
+class LogDriverLoader : public GenLoader<LogDriverBase, std::string> {
public:
virtual int loggerLevel() const = 0;
};
diff --git a/project2/common/options.h b/project2/common/options.h
index cee95d4..3a7a28b 100644
--- a/project2/common/options.h
+++ b/project2/common/options.h
@@ -101,19 +101,20 @@ class Options {
// Registration helpers
// These work pluggable component style
+typedef PluginsSameBase<Options, std::string> OptionsSets;
#define DECLARE_OPTIONS(Type, Label) \
static void init_options_##Type() __attribute__ ((constructor(200))); \
static void init_options_##Type() { \
Options * o = new Options(Label); \
Type::InitOptions(*o); \
- Plugable::newLoader<Options, Options>(#Type, o); } \
+ OptionsSets::Add(#Type, o); } \
void Type::InitOptions(Options & o) { o
#define END_OPTIONS(Type) \
;} \
static void kill_options_##Type() __attribute__ ((destructor(200))); \
- static void kill_options_##Type() { Plugable::removeLoader<Options, Options>(#Type); }
+ static void kill_options_##Type() { OptionsSets::Remove(#Type); }
#define INITOPTIONS \
static void InitOptions(Options &)
diff --git a/project2/common/optionsSource.cpp b/project2/common/optionsSource.cpp
index 702b852..ef755c1 100644
--- a/project2/common/optionsSource.cpp
+++ b/project2/common/optionsSource.cpp
@@ -4,11 +4,11 @@
class DefaultConfigConsumer : public ConfigConsumer {
public:
void operator()(const Glib::ustring & n, const Glib::ustring & p, const Glib::ustring & v, const Options::CurrentPlatform & cp) const {
- Plugable::onAll<Options>(boost::bind(&Options::consume, _1, n, p, v, cp));
+ InstanceSet<Options>::OnAll(boost::bind(&Options::consume, _1, n, p, v, cp));
}
const Options::Option * get(const Glib::ustring & n) const {
const Options::Option * rtn = NULL;
- Plugable::onAll<Options>([n,&rtn](const Options * os) {
+ InstanceSet<Options>::OnAll([n,&rtn](const Options * os) {
const Options::Option * o = os->find(n);
if (o) {
rtn = o;
@@ -21,12 +21,12 @@ class DefaultConfigConsumer : public ConfigConsumer {
void
OptionsSource::loadSources(const Options::CurrentPlatform & platform)
{
- const auto & configs = Plugable::ComponentType<OptionsSource>::components();
- if (std::find_if(configs->begin(), configs->end(), boost::bind(&OptionsSource::needReload, _1)) != configs->end()) {
- Plugable::onAll<Options>(boost::bind(&Options::reset, _1));
+ const auto & configs = InstanceSet<OptionsSource>::GetAll();
+ if (std::find_if(configs.begin(), configs.end(), boost::bind(&OptionsSource::needReload, _1)) != configs.end()) {
+ InstanceSet<Options>::OnAll(boost::bind(&Options::reset, _1));
DefaultConfigConsumer dcc;
- BOOST_FOREACH(const auto & c, *configs) {
+ BOOST_FOREACH(const auto & c, configs) {
c->loadInto(dcc, platform);
}
Plugable::onAllComponents(boost::bind(&ComponentLoader::onConfigLoad, _1));
diff --git a/project2/common/optionsSource.h b/project2/common/optionsSource.h
index d6f41ab..53df0ea 100644
--- a/project2/common/optionsSource.h
+++ b/project2/common/optionsSource.h
@@ -23,11 +23,12 @@ class OptionsSource {
};
typedef boost::intrusive_ptr<OptionsSource> OptionsSourcePtr;
+typedef PluginsSameBase<OptionsSource, std::string> OptionsSources;
#define DECLARE_OPTIONSSOURCE(Id, Inst) \
static void init_optionsSource_##Type() __attribute__ ((constructor(200))); \
- static void init_optionsSource_##Type() { Plugable::newLoader<OptionsSource, OptionsSource>(Id, Inst); } \
+ static void init_optionsSource_##Type() { OptionsSources::Add(Id, Inst); } \
static void kill_optionsSource_##Type() __attribute__ ((destructor(200))); \
- static void kill_optionsSource_##Type() { Plugable::removeLoader<OptionsSource, OptionsSource>(Id); }
+ static void kill_optionsSource_##Type() { OptionsSources::Remove(Id); }
#endif
diff --git a/project2/common/plugable.h b/project2/common/plugable.h
index 4b46f8c..2a9c58c 100644
--- a/project2/common/plugable.h
+++ b/project2/common/plugable.h
@@ -1,112 +1,82 @@
#ifndef PLUGABLE_H
#define PLUGABLE_H
-#include <set>
-#include <map>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
-#include <boost/foreach.hpp>
+#include "instanceStore.h"
#include "exceptions.h"
class ComponentLoader;
-class Plugable {
+class Plugable : public InstanceSet<ComponentLoader> {
public:
- template <class CT>
- class ComponentType {
- public:
- static std::set<boost::shared_ptr<CT>> * & components()
- {
- static std::set<boost::shared_ptr<CT>> * _comp = NULL;
- if (!_comp) {
- _comp = new std::set<boost::shared_ptr<CT>>();
- }
- return _comp;
- }
- };
+ static void onAllComponents(const boost::function<void(ComponentLoader *)> & func) { InstanceSet<ComponentLoader>::OnAll(func); }
+};
+
+/// All loaders, keyed by string, enum, int, etc
+template<class Base, class Key, class AnonBase>
+class PluginsDiffBase {
+ public:
+ typedef Key KeyType;
+ typedef InstanceMap<Base, KeyType> Map;
+ typedef InstanceSet<Base> Set;
+ typedef InstanceSet<AnonBase> AnonSet;
- static inline void onAllComponents(const boost::function<void(ComponentLoader *)> & func)
+ static void Add(const KeyType & k, Base * i)
{
- onAll<ComponentLoader>(func);
+ auto p = boost::shared_ptr<Base>(i);
+ Map::Add(k, p);
+ Set::Add(p);
+ AnonSet::Add(p);
}
- template <class CT>
- static void onAll(const boost::function<void(CT *)> & func) {
- BOOST_FOREACH(const auto & l, *ComponentType<CT>::components()) {
- try {
- func(l.get());
- }
- catch (...) {
- }
- }
- }
-
- template <class T>
- static std::map<std::string, boost::shared_ptr<T> > * & objLoaders()
- {
- static std::map<std::string, boost::shared_ptr<T> > * _objLoaders = NULL;
- if (!_objLoaders) {
- _objLoaders = new std::map<std::string, boost::shared_ptr<T> >();
- }
- return _objLoaders;
- }
+ static void Remove(const KeyType & k)
+ {
+ auto p = Map::GetAll().find(k)->second;
+ Set::Remove(p);
+ AnonSet::Remove(p);
+ Map::Remove(k);
+ }
+};
- template <class T, class BT>
- static void newLoader(const std::string & n, T * l)
- {
- boost::shared_ptr<T> p = boost::shared_ptr<T>(l);
- objLoaders<T>()->insert(std::pair<std::string, boost::shared_ptr<T> >(n, p));
- ComponentType<BT>::components()->insert(boost::shared_ptr<T>(p));
- }
+template<class Base, class Key>
+class PluginsSameBase {
+ public:
+ typedef Key KeyType;
+ typedef InstanceMap<Base, KeyType> Map;
+ typedef InstanceSet<Base> Set;
- template <class T, class BT>
- static void removeLoader(const std::string & n)
- {
- std::map<std::string, boost::shared_ptr<T> > * & o = objLoaders<T>();
- std::set<boost::shared_ptr<BT> > * & c = ComponentType<BT>::components();
- typename std::map<std::string, boost::shared_ptr<T> >::iterator i = o->find(n);
- c->erase(i->second);
- o->erase(i);
- if (o->empty()) {
- delete o;
- o = NULL;
- }
- if (c->empty()) {
- delete c;
- c = NULL;
- }
- }
+ static void Add(const KeyType & k, Base * i)
+ {
+ auto p = boost::shared_ptr<Base>(i);
+ Map::Add(k, p);
+ Set::Add(p);
+ }
- template <class L, class E>
- static boost::shared_ptr<L> getLoader(const std::string & n)
- {
- typename std::map<std::string, boost::shared_ptr<L> >::const_iterator i = objLoaders<L>()->find(n);
- if (i != objLoaders<L>()->end()) {
- return i->second;
- }
- else {
- throw E(n);
- }
- }
+ static void Remove(const KeyType & k)
+ {
+ Set::Remove(Map::GetAll().find(k)->second);
+ Map::Remove(k);
+ }
};
#define TOKENPASTE(x, y) x ## y
#define TOKENPASTE2(x, y) TOKENPASTE(x, y)
-#define DECLARE_CUSTOM_COMPONENT_LOADER(N, I, T, B) \
-namespace TOKENPASTE2(I, __LINE__) { \
- static void init_loader_##I() __attribute__ ((constructor(201))); \
- static void init_loader_##I() { Plugable::newLoader<B, ComponentLoader>(N, new T()); } \
- static void kill_loader_##I() __attribute__ ((destructor(201))); \
- static void kill_loader_##I() { Plugable::removeLoader<B, ComponentLoader>(N); } \
+#define DECLARE_CUSTOM_COMPONENT_LOADER(Key, Impl, Loader, BaseLoader) \
+namespace TOKENPASTE2(Impl, __LINE__) { \
+ static void init_loader_##Impl() __attribute__ ((constructor(201))); \
+ static void init_loader_##Impl() { PluginsDiffBase<BaseLoader, BaseLoader::KeyType, ComponentLoader>::Add(Key, new Loader()); } \
+ static void kill_loader_##Impl() __attribute__ ((destructor(201))); \
+ static void kill_loader_##Impl() { PluginsDiffBase<BaseLoader, BaseLoader::KeyType, ComponentLoader>::Remove(Key); } \
}
-#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::For<T>, 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<T>, B);
+#define DECLARE_CUSTOM_LOADER(Key, T) \
+ DECLARE_CUSTOM_COMPONENT_LOADER(Key, T, T, ElementLoader)
+#define DECLARE_COMPONENT_LOADER(Key, Type, BaseLoader) \
+ DECLARE_CUSTOM_COMPONENT_LOADER(Key, Type, BaseLoader::For<Type>, BaseLoader)
+#define DECLARE_LOADER(Key, Loader) \
+ DECLARE_COMPONENT_LOADER(Key, Loader, ElementLoader)
+#define DECLARE_GENERIC_LOADER(Key, B, T) \
+ DECLARE_CUSTOM_COMPONENT_LOADER(Key, T, B::For<T>, B);
#endif
diff --git a/project2/common/presenter.h b/project2/common/presenter.h
index 3ea56e7..107e878 100644
--- a/project2/common/presenter.h
+++ b/project2/common/presenter.h
@@ -77,7 +77,7 @@ typedef boost::intrusive_ptr<RowSetPresenter> RowSetPresenterPtr;
typedef boost::intrusive_ptr<MultiRowSetPresenter> MultiRowSetPresenterPtr;
typedef boost::intrusive_ptr<NameValuePairPresenter> NameValuePairPresenterPtr;
-typedef GenLoader<MultiRowSetPresenter, ScriptNodePtr, ObjectSource, ExecContext *> PresenterLoader;
+typedef GenLoader<MultiRowSetPresenter, std::string, ScriptNodePtr, ObjectSource, ExecContext *> PresenterLoader;
#endif
diff --git a/project2/common/scriptLoader.h b/project2/common/scriptLoader.h
index 181292c..00ad9b5 100644
--- a/project2/common/scriptLoader.h
+++ b/project2/common/scriptLoader.h
@@ -48,7 +48,7 @@ class LoaderBase {
};
/// Helper for loading and maintaining Project2 script components
-typedef GenLoader<SourceObject, ScriptNodePtr> ElementLoader;
+typedef GenLoader<SourceObject, std::string, ScriptNodePtr> ElementLoader;
#endif
diff --git a/project2/common/scriptStorage.h b/project2/common/scriptStorage.h
index 8c37a65..cb947aa 100644
--- a/project2/common/scriptStorage.h
+++ b/project2/common/scriptStorage.h
@@ -50,10 +50,10 @@ class StorerBase : public Storer {
{
}
boost::intrusive_ptr<IntrusivePtrBase> create(ScriptNodePtr p) const {
- return creator(Plugable::getLoader<L, NotSupported>(p->get_name()).get(), p);
+ return creator(InstanceMap<L, std::string>::template Get<NotSupported>(p->get_name()).get(), p);
}
bool cacheable(ScriptNodePtr p) const {
- return Plugable::getLoader<L, NotSupported>(p->get_name())->cacheable();
+ return InstanceMap<L, std::string>::template Get<NotSupported>(p->get_name())->cacheable();
}
bool save(boost::intrusive_ptr<IntrusivePtrBase> o, ScriptNodePtr name) {
boost::intrusive_ptr<X> O = boost::dynamic_pointer_cast<X>(o);
diff --git a/project2/common/scripts.cpp b/project2/common/scripts.cpp
index f065e4b..0f798a7 100644
--- a/project2/common/scripts.cpp
+++ b/project2/common/scripts.cpp
@@ -69,8 +69,8 @@ ScriptReader::resolveScript(const std::string & group, const std::string & name,
return i->second;
}
else {
- BOOST_FOREACH(const ReaderLoaders::value_type & rl, *Plugable::objLoaders<ScriptReaderLoader>()) {
- ScriptReaderPtr rs = rl.second->resolveScript(group, e.string());
+ BOOST_FOREACH(const auto & rl, InstanceSet<ScriptReaderLoader>::GetAll()) {
+ ScriptReaderPtr rs = rl->resolveScript(group, e.string());
if (rs) {
return (scriptCache[sk] = rs);
}
diff --git a/project2/common/scripts.h b/project2/common/scripts.h
index 7bf6326..b7e9cdb 100644
--- a/project2/common/scripts.h
+++ b/project2/common/scripts.h
@@ -82,6 +82,8 @@ class ScriptReader : public virtual IntrusivePtrBase {
/// Base class to implement script reader modules
class ScriptReaderLoader : public ComponentLoader {
public:
+ typedef std::string KeyType;
+
virtual ScriptReaderPtr resolveScript(const std::string & group, const std::string & name) const = 0;
};
diff --git a/project2/common/sessionContainer.h b/project2/common/sessionContainer.h
index 4ce2a33..b842457 100644
--- a/project2/common/sessionContainer.h
+++ b/project2/common/sessionContainer.h
@@ -21,7 +21,7 @@ class SessionContainer : public IntrusivePtrBase {
virtual SessionPtr getSession(const boost::uuids::uuid & sid) const = 0;
};
typedef boost::intrusive_ptr<SessionContainer> SessionContainerPtr;
-typedef GenLoader<SessionContainer> SessionContainerLoader;
+typedef GenLoader<SessionContainer, std::string> SessionContainerLoader;
#endif
diff --git a/project2/common/transform.cpp b/project2/common/transform.cpp
index def1060..d392110 100644
--- a/project2/common/transform.cpp
+++ b/project2/common/transform.cpp
@@ -13,7 +13,7 @@ class TransformTargetStorer : public Storer {
}
boost::intrusive_ptr<IntrusivePtrBase> create(ScriptNodePtr p) const
{
- return Plugable::getLoader<TransformTargetLoader, NotSupported>(p->get_name())->create(p, Scripted);
+ return InstanceMap<TransformTargetLoader, std::string>::Get<NotSupported>(p->get_name())->create(p, Scripted);
}
bool save(boost::intrusive_ptr<IntrusivePtrBase> o, ScriptNodePtr s)
{
@@ -46,8 +46,8 @@ typedef std::map<std::string, boost::shared_ptr<TransformLoader> > TransformLoad
void
TransformSource::addTarget(TransformChainLinkPtr tcl, ExecContext * ec, ScriptNodePtr e)
{
- BOOST_FOREACH(const TransformLoaderMap::value_type & tl, *Plugable::objLoaders<TransformLoader>()) {
- TransformPtr t = tl.second->create();
+ BOOST_FOREACH(const auto & tl, InstanceSet<TransformLoader>::GetAll()) {
+ TransformPtr t = tl->create();
if (t->canTransform(this, tcl.get())) {
if (e) {
t->configure(e, ec);
diff --git a/project2/common/transform.h b/project2/common/transform.h
index 34e91b7..978e7df 100644
--- a/project2/common/transform.h
+++ b/project2/common/transform.h
@@ -48,10 +48,10 @@ class Transform : public virtual IntrusivePtrBase {
virtual void configure(ScriptNodePtr, ExecContext *) { };
};
-typedef GenLoader<Transform> TransformLoader;
+typedef GenLoader<Transform, std::string> TransformLoader;
#define DECLARE_TRANSFORM(T) DECLARE_COMPONENT_LOADER(#T, T, TransformLoader)
-typedef GenLoader<TransformChainLink, ScriptNodePtr, ObjectSource> TransformTargetLoader;
+typedef GenLoader<TransformChainLink, std::string, ScriptNodePtr, ObjectSource> TransformTargetLoader;
#define DECLARE_TRANSFORMTARGET(N, T) DECLARE_COMPONENT_LOADER(N, T, TransformTargetLoader)
template <class Source, class Destination>
diff --git a/project2/common/variables.h b/project2/common/variables.h
index 7713667..b57ee81 100644
--- a/project2/common/variables.h
+++ b/project2/common/variables.h
@@ -53,7 +53,7 @@ class VariableImplDyn : public VariableImpl {
};
/// Base class to create variables
-typedef GenLoader<VariableImpl, ScriptNodePtr> VariableLoader;
+typedef GenLoader<VariableImpl, std::string, ScriptNodePtr> VariableLoader;
#endif
diff --git a/project2/compression/decompressor.h b/project2/compression/decompressor.h
index 32be53a..c57ff61 100644
--- a/project2/compression/decompressor.h
+++ b/project2/compression/decompressor.h
@@ -12,6 +12,6 @@ class Decompressor : public IntrusivePtrBase {
virtual void decompress(const char * dataIn, size_t lengthIn, const Stream::Sink &) = 0;
};
typedef boost::intrusive_ptr<Decompressor> DecompressorPtr;
-typedef GenLoader<Decompressor> DecompressorLoader;
+typedef GenLoader<Decompressor, std::string> DecompressorLoader;
#endif
diff --git a/project2/console/consoleAppEngine.cpp b/project2/console/consoleAppEngine.cpp
index 592b006..98e5d4d 100644
--- a/project2/console/consoleAppEngine.cpp
+++ b/project2/console/consoleAppEngine.cpp
@@ -24,7 +24,7 @@ class ShowHelpTrigger : public Options::Target {
}
void consume(const Glib::ustring &, const VariableType &, const Options::CurrentPlatform &) const {
fprintf(stdout, "Help\n");
- Plugable::onAll<Options>(boost::bind(&ShowHelpTrigger::outputOptions, this, _1));
+ InstanceSet<Options>::OnAll(boost::bind(&ShowHelpTrigger::outputOptions, this, _1));
exit(1);
}
private:
diff --git a/project2/console/p2consoleMain.cpp b/project2/console/p2consoleMain.cpp
index 6b9a2ea..31ffe70 100644
--- a/project2/console/p2consoleMain.cpp
+++ b/project2/console/p2consoleMain.cpp
@@ -6,7 +6,7 @@
int
main(int argc, char ** argv)
{
- Plugable::newLoader<OptionsSource, OptionsSource>("", new CommandLineArguments(argc, argv, &ConsoleApplicationEngine::appendScript));
+ OptionsSources::Add("", new CommandLineArguments(argc, argv, &ConsoleApplicationEngine::appendScript));
Plugable::onAllComponents(boost::bind(&ComponentLoader::onBegin, _1));
OptionsSource::loadSources([] { return ConsoleApplicationEngine::reqPlatform;} );
diff --git a/project2/daemon/lib/daemon.h b/project2/daemon/lib/daemon.h
index ca57b5d..acb4abf 100644
--- a/project2/daemon/lib/daemon.h
+++ b/project2/daemon/lib/daemon.h
@@ -15,7 +15,7 @@ class Daemon : public IntrusivePtrBase {
};
typedef boost::intrusive_ptr<Daemon> DaemonPtr;
-typedef GenLoader<Daemon, int &, char **> DaemonLoader;
+typedef GenLoader<Daemon, std::string, int &, char **> DaemonLoader;
#endif
diff --git a/project2/daemon/p2daemonMain.cpp b/project2/daemon/p2daemonMain.cpp
index 2399827..6dfb3ac 100644
--- a/project2/daemon/p2daemonMain.cpp
+++ b/project2/daemon/p2daemonMain.cpp
@@ -11,7 +11,7 @@ int
main(int argc, char ** argv)
{
Plugable::onAllComponents(boost::bind(&ComponentLoader::onBegin, _1));
- Plugable::newLoader<OptionsSource, OptionsSource>("_2", new CommandLineArguments(argc, argv,
+ OptionsSources::Add("_2", new CommandLineArguments(argc, argv,
[](const char * a) { throw UnsupportedArguments(a); }));
OptionsSource::loadSources([] { return DaemonAppEngine::reqPlatform;} );
//Plugable::onAllComponents(boost::bind(&ComponentLoader::onBefore, _1));
diff --git a/project2/files/fsRows.cpp b/project2/files/fsRows.cpp
index 71c0dca..aca1626 100644
--- a/project2/files/fsRows.cpp
+++ b/project2/files/fsRows.cpp
@@ -80,7 +80,7 @@ FsRows::execute(const Glib::ustring &, const RowProcessorCallback & rp, ExecCont
for (SpecSpec::const_iterator sf = s.begin(); sf != s.end(); ) {
const Glib::ustring & name = (*sf++);
if (name[0] == '-') {
- ss.specs.insert(Plugable::getLoader<SpecBaseLoader, NotSupported>(name.substr(1))->createWith(*sf++));
+ ss.specs.insert(InstanceMap<SpecBaseLoader, std::string>::Get<NotSupported>(name.substr(1))->createWith(*sf++));
}
else {
throw NotSupported(name);
diff --git a/project2/files/fsRows.h b/project2/files/fsRows.h
index 5988865..fe4322c 100644
--- a/project2/files/fsRows.h
+++ b/project2/files/fsRows.h
@@ -26,7 +26,7 @@ class FsRows : public RowSet {
};
typedef boost::intrusive_ptr<SpecBase> SpecBasePtr;
template <class X>
- class SpecBaseLoaderX : public GenLoader<SpecBase, ScriptNodePtr> {
+ class SpecBaseLoaderX : public GenLoader<SpecBase, std::string, ScriptNodePtr> {
public:
virtual SpecBase * createWith(const Glib::ustring &) const = 0;
template <class T>
diff --git a/project2/sql/Jamfile.jam b/project2/sql/Jamfile.jam
index 8b075fc..ca82d21 100644
--- a/project2/sql/Jamfile.jam
+++ b/project2/sql/Jamfile.jam
@@ -8,7 +8,7 @@ obj sql-modMySQL :
<library>../../libmysqlpp//mysqlpp
<library>glibmm
<include>../../libmisc
- <include>../common
+ <library>../common
: :
<library>../../libmysqlpp//mysqlpp
;
@@ -19,7 +19,7 @@ obj sql-modODBC :
<library>../../libodbcpp//odbcpp
<library>glibmm
<include>../../libmisc
- <include>../common
+ <library>../common
: :
<library>../../libodbcpp//odbcpp
;
@@ -30,7 +30,7 @@ obj sql-modPQ :
<library>../../libpqpp//pqpp
<library>glibmm
<include>../../libmisc
- <include>../common
+ <library>../common
: :
<library>../../libpqpp//pqpp
;
diff --git a/project2/sql/connectionLoader.h b/project2/sql/connectionLoader.h
index 89de76b..9fb7149 100644
--- a/project2/sql/connectionLoader.h
+++ b/project2/sql/connectionLoader.h
@@ -4,7 +4,7 @@
#include "scriptLoader.h"
#include "../libdbpp/connection.h"
-typedef GenLoader<DB::Connection, std::string> ConnectionLoader;
+typedef GenLoader<DB::Connection, std::string, std::string> ConnectionLoader;
#endif
diff --git a/project2/sql/rdbmsDataSource.cpp b/project2/sql/rdbmsDataSource.cpp
index de20844..bf69dcd 100644
--- a/project2/sql/rdbmsDataSource.cpp
+++ b/project2/sql/rdbmsDataSource.cpp
@@ -195,7 +195,7 @@ RdbmsDataSource::RdbmsConnection::isExpired() const
RdbmsDataSource::ConnectionInfo::ConnectionInfo(ScriptNodePtr node) :
dsn(node->value("dsn", NULL).as<std::string>()),
- typeId(Plugable::getLoader<ConnectionLoader, UnknownConnectionProvider>(node->value("provider", NULL)))
+ typeId(InstanceMap<ConnectionLoader, std::string>::Get<UnknownConnectionProvider>(node->value("provider", NULL)))
{
}
diff --git a/project2/xml/xmlDocumentCache.cpp b/project2/xml/xmlDocumentCache.cpp
index 7b9a12d..cbfaf74 100644
--- a/project2/xml/xmlDocumentCache.cpp
+++ b/project2/xml/xmlDocumentCache.cpp
@@ -107,6 +107,8 @@ XmlDocumentCache::queue(const Glib::ustring & url, const char * encoding, ExecCo
class XmlDocumentCacheClearer : public ComponentLoader {
public:
+ typedef bool KeyType;
+
void onIteration()
{
Logger()->messagef(LOG_DEBUG, "%s: Clearing XML document cache", __PRETTY_FUNCTION__);
@@ -114,5 +116,5 @@ class XmlDocumentCacheClearer : public ComponentLoader {
Logger()->messagef(LOG_DEBUG, "%s: Cleared XML document cache", __PRETTY_FUNCTION__);
}
};
-DECLARE_CUSTOM_COMPONENT_LOADER("XmlDocumentCacheClearer", XmlDocumentCacheClearer, XmlDocumentCacheClearer, ComponentLoader);
+DECLARE_CUSTOM_COMPONENT_LOADER("XmlDocumentCacheClearer", XmlDocumentCacheClearer, XmlDocumentCacheClearer, XmlDocumentCacheClearer);
diff --git a/project2/xml/xmlPresenter.h b/project2/xml/xmlPresenter.h
index 6dbee7e..fe4af60 100644
--- a/project2/xml/xmlPresenter.h
+++ b/project2/xml/xmlPresenter.h
@@ -18,7 +18,7 @@ class XmlDocMutator : public IntrusivePtrBase {
virtual void mutateElement(xmlpp::Element *) const = 0;
};
typedef boost::intrusive_ptr<XmlDocMutator> XmlDocMutatorPtr;
-typedef GenLoader<XmlDocMutator, ScriptNodePtr> XmlDocMutatorLoader;
+typedef GenLoader<XmlDocMutator, std::string, ScriptNodePtr> XmlDocMutatorLoader;
class XmlPresenter : public Presenter, public ContentPresenter, public SourceOf<xmlpp::Document>, public SourceOf<xmlDoc>, public SourceOf<boost::shared_ptr<xmlpp::Document> >, public WritableContent, public SourceOf<WritableContent> {
public:
diff --git a/project2/xml/xmlScriptParser.cpp b/project2/xml/xmlScriptParser.cpp
index 5d0d37c..50dba96 100644
--- a/project2/xml/xmlScriptParser.cpp
+++ b/project2/xml/xmlScriptParser.cpp
@@ -188,7 +188,7 @@ XmlScriptNode::variable(const Glib::ustring & n) const
if (cs.size() == 1) {
if (const xmlpp::Element * c = dynamic_cast<const xmlpp::Element *>(cs.front())) {
if (const xmlpp::Attribute * source = c->get_attribute("source")) {
- return Plugable::getLoader<VariableLoader, UnknownVariableSource>(source->get_value())->create(new XmlScriptNode(c, script));
+ return InstanceMap<VariableLoader, std::string>::Get<UnknownVariableSource>(source->get_value())->create(new XmlScriptNode(c, script));
}
else {
return new VariableLiteral(new XmlScriptNode(c, script));
@@ -202,10 +202,10 @@ VariableImpl *
XmlScriptNode::variable(const boost::optional<Glib::ustring> & defaultSource) const
{
if (const xmlpp::Attribute * source = element->get_attribute("source")) {
- return Plugable::getLoader<VariableLoader, UnknownVariableSource>(source->get_value())->create(new XmlScriptNode(element, script));
+ return InstanceMap<VariableLoader, std::string>::Get<UnknownVariableSource>(source->get_value())->create(new XmlScriptNode(element, script));
}
else if (defaultSource) {
- return Plugable::getLoader<VariableLoader, UnknownVariableSource>(defaultSource.get())->create(new XmlScriptNode(element, script));
+ return InstanceMap<VariableLoader, std::string>::Get<UnknownVariableSource>(defaultSource.get())->create(new XmlScriptNode(element, script));
}
else {
return new VariableLiteral(new XmlScriptNode(element, script));
@@ -224,7 +224,7 @@ XmlScriptNode::applyValue(const Glib::ustring & n, VariableType & val, ExecConte
if (const xmlpp::Element * c = dynamic_cast<const xmlpp::Element *>(cs.front())) {
boost::intrusive_ptr<VariableImpl> v;
if (const xmlpp::Attribute * source = c->get_attribute("source")) {
- v = Plugable::getLoader<VariableLoader, UnknownVariableSource>(source->get_value())->create(new XmlScriptNode(c, script));
+ v = InstanceMap<VariableLoader, std::string>::Get<UnknownVariableSource>(source->get_value())->create(new XmlScriptNode(c, script));
}
else {
v = new VariableLiteral(new XmlScriptNode(c, script));