forked from mirror/openmw-tes3mp
Change compilation error to runtime exception and decide that inheriting from std::string may have been a bad idea in C++
This commit is contained in:
parent
7697406467
commit
fbe6dc9704
4 changed files with 52 additions and 37 deletions
|
@ -69,8 +69,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
|
|||
{
|
||||
// Create a local alias for brevity
|
||||
namespace bpo = boost::program_options;
|
||||
typedef Files::EscapeHashString string;
|
||||
typedef std::vector<string> StringsVector;
|
||||
typedef std::vector<Files::EscapeHashString> StringsVector;
|
||||
|
||||
bpo::options_description desc("Syntax: openmw <options>\nAllowed options");
|
||||
|
||||
|
@ -80,16 +79,16 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
|
|||
("data", bpo::value<Files::PathContainer>()->default_value(Files::PathContainer(), "data")
|
||||
->multitoken()->composing(), "set data directories (later directories have higher priority)")
|
||||
|
||||
("data-local", bpo::value<string>()->default_value(""),
|
||||
("data-local", bpo::value<Files::EscapeHashString>()->default_value(""),
|
||||
"set local data directory (highest priority)")
|
||||
|
||||
("fallback-archive", bpo::value<StringsVector>()->default_value(StringsVector(), "fallback-archive")
|
||||
->multitoken(), "set fallback BSA archives (later archives have higher priority)")
|
||||
|
||||
("resources", bpo::value<string>()->default_value("resources"),
|
||||
("resources", bpo::value<Files::EscapeHashString>()->default_value("resources"),
|
||||
"set resources directory")
|
||||
|
||||
("start", bpo::value<std::string>()->default_value(""),
|
||||
("start", bpo::value<Files::EscapeHashString>()->default_value(""),
|
||||
"set initial cell")
|
||||
|
||||
("content", bpo::value<StringsVector>()->default_value(StringsVector(), "")
|
||||
|
@ -110,7 +109,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
|
|||
("script-console", bpo::value<bool>()->implicit_value(true)
|
||||
->default_value(false), "enable console-only script functionality")
|
||||
|
||||
("script-run", bpo::value<string>()->default_value(""),
|
||||
("script-run", bpo::value<Files::EscapeHashString>()->default_value(""),
|
||||
"select a file containing a list of console commands that is executed on startup")
|
||||
|
||||
("script-warn", bpo::value<int>()->implicit_value (1)
|
||||
|
@ -126,7 +125,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
|
|||
("script-blacklist-use", bpo::value<bool>()->implicit_value(true)
|
||||
->default_value(true), "enable script blacklisting")
|
||||
|
||||
("load-savegame", bpo::value<string>()->default_value(""),
|
||||
("load-savegame", bpo::value<Files::EscapeHashString>()->default_value(""),
|
||||
"load a save game file on game startup (specify an absolute filename or a filename relative to the current working directory)")
|
||||
|
||||
("skip-menu", bpo::value<bool>()->implicit_value(true)
|
||||
|
@ -138,7 +137,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
|
|||
("fs-strict", bpo::value<bool>()->implicit_value(true)
|
||||
->default_value(false), "strict file system handling (no case folding)")
|
||||
|
||||
( "encoding", bpo::value<string>()->
|
||||
("encoding", bpo::value<Files::EscapeHashString>()->
|
||||
default_value("win1252"),
|
||||
"Character encoding used in OpenMW game messages:\n"
|
||||
"\n\twin1250 - Central and Eastern European such as Polish, Czech, Slovak, Hungarian, Slovene, Bosnian, Croatian, Serbian (Latin script), Romanian and Albanian languages\n"
|
||||
|
@ -242,7 +241,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
|
|||
engine.setScriptConsoleMode (variables["script-console"].as<bool>());
|
||||
engine.setStartupScript (variables["script-run"].as<std::string>());
|
||||
engine.setWarningsMode (variables["script-warn"].as<int>());
|
||||
engine.setScriptBlacklist (string::toStdStringVector(variables["script-blacklist"].as<StringsVector>()));
|
||||
engine.setScriptBlacklist (Files::EscapeHashString::toStdStringVector(variables["script-blacklist"].as<StringsVector>()));
|
||||
engine.setScriptBlacklistUse (variables["script-blacklist-use"].as<bool>());
|
||||
engine.setSaveGameFile (variables["load-savegame"].as<std::string>());
|
||||
|
||||
|
|
|
@ -12,11 +12,11 @@
|
|||
namespace Fallback
|
||||
{
|
||||
|
||||
struct FallbackMap {
|
||||
std::map<std::string, std::string> mMap;
|
||||
};
|
||||
struct FallbackMap {
|
||||
std::map<std::string, std::string> mMap;
|
||||
};
|
||||
|
||||
struct EscapeFallbackMap : FallbackMap
|
||||
struct EscapeFallbackMap : FallbackMap
|
||||
{
|
||||
std::map<Files::EscapeHashString, Files::EscapeHashString> mMap;
|
||||
|
||||
|
@ -29,34 +29,34 @@ namespace Fallback
|
|||
}
|
||||
};
|
||||
|
||||
void validate(boost::any &v, std::vector<std::string> const &tokens, FallbackMap*, int)
|
||||
{
|
||||
if(v.empty())
|
||||
{
|
||||
v = boost::any(FallbackMap());
|
||||
}
|
||||
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);
|
||||
FallbackMap *map = boost::any_cast<FallbackMap>(&v);
|
||||
|
||||
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)
|
||||
#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
|
||||
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)
|
||||
#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(it->substr(0, sep));
|
||||
std::string value(it->substr(sep + 1));
|
||||
|
||||
if(map->mMap.find(key) == map->mMap.end())
|
||||
{
|
||||
map->mMap.insert(std::make_pair (key,value));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (map->mMap.find(key) == map->mMap.end())
|
||||
{
|
||||
map->mMap.insert(std::make_pair(key, value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void validate(boost::any &v, std::vector<std::string> const &tokens, EscapeFallbackMap* eFM, int a)
|
||||
{
|
||||
|
@ -64,4 +64,13 @@ namespace Fallback
|
|||
}
|
||||
}
|
||||
|
||||
namespace Files {
|
||||
void validate(boost::any &v, const std::vector<std::string> &tokens, Files::EscapeHashString * eHS, int a)
|
||||
{
|
||||
std::string * temp = eHS->toStdStringPtr();
|
||||
boost::program_options::validate(v, tokens, temp, a);
|
||||
delete temp;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -285,6 +285,12 @@ std::string EscapeHashString::toStdString() const
|
|||
return std::string(* this);
|
||||
}
|
||||
|
||||
std::string * EscapeHashString::toStdStringPtr() const
|
||||
{
|
||||
std::string * ret = new std::string(*this);
|
||||
return ret;
|
||||
}
|
||||
|
||||
const boost::filesystem::path& ConfigurationManager::getGlobalPath() const
|
||||
{
|
||||
return mFixedPath.getGlobalConfigPath();
|
||||
|
|
|
@ -107,6 +107,7 @@ class EscapeHashString : public std::string
|
|||
EscapeHashString(InputIterator first, InputIterator last);
|
||||
|
||||
std::string toStdString() const;
|
||||
std::string * toStdStringPtr() const;
|
||||
};
|
||||
|
||||
} /* namespace Cfg */
|
||||
|
|
Loading…
Reference in a new issue