Make it work by realising that what boost::program_options calls validation is what any sane person would regard as parsing

pull/998/head
AnyOldName3 9 years ago
parent 195dd27780
commit 1a0642f1db

@ -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<EscapeFallbackMap>()->default_value(EscapeFallbackMap(), "")
("fallback", bpo::value<FallbackMap>()->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<bool>());
engine.setFallbackValues(variables["fallback"].as<EscapeFallbackMap>().toFallbackMap().mMap);
engine.setFallbackValues(variables["fallback"].as<FallbackMap>().mMap);
engine.setActivationDistanceOverride (variables["activate-dist"].as<int>());
engine.enableFontExport(variables["export-fonts"].as<bool>());

@ -16,19 +16,6 @@ namespace Fallback
std::map<std::string, std::string> mMap;
};
struct EscapeFallbackMap : FallbackMap
{
std::map<Files::EscapeHashString, Files::EscapeHashString> mMap;
FallbackMap toFallbackMap() const
{
FallbackMap temp = FallbackMap();
for (std::map<Files::EscapeHashString, Files::EscapeHashString>::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<std::string> const &tokens, FallbackMap*, int)
{
if (v.empty())
@ -40,16 +27,17 @@ namespace Fallback
for (std::vector<std::string>::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<std::string> const &tokens, EscapeFallbackMap* eFM, int a)
{
validate(v, tokens, (FallbackMap *)eFM, a);
}
}
namespace Files {
void validate(boost::any &v, const std::vector<std::string> &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)));
}
}

Loading…
Cancel
Save