diff options
author | Torsten Paul <Torsten.Paul@gmx.de> | 2014-01-02 22:27:52 (GMT) |
---|---|---|
committer | Torsten Paul <Torsten.Paul@gmx.de> | 2014-01-02 22:27:52 (GMT) |
commit | 72865e17dae7f51c60e0db54c1aa070f8125f273 (patch) | |
tree | e72ca64bb9ec80b330b3c48b1fad9e1d294c50b3 /src/feature.cc | |
parent | 6443df394b7754509ddfd781df7758ba912ebcbd (diff) |
Add feature registry.
Diffstat (limited to 'src/feature.cc')
-rw-r--r-- | src/feature.cc | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/feature.cc b/src/feature.cc new file mode 100644 index 0000000..5beece1 --- /dev/null +++ b/src/feature.cc @@ -0,0 +1,84 @@ +#include <stdio.h> +#include <iostream> +#include <string> +#include <map> + +#include "feature.h" + +/** + * Feature registration map for later lookup. This must be initialized + * before the static feature instances as those register with this map. + */ +std::map<std::string, Feature *> Feature::feature_map; + +/* + * List of features, the names given here are used in both command line + * argument to enable the option and for saving the option value in GUI + * context. + */ +const Feature Feature::ExperimentalConcatFunction("concat"); + +Feature::Feature(std::string name) : enabled_cmdline(false), enabled_options(false), name(name) +{ + feature_map[name] = this; +} + +Feature::~Feature() +{ +} + +const std::string& Feature::get_name() const +{ + return name; +} + +void Feature::set_enable_cmdline() +{ + enabled_cmdline = true; +} + +void Feature::set_enable_options(bool status) +{ + enabled_options = status; +} + +bool Feature::is_enabled() const +{ + if (enabled_cmdline) { + return true; + } + return enabled_options; +} + +bool operator ==(const Feature& lhs, const Feature& rhs) +{ + return lhs.get_name() == rhs.get_name(); +} + +bool operator !=(const Feature& lhs, const Feature& rhs) +{ + return !(lhs == rhs); +} + +void Feature::enable_feature(std::string feature_name) +{ + map_t::iterator it = feature_map.find(feature_name); + if (it != feature_map.end()) { + (*it).second->set_enable_cmdline(); + } +} + +void Feature::enable_feature(std::string feature_name, bool status) +{ + map_t::iterator it = feature_map.find(feature_name); + if (it != feature_map.end()) { + (*it).second->set_enable_options(status); + } +} + +void Feature::dump_features() +{ + for (map_t::iterator it = feature_map.begin(); it != feature_map.end(); it++) { + std::cout << "Feature('" << (*it).first << "') = " << ((*it).second->is_enabled() ? "enabled" : "disabled") << std::endl; + } +} |