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 | |
parent | 6443df394b7754509ddfd781df7758ba912ebcbd (diff) |
Add feature registry.
-rw-r--r-- | openscad.pro | 2 | ||||
-rw-r--r-- | src/feature.cc | 84 | ||||
-rw-r--r-- | src/feature.h | 47 | ||||
-rw-r--r-- | src/openscad.cc | 9 |
4 files changed, 141 insertions, 1 deletions
diff --git a/openscad.pro b/openscad.pro index 6d8282a..fa5c8b4 100644 --- a/openscad.pro +++ b/openscad.pro @@ -221,6 +221,7 @@ HEADERS += src/typedefs.h \ src/highlighter.h \ src/localscope.h \ src/module.h \ + src/feature.h \ src/node.h \ src/csgnode.h \ src/linearextrudenode.h \ @@ -279,6 +280,7 @@ SOURCES += src/version_check.cc \ src/func.cc \ src/localscope.cc \ src/module.cc \ + src/feature.cc \ src/node.cc \ src/context.cc \ src/modcontext.cc \ 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; + } +} diff --git a/src/feature.h b/src/feature.h new file mode 100644 index 0000000..3c97edc --- /dev/null +++ b/src/feature.h @@ -0,0 +1,47 @@ +#ifndef FEATURE_H_ +#define FEATURE_H_ + +#include <stdio.h> +#include <iostream> +#include <string> +#include <map> + +class Feature { +private: + /** + * Set to true in case the matching feature was given as commandline + * argument. + */ + bool enabled_cmdline; + /** + * Set from the GUI options. This will not be set in case the GUI is + * not started at all. + */ + bool enabled_options; + + std::string name; + + typedef std::map<std::string, Feature *> map_t; + static map_t feature_map; + + Feature(std::string name); + virtual ~Feature(); + virtual void set_enable_cmdline(); + virtual void set_enable_options(bool status); + +public: + static const Feature ExperimentalConcatFunction; + + const std::string& get_name() const; + + bool is_enabled() const; + + friend bool operator ==(const Feature& lhs, const Feature& rhs); + friend bool operator !=(const Feature& lhs, const Feature& rhs); + + static void dump_features(); + static void enable_feature(std::string feature_name); + static void enable_feature(std::string feature_name, bool status); +}; + +#endif diff --git a/src/openscad.cc b/src/openscad.cc index ab84235..574e87b 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -33,6 +33,7 @@ #include "builtin.h" #include "printutils.h" #include "handle_dep.h" +#include "feature.h" #include "parsersettings.h" #include "rendersettings.h" #include "PlatformUtils.h" @@ -587,7 +588,8 @@ int main(int argc, char **argv) ("x,x", po::value<string>(), "dxf-file") ("d,d", po::value<string>(), "deps-file") ("m,m", po::value<string>(), "makefile") - ("D,D", po::value<vector<string> >(), "var=val"); + ("D,D", po::value<vector<string> >(), "var=val") + ("enable-feature", po::value<vector<string> >(), "enable experimental features"); po::options_description hidden("Hidden options"); hidden.add_options() @@ -651,6 +653,11 @@ int main(int argc, char **argv) commandline_commands += ";\n"; } } + if (vm.count("enable-feature")) { + BOOST_FOREACH(const string &feature, vm["enable-feature"].as<vector<string> >()) { + Feature::enable_feature(feature); + } + } vector<string> inputFiles; if (vm.count("input-file")) { inputFiles = vm["input-file"].as<vector<string> >(); |