diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index e96b6e595..f54905a2c 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -69,7 +69,6 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat { // Create a local alias for brevity namespace bpo = boost::program_options; - typedef std::vector EscapeStringsVector; typedef std::vector StringsVector; bpo::options_description desc("Syntax: openmw \nAllowed options"); @@ -83,7 +82,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat ("data-local", bpo::value()->default_value(""), "set local data directory (highest priority)") - ("fallback-archive", bpo::value()->default_value(EscapeStringsVector(), "fallback-archive") + ("fallback-archive", bpo::value()->default_value(Files::EscapeStringVector(), "fallback-archive") ->multitoken(), "set fallback BSA archives (later archives have higher priority)") ("resources", bpo::value()->default_value("resources"), @@ -92,7 +91,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat ("start", bpo::value()->default_value(""), "set initial cell") - ("content", bpo::value()->default_value(EscapeStringsVector(), "") + ("content", bpo::value()->default_value(Files::EscapeStringVector(), "") ->multitoken(), "content file(s): esm/esp, or omwgame/omwaddon") ("no-sound", bpo::value()->implicit_value(true) @@ -120,7 +119,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat "\t1 - show warning but consider script as correctly compiled anyway\n" "\t2 - treat warnings as errors") - ("script-blacklist", bpo::value()->default_value(EscapeStringsVector(), "") + ("script-blacklist", bpo::value()->default_value(Files::EscapeStringVector(), "") ->multitoken(), "ignore the specified script (if the use of the blacklist is enabled)") ("script-blacklist-use", bpo::value()->implicit_value(true) @@ -207,7 +206,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat engine.setDataDirs(dataDirs); // fallback archives - StringsVector archives = Files::EscapeHashString::toStdStringVector(variables["fallback-archive"].as()); + StringsVector archives = variables["fallback-archive"].as().toStdStringVector(); for (StringsVector::const_iterator it = archives.begin(); it != archives.end(); ++it) { engine.addArchive(*it); @@ -215,7 +214,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat engine.setResourceDir(variables["resources"].as().toStdString()); - StringsVector content = Files::EscapeHashString::toStdStringVector(variables["content"].as()); + StringsVector content = variables["content"].as().toStdStringVector(); if (content.empty()) { std::cout << "No content file given (esm/esp, nor omwgame/omwaddon). Aborting..." << std::endl; @@ -242,7 +241,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat engine.setScriptConsoleMode (variables["script-console"].as()); engine.setStartupScript (variables["script-run"].as().toStdString()); engine.setWarningsMode (variables["script-warn"].as()); - engine.setScriptBlacklist (Files::EscapeHashString::toStdStringVector(variables["script-blacklist"].as())); + engine.setScriptBlacklist (variables["script-blacklist"].as().toStdStringVector()); engine.setScriptBlacklistUse (variables["script-blacklist-use"].as()); engine.setSaveGameFile (variables["load-savegame"].as().toStdString()); diff --git a/components/fallback/validate.hpp b/components/fallback/validate.hpp index e609297ae..d82ef5770 100644 --- a/components/fallback/validate.hpp +++ b/components/fallback/validate.hpp @@ -55,6 +55,17 @@ namespace Files { if (v.empty()) v = boost::any(EscapeHashString(boost::program_options::validators::get_single_string(tokens))); } + + void validate(boost::any &v, const std::vector &tokens, EscapeStringVector *, int) + { + if (v.empty()) + v = boost::any(EscapeStringVector()); + + EscapeStringVector * eSV = boost::any_cast(&v); + + for (std::vector::const_iterator it = tokens.begin(); it != tokens.end(); ++it) + eSV->mVector.push_back(EscapeHashString(*it)); + } } #endif diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 511dbe411..3a7f57949 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -244,17 +244,6 @@ std::string EscapeHashString::processString(const std::string & str) return temp; } - -std::vector EscapeHashString::toStdStringVector(const std::vector & vec) -{ - std::vector temp = std::vector(); - for (std::vector::const_iterator it = vec.begin(); it != vec.end(); ++it) - { - temp.push_back(it->toStdString()); - } - return temp; -} - EscapeHashString::EscapeHashString() : mData() { } @@ -289,9 +278,36 @@ std::string EscapeHashString::toStdString() const return std::string(mData); } -std::string * EscapeHashString::toStdStringPtr() const +std::istream & operator>> (std::istream & is, EscapeHashString & eHS) +{ + std::string temp; + is >> temp; + eHS = EscapeHashString(temp); + return is; +} + +std::ostream & operator<< (std::ostream & os, const EscapeHashString & eHS) +{ + os << eHS.mData; + return os; +} + +EscapeStringVector::EscapeStringVector() : mVector() { - return new std::string(mData); +} + +EscapeStringVector::~EscapeStringVector() +{ +} + +std::vector EscapeStringVector::toStdStringVector() const +{ + std::vector temp = std::vector(); + for (std::vector::const_iterator it = mVector.begin(); it != mVector.end(); ++it) + { + temp.push_back(it->toStdString()); + } + return temp; } const boost::filesystem::path& ConfigurationManager::getGlobalPath() const diff --git a/components/files/configurationmanager.hpp b/components/files/configurationmanager.hpp index 5138b3ca7..3ce995983 100644 --- a/components/files/configurationmanager.hpp +++ b/components/files/configurationmanager.hpp @@ -91,13 +91,12 @@ struct escape_hash_filter : public boost::iostreams::input_filter /** * \class EscapeHashString */ -class EscapeHashString : public std::string +class EscapeHashString { private: std::string mData; public: static std::string processString(const std::string & str); - static std::vector toStdStringVector(const std::vector & vec); EscapeHashString(); EscapeHashString(const std::string & str); @@ -109,7 +108,20 @@ class EscapeHashString : public std::string EscapeHashString(InputIterator first, InputIterator last); std::string toStdString() const; - std::string * toStdStringPtr() const; + + friend std::ostream & operator<< (std::ostream & os, const EscapeHashString & eHS); +}; + +std::istream & operator>> (std::istream & is, EscapeHashString & eHS); + +struct EscapeStringVector +{ + std::vector mVector; + + EscapeStringVector(); + virtual ~EscapeStringVector(); + + std::vector toStdStringVector() const; }; } /* namespace Cfg */