fixed: name clashing

master v0.1.2
cobrapitz 3 years ago
parent 6897f5681e
commit 18c0cf5bd5

@ -8,15 +8,15 @@
namespace cb::argparser {
enum class Mode {
POSITIONAL,
REQUIRED,
OPTIONAL,
POSITIONAL_MODE,
REQUIRED_MODE,
OPTIONAL_MODE,
};
enum class Type {
STRING,
BOOL,
INTEGER,
STRING_TYPE,
BOOL_TYPE,
INTEGER_TYPE,
};
struct ParseArgument {
@ -34,12 +34,12 @@ struct ParseArgument {
class Argument {
private:
std::string content;
Type type{Type::STRING};
Type type{Type::STRING_TYPE};
public:
Argument() = default;
explicit Argument(std::string content, Type type = Type::STRING);
explicit Argument(std::string content, Type type = Type::STRING_TYPE);
[[nodiscard]] const std::string &as_str() const {
return content;
@ -50,7 +50,7 @@ public:
}
int as_int() {
assert(type == Type::INTEGER);
assert(type == Type::INTEGER_TYPE);
return std::stoi(content);
}

@ -35,19 +35,19 @@ private:
public:
void add_argument(const std::string &short_name, const std::string &name, Type type, std::string description,
bool default_value,
Mode mode = Mode::OPTIONAL);
Mode mode = Mode::OPTIONAL_MODE);
void add_argument(const std::string &short_name, const std::string &name, Type type, std::string description,
const char *default_value,
Mode mode = Mode::OPTIONAL);
Mode mode = Mode::OPTIONAL_MODE);
void add_argument(const std::string &short_name, const std::string &name, Type type, std::string description,
int default_value,
Mode mode = Mode::OPTIONAL);
Mode mode = Mode::OPTIONAL_MODE);
void add_argument(const std::string &short_name, const std::string &name, Type type, std::string description,
std::string default_value = "",
Mode mode = Mode::OPTIONAL);
Mode mode = Mode::OPTIONAL_MODE);
ArgumentMap parse(int argc, char *argv[]);

@ -3,7 +3,7 @@
cb::argparser::Argument::Argument(std::string content, cb::argparser::Type type) : content{std::move(content)}, type{type} {
if (type == Type::BOOL && this->content == "false") {
if (type == Type::BOOL_TYPE && this->content == "false") {
this->content = "";
}
}
@ -16,7 +16,7 @@ void cb::argparser::ArgumentParser::add_argument(const std::string &short_name,
throw std::runtime_error(error_message);
}
if (mode == Mode::POSITIONAL) {
if (mode == Mode::POSITIONAL_MODE) {
assert(short_name.empty() && "The name should be left empty if it's a positional argument!");
assert(name.empty() && "The name should be left empty if it's a positional argument!");
} else {
@ -31,7 +31,7 @@ void cb::argparser::ArgumentParser::add_argument(const std::string &short_name,
argument.description = std::move(description);
argument.default_value = std::move(default_value);
if (mode == Mode::POSITIONAL) {
if (mode == Mode::POSITIONAL_MODE) {
positional_arguments.push_back(argument);
} else {
arguments.push_back(argument);
@ -115,7 +115,7 @@ cb::argparser::ArgumentMap cb::argparser::ArgumentParser::parse_arguments(int ar
bool
cb::argparser::ArgumentParser::requiresAdditionalArgument(const cb::argparser::ParseArgument &parseArgument, int argc,
char *const *argv, int i) {
if (parseArgument.type != Type::BOOL) {
if (parseArgument.type != Type::BOOL_TYPE) {
return true;
}
@ -132,7 +132,7 @@ cb::argparser::ArgumentParser::requiresAdditionalArgument(const cb::argparser::P
void cb::argparser::ArgumentParser::verify_required_arguments_present() const {
for (auto &&argument: arguments) {
if (argument.mode != Mode::REQUIRED) {
if (argument.mode != Mode::REQUIRED_MODE) {
continue;
}
if (!argument.is_present) {
@ -162,7 +162,7 @@ void cb::argparser::ArgumentParser::consume_argument(cb::argparser::ArgumentMap
void cb::argparser::ArgumentParser::add_argument(const std::string &short_name, const std::string &name,
cb::argparser::Type type, std::string description, bool default_value,
cb::argparser::Mode mode) {
assert(type == Type::BOOL);
assert(type == Type::BOOL_TYPE);
std::string value = default_value ? "1" : "";
add_argument(short_name, name, type, std::move(description), value, mode);
}
@ -176,6 +176,6 @@ void cb::argparser::ArgumentParser::add_argument(const std::string &short_name,
void cb::argparser::ArgumentParser::add_argument(const std::string &short_name, const std::string &name,
cb::argparser::Type type, std::string description, int default_value,
cb::argparser::Mode mode) {
assert(type == Type::INTEGER);
assert(type == Type::INTEGER_TYPE);
add_argument(short_name, name, type, std::move(description), std::to_string(default_value), mode);
}

Loading…
Cancel
Save