mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-05-08 11:38:19 +03:00
Get rid of unnecessary string streams
This commit is contained in:
parent
88edc1a120
commit
0937f02598
16 changed files with 111 additions and 176 deletions
|
@ -1,7 +1,6 @@
|
|||
#include "loadcell.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <list>
|
||||
|
||||
#include <boost/concept_check.hpp>
|
||||
|
@ -209,9 +208,7 @@ namespace ESM
|
|||
}
|
||||
else
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << mData.mX << ", " << mData.mY;
|
||||
return stream.str();
|
||||
return std::to_string(mData.mX) + ", " + std::to_string(mData.mY);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "interpreter.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "opcodes.hpp"
|
||||
|
@ -116,20 +115,14 @@ namespace Interpreter
|
|||
|
||||
void Interpreter::abortUnknownCode (int segment, int opcode)
|
||||
{
|
||||
std::ostringstream error;
|
||||
|
||||
error << "unknown opcode " << opcode << " in segment " << segment;
|
||||
|
||||
throw std::runtime_error (error.str());
|
||||
const std::string error = "unknown opcode " + std::to_string(opcode) + " in segment " + std::to_string(segment);
|
||||
throw std::runtime_error (error);
|
||||
}
|
||||
|
||||
void Interpreter::abortUnknownSegment (Type_Code code)
|
||||
{
|
||||
std::ostringstream error;
|
||||
|
||||
error << "opcode outside of the allocated segment range: " << code;
|
||||
|
||||
throw std::runtime_error (error.str());
|
||||
const std::string error = "opcode outside of the allocated segment range: " + std::to_string(code);
|
||||
throw std::runtime_error (error);
|
||||
}
|
||||
|
||||
void Interpreter::begin()
|
||||
|
|
|
@ -8,48 +8,6 @@
|
|||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
bool parseBool(const std::string& string)
|
||||
{
|
||||
return (Misc::StringUtils::ciEqual(string, "true"));
|
||||
}
|
||||
|
||||
float parseFloat(const std::string& string)
|
||||
{
|
||||
std::stringstream stream;
|
||||
stream << string;
|
||||
float ret = 0.f;
|
||||
stream >> ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int parseInt(const std::string& string)
|
||||
{
|
||||
std::stringstream stream;
|
||||
stream << string;
|
||||
int ret = 0;
|
||||
stream >> ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::string toString(T val)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << val;
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
template <>
|
||||
std::string toString(bool val)
|
||||
{
|
||||
return val ? "true" : "false";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Settings
|
||||
{
|
||||
|
||||
|
@ -393,17 +351,36 @@ std::string Manager::getString(const std::string &setting, const std::string &ca
|
|||
|
||||
float Manager::getFloat (const std::string& setting, const std::string& category)
|
||||
{
|
||||
return parseFloat( getString(setting, category) );
|
||||
const std::string value = getString(setting, category);
|
||||
try
|
||||
{
|
||||
return std::stof(value);
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
Log(Debug::Warning) << "Cannot parse setting '" << setting << "' (invalid setting value: " << value << ").";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int Manager::getInt (const std::string& setting, const std::string& category)
|
||||
{
|
||||
return parseInt( getString(setting, category) );
|
||||
const std::string value = getString(setting, category);
|
||||
try
|
||||
{
|
||||
return std::stoi(value);
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
Log(Debug::Warning) << "Cannot parse setting '" << setting << "' (invalid setting value: " << value << ").";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool Manager::getBool (const std::string& setting, const std::string& category)
|
||||
{
|
||||
return parseBool( getString(setting, category) );
|
||||
const std::string& string = getString(setting, category);
|
||||
return Misc::StringUtils::ciEqual(string, "true");
|
||||
}
|
||||
|
||||
void Manager::setString(const std::string &setting, const std::string &category, const std::string &value)
|
||||
|
@ -424,17 +401,17 @@ void Manager::setString(const std::string &setting, const std::string &category,
|
|||
|
||||
void Manager::setInt (const std::string& setting, const std::string& category, const int value)
|
||||
{
|
||||
setString(setting, category, toString(value));
|
||||
setString(setting, category, std::to_string(value));
|
||||
}
|
||||
|
||||
void Manager::setFloat (const std::string &setting, const std::string &category, const float value)
|
||||
{
|
||||
setString(setting, category, toString(value));
|
||||
setString(setting, category, std::to_string(value));
|
||||
}
|
||||
|
||||
void Manager::setBool(const std::string &setting, const std::string &category, const bool value)
|
||||
{
|
||||
setString(setting, category, toString(value));
|
||||
setString(setting, category, value ? "true" : "false");
|
||||
}
|
||||
|
||||
const CategorySettingVector Manager::apply()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue