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:
Amar Takhar 2011-01-04 04:24:40 +00:00
parent 010f3c14e5
commit cdc73b17d2
2 changed files with 19 additions and 4 deletions

View file

@ -37,15 +37,19 @@
namespace agi { namespace agi {
Options::Options(const std::string &file, const std::string& default_config): Options::Options(const std::string &file, const std::string& default_config, const OptionSetting setting):
config_file(file), config_default(default_config), config_loaded(false) { config_file(file), config_default(default_config), config_loaded(false), setting(setting) {
LOG_D("agi/options") << "New Options object"; LOG_D("agi/options") << "New Options object";
std::istringstream stream(default_config); std::istringstream stream(default_config);
LoadConfig(stream); LoadConfig(stream);
} }
Options::~Options() { Options::~Options() {
Flush();
if ((setting & FLUSH_SKIP) != FLUSH_SKIP) {
Flush();
}
for (OptionValueMap::iterator i = values.begin(); i != values.end(); i++) { for (OptionValueMap::iterator i = values.begin(); i != values.end(); i++) {
delete i->second; delete i->second;
} }

View file

@ -52,6 +52,14 @@ public:
class Options { class Options {
friend class PutOptionVisitor; 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 /// Internal OptionValueMap
OptionValueMap values; OptionValueMap values;
@ -68,6 +76,9 @@ class Options {
/// Whether the user (final) config has been loaded /// Whether the user (final) config has been loaded
bool config_loaded; bool config_loaded;
/// Settings.
const OptionSetting setting;
/// @brief Load a config file into the Options object. /// @brief Load a config file into the Options object.
/// @param config Config to load. /// @param config Config to load.
void LoadConfig(std::istream& stream); void LoadConfig(std::istream& stream);
@ -85,7 +96,7 @@ public:
/// @brief Constructor /// @brief Constructor
/// @param file User config that will be loaded from and written back to. /// @param file User config that will be loaded from and written back to.
/// @param default_config Default configuration. /// @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 /// Destructor
~Options(); ~Options();