refactor for better support with ch341 and other unreliable rs232 adapters

This commit is contained in:
David
2019-07-27 22:34:34 +10:00
parent c9ba895410
commit ccb999b8dc
28 changed files with 800 additions and 774 deletions
+33
View File
@@ -0,0 +1,33 @@
// @author iain
#include <algorithm>
#include <string>
#include <vector>
#include "inputparser.h"
// This class simply finds cmd line args and parses them for use in a program.
// It is not posix compliant and wont work with args like: ./program -xf filename
// You must place each arg after its own seperate dash like: ./program -x -f filename
InputParser::InputParser (int &argc, char **argv) {
for (int i=1; i < argc; ++i)
this->tokens.push_back(std::string(argv[i]));
}
const std::string& InputParser::getCmdOption(const std::string &option) const {
std::vector<std::string>::const_iterator itr;
itr = std::find(this->tokens.begin(), this->tokens.end(), option);
if (itr != this->tokens.end() && ++itr != this->tokens.end())
{
return *itr;
}
static const std::string empty_string("");
return empty_string;
}
bool InputParser::cmdOptionExists(const std::string &option) const {
return std::find(this->tokens.begin(), this->tokens.end(), option)
!= this->tokens.end();
}
std::vector <std::string> tokens;