1 #ifndef CORE_UTILS_HPP_ 2 #define CORE_UTILS_HPP_ 6 #include <boost/algorithm/string/predicate.hpp> 7 #include <boost/algorithm/string/trim.hpp> 8 #include <boost/optional.hpp> 9 #include <boost/property_tree/ptree.hpp> 21 inline bool equal(
double x,
double y,
int nEpsilon) {
22 return std::abs(x - y) < std::numeric_limits<double>::epsilon() *
23 std::abs(x + y) * nEpsilon ||
24 std::abs(x - y) < std::numeric_limits<double>::min();
28 double originalVal = value;
31 while (value < -1.0 * M_PI)
33 if (value != originalVal)
34 LOG(DEBUG) <<
"shiftAngle() | Shifting parameter from " << originalVal
35 <<
" to " << value <<
"!";
41 inline std::vector<std::string>
splitString(
const std::string &str,
42 char separator =
' ') {
43 std::vector<std::string> result;
44 std::istringstream ss(str);
47 while (std::getline(ss, token, separator)) {
48 result.push_back(token);
61 boost::optional<external_type>
get_value(
const internal_type &str) {
65 using boost::algorithm::iequals;
66 using boost::algorithm::trim;
68 if (iequals(strcopy,
"true") || iequals(strcopy,
"yes") || strcopy ==
"1")
69 return boost::optional<external_type>(
true);
71 return boost::optional<external_type>(
false);
73 return boost::optional<external_type>(boost::none);
77 boost::optional<internal_type>
put_value(
const external_type &b) {
78 return boost::optional<internal_type>(b ?
"true" :
"false");
83 namespace property_tree {
85 template <
typename Ch,
typename Traits,
typename Alloc>
86 struct translator_between<std::basic_string<Ch, Traits, Alloc>, bool> {
bool equal(double x, double y, int nEpsilon)
Check of numbers x and are equal within nEpsion times the numerical limit.
Support for serialization of std::shared_ptr (and other types) is added in boost 1.56 .
boost::optional< external_type > get_value(const internal_type &str)
double shiftAngle(double value)
std::vector< std::string > splitString(const std::string &str, char separator=' ')
split the string into pieces, which are separated by the separator character (default separator: spac...
boost::optional< internal_type > put_value(const external_type &b)
std::string internal_type