Add support for bitmask options to Options. First one is to avoid flushing the config to disk which we don't want to happen when the reporter uses Options to read config values.
Originally committed to SVN as r5123.
This commit is contained in:
parent
010f3c14e5
commit
cdc73b17d2
2 changed files with 19 additions and 4 deletions
|
@ -37,15 +37,19 @@
|
|||
|
||||
namespace agi {
|
||||
|
||||
Options::Options(const std::string &file, const std::string& default_config):
|
||||
config_file(file), config_default(default_config), config_loaded(false) {
|
||||
Options::Options(const std::string &file, const std::string& default_config, const OptionSetting setting):
|
||||
config_file(file), config_default(default_config), config_loaded(false), setting(setting) {
|
||||
LOG_D("agi/options") << "New Options object";
|
||||
std::istringstream stream(default_config);
|
||||
LoadConfig(stream);
|
||||
}
|
||||
|
||||
Options::~Options() {
|
||||
Flush();
|
||||
|
||||
if ((setting & FLUSH_SKIP) != FLUSH_SKIP) {
|
||||
Flush();
|
||||
}
|
||||
|
||||
for (OptionValueMap::iterator i = values.begin(); i != values.end(); i++) {
|
||||
delete i->second;
|
||||
}
|
||||
|
|
|
@ -52,6 +52,14 @@ public:
|
|||
class Options {
|
||||
friend class PutOptionVisitor;
|
||||
|
||||
public:
|
||||
/// Options class settings.
|
||||
enum OptionSetting {
|
||||
NONE = 0x000, ///< Do nothing (default)
|
||||
FLUSH_SKIP = 0x001, ///< Skip writing the config file to disk
|
||||
};
|
||||
|
||||
private:
|
||||
/// Internal OptionValueMap
|
||||
OptionValueMap values;
|
||||
|
||||
|
@ -68,6 +76,9 @@ class Options {
|
|||
/// Whether the user (final) config has been loaded
|
||||
bool config_loaded;
|
||||
|
||||
/// Settings.
|
||||
const OptionSetting setting;
|
||||
|
||||
/// @brief Load a config file into the Options object.
|
||||
/// @param config Config to load.
|
||||
void LoadConfig(std::istream& stream);
|
||||
|
@ -85,7 +96,7 @@ public:
|
|||
/// @brief Constructor
|
||||
/// @param file User config that will be loaded from and written back to.
|
||||
/// @param default_config Default configuration.
|
||||
Options(const std::string &file, const std::string &default_config);
|
||||
Options(const std::string &file, const std::string &default_config, const OptionSetting setting=NONE);
|
||||
|
||||
/// Destructor
|
||||
~Options();
|
||||
|
|
Loading…
Reference in a new issue