summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2013-11-30 17:11:13 +0000
committerrandomdan <randomdan@localhost>2013-11-30 17:11:13 +0000
commit3b33a7a6d148c6e51cea19618588f5a63ed29d4f (patch)
treed11ca82bb7ef65d17fb90d33f5182acebd439de1
parentAllow specification of log file access mode (diff)
downloadproject2-3b33a7a6d148c6e51cea19618588f5a63ed29d4f.tar.bz2
project2-3b33a7a6d148c6e51cea19618588f5a63ed29d4f.tar.xz
project2-3b33a7a6d148c6e51cea19618588f5a63ed29d4f.zip
Support for options registering new options sources
-rw-r--r--project2/common/optionsSource.cpp10
-rw-r--r--project2/files/optionsSource.cpp25
-rw-r--r--project2/files/optionsSource.h6
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<Options>::OnAll(boost::bind(&Options::reset, _1));
DefaultConfigConsumer dcc;
- BOOST_FOREACH(const auto & c, configs) {
- c->loadInto(dcc, platform);
+ std::set<boost::shared_ptr<OptionsSource>> 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 <glibmm/fileutils.h>
#include <boost/algorithm/string/trim.hpp>
-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<FileOptions>(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<std::string, boost::shared_ptr<FileOptions>> ExtraFileOptions;
+ static ExtraFileOptions extraFileOptions;
};
#endif