mirror of
https://github.com/lucaspalomodevelop/autom.git
synced 2026-03-12 23:27:21 +00:00
42 lines
884 B
C++
42 lines
884 B
C++
#include "./inputparser.h"
|
|
|
|
InputParser::InputParser(int argc, char *argv[])
|
|
{
|
|
for (int i = 1; i < argc; i++)
|
|
{
|
|
std::string arg(argv[i]);
|
|
if (arg.find("-") == 0)
|
|
{
|
|
std::string key = arg.substr(1);
|
|
if (i + 1 < argc)
|
|
{
|
|
std::string value(argv[i + 1]);
|
|
if (value.find("-") != 0)
|
|
{
|
|
args[key] = value;
|
|
i++;
|
|
}
|
|
else
|
|
{
|
|
args[key] = "";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
args[key] = "";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// get the value of a key
|
|
std::string InputParser::getValue(std::string key)
|
|
{
|
|
return args[key];
|
|
}
|
|
|
|
// check if a key exists
|
|
bool InputParser::hasKey(std::string key)
|
|
{
|
|
return args.count(key) > 0;
|
|
} |