From 9585a3e564c84bd1c48b8c40c27e34d2f54eb687 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 15 Jul 2018 10:12:28 -0500 Subject: [PATCH] Default to pulling from defaults with get() functions. --- xs/src/libslic3r/Config.hpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp index f115d940e..6895df78f 100644 --- a/xs/src/libslic3r/Config.hpp +++ b/xs/src/libslic3r/Config.hpp @@ -58,24 +58,17 @@ public: /// Parse a windows-style opt=value ini file with categories and load the configuration store. void read_ini(const std::string& file); - /// Template function to retrieve and cast in hopefully a slightly nicer - /// format than longwinded dynamic_cast<> - template - T& get(const t_config_option_key& opt_key, bool create=false) { - if (print_config_def.options.count(opt_key) == 0) throw InvalidOptionType(opt_key + std::string(" is an invalid option.")); - return *(dynamic_cast(this->_config.optptr(opt_key, create))); - } - - double getFloat(const t_config_option_key& opt_key, bool create=false) { + + double getFloat(const t_config_option_key& opt_key, bool create=true) { if (print_config_def.options.count(opt_key) == 0) throw InvalidOptionType(opt_key + std::string(" is an invalid option.")); return (dynamic_cast(this->_config.optptr(opt_key, create)))->getFloat(); } - int getInt(const t_config_option_key& opt_key, bool create=false) { + int getInt(const t_config_option_key& opt_key, bool create=true) { if (print_config_def.options.count(opt_key) == 0) throw InvalidOptionType(opt_key + std::string(" is an invalid option.")); return (dynamic_cast(this->_config.optptr(opt_key, create)))->getInt(); } - std::string getString(const t_config_option_key& opt_key, bool create=false) { + std::string getString(const t_config_option_key& opt_key, bool create=true) { if (print_config_def.options.count(opt_key) == 0) throw InvalidOptionType(opt_key + std::string(" is an invalid option.")); return (dynamic_cast(this->_config.optptr(opt_key, create)))->getString(); } @@ -83,11 +76,19 @@ public: /// Template function to dynamic cast and leave it in pointer form. template - T* get_ptr(const t_config_option_key& opt_key, bool create=false) { + T* get_ptr(const t_config_option_key& opt_key, bool create=true) { if (print_config_def.options.count(opt_key) == 0) throw InvalidOptionType(opt_key + std::string(" is an invalid option.")); return dynamic_cast(this->_config.optptr(opt_key, create)); } + /// Template function to retrieve and cast in hopefully a slightly nicer + /// format than longwinded dynamic_cast<> + template + T& get(const t_config_option_key& opt_key, bool create=true) { + if (print_config_def.options.count(opt_key) == 0) throw InvalidOptionType(opt_key + std::string(" is an invalid option.")); + return *(dynamic_cast(this->_config.optptr(opt_key, create))); + } + /// Function to parse value from a string to whatever opt_key is. void set(const t_config_option_key& opt_key, const std::string& value);