-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThrowInputParser.cxx
48 lines (41 loc) · 1.12 KB
/
ThrowInputParser.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* \file ThrowInputParser.cxx
* \brief Implementation of InputParser.
*/
// std
#include <string>
#include <vector>
// Throw
#include "Throw.h"
/**
* \brief Default constructor of InputParser.
* \param argc number of program parameters.
* \param argv array of program parameters.
*/
Throw::InputParser::InputParser (int& argc, char** argv) {
for (size_t i = 1; i < argc; ++i) {
this->tokens.emplace_back(std::string(argv[i]));
}
}
/**
* \brief Get parameter value.
* \param option parameter name.
*/
const std::string& Throw::InputParser::getCmdOption(
const std::string& option) const {
std::vector<std::string>::const_iterator itr;
itr = 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;
}
/**
* \brief Test whether the parameter exists.
* \param option parameter name.
*/
bool Throw::InputParser::cmdOptionExists(const std::string& option) const {
return find(this->tokens.begin(), this->tokens.end(), option)
!= this->tokens.end();
}