Replaced boost::lexical_cast<> with str2bool/str2int/str2float
Fixes #150
This commit is contained in:
parent
2da23aac89
commit
e75d0e1e82
30 changed files with 154 additions and 81 deletions
|
@ -18,8 +18,8 @@
|
|||
|
||||
#include "axis_filter.hpp"
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
|
||||
#include "axisfilter/calibration_axis_filter.hpp"
|
||||
#include "axisfilter/const_axis_filter.hpp"
|
||||
|
|
|
@ -48,7 +48,7 @@ KeyAxisEventHandler::from_string(const std::string& str)
|
|||
if (is_number(*i))
|
||||
{
|
||||
// bit of hackery to handle simplified syntax for trigger button that don't need up/down events
|
||||
ev->m_threshold = boost::lexical_cast<int>(*i);
|
||||
ev->m_threshold = str2int(*i);
|
||||
ev->m_down_codes = ev->m_up_codes;
|
||||
ev->m_up_codes.clear();
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ KeyAxisEventHandler::from_string(const std::string& str)
|
|||
break;
|
||||
|
||||
case 2:
|
||||
ev->m_threshold = boost::lexical_cast<int>(*i);
|
||||
ev->m_threshold = str2int(*i);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <math.h>
|
||||
|
||||
#include "evdev_helper.hpp"
|
||||
#include "helper.hpp"
|
||||
#include "uinput.hpp"
|
||||
|
||||
RelAxisEventHandler*
|
||||
|
@ -42,11 +43,11 @@ RelAxisEventHandler::from_string(const std::string& str)
|
|||
break;
|
||||
|
||||
case 1:
|
||||
ev->m_value = boost::lexical_cast<float>(*i);
|
||||
ev->m_value = str2float(*i);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
ev->m_repeat = boost::lexical_cast<int>(*i);
|
||||
ev->m_repeat = str2int(*i);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -20,8 +20,10 @@
|
|||
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <math.h>
|
||||
#include <sstream>
|
||||
|
||||
#include "evdev_helper.hpp"
|
||||
#include "helper.hpp"
|
||||
#include "raise_exception.hpp"
|
||||
#include "uinput.hpp"
|
||||
|
||||
|
@ -37,8 +39,8 @@ RelRepeatAxisEventHandler::from_string(const std::string& str)
|
|||
if (args.size() == 3)
|
||||
{
|
||||
return new RelRepeatAxisEventHandler(str2rel_event(args[0]),
|
||||
boost::lexical_cast<int>(args[1]),
|
||||
boost::lexical_cast<float>(args[2]));
|
||||
str2int(args[1]),
|
||||
str2float(args[2]));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "axisfilter/calibration_axis_filter.hpp"
|
||||
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <sstream>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
|
@ -38,9 +38,9 @@ CalibrationAxisFilter::from_string(const std::string& str)
|
|||
{
|
||||
switch(j)
|
||||
{
|
||||
case 0: min = boost::lexical_cast<int>(*i); break;
|
||||
case 1: center = boost::lexical_cast<int>(*i); break;
|
||||
case 2: max = boost::lexical_cast<int>(*i); break;
|
||||
case 0: min = str2int(*i); break;
|
||||
case 1: center = str2int(*i); break;
|
||||
case 2: max = str2int(*i); break;
|
||||
default: throw std::runtime_error("to many arguments");
|
||||
};
|
||||
}
|
||||
|
|
|
@ -18,13 +18,14 @@
|
|||
|
||||
#include "axisfilter/const_axis_filter.hpp"
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <sstream>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
ConstAxisFilter*
|
||||
ConstAxisFilter::from_string(const std::string& rest)
|
||||
{
|
||||
return new ConstAxisFilter(boost::lexical_cast<int>(rest));
|
||||
return new ConstAxisFilter(str2int(rest));
|
||||
}
|
||||
|
||||
ConstAxisFilter::ConstAxisFilter(int value) :
|
||||
|
|
|
@ -19,7 +19,9 @@
|
|||
#include "axisfilter/deadzone_axis_filter.hpp"
|
||||
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <sstream>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
DeadzoneAxisFilter*
|
||||
DeadzoneAxisFilter::from_string(const std::string& str)
|
||||
|
@ -36,17 +38,17 @@ DeadzoneAxisFilter::from_string(const std::string& str)
|
|||
switch(idx)
|
||||
{
|
||||
case 0:
|
||||
max_deadzone = boost::lexical_cast<int>(*t);
|
||||
max_deadzone = str2int(*t);
|
||||
min_deadzone = -max_deadzone;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
min_deadzone = -min_deadzone;
|
||||
max_deadzone = boost::lexical_cast<int>(*t);
|
||||
max_deadzone = str2int(*t);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
smooth = boost::lexical_cast<bool>(*t);
|
||||
smooth = str2bool(*t);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "axisfilter/relative_axis_filter.hpp"
|
||||
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <sstream>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
|
@ -35,7 +35,7 @@ RelativeAxisFilter::from_string(const std::string& str)
|
|||
{
|
||||
switch(idx)
|
||||
{
|
||||
case 0: speed = boost::lexical_cast<int>(*t); break;
|
||||
case 0: speed = str2int(*t); break;
|
||||
default: throw std::runtime_error("to many arguments"); break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,9 @@
|
|||
#include "response_curve_axis_filter.hpp"
|
||||
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <sstream>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
ResponseCurveAxisFilter*
|
||||
ResponseCurveAxisFilter::from_string(const std::string& str)
|
||||
|
@ -31,7 +33,7 @@ ResponseCurveAxisFilter::from_string(const std::string& str)
|
|||
int idx = 0;
|
||||
for(tokenizer::iterator t = tokens.begin(); t != tokens.end(); ++t, ++idx)
|
||||
{
|
||||
samples.push_back(boost::lexical_cast<int>(*t));
|
||||
samples.push_back(str2int(*t));
|
||||
}
|
||||
|
||||
return new ResponseCurveAxisFilter(samples);
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
#include "sensitivity_axis_filter.hpp"
|
||||
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <math.h>
|
||||
#include <sstream>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
|
@ -37,7 +37,7 @@ SensitivityAxisFilter::from_string(const std::string& str)
|
|||
{
|
||||
switch(j)
|
||||
{
|
||||
case 0: sensitivity = boost::lexical_cast<float>(*i); break;
|
||||
case 0: sensitivity = str2float(*i); break;
|
||||
default: throw std::runtime_error("to many arguments");
|
||||
};
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "button_filter.hpp"
|
||||
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <sstream>
|
||||
|
||||
#include "buttonfilter/autofire_button_filter.hpp"
|
||||
#include "buttonfilter/click_button_filter.hpp"
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
#include "abs_button_event_handler.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "uinput.hpp"
|
||||
|
||||
AbsButtonEventHandler*
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <boost/tokenizer.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "helper.hpp"
|
||||
#include "ui_event_sequence.hpp"
|
||||
#include "raise_exception.hpp"
|
||||
|
||||
|
@ -101,7 +102,7 @@ CycleKeyButtonEventHandler::from_string_ref(const std::string& value)
|
|||
{
|
||||
std::string name = args[0];
|
||||
Direction direction = (args.size() > 1) ? direction_from_string(args[1]) : kBackward;
|
||||
bool press = (args.size() > 2) ? boost::lexical_cast<bool>(args[2]) : true;
|
||||
bool press = (args.size() > 2) ? str2bool(args[2]) : true;
|
||||
|
||||
CycleKeySequencePtr cycle_sequence = CycleKeyButtonEventHandler::lookup(name);
|
||||
if (!cycle_sequence)
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <linux/input.h>
|
||||
|
||||
#include "evdev_helper.hpp"
|
||||
#include "helper.hpp"
|
||||
#include "uinput.hpp"
|
||||
|
||||
KeyButtonEventHandler*
|
||||
|
@ -54,7 +55,7 @@ KeyButtonEventHandler::from_string(const std::string& str)
|
|||
|
||||
case 2:
|
||||
{
|
||||
ev->m_hold_threshold = boost::lexical_cast<int>(*i);
|
||||
ev->m_hold_threshold = str2int(*i);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "evdev_helper.hpp"
|
||||
#include "helper.hpp"
|
||||
#include "log.hpp"
|
||||
#include "raise_exception.hpp"
|
||||
#include "uinput.hpp"
|
||||
|
@ -80,12 +81,12 @@ MacroButtonEventHandler::macro_event_from_string(const std::string& str)
|
|||
MacroEvent event;
|
||||
event.type = MacroEvent::kInitOp;
|
||||
event.init.event = UIEvent::from_string(args[1]);
|
||||
event.init.minimum = boost::lexical_cast<int>(args[2]);
|
||||
event.init.maximum = boost::lexical_cast<int>(args[3]);
|
||||
event.init.minimum = str2int(args[2]);
|
||||
event.init.maximum = str2int(args[3]);
|
||||
event.init.fuzz = 0;
|
||||
event.init.flat = 0;
|
||||
if (args.size() > 4) event.init.fuzz = boost::lexical_cast<int>(args[4]);
|
||||
if (args.size() > 5) event.init.flat = boost::lexical_cast<int>(args[5]);
|
||||
if (args.size() > 4) event.init.fuzz = str2int(args[4]);
|
||||
if (args.size() > 5) event.init.flat = str2int(args[5]);
|
||||
|
||||
return event;
|
||||
}
|
||||
|
@ -101,7 +102,7 @@ MacroButtonEventHandler::macro_event_from_string(const std::string& str)
|
|||
MacroEvent event;
|
||||
event.type = MacroEvent::kSendOp;
|
||||
event.send.event = UIEvent::from_string(args[1]);
|
||||
event.send.value = boost::lexical_cast<int>(args[2]);
|
||||
event.send.value = str2int(args[2]);
|
||||
return event;
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +116,7 @@ MacroButtonEventHandler::macro_event_from_string(const std::string& str)
|
|||
{
|
||||
MacroEvent event;
|
||||
event.type = MacroEvent::kWaitOp;
|
||||
event.wait.msec = boost::lexical_cast<int>(args[1]);
|
||||
event.wait.msec = str2int(args[1]);
|
||||
return event;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <boost/tokenizer.hpp>
|
||||
|
||||
#include "evdev_helper.hpp"
|
||||
#include "helper.hpp"
|
||||
#include "uinput.hpp"
|
||||
|
||||
RelButtonEventHandler*
|
||||
|
@ -41,11 +42,11 @@ RelButtonEventHandler::from_string(const std::string& str)
|
|||
break;
|
||||
|
||||
case 1:
|
||||
ev->m_value = boost::lexical_cast<int>(*i);
|
||||
ev->m_value = str2int(*i);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
ev->m_repeat = boost::lexical_cast<int>(*i);
|
||||
ev->m_repeat = str2int(*i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,9 @@
|
|||
#include "buttonfilter/autofire_button_filter.hpp"
|
||||
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <sstream>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
AutofireButtonFilter*
|
||||
AutofireButtonFilter::from_string(const std::string& str)
|
||||
|
@ -34,8 +36,8 @@ AutofireButtonFilter::from_string(const std::string& str)
|
|||
{
|
||||
switch(idx)
|
||||
{
|
||||
case 0: rate = boost::lexical_cast<int>(*t); break;
|
||||
case 1: delay = boost::lexical_cast<int>(*t); break;
|
||||
case 0: rate = str2int(*t); break;
|
||||
case 1: delay = str2int(*t); break;
|
||||
default: throw std::runtime_error("to many arguments"); break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,12 +18,14 @@
|
|||
|
||||
#include "buttonfilter/const_button_filter.hpp"
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <sstream>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
ConstButtonFilter*
|
||||
ConstButtonFilter::from_string(const std::string& str)
|
||||
{
|
||||
return new ConstButtonFilter(boost::lexical_cast<bool>(str));
|
||||
return new ConstButtonFilter(str2bool(str));
|
||||
}
|
||||
|
||||
ConstButtonFilter::ConstButtonFilter(bool value) :
|
||||
|
|
|
@ -18,12 +18,14 @@
|
|||
|
||||
#include "buttonfilter/delay_button_filter.hpp"
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <sstream>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
DelayButtonFilter*
|
||||
DelayButtonFilter::from_string(const std::string& str)
|
||||
{
|
||||
return new DelayButtonFilter(boost::lexical_cast<int>(str));
|
||||
return new DelayButtonFilter(str2int(str));
|
||||
}
|
||||
|
||||
DelayButtonFilter::DelayButtonFilter(int delay) :
|
||||
|
|
|
@ -597,7 +597,7 @@ CommandLineParser::apply_opt(ArgParser::ParsedOption const& opt, Options& opts)
|
|||
break;
|
||||
|
||||
case OPTION_TIMEOUT:
|
||||
opts.timeout = boost::lexical_cast<int>(opt.argument);
|
||||
opts.timeout = str2int(opt.argument);
|
||||
break;
|
||||
|
||||
case OPTION_NO_UINPUT:
|
||||
|
@ -741,11 +741,11 @@ CommandLineParser::apply_opt(ArgParser::ParsedOption const& opt, Options& opts)
|
|||
break;
|
||||
|
||||
case OPTION_CONTROLLER_SLOT:
|
||||
opts.controller_slot = boost::lexical_cast<int>(opt.argument);
|
||||
opts.controller_slot = str2int(opt.argument);
|
||||
break;
|
||||
|
||||
case OPTION_CONFIG_SLOT:
|
||||
opts.config_slot = boost::lexical_cast<int>(opt.argument);
|
||||
opts.config_slot = str2int(opt.argument);
|
||||
break;
|
||||
|
||||
case OPTION_TOGGLE:
|
||||
|
@ -797,11 +797,11 @@ CommandLineParser::apply_opt(ArgParser::ParsedOption const& opt, Options& opts)
|
|||
break;
|
||||
|
||||
case OPTION_ID:
|
||||
opts.controller_id = boost::lexical_cast<int>(opt.argument);
|
||||
opts.controller_id = str2int(opt.argument);
|
||||
break;
|
||||
|
||||
case OPTION_WID:
|
||||
opts.wireless_id = boost::lexical_cast<int>(opt.argument);
|
||||
opts.wireless_id = str2int(opt.argument);
|
||||
if (opts.wireless_id < 0 || opts.wireless_id > 3)
|
||||
{
|
||||
throw std::runtime_error("wireless id must be within 0 and 3");
|
||||
|
@ -1243,14 +1243,14 @@ void
|
|||
CommandLineParser::set_relative_axis(const std::string& name, const std::string& value)
|
||||
{
|
||||
m_options->get_controller_options().relative_axis_map[string2axis(name)]
|
||||
= AxisFilterPtr(new RelativeAxisFilter(boost::lexical_cast<int>(value)));
|
||||
= AxisFilterPtr(new RelativeAxisFilter(str2int(value)));
|
||||
}
|
||||
|
||||
void
|
||||
CommandLineParser::set_autofire(const std::string& name, const std::string& value)
|
||||
{
|
||||
m_options->get_controller_options().autofire_map[string2btn(name)]
|
||||
= ButtonFilterPtr(new AutofireButtonFilter(boost::lexical_cast<int>(value), 0));
|
||||
= ButtonFilterPtr(new AutofireButtonFilter(str2int(value), 0));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1267,9 +1267,9 @@ CommandLineParser::set_calibration(const std::string& name, const std::string& v
|
|||
else
|
||||
{
|
||||
m_options->get_controller_options().calibration_map[string2axis(name)]
|
||||
= AxisFilterPtr(new CalibrationAxisFilter(boost::lexical_cast<int>(args[0]),
|
||||
boost::lexical_cast<int>(args[1]),
|
||||
boost::lexical_cast<int>(args[2])));
|
||||
= AxisFilterPtr(new CalibrationAxisFilter(str2int(args[0]),
|
||||
str2int(args[1]),
|
||||
str2int(args[2])));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1277,7 +1277,7 @@ void
|
|||
CommandLineParser::set_axis_sensitivity(const std::string& name, const std::string& value)
|
||||
{
|
||||
m_options->get_controller_options().sensitivity_map[string2axis(name)]
|
||||
= AxisFilterPtr(new SensitivityAxisFilter(boost::lexical_cast<float>(value)));
|
||||
= AxisFilterPtr(new SensitivityAxisFilter(str2float(value)));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1307,7 +1307,7 @@ CommandLineParser::set_four_way_restrictor()
|
|||
void
|
||||
CommandLineParser::set_dpad_rotation(const std::string& value)
|
||||
{
|
||||
int degree = boost::lexical_cast<int>(value);
|
||||
int degree = str2int(value);
|
||||
degree /= 45;
|
||||
degree %= 8;
|
||||
if (degree < 0) degree += 8;
|
||||
|
@ -1403,14 +1403,14 @@ void
|
|||
CommandLineParser::set_relative_axis_n(int controller, int config, const std::string& name, const std::string& value)
|
||||
{
|
||||
m_options->controller_slots[controller].get_options(config)
|
||||
.relative_axis_map[string2axis(name)] = AxisFilterPtr(new RelativeAxisFilter(boost::lexical_cast<int>(value)));
|
||||
.relative_axis_map[string2axis(name)] = AxisFilterPtr(new RelativeAxisFilter(str2int(value)));
|
||||
}
|
||||
|
||||
void
|
||||
CommandLineParser::set_autofire_n(int controller, int config, const std::string& name, const std::string& value)
|
||||
{
|
||||
m_options->controller_slots[controller].get_options(config)
|
||||
.autofire_map[string2btn(name)] = ButtonFilterPtr(new AutofireButtonFilter(boost::lexical_cast<int>(value), 0));
|
||||
.autofire_map[string2btn(name)] = ButtonFilterPtr(new AutofireButtonFilter(str2int(value), 0));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1424,7 +1424,7 @@ void
|
|||
CommandLineParser::set_axis_sensitivity_n(int controller, int config, const std::string& name, const std::string& value)
|
||||
{
|
||||
m_options->controller_slots[controller].get_options(config)
|
||||
.sensitivity_map[string2axis(name)] = AxisFilterPtr(new SensitivityAxisFilter(boost::lexical_cast<float>(value)));
|
||||
.sensitivity_map[string2axis(name)] = AxisFilterPtr(new SensitivityAxisFilter(str2float(value)));
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include <linux/input.h>
|
||||
|
||||
#include "helper.hpp"
|
||||
#include "log.hpp"
|
||||
|
||||
EvDevRelEnum evdev_rel_names;
|
||||
|
@ -136,7 +137,7 @@ void str2event(const std::string& name, int& type, int& code)
|
|||
else if (name.compare(0, 2, "JS") == 0)
|
||||
{
|
||||
type = EV_KEY;
|
||||
code = BTN_JOYSTICK + boost::lexical_cast<int>(name.substr(3));
|
||||
code = BTN_JOYSTICK + str2int(name.substr(3));
|
||||
}
|
||||
else if (name.compare(0, 3, "KEY") == 0 ||
|
||||
name.compare(0, 3, "BTN") == 0)
|
||||
|
@ -181,7 +182,7 @@ int str2abs(const std::string& name)
|
|||
{
|
||||
if (name.compare(0, 5, "ABS_#") == 0)
|
||||
{
|
||||
return boost::lexical_cast<int>(name.substr(5));
|
||||
return str2int(name.substr(5));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -197,11 +198,11 @@ int str2key(const std::string& name)
|
|||
}
|
||||
else if (name.compare(0, 2, "JS") == 0)
|
||||
{
|
||||
return BTN_JOYSTICK + boost::lexical_cast<int>(name.substr(3));
|
||||
return BTN_JOYSTICK + str2int(name.substr(3));
|
||||
}
|
||||
else if (name.compare(0, 5, "KEY_#") == 0)
|
||||
{
|
||||
return boost::lexical_cast<int>(name.substr(5));
|
||||
return str2int(name.substr(5));
|
||||
}
|
||||
else if (name.compare(0, 3, "KEY") == 0 ||
|
||||
name.compare(0, 3, "BTN") == 0)
|
||||
|
@ -218,7 +219,7 @@ int str2rel(const std::string& name)
|
|||
{
|
||||
if (name.compare(0, 5, "REL_#") == 0)
|
||||
{
|
||||
return boost::lexical_cast<int>(name.substr(5));
|
||||
return str2int(name.substr(5));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -47,6 +47,48 @@ int hexstr2int(const std::string& str)
|
|||
raise_exception(std::runtime_error, "couldn't convert '" << str << "' to int");
|
||||
}
|
||||
}
|
||||
|
||||
bool str2bool(std::string const& str)
|
||||
{
|
||||
try
|
||||
{
|
||||
return boost::lexical_cast<bool>(str);
|
||||
}
|
||||
catch(boost::bad_lexical_cast const& err)
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "str2bool(): couldn't convert '" << str << "' to bool";
|
||||
throw std::runtime_error(out.str());
|
||||
}
|
||||
}
|
||||
|
||||
int str2int(std::string const& str)
|
||||
{
|
||||
try
|
||||
{
|
||||
return boost::lexical_cast<int>(str);
|
||||
}
|
||||
catch(boost::bad_lexical_cast const& err)
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "str2int(): couldn't convert '" << str << "' to int";
|
||||
throw std::runtime_error(out.str());
|
||||
}
|
||||
}
|
||||
|
||||
float str2float(std::string const& str)
|
||||
{
|
||||
try
|
||||
{
|
||||
return boost::lexical_cast<float>(str);
|
||||
}
|
||||
catch(boost::bad_lexical_cast const& err)
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "str2float(): couldn't convert '" << str << "' to float";
|
||||
throw std::runtime_error(out.str());
|
||||
}
|
||||
}
|
||||
|
||||
std::string raw2str(uint8_t* data, int len)
|
||||
{
|
||||
|
@ -119,12 +161,12 @@ int to_number(int range, const std::string& str)
|
|||
{
|
||||
if (str[str.size() - 1] == '%')
|
||||
{
|
||||
int percent = boost::lexical_cast<int>(str.substr(0, str.size()-1));
|
||||
int percent = str2int(str.substr(0, str.size()-1));
|
||||
return range * percent / 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
return boost::lexical_cast<int>(str);
|
||||
return str2int(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,10 @@
|
|||
|
||||
int hexstr2int(const std::string& str);
|
||||
|
||||
bool str2bool(std::string const& str);
|
||||
int str2int(std::string const& str);
|
||||
float str2float(std::string const& str);
|
||||
|
||||
std::string raw2str(uint8_t* buffer, int len);
|
||||
std::string to_lower(const std::string &str);
|
||||
bool is_number(const std::string& str);
|
||||
|
|
|
@ -19,7 +19,9 @@
|
|||
#include "modifier/dpad_rotation_modifier.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <sstream>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
DpadRotationModifier*
|
||||
DpadRotationModifier::from_string(const std::vector<std::string>& args)
|
||||
|
@ -37,7 +39,7 @@ DpadRotationModifier::from_string(const std::vector<std::string>& args)
|
|||
DpadRotationModifier*
|
||||
DpadRotationModifier::from_string(const std::string& value)
|
||||
{
|
||||
int degree = boost::lexical_cast<int>(value);
|
||||
int degree = str2int(value);
|
||||
degree /= 45;
|
||||
degree %= 8;
|
||||
if (degree < 0)
|
||||
|
|
|
@ -18,9 +18,11 @@
|
|||
|
||||
#include "rotate_axis_modifier.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <math.h>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
RotateAxisModifier*
|
||||
RotateAxisModifier::from_string(const std::vector<std::string>& args)
|
||||
|
@ -33,8 +35,8 @@ RotateAxisModifier::from_string(const std::vector<std::string>& args)
|
|||
{
|
||||
return new RotateAxisModifier(string2axis(args[0]),
|
||||
string2axis(args[1]),
|
||||
boost::lexical_cast<float>(args[2]) * M_PI / 180.0f,
|
||||
args.size() == 3 ? false : boost::lexical_cast<bool>(args[3]));
|
||||
str2float(args[2]) * M_PI / 180.0f,
|
||||
args.size() == 3 ? false : str2bool(args[3]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,11 +42,11 @@ Options::GenericUSBSpec::apply_pair(const std::string& name,
|
|||
{
|
||||
if (name == "if" || name == "interface")
|
||||
{
|
||||
m_interface = boost::lexical_cast<int>(value);
|
||||
m_interface = str2int(value);
|
||||
}
|
||||
else if (name == "ep" || name == "endpoint")
|
||||
{
|
||||
m_endpoint = boost::lexical_cast<int>(value);
|
||||
m_endpoint = str2int(value);
|
||||
}
|
||||
else if (name == "vid" || name == "vendor_id" || name == "vendorid" || name == "vendor")
|
||||
{
|
||||
|
@ -249,7 +249,7 @@ Options::set_dbus_mode(const std::string& value)
|
|||
{
|
||||
try {
|
||||
// Fallback for backward compatibility
|
||||
if (boost::lexical_cast<bool>(value))
|
||||
if (str2bool(value))
|
||||
{
|
||||
dbus = kDBusAuto;
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ Options::set_dbus_mode(const std::string& value)
|
|||
void
|
||||
Options::set_led(const std::string& value)
|
||||
{
|
||||
get_controller_slot().set_led_status(boost::lexical_cast<int>(value));
|
||||
get_controller_slot().set_led_status(str2int(value));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -335,7 +335,7 @@ Options::set_dpad_only()
|
|||
void
|
||||
Options::set_force_feedback(const std::string& value)
|
||||
{
|
||||
get_controller_slot().set_force_feedback(boost::lexical_cast<bool>(value));
|
||||
get_controller_slot().set_force_feedback(str2bool(value));
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "ui_event.hpp"
|
||||
|
||||
#include "evdev_helper.hpp"
|
||||
#include "helper.hpp"
|
||||
#include "uinput.hpp"
|
||||
|
||||
bool
|
||||
|
@ -174,7 +175,7 @@ int str2deviceid(const std::string& device)
|
|||
}
|
||||
else
|
||||
{
|
||||
return boost::lexical_cast<int>(device);
|
||||
return str2int(device);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,7 +187,7 @@ int str2slotid(const std::string& slot)
|
|||
}
|
||||
else
|
||||
{
|
||||
return boost::lexical_cast<int>(slot);
|
||||
return str2int(slot);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
#ifndef HEADER_XBOXDRV_UI_EVENT_HPP
|
||||
#define HEADER_XBOXDRV_UI_EVENT_HPP
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
enum {
|
||||
DEVICEID_INVALID = static_cast<uint16_t>(-5),
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <stdexcept>
|
||||
#include <boost/format.hpp>
|
||||
|
||||
#include "helper.hpp"
|
||||
#include "options.hpp"
|
||||
#include "raise_exception.hpp"
|
||||
#include "usb_gsource.hpp"
|
||||
|
@ -108,8 +109,8 @@ bool
|
|||
USBSubsystem::find_controller_by_path(const std::string& busid_str, const std::string& devid_str,
|
||||
libusb_device** xbox_device)
|
||||
{
|
||||
int busid = boost::lexical_cast<int>(busid_str);
|
||||
int devid = boost::lexical_cast<int>(devid_str);
|
||||
int busid = str2int(busid_str);
|
||||
int devid = str2int(devid_str);
|
||||
|
||||
libusb_device** list;
|
||||
ssize_t num_devices = libusb_get_device_list(NULL, &list);
|
||||
|
|
|
@ -79,7 +79,7 @@ bool get_usb_path(udev_device* device, int* bus, int* dev)
|
|||
}
|
||||
else
|
||||
{
|
||||
*bus = boost::lexical_cast<int>(busnum_str);
|
||||
*bus = str2int(busnum_str);
|
||||
}
|
||||
|
||||
const char* devnum_str = udev_device_get_property_value(device, "DEVNUM");
|
||||
|
@ -89,7 +89,7 @@ bool get_usb_path(udev_device* device, int* bus, int* dev)
|
|||
}
|
||||
else
|
||||
{
|
||||
*dev = boost::lexical_cast<int>(devnum_str);
|
||||
*dev = str2int(devnum_str);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue