Raspberry Pi Weighting Control System
This project serves as a simple weighting control system, that was realized as a Bachelor Thesis
utility.cpp
Go to the documentation of this file.
1 #include "utility.h"
2 
3 #include <algorithm>
4 
6 input_parser::input_parser (int &argc, char **argv) {
7  for (int i=1; i < argc; ++i)
8  this->tokens.push_back(std::string(argv[i]));
9 }
10 
12 const std::string& input_parser::get_cmd_option(const std::string &option) const {
13  std::vector<std::string>::const_iterator itr;
14  itr = std::find(this->tokens.begin(), this->tokens.end(), option);
15 
16  if (itr != this->tokens.end() && ++itr != this->tokens.end()){
17  return *itr;
18  }
19 
20  static const std::string empty_string("");
21  return empty_string;
22 }
23 
25 bool input_parser::cmd_option_exists(const std::string &option) const {
26  return std::find(this->tokens.begin(), this->tokens.end(), option)
27  != this->tokens.end();
28 }
29 
30 // DEFINED IN HEADER
31 //
32 // // https://stackoverflow.com/questions/216823/how-to-trim-a-stdstring
33 // // trim from start (in place)
34 // void ltrim(std::string &s) {
35 // s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
36 // return !std::isspace(ch);
37 // }));
38 // }
39 
40 // // trim from end (in place)
41 // void rtrim(std::string &s) {
42 // s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
43 // return !std::isspace(ch);
44 // }).base(), s.end());
45 // }
46 
47 // // trim from both ends (in place)
48 // void trim(std::string &s) {
49 // ltrim(s);
50 // rtrim(s);
51 // }
const std::string & get_cmd_option(const std::string &option) const
Definition: utility.cpp:12
input_parser(int &argc, char **argv)
Definition: utility.cpp:6
bool cmd_option_exists(const std::string &option) const
Definition: utility.cpp:25