Replaced boost::lexical_cast with other implementations

Changes based on f0f6f61cab
dev
Tomasz Kapuściński 2023-08-09 19:32:59 +02:00
parent f7a33bbeb0
commit 1b69589302
16 changed files with 73 additions and 64 deletions

View File

@ -22,6 +22,7 @@
#include "common/config_file.h"
#include "common/logger.h"
#include "common/restext.h"
#include "common/stringutils.h"
#include "graphics/engine/engine.h"
@ -30,7 +31,6 @@
#include "math/func.h"
#include <sstream>
#include <boost/lexical_cast.hpp>
#include <SDL_system.h>
CInput::CInput()
@ -355,8 +355,8 @@ void CInput::SaveKeyBindings()
{
JoyAxisBinding b = GetJoyAxisBinding(static_cast<JoyAxisSlot>(i));
GetConfigFile().SetIntProperty("Setup", "JoystickAxisBinding"+boost::lexical_cast<std::string>(i), b.axis);
GetConfigFile().SetIntProperty("Setup", "JoystickAxisInvert"+boost::lexical_cast<std::string>(i), b.invert);
GetConfigFile().SetIntProperty("Setup", "JoystickAxisBinding" + StrUtils::ToString(i), b.axis);
GetConfigFile().SetIntProperty("Setup", "JoystickAxisInvert" + StrUtils::ToString(i), b.invert);
}
GetConfigFile().SetFloatProperty("Setup", "JoystickDeadzone", GetJoystickDeadzone());
}
@ -387,11 +387,11 @@ void CInput::LoadKeyBindings()
{
JoyAxisBinding b;
if (!GetConfigFile().GetIntProperty("Setup", "JoystickAxisBinding"+boost::lexical_cast<std::string>(i), b.axis))
if (!GetConfigFile().GetIntProperty("Setup", "JoystickAxisBinding" + std::to_string(i), b.axis))
continue;
int x = 0;
GetConfigFile().GetIntProperty("Setup", "JoystickAxisInvert"+boost::lexical_cast<std::string>(i), x); // If doesn't exist, use default (0)
GetConfigFile().GetIntProperty("Setup", "JoystickAxisInvert" + std::to_string(i), x); // If doesn't exist, use default (0)
b.invert = (x != 0);
SetJoyAxisBinding(static_cast<JoyAxisSlot>(i), b);

View File

@ -26,6 +26,7 @@
#include "common/config_file.h"
#include "common/logger.h"
#include "common/stringutils.h"
#include "common/resources/resourcemanager.h"
@ -275,9 +276,9 @@ void CModManager::LoadModData(Mod& mod)
}
else if (line->GetParam("major")->IsDefined() && line->GetParam("minor")->IsDefined() && line->GetParam("patch")->IsDefined())
{
auto major = boost::lexical_cast<std::string>(line->GetParam("major")->AsInt());
auto minor = boost::lexical_cast<std::string>(line->GetParam("minor")->AsInt());
auto patch = boost::lexical_cast<std::string>(line->GetParam("patch")->AsInt());
auto major = StrUtils::ToString(line->GetParam("major")->AsInt());
auto minor = StrUtils::ToString(line->GetParam("minor")->AsInt());
auto patch = StrUtils::ToString(line->GetParam("patch")->AsInt());
data.version = boost::algorithm::join(std::vector<std::string>{ major, minor, patch }, ".");
}
}

View File

@ -29,7 +29,6 @@
#include "common/logger.h"
#include <boost/property_tree/ptree.hpp>
#include <boost/lexical_cast.hpp>
#include <string>
#include <sstream>
@ -157,9 +156,22 @@ private:
std::vector<T> result;
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, ','))
{
result.push_back(boost::lexical_cast<T>(item));
if constexpr (std::is_same_v<T, std::string>)
{
result.push_back(item);
}
else
{
std::stringstream stream(item);
T value;
stream >> value;
result.push_back(value);
}
}
return result;
}

View File

@ -21,8 +21,9 @@
#include "common/event.h"
#include "common/logger.h"
#include "common/stringutils.h"
#include <boost/lexical_cast.hpp>
#include <sstream>
namespace
{
@ -580,12 +581,12 @@ std::string ParseEventType(EventType eventType)
{
if(eventType >= EVENT_INTERFACE_KEY && eventType <= EVENT_INTERFACE_KEY_END)
{
return "EVENT_INTERFACE_KEY"+boost::lexical_cast<std::string>(eventType-EVENT_INTERFACE_KEY);
return "EVENT_INTERFACE_KEY" + StrUtils::ToString(eventType-EVENT_INTERFACE_KEY);
}
if(eventType >= EVENT_OBJECT_SHORTCUT && eventType <= EVENT_OBJECT_SHORTCUT_MAX)
{
return "EVENT_OBJECT_SHORTCUT"+boost::lexical_cast<std::string>(eventType-EVENT_OBJECT_SHORTCUT);
return "EVENT_OBJECT_SHORTCUT" + StrUtils::ToString(eventType-EVENT_OBJECT_SHORTCUT);
}
const char* stdEvent = EVENT_TYPE_TEXT[eventType];

View File

@ -26,8 +26,8 @@
#include "graphics/model/model_io_structs.h"
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <array>
#include <iostream>
using namespace IOUtils;

View File

@ -26,7 +26,6 @@
#include "graphics/model/model_io_structs.h"
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
using namespace IOUtils;
@ -58,7 +57,7 @@ std::unique_ptr<CModel> ReadTextModel(const std::filesystem::path& path)
int version = 0;
try
{
version = boost::lexical_cast<int>(ReadLineString(stream, "version"));
version = std::stoi(ReadLineString(stream, "version"));
stream.seekg(std::ios_base::beg);
}
catch (const std::exception& e)
@ -73,7 +72,7 @@ std::unique_ptr<CModel> ReadTextModel(const std::filesystem::path& path)
else if (version == 3)
ReadTextModelV3(*model, stream);
else
throw CModelIOException(std::string("Unexpected version number: ") + boost::lexical_cast<std::string>(version));
throw CModelIOException(std::string("Unexpected version number: ") + std::to_string(version));
return model;
}
@ -84,8 +83,8 @@ void ReadTextModelV1AndV2(CModel& model, std::istream& stream)
try
{
header.version = boost::lexical_cast<int>(ReadLineString(stream, "version"));
header.totalTriangles = boost::lexical_cast<int>(ReadLineString(stream, "total_triangles"));
header.version = std::stoi(ReadLineString(stream, "version"));
header.totalTriangles = std::stoi(ReadLineString(stream, "total_triangles"));
}
catch (const std::exception& e)
{
@ -121,9 +120,9 @@ void ReadTextModelV1AndV2(CModel& model, std::istream& stream)
t.variableTex2 = varTex2Ch == "Y";
if (header.version == 1)
t.lodLevel = static_cast<ModelLODLevel>(boost::lexical_cast<int>(ReadLineString(stream, "lod_level")));
t.lodLevel = static_cast<ModelLODLevel>(std::stoi(ReadLineString(stream, "lod_level")));
t.state = boost::lexical_cast<int>(ReadLineString(stream, "state"));
t.state = std::stoi(ReadLineString(stream, "state"));
if (t.lodLevel == ModelLODLevel::Low ||
t.lodLevel == ModelLODLevel::Medium)
@ -186,11 +185,11 @@ void ReadTextModelV3(CModel& model, std::istream& stream)
ModelHeaderV3 ReadTextHeader(std::istream& stream)
{
ModelHeaderV3 header;
header.version = boost::lexical_cast<int>(ReadLineString(stream, "version"));
header.totalCrashSpheres = boost::lexical_cast<int>(ReadLineString(stream, "total_crash_spheres"));
header.version = std::stoi(ReadLineString(stream, "version"));
header.totalCrashSpheres = std::stoi(ReadLineString(stream, "total_crash_spheres"));
header.hasShadowSpot = ReadLineString(stream, "has_shadow_spot") == std::string("Y");
header.hasCameraCollisionSphere = ReadLineString(stream, "has_camera_collision_sphere") == std::string("Y");
header.totalMeshes = boost::lexical_cast<int>(ReadLineString(stream, "total_meshes"));
header.totalMeshes = std::stoi(ReadLineString(stream, "total_meshes"));
return header;
}
@ -203,7 +202,7 @@ std::unique_ptr<CModelMesh> ReadTextMesh(std::istream& stream)
mesh->SetScale(ParseVector(ReadLineString(stream, "scale")));
mesh->SetParent(ReadLineString(stream, "parent"));
int totalTriangles = boost::lexical_cast<int>(ReadLineString(stream, "total_triangles"));
int totalTriangles = std::stoi(ReadLineString(stream, "total_triangles"));
for (int i = 0; i < totalTriangles; ++i)
{

View File

@ -40,7 +40,6 @@
#include <boost/algorithm/string/trim.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/lexical_cast.hpp>
CLevelParser::CLevelParser()
{
@ -255,13 +254,13 @@ void CLevelParser::Load()
{
pos = line.find_first_of("\"", 1);
if (pos == std::string::npos)
throw CLevelParserException("Unclosed \" in " + m_filename + ":" + boost::lexical_cast<std::string>(lineNumber));
throw CLevelParserException("Unclosed \" in " + m_filename + ":" + StrUtils::ToString(lineNumber));
}
else if (line[0] == '\'')
{
pos = line.find_first_of("'", 1);
if (pos == std::string::npos)
throw CLevelParserException("Unclosed ' in " + m_filename + ":" + boost::lexical_cast<std::string>(lineNumber));
throw CLevelParserException("Unclosed ' in " + m_filename + ":" + StrUtils::ToString(lineNumber));
}
else
{

View File

@ -21,13 +21,13 @@
#include "level/parser/parser.h"
#include <boost/lexical_cast.hpp>
#include "common/stringutils.h"
static std::string FormatMissingParamError(CLevelParserParam* thisParam) NOEXCEPT
{
auto paramName = thisParam->GetName();
auto lineNumber = boost::lexical_cast<std::string>(thisParam->GetLine()->GetLineNumber());
auto lineNumber = StrUtils::ToString(thisParam->GetLine()->GetLineNumber());
auto fileName = thisParam->GetLine()->GetLevelFilename();
return "Missing required param '" + paramName + "' (in " + fileName + ":" + lineNumber + ")";
}
@ -41,7 +41,7 @@ static std::string FormatBadParamError(CLevelParserParam* thisParam, std::string
{
auto paramName = thisParam->GetName();
auto paramValue = thisParam->GetValue();
auto lineNumber = boost::lexical_cast<std::string>(thisParam->GetLine()->GetLineNumber());
auto lineNumber = StrUtils::ToString(thisParam->GetLine()->GetLineNumber());
auto fileName = thisParam->GetLine()->GetLevelFilename();
return "Unable to parse '" + paramValue + "' as " + requestedType + " (param '" + paramName + "' in " + fileName + ":" + lineNumber + ")";
}

View File

@ -33,7 +33,6 @@
#include "level/parser/parser.h"
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
CLevelParserParam::CLevelParserParam(std::string name, std::string value)
@ -49,11 +48,11 @@ CLevelParserParam::CLevelParserParam(std::string name, bool empty)
}
CLevelParserParam::CLevelParserParam(int value)
: m_value(boost::lexical_cast<std::string>(value))
: m_value(StrUtils::ToString(value))
{}
CLevelParserParam::CLevelParserParam(float value)
: m_value(boost::lexical_cast<std::string>(value))
: m_value(StrUtils::ToString(value))
{}
CLevelParserParam::CLevelParserParam(std::string value)
@ -133,11 +132,14 @@ bool CLevelParserParam::IsDefined()
}
template<typename T>
T CLevelParserParam::Cast(std::string value, std::string requestedType)
T CLevelParserParam::Cast(const std::string& value, const std::string& requestedType)
{
try
{
return boost::lexical_cast<T>(value);
std::stringstream stream(value);
T result;
stream >> result;
return result;
}
catch(...)
{
@ -146,7 +148,7 @@ T CLevelParserParam::Cast(std::string value, std::string requestedType)
}
template<typename T>
T CLevelParserParam::Cast(std::string requestedType)
T CLevelParserParam::Cast(const std::string& requestedType)
{
return Cast<T>(m_value, requestedType);
}
@ -750,7 +752,7 @@ const std::string CLevelParserParam::FromObjectType(ObjectType value)
if (value == OBJECT_HUMAN ) return "Me";
if (value == OBJECT_TECH ) return "Tech";
if (value == OBJECT_CONTROLLER ) return "MissionController";
return boost::lexical_cast<std::string>(static_cast<int>(value));
return StrUtils::ToString(static_cast<int>(value));
}
ObjectType CLevelParserParam::AsObjectType()
@ -1052,7 +1054,7 @@ const std::string CLevelParserParam::FromCameraType(Gfx::CameraType value)
{
if (value == Gfx::CAM_TYPE_ONBOARD) return "ONBOARD";
if (value == Gfx::CAM_TYPE_FIX ) return "FIX";
return boost::lexical_cast<std::string>(static_cast<int>(value));
return StrUtils::ToString(static_cast<int>(value));
}
Gfx::CameraType CLevelParserParam::AsCameraType()
@ -1115,7 +1117,7 @@ void CLevelParserParam::ParseArray()
{
boost::algorithm::trim(value);
if (value.empty()) continue;
auto param = std::make_unique<CLevelParserParam>(m_name + "[" + boost::lexical_cast<std::string>(i) + "]", value);
auto param = std::make_unique<CLevelParserParam>(m_name + "[" + StrUtils::ToString(i) + "]", value);
param->SetLine(m_line);
m_array.push_back(std::move(param));
i++;

View File

@ -139,8 +139,8 @@ private:
void ParseArray();
void LoadArray();
template<typename T> T Cast(std::string value, std::string requestedType);
template<typename T> T Cast(std::string requestedType);
template<typename T> T Cast(const std::string& value, const std::string& requestedType);
template<typename T> T Cast(const std::string& requestedType);
std::string ToPath(std::string path, const std::string defaultDir);
ObjectType ToObjectType(std::string value);

View File

@ -117,8 +117,6 @@
#include <cmath>
#include <ctime>
#include <boost/lexical_cast.hpp>
// Global variables.
@ -2914,7 +2912,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
{
try
{
int rank = boost::lexical_cast<int>(line->GetParam(type)->GetValue());
int rank = std::stoi(line->GetParam(type)->GetValue());
if (rank >= 0)
{
// TODO: Fix default levels and add a future removal warning
@ -2931,7 +2929,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
}
}
catch (boost::bad_lexical_cast &e)
catch (std::invalid_argument &e)
{
return line->GetParam(type)->AsPath("levels");
}
@ -3767,7 +3765,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (!m_sceneReadPath.empty()) continue; // ignore errors when loading saved game (TODO: don't report ones that are just not loaded when loading saved game)
if (resetObject) continue; // ignore when reseting just objects (TODO: see above)
throw CLevelParserException("Unknown command: '" + line->GetCommand() + "' in " + line->GetLevelFilename() + ":" + boost::lexical_cast<std::string>(line->GetLineNumber()));
throw CLevelParserException("Unknown command: '" + line->GetCommand() + "' in " + line->GetLevelFilename() + ":" + StrUtils::ToString(line->GetLineNumber()));
}
// Do this here to prevent the first frame from taking a long time to render

View File

@ -30,7 +30,7 @@
#include "ui/displaytext.h"
#include <boost/lexical_cast.hpp>
#include <algorithm>
void CScoreboard::CScoreboardRule::Read(CLevelParserLine* line)
{

View File

@ -46,8 +46,6 @@
#include "ui/controls/edit.h"
#include <boost/lexical_cast.hpp>
#include <algorithm>
#include <iomanip>
#include <regex>
@ -240,7 +238,7 @@ void CProgramStorageObjectImpl::SaveAllUserPrograms(const std::string& userSourc
std::smatch matches;
if (std::regex_match(filename, matches, regex))
{
unsigned int id = boost::lexical_cast<unsigned int>(matches[1]);
unsigned int id = std::stoul(matches[1]);
if (id >= m_program.size() || !m_program[id]->filename.empty())
{
GetLogger()->Trace("Removing old program '%s/%s'\n", dir.c_str(), filename.c_str());
@ -303,7 +301,7 @@ void CProgramStorageObjectImpl::LoadAllProgramsForLevel(CLevelParserLine* levelS
std::smatch matches;
if (std::regex_match(filename, matches, regex))
{
unsigned int i = boost::lexical_cast<unsigned int>(matches[1]);
unsigned int i = std::stoul(matches[1]);
Program* program = GetOrAddProgram(i);
if(GetCompile(program)) program = AddProgram(); // If original slot is already used, get a new one
GetLogger()->Trace("Loading program '%s/%s' from user directory\n", dir.c_str(), filename.c_str());
@ -348,7 +346,7 @@ void CProgramStorageObjectImpl::SaveAllProgramsForSavedScene(CLevelParserLine* l
std::smatch matches;
if (std::regex_match(filename, matches, regex))
{
unsigned int id = boost::lexical_cast<unsigned int>(matches[1]);
unsigned int id = std::stoul(matches[1]);
if (id >= m_program.size() || !m_program[id]->filename.empty())
{
GetLogger()->Trace("Removing old program '%s/%s' from saved scene\n", levelSource.c_str(), filename.c_str());

View File

@ -21,18 +21,19 @@
#include "object/object_type.h"
#include "common/stringutils.h"
#include <stdexcept>
#include <boost/lexical_cast.hpp>
class CObjectCreateException : public std::runtime_error
{
public:
explicit CObjectCreateException(const std::string& error, ObjectType type)
: std::runtime_error("Error creating object type " + boost::lexical_cast<std::string>(type))
: std::runtime_error("Error creating object type " + StrUtils::ToString(type))
{}
explicit CObjectCreateException(const std::string& error, ObjectType type, const std::string& modelName)
: std::runtime_error("Error creating object type " +
boost::lexical_cast<std::string>(type) +
StrUtils::ToString(type) +
" from model " + modelName + ": " + error)
{}
};

View File

@ -65,7 +65,6 @@
#include "ui/controls/edit.h"
#include <boost/lexical_cast.hpp>
#include <iomanip>
@ -1242,7 +1241,7 @@ void COldObject::Read(CLevelParserLine* line)
m_auto->SetType(line->GetParam("autoType")->AsObjectType(OBJECT_NULL));
for (int i = 0; i < 5; i++)
{
std::string op = "autoValue" + boost::lexical_cast<std::string>(i+1); // autoValue1..autoValue5
std::string op = "autoValue" + StrUtils::ToString(i+1); // autoValue1..autoValue5
m_auto->SetValue(i, line->GetParam(op)->AsFloat(0.0f));
}
m_auto->SetString(const_cast<char*>(line->GetParam("autoString")->AsString("").c_str()));

View File

@ -20,6 +20,7 @@
#include "object/subclass/exchange_post.h"
#include "common/regex_utils.h"
#include "common/stringutils.h"
#include "graphics/engine/engine.h"
#include "graphics/engine/oldmodelmanager.h"
@ -38,8 +39,6 @@
#include "ui/controls/list.h"
#include "ui/controls/window.h"
#include <boost/lexical_cast.hpp>
CExchangePost::CExchangePost(int id)
: CBaseBuilding(id, OBJECT_INFO)
@ -202,8 +201,8 @@ void CExchangePost::Write(CLevelParserLine* line)
++i;
if (!info.name.empty())
{
auto key = "info" + boost::lexical_cast<std::string>(i);
auto paramValue = info.name + "=" + boost::lexical_cast<std::string>(info.value);
auto key = "info" + StrUtils::ToString(i);
auto paramValue = info.name + "=" + StrUtils::ToString(info.value);
line->AddParam(key, std::make_unique<CLevelParserParam>(paramValue));
}
}
@ -220,7 +219,7 @@ void CExchangePost::ReadInfo(CLevelParserLine* line)
{
for (int i = 1; i <= GetMaximumInfoListSize(); i++)
{
std::string op = std::string("info") + boost::lexical_cast<std::string>(i);
std::string op = std::string("info") + StrUtils::ToString(i);
if (!line->GetParam(op)->IsDefined())
break;
@ -233,7 +232,7 @@ void CExchangePost::ReadInfo(CLevelParserLine* line)
{
auto matches = RegexUtils::AssertRegexMatch(text, "([^=]+)=(.*)");
info.name = matches[1];
info.value = boost::lexical_cast<float>(matches[2]);
info.value = std::stof(matches[2]);
}
catch (...)
{