diff --git a/src/data/settings.hpp b/src/data/settings.hpp index 609dc572..86ecf68a 100644 --- a/src/data/settings.hpp +++ b/src/data/settings.hpp @@ -43,7 +43,7 @@ enum InstallType , INSTALL_GLOBAL // install to the global files }; -bool parse_enum(const String&, InstallType&); +void parse_enum(const String&, InstallType&); bool is_install_local(InstallType type); /// How to handle filename conflicts diff --git a/src/script/functions/image.cpp b/src/script/functions/image.cpp index 5f6e8b10..9966eea4 100644 --- a/src/script/functions/image.cpp +++ b/src/script/functions/image.cpp @@ -21,7 +21,7 @@ DECLARE_TYPEOF_COLLECTION(SymbolVariationP); -bool parse_enum(const String&, ImageCombine& out); +void parse_enum(const String&, ImageCombine& out); // ----------------------------------------------------------------------------- : Utility @@ -56,9 +56,7 @@ SCRIPT_FUNCTION(combine_blend) { SCRIPT_PARAM(GeneratedImageP, image1); SCRIPT_PARAM(GeneratedImageP, image2); ImageCombine image_combine; - if (!parse_enum(combine, image_combine)) { - throw ScriptError(_("Not a valid combine mode: '") + combine + _("'")); - } + parse_enum(combine, image_combine); return new_intrusive3(image1, image2, image_combine); } @@ -78,9 +76,7 @@ SCRIPT_FUNCTION(set_combine) { SCRIPT_PARAM(String, combine); SCRIPT_PARAM_C(GeneratedImageP, input); ImageCombine image_combine; - if (!parse_enum(combine, image_combine)) { - throw ScriptError(_("Not a valid combine mode: '") + combine + _("'")); - } + parse_enum(combine, image_combine); return new_intrusive2(input, image_combine); } diff --git a/src/script/scriptable.cpp b/src/script/scriptable.cpp index d6d7e853..f14e96b7 100644 --- a/src/script/scriptable.cpp +++ b/src/script/scriptable.cpp @@ -15,7 +15,7 @@ #include Alignment from_string(const String&); -bool parse_enum(const String&,Direction&); +void parse_enum(const String&,Direction&); DECLARE_TYPEOF_COLLECTION(ScriptParseError); diff --git a/src/util/io/reader.cpp b/src/util/io/reader.cpp index a17a0ecc..7f259e7b 100644 --- a/src/util/io/reader.cpp +++ b/src/util/io/reader.cpp @@ -411,3 +411,17 @@ template <> void Reader::handle(FileName& f) { handle(static_cast(f)); } } + +// ----------------------------------------------------------------------------- : EnumReader + +void EnumReader::warnIfNotDone(Reader* errors_to) { + if (!done) { + // warning: unknown value + errors_to->warning(_ERROR_1_("unrecognized value", read)); + } +} +void EnumReader::errorIfNotDone() { + if (!done) { + throw ParseError(_ERROR_1_("unrecognized value", read)); + } +} diff --git a/src/util/io/reader.hpp b/src/util/io/reader.hpp index d36c2996..1341bc7c 100644 --- a/src/util/io/reader.hpp +++ b/src/util/io/reader.hpp @@ -256,15 +256,12 @@ void Reader::handle(IndexMap& m) { template<> void Reader::handle(Enum& enum_) { \ EnumReader reader(getValue()); \ reflect_ ## Enum(enum_, reader); \ - if (!reader.isDone()) { \ - /* warning: unknown value */ \ - warning(_ERROR_1_("unrecognized value", value)); \ - } \ + reader.warnIfNotDone(this); \ } \ - bool parse_enum(const String& value, Enum& out) { \ + void parse_enum(const String& value, Enum& out) { \ EnumReader reader(value); \ reflect_ ## Enum(out, reader); \ - return reader.isDone(); \ + reader.errorIfNotDone(); \ } /// 'Tag' to be used when reflecting enumerations for Reader @@ -287,6 +284,8 @@ class EnumReader { } inline bool isDone() const { return done; } + void warnIfNotDone(Reader* errors_to); + void errorIfNotDone(); private: String read; ///< The string to match to a value name