diff options
author | Marius Kintel <marius@kintel.net> | 2014-01-03 18:58:13 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2014-01-03 18:58:13 (GMT) |
commit | 064247ae5e3975c3e9f529f4a4c4a0546892d96f (patch) | |
tree | b2a11e24e73a26fc4f6551982a1677d261dea9e5 /src/feature.cc | |
parent | 8dca991045a9f0563e6b654b1b946e5d778e8fd2 (diff) | |
parent | c4a1d855f11d076d30e98f799315446da021514a (diff) |
Merge branch 'master' of github.com:openscad/openscad
Diffstat (limited to 'src/feature.cc')
-rw-r--r-- | src/feature.cc | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/feature.cc b/src/feature.cc new file mode 100644 index 0000000..80d7887 --- /dev/null +++ b/src/feature.cc @@ -0,0 +1,79 @@ +#include <stdio.h> +#include <iostream> +#include <string> +#include <map> + +#include "feature.h" +#include "printutils.h" + +/** + * Feature registration map/list for later lookup. This must be initialized + * before the static feature instances as those register with this map. + */ +Feature::map_t Feature::feature_map; +Feature::list_t Feature::feature_list; + +/* + * 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", "Enable the <code>concat()</code> function."); + +Feature::Feature(const std::string &name, const std::string &description) + : enabled(false), name(name), description(description) +{ + feature_map[name] = this; + feature_list.push_back(this); +} + +Feature::~Feature() +{ +} + +const std::string &Feature::get_name() const +{ + return name; +} + +const std::string &Feature::get_description() const +{ + return description; +} + +bool Feature::is_enabled() const +{ + return enabled; +} + +void Feature::enable(bool status) +{ + enabled = status; +} + +void Feature::enable_feature(const std::string &feature_name, bool status) +{ + map_t::iterator it = feature_map.find(feature_name); + if (it != feature_map.end()) { + it->second->enable(status); + } else { + PRINTB("WARNING: Ignoring request to enable unknown feature '%s'.", feature_name); + } +} + +Feature::iterator Feature::begin() +{ + return feature_list.begin(); +} + +Feature::iterator Feature::end() +{ + return feature_list.end(); +} + +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; + } +} |