parser_utils.cpp
Go to the documentation of this file.
2 
3 #include <boost/algorithm/string/split.hpp>
4 #include <iostream>
5 
6 const std::vector<std::string> parser_utils::split(const std::string& str, const char delim)
7 {
8  std::vector<std::string> results;
9  boost::split(results, str, [delim](char c) { return c == delim; });
10  return results;
11 }
12 
13 int64_t parser_utils::to_long(const std::string& s)
14 {
15  std::int64_t int_val = 0;
16  try
17  {
18  int_val = std::stoll(s);
19  }
20  catch (std::exception& e)
21  {
22  std::cerr << "conversion of data from string failed: " << s << std::endl;
23  return std::numeric_limits<std::int64_t>::quiet_NaN();
24  }
25  return int_val;
26 }
27 
28 float parser_utils::to_float(const std::string& s)
29 {
30  float float_val = 0;
31  try
32  {
33  float_val = std::stof(s);
34  }
35  catch (std::exception& e)
36  {
37  std::cerr << "conversion of data from string failed " << s << std::endl;
38  return std::numeric_limits<float>::quiet_NaN();
39  }
40  return float_val;
41 }
float to_float(const std::string &s)
const std::vector< std::string > split(const std::string &str, const char delim=';')
Definition: parser_utils.cpp:6
std::int64_t to_long(const std::string &s)


pf_driver
Author(s): Harsh Deshpande
autogenerated on Fri Feb 24 2023 03:59:35