From aec68e777395d7dbecd9003838353cdfdb888928 Mon Sep 17 00:00:00 2001 From: randomdan Date: Sat, 30 Nov 2013 17:11:13 +0000 Subject: Support for options registering new options sources --- project2/common/optionsSource.cpp | 10 ++++++++-- project2/files/optionsSource.cpp | 25 ++++++++++++++++++------- project2/files/optionsSource.h | 6 +++++- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/project2/common/optionsSource.cpp b/project2/common/optionsSource.cpp index ef755c1..0f24f9e 100644 --- a/project2/common/optionsSource.cpp +++ b/project2/common/optionsSource.cpp @@ -26,8 +26,14 @@ OptionsSource::loadSources(const Options::CurrentPlatform & platform) InstanceSet::OnAll(boost::bind(&Options::reset, _1)); DefaultConfigConsumer dcc; - BOOST_FOREACH(const auto & c, configs) { - c->loadInto(dcc, platform); + std::set> loadedConfigs; + while (loadedConfigs.size() != configs.size()) { + BOOST_FOREACH(const auto & c, configs) { + if (loadedConfigs.find(c) == loadedConfigs.end()) { + c->loadInto(dcc, platform); + loadedConfigs.insert(c); + } + } } Plugable::onAllComponents(boost::bind(&ComponentLoader::onConfigLoad, _1)); diff --git a/project2/files/optionsSource.cpp b/project2/files/optionsSource.cpp index 437eaf4..bb8c549 100644 --- a/project2/files/optionsSource.cpp +++ b/project2/files/optionsSource.cpp @@ -5,12 +5,6 @@ #include #include -FileOptions::FileOptions() : - file(".p2config"), - loadedAt(0) -{ -} - FileOptions::FileOptions(const Glib::ustring & f) : file(f), loadedAt(0) @@ -75,6 +69,23 @@ FileOptions::needReload() const return (loadedAt != st.st_mtime); } +FileOptions::ExtraFileOptions FileOptions::extraFileOptions; + // Z... process last :) -DECLARE_OPTIONSSOURCE("Z_configfile", new FileOptions()) +DECLARE_OPTIONSSOURCE("Z_configfile", new FileOptions(".p2config")) +DECLARE_OPTIONS(FileOptions, "File Options options") +("file.options.read", Options::functions( + [](const VariableType & vt) { + auto fo = new FileOptions(vt); + extraFileOptions[vt] = boost::shared_ptr(fo); + OptionsSources::Add(vt, fo); + }, + []() { + BOOST_FOREACH(const auto & fo, extraFileOptions) { + OptionsSources::Remove(fo.first); + } + extraFileOptions.clear(); + }), + "Path of options file(s) to read") +END_OPTIONS(FileOptions); diff --git a/project2/files/optionsSource.h b/project2/files/optionsSource.h index e1de4b9..6f25459 100644 --- a/project2/files/optionsSource.h +++ b/project2/files/optionsSource.h @@ -2,18 +2,22 @@ #define FILES_OPTIONSSOURCE_H #include "../common/optionsSource.h" +#include "../common/options.h" class FileOptions : public OptionsSource { public: - FileOptions(); FileOptions(const Glib::ustring & file); void loadInto(const ConfigConsumer & consume, const Options::CurrentPlatform & platform) const; bool needReload() const; + INITOPTIONS; private: const Glib::ustring file; mutable time_t loadedAt; + + typedef std::map> ExtraFileOptions; + static ExtraFileOptions extraFileOptions; }; #endif -- cgit v1.2.3