input_parser.h
Go to the documentation of this file.
1 #include <sstream>
2 #include <vector>
3 
5 {
6 public:
7  InputParser(int &argc, char **argv)
8  {
9  for (int i = 1; i < argc; ++i) this->tokens.push_back(std::string(argv[i]));
10  }
11 
12  template <typename T>
13  bool getCmdOption(const std::string &option, T &ret) const
14  {
15  std::stringstream ss;
16  auto itr = std::find(this->tokens.begin(), this->tokens.end(), option);
17  if (itr != this->tokens.end() && ++itr != this->tokens.end())
18  {
19  ss << *itr;
20  ss >> ret;
21  return true;
22  }
23  return false;
24  }
25 
26  bool cmdOptionExists(const std::string &option) const
27  {
28  return std::find(this->tokens.begin(), this->tokens.end(), option) != this->tokens.end();
29  }
30 
31 private:
32  std::vector<std::string> tokens;
33 };
InputParser(int &argc, char **argv)
Definition: input_parser.h:7
std::vector< std::string > tokens
Definition: input_parser.h:32
bool cmdOptionExists(const std::string &option) const
Definition: input_parser.h:26
int i
bool getCmdOption(const std::string &option, T &ret) const
Definition: input_parser.h:13


rosflight_utils
Author(s):
autogenerated on Thu Apr 15 2021 05:10:06