From 6fd18bd0f041e6651abc7f1e74110a15e4988af4 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Wed, 25 Oct 2017 14:11:43 +0300 Subject: [PATCH] Make wrapper for boost::lexical_cast This makes it easier to eventually get rid of boost::lexical_cast. --- include/library/string.hpp | 7 ++++++- src/platform/libao/sound.cpp | 1 - src/platform/portaudio/sound.cpp | 4 ++-- src/platform/wxwidgets/main.cpp | 1 - src/platform/wxwidgets/romselect.cpp | 9 ++++----- src/platform/wxwidgets/settings-joysticks.cpp | 10 +++++----- src/util/lsnes-dumpavi.cpp | 4 ++-- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/include/library/string.hpp b/include/library/string.hpp index bb14aaac..359b08c2 100644 --- a/include/library/string.hpp +++ b/include/library/string.hpp @@ -265,6 +265,11 @@ bool regex_match(const std::string& regex, const std::string& str, enum regex_ma */ int string_to_bool(const std::string& cast_to_bool); +template T raw_lexical_cast(const std::string& value) +{ + return boost::lexical_cast(value); +} + /** * \brief Typeconvert string. */ @@ -315,7 +320,7 @@ template inline T parse_value(const std::string& value) throw(std::b } return val; } - return boost::lexical_cast(value); + return raw_lexical_cast(value); } catch(std::exception& e) { throw std::runtime_error("Can't parse value '" + value + "': " + e.what()); } diff --git a/src/platform/libao/sound.cpp b/src/platform/libao/sound.cpp index 75cf6ef0..e3c9d831 100644 --- a/src/platform/libao/sound.cpp +++ b/src/platform/libao/sound.cpp @@ -29,7 +29,6 @@ #include #include #include -#include namespace { diff --git a/src/platform/portaudio/sound.cpp b/src/platform/portaudio/sound.cpp index dae73799..df180c7f 100644 --- a/src/platform/portaudio/sound.cpp +++ b/src/platform/portaudio/sound.cpp @@ -11,6 +11,7 @@ #include "core/settings.hpp" #include "core/window.hpp" #include "library/framebuffer.hpp" +#include "library/string.hpp" #include #include @@ -25,7 +26,6 @@ #include #include #include -#include namespace { @@ -320,7 +320,7 @@ namespace idx = paNoDevice; } else { try { - idx = boost::lexical_cast(dev); + idx = raw_lexical_cast(dev); if(idx < 0 || !Pa_GetDeviceInfo(idx)) throw std::runtime_error("foo"); } catch(std::exception& e) { diff --git a/src/platform/wxwidgets/main.cpp b/src/platform/wxwidgets/main.cpp index 927e591d..76bb1e54 100644 --- a/src/platform/wxwidgets/main.cpp +++ b/src/platform/wxwidgets/main.cpp @@ -40,7 +40,6 @@ #include #include -#include #include #include diff --git a/src/platform/wxwidgets/romselect.cpp b/src/platform/wxwidgets/romselect.cpp index a0e04492..f52b234a 100644 --- a/src/platform/wxwidgets/romselect.cpp +++ b/src/platform/wxwidgets/romselect.cpp @@ -21,7 +21,6 @@ #include "library/directory.hpp" #include "library/string.hpp" #include "library/zip.hpp" -#include #include "platform/wxwidgets/platform.hpp" #include "platform/wxwidgets/loadsave.hpp" @@ -624,8 +623,8 @@ void wxwin_project::on_filename_change(wxCommandEvent& e) { CHECK_UI_THREAD; try { - boost::lexical_cast(tostdstring(rtc_sec->GetValue())); - if(boost::lexical_cast(tostdstring(rtc_subsec->GetValue())) < 0) + raw_lexical_cast(tostdstring(rtc_sec->GetValue())); + if(raw_lexical_cast(tostdstring(rtc_subsec->GetValue())) < 0) throw 42; size_t lines = authors->GetNumberOfLines(); for(size_t i = 0; i < lines; i++) { @@ -705,9 +704,9 @@ struct moviefile& wxwin_project::make_movie() *target = zip::readrel(sf, ""); } } - f.movie_rtc_second = f.dyn.rtc_second = boost::lexical_cast(tostdstring(rtc_sec->GetValue())); + f.movie_rtc_second = f.dyn.rtc_second = raw_lexical_cast(tostdstring(rtc_sec->GetValue())); f.movie_rtc_subsecond = f.dyn.rtc_subsecond = - boost::lexical_cast(tostdstring(rtc_subsec->GetValue())); + raw_lexical_cast(tostdstring(rtc_subsec->GetValue())); if(f.movie_rtc_subsecond < 0) throw std::runtime_error("RTC subsecond must be positive"); auto ctrldata = inst.rom->controllerconfig(f.settings); diff --git a/src/platform/wxwidgets/settings-joysticks.cpp b/src/platform/wxwidgets/settings-joysticks.cpp index bfbbc5f2..d5619772 100644 --- a/src/platform/wxwidgets/settings-joysticks.cpp +++ b/src/platform/wxwidgets/settings-joysticks.cpp @@ -88,15 +88,15 @@ namespace try { bad_what = "Bad low calibration value"; - minus = boost::lexical_cast(tostdstring(low->GetValue())); + minus = raw_lexical_cast(tostdstring(low->GetValue())); bad_what = "Bad middle calibration value"; - zero = boost::lexical_cast(tostdstring(mid->GetValue())); + zero = raw_lexical_cast(tostdstring(mid->GetValue())); bad_what = "Bad high calibration value"; - plus = boost::lexical_cast(tostdstring(hi->GetValue())); + plus = raw_lexical_cast(tostdstring(hi->GetValue())); bad_what = "Bad neutral zone width"; - neutral = boost::lexical_cast(tostdstring(null->GetValue())); + neutral = raw_lexical_cast(tostdstring(null->GetValue())); bad_what = "Bad threshold (range is 0 - 1)"; - threshold = boost::lexical_cast(tostdstring(thresh->GetValue())); + threshold = raw_lexical_cast(tostdstring(thresh->GetValue())); if(threshold <= 0 || threshold >= 1) throw 42; pressure = _pressure->GetValue(); diff --git a/src/util/lsnes-dumpavi.cpp b/src/util/lsnes-dumpavi.cpp index 6dd55d3d..1f6e8175 100644 --- a/src/util/lsnes-dumpavi.cpp +++ b/src/util/lsnes-dumpavi.cpp @@ -217,7 +217,7 @@ namespace prefix = a.substr(9); else if(a.length() >= 9 && a.substr(0, 9) == "--length=") try { - length = boost::lexical_cast(a.substr(9)); + length = raw_lexical_cast(a.substr(9)); if(!length) throw std::runtime_error("Length out of range (1-)"); if(overdump_mode) @@ -229,7 +229,7 @@ namespace } else if(a.length() >= 18 && a.substr(0, 18) == "--overdump-length=") try { - overdump_length = boost::lexical_cast(a.substr(18)); + overdump_length = raw_lexical_cast(a.substr(18)); overdump_mode = true; if(length) throw std::runtime_error("--length and --overdump-length are " -- 2.11.4.GIT