From 1a0642f1dbcbcfdc341989f2ec7e81aedee86f3f Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Mon, 11 Jul 2016 22:33:15 +0100 Subject: [PATCH] Make it work by realising that what boost::program_options calls validation is what any sane person would regard as parsing --- apps/openmw/main.cpp | 4 ++-- components/fallback/validate.hpp | 39 ++++++++------------------------ 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index d63d1f60cb..e57ff867ce 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -145,7 +145,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat "\n\twin1251 - Cyrillic alphabet such as Russian, Bulgarian, Serbian Cyrillic and other languages\n" "\n\twin1252 - Western European (Latin) alphabet, used by default") - ("fallback", bpo::value()->default_value(EscapeFallbackMap(), "") + ("fallback", bpo::value()->default_value(FallbackMap(), "") ->multitoken()->composing(), "fallback values") ("no-grab", "Don't grab mouse cursor") @@ -248,7 +248,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat // other settings engine.setSoundUsage(!variables["no-sound"].as()); - engine.setFallbackValues(variables["fallback"].as().toFallbackMap().mMap); + engine.setFallbackValues(variables["fallback"].as().mMap); engine.setActivationDistanceOverride (variables["activate-dist"].as()); engine.enableFontExport(variables["export-fonts"].as()); diff --git a/components/fallback/validate.hpp b/components/fallback/validate.hpp index 7683a12970..605b647020 100644 --- a/components/fallback/validate.hpp +++ b/components/fallback/validate.hpp @@ -16,19 +16,6 @@ namespace Fallback std::map mMap; }; - struct EscapeFallbackMap : FallbackMap - { - std::map mMap; - - FallbackMap toFallbackMap() const - { - FallbackMap temp = FallbackMap(); - for (std::map::const_iterator it = mMap.begin(); it != mMap.end(); ++it) - temp.mMap[it->first.toStdString()] = it->second.toStdString(); - return temp; - } - }; - void validate(boost::any &v, std::vector const &tokens, FallbackMap*, int) { if (v.empty()) @@ -40,16 +27,17 @@ namespace Fallback for (std::vector::const_iterator it = tokens.begin(); it != tokens.end(); ++it) { - int sep = it->find(","); - if (sep < 1 || sep == (int)it->length() - 1) + std::string temp = Files::EscapeHashString::processString(*it); + int sep = temp.find(","); + if (sep < 1 || sep == (int)temp.length() - 1) #if (BOOST_VERSION < 104200) throw boost::program_options::validation_error("invalid value"); #else throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value); #endif - std::string key(it->substr(0, sep)); - std::string value(it->substr(sep + 1)); + std::string key(temp.substr(0, sep)); + std::string value(temp.substr(sep + 1)); if (map->mMap.find(key) == map->mMap.end()) { @@ -57,24 +45,15 @@ namespace Fallback } } } - - void validate(boost::any &v, std::vector const &tokens, EscapeFallbackMap* eFM, int a) - { - validate(v, tokens, (FallbackMap *)eFM, a); - } } namespace Files { void validate(boost::any &v, const std::vector &tokens, Files::EscapeHashString * eHS, int a) { - if (eHS == NULL) - boost::program_options::validate(v, tokens, (std::string *) NULL, a); - else - { - std::string * temp = eHS->toStdStringPtr(); - boost::program_options::validate(v, tokens, temp, a); - delete temp; - } + boost::program_options::validators::check_first_occurrence(v); + + if (v.empty()) + v = boost::any(EscapeHashString(boost::program_options::validators::get_single_string(tokens))); } }