From 00e36ad1c77c478bf86abef5751a5d027c3486f3 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 28 Sep 2015 23:45:17 +0100 Subject: Use AdHoc plugins for options --- project2/basics/options/preload.cpp | 6 +++--- project2/basics/options/showHelp.cpp | 4 +++- project2/common/options.cpp | 4 ++-- project2/common/options.h | 14 ++++++-------- project2/common/optionsSource.cpp | 25 +++++++++++++++---------- project2/common/variables/config.cpp | 4 ++-- 6 files changed, 31 insertions(+), 26 deletions(-) diff --git a/project2/basics/options/preload.cpp b/project2/basics/options/preload.cpp index 5cf42e8..4781abb 100644 --- a/project2/basics/options/preload.cpp +++ b/project2/basics/options/preload.cpp @@ -19,7 +19,7 @@ class Preload { static void LoadLibrary(const VariableType & librarypath) { - const auto beforeOpts = InstanceSet::GetAll(); + const auto beforeOpts = AdHoc::PluginManager::getDefault()->getAll(); void * handle = dlopen(librarypath, RTLD_GLOBAL | RTLD_NOW); if (handle) { @@ -32,10 +32,10 @@ class Preload { } libs[librarypath.as()] = boost::shared_ptr(handle, &dlclose); - const auto afterOpts = InstanceSet::GetAll(); + const auto afterOpts = AdHoc::PluginManager::getDefault()->getAll(); for (const auto & opt : afterOpts) { if (std::find(beforeOpts.begin(), beforeOpts.end(), opt) == beforeOpts.end()) { - opt->reset(); + opt->implementation()->reset(); } } } diff --git a/project2/basics/options/showHelp.cpp b/project2/basics/options/showHelp.cpp index 86dbc6f..b7f481c 100644 --- a/project2/basics/options/showHelp.cpp +++ b/project2/basics/options/showHelp.cpp @@ -8,7 +8,9 @@ void ShowHelpComponent::onConfigLoad() if (!showHelp) return; fprintf(stdout, "Help\n"); - InstanceSet::OnAll(boost::bind(&ShowHelpComponent::outputOptions, this, _1)); + for (auto opts : AdHoc::PluginManager::getDefault()->getAll()) { + outputOptions(opts->implementation()); + } exit(1); } diff --git a/project2/common/options.cpp b/project2/common/options.cpp index c1ed762..7819bd9 100644 --- a/project2/common/options.cpp +++ b/project2/common/options.cpp @@ -1,6 +1,6 @@ #include #include "options.h" -#include "instanceStore.impl.h" +#include class NamedOption : public Options::Option { public: @@ -169,5 +169,5 @@ Options::InstanceTarget::assign(const VariableType & value) const assigner(value); } -INSTANTIATESTORE(std::string, Options); +INSTANTIATEPLUGINOF(Options); diff --git a/project2/common/options.h b/project2/common/options.h index 0d90826..6e734bb 100644 --- a/project2/common/options.h +++ b/project2/common/options.h @@ -9,9 +9,9 @@ #include #include #include "variableType.h" -#include "plugable.h" +#include -class Options { +class Options : public AdHoc::AbstractPluginImplementation { public: class Target; @@ -99,22 +99,20 @@ class Options { OptionList options; }; -// Registration helpers -// These work pluggable component style -typedef PluginsSameBase 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); \ - OptionsSets::Add(#Type, o); } \ + AdHoc::PluginManager::getDefault()->add(o, #Type, __FILE__, __LINE__); } \ void Type::InitOptions(Options & o) { o #define END_OPTIONS(Type) \ ;} \ static void kill_options_##Type() __attribute__ ((destructor(200))); \ - static void kill_options_##Type() { OptionsSets::Remove(#Type); } + static void kill_options_##Type() { \ + AdHoc::PluginManager::getDefault()->remove(#Type); \ + } #define INITOPTIONS \ static void InitOptions(Options &) diff --git a/project2/common/optionsSource.cpp b/project2/common/optionsSource.cpp index 0e1d751..c74243d 100644 --- a/project2/common/optionsSource.cpp +++ b/project2/common/optionsSource.cpp @@ -5,17 +5,18 @@ class DefaultConfigConsumer : public ConfigConsumer { public: void operator()(const Glib::ustring & n, const Glib::ustring & p, const Glib::ustring & v, const Options::CurrentPlatform & cp) const { - InstanceSet::OnAll(boost::bind(&Options::consume, _1, n, p, v, cp)); + for (auto opts : AdHoc::PluginManager::getDefault()->getAll()) { + opts->implementation()->consume(n, p, v, cp); + } } const Options::Option * get(const Glib::ustring & n) const { - const Options::Option * rtn = NULL; - InstanceSet::OnAll([n,&rtn](const Options * os) { - const Options::Option * o = os->find(n); + for (auto opts : AdHoc::PluginManager::getDefault()->getAll()) { + const Options::Option * o = opts->implementation()->find(n); if (o) { - rtn = o; + return o; } - }); - return rtn; + } + return nullptr; } }; @@ -27,7 +28,9 @@ OptionsSource::loadSources(const Options::CurrentPlatform & platform) { const auto & configs = InstanceSet::GetAll(); if (std::find_if(configs.begin(), configs.end(), [](const OptionsSourcePtr & c) { return c->modifiedTime() > loadedTime; }) != configs.end()) { - InstanceSet::OnAll(boost::bind(&Options::reset, _1)); + for (auto opts : AdHoc::PluginManager::getDefault()->getAll()) { + opts->implementation()->reset(); + } DefaultConfigConsumer dcc; std::set> loadedConfigs; @@ -40,7 +43,7 @@ OptionsSource::loadSources(const Options::CurrentPlatform & platform) } } Plugable::onAllComponents(boost::bind(&ComponentLoader::onConfigLoad, _1)); - + loadedTime = boost::posix_time::microsec_clock::universal_time(); Logger()->messagebf(LOG_DEBUG, "Loaded configuration at %s", loadedTime); } @@ -49,7 +52,9 @@ OptionsSource::loadSources(const Options::CurrentPlatform & platform) void OptionsSource::loadSource(const Options::CurrentPlatform & platform, OptionsSourcePtr opts) { - InstanceSet::OnAll(boost::bind(&Options::reset, _1)); + for (auto opts : AdHoc::PluginManager::getDefault()->getAll()) { + opts->implementation()->reset(); + } DefaultConfigConsumer dcc; opts->loadInto(dcc, platform); diff --git a/project2/common/variables/config.cpp b/project2/common/variables/config.cpp index 273b5aa..1696f43 100644 --- a/project2/common/variables/config.cpp +++ b/project2/common/variables/config.cpp @@ -72,12 +72,12 @@ class VariableConfigLoader : public VariableFactory::For { opts(new Options("Variables - ModConfig options")) { (*opts)(new AppSettings()); - OptionsSets::Add(typeid(AppSettings).name(), opts); + AdHoc::PluginManager::getDefault()->add(opts, typeid(AppSettings).name(), __FILE__, __LINE__); } ~VariableConfigLoader() { - OptionsSets::Remove(typeid(AppSettings).name()); + AdHoc::PluginManager::getDefault()->remove(typeid(AppSettings).name()); } const Options * options() const { -- cgit v1.2.3