Files
TopTeamBedrijfssimulaties-S…/external/cmdLineArgs/cmdLineArgs.cpp

71 lines
1.5 KiB
C++

#include "cmdLineArgs.hpp"
cmdLineArgs_c::cmdLineArgs_c(int argc, char *argv[])
{
for (int i = 0; i < argc; i++)
{
this->args.push_back(argv[i]);
}
}
std::string cmdLineArgs_c::get_option(
const std::string &option_name)
{
for (auto it = this->args.begin(), end = this->args.end(); it != end; ++it)
{
if (*it == option_name)
if (it + 1 != end)
return *(it + 1);
}
return "";
}
bool cmdLineArgs_c::has_option(
const std::string &option_name)
{
for (auto it = this->args.begin(), end = this->args.end(); it != end; ++it)
{
if (*it == option_name)
return true;
}
return false;
}
void cmdLineArgs_c::setUsage(std::string usage)
{
this->usage = usage;
}
std::string cmdLineArgs_c::getUsage()
{
return this->usage;
}
bool cmdLineArgs_c::available(
const std::string &option_name,
const std::string usage
)
{
for (auto it = this->args.begin(), end = this->args.end(); it != end; ++it)
{
if (*it == option_name)
return true;
}
debugWarnln("Missing option: " << option_name << " " << usage);
return false;
}
bool cmdLineArgs_c::available(
const std::string &option_name
)
{
for (auto it = this->args.begin(), end = this->args.end(); it != end; ++it)
{
if (*it == option_name)
return true;
}
debugWarnln("Missing option: " << option_name << std::endl << "\t" << this->usage);
return false;
}