mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-07-12 15:51:42 +00:00
Move FallbackMap validator implementation to source file
This commit is contained in:
parent
8b28b6e55e
commit
350f6e61f7
2 changed files with 29 additions and 26 deletions
28
components/fallback/validate.cpp
Normal file
28
components/fallback/validate.cpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#include "validate.hpp"
|
||||||
|
|
||||||
|
void Fallback::validate(boost::any& v, std::vector<std::string> const& tokens, FallbackMap*, int)
|
||||||
|
{
|
||||||
|
if (v.empty())
|
||||||
|
{
|
||||||
|
v = boost::any(FallbackMap());
|
||||||
|
}
|
||||||
|
|
||||||
|
FallbackMap *map = boost::any_cast<FallbackMap>(&v);
|
||||||
|
|
||||||
|
for (std::vector<std::string>::const_iterator it = tokens.begin(); it != tokens.end(); ++it)
|
||||||
|
{
|
||||||
|
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(temp.substr(0, sep));
|
||||||
|
std::string value(temp.substr(sep + 1));
|
||||||
|
|
||||||
|
map->mMap[key] = value;
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,32 +16,7 @@ namespace Fallback
|
||||||
std::map<std::string, std::string> mMap;
|
std::map<std::string, std::string> mMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
void validate(boost::any &v, std::vector<std::string> const &tokens, FallbackMap*, int)
|
void validate(boost::any &v, std::vector<std::string> const &tokens, FallbackMap*, int);
|
||||||
{
|
|
||||||
if (v.empty())
|
|
||||||
{
|
|
||||||
v = boost::any(FallbackMap());
|
|
||||||
}
|
|
||||||
|
|
||||||
FallbackMap *map = boost::any_cast<FallbackMap>(&v);
|
|
||||||
|
|
||||||
for (std::vector<std::string>::const_iterator it = tokens.begin(); it != tokens.end(); ++it)
|
|
||||||
{
|
|
||||||
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(temp.substr(0, sep));
|
|
||||||
std::string value(temp.substr(sep + 1));
|
|
||||||
|
|
||||||
map->mMap[key] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue