Raspberry Pi Weighting Control System
This project serves as a simple weighting control system, that was realized as a Bachelor Thesis
Public Member Functions | List of all members
input_parser Class Reference

Simple argument parser. More...

#include <utility.h>

Public Member Functions

 input_parser (int &argc, char **argv)
 
const std::string & get_cmd_option (const std::string &option) const
 
bool cmd_option_exists (const std::string &option) const
 

Detailed Description

Simple argument parser.

https://stackoverflow.com/questions/865668/parsing-command-line-arguments-in-c

Definition at line 16 of file utility.h.

Constructor & Destructor Documentation

◆ input_parser()

input_parser::input_parser ( int &  argc,
char **  argv 
)
Author
iain

Definition at line 6 of file utility.cpp.

6  {
7  for (int i=1; i < argc; ++i)
8  this->tokens.push_back(std::string(argv[i]));
9 }

Member Function Documentation

◆ cmd_option_exists()

bool input_parser::cmd_option_exists ( const std::string &  option) const
Author
iain

Definition at line 25 of file utility.cpp.

25  {
26  return std::find(this->tokens.begin(), this->tokens.end(), option)
27  != this->tokens.end();
28 }

◆ get_cmd_option()

const std::string & input_parser::get_cmd_option ( const std::string &  option) const
Author
iain

Definition at line 12 of file utility.cpp.

12  {
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 }

The documentation for this class was generated from the following files: