From 18c0cf5bd5968c8ffba22694fd82cd1a9ecd509f Mon Sep 17 00:00:00 2001 From: cobrapitz <12397702+cobrapitz@users.noreply.github.com> Date: Sun, 7 May 2023 16:50:23 +0200 Subject: [PATCH] fixed: name clashing --- include/cb/argparser/argument.h | 18 +++++++++--------- include/cb/argparser/argument_parser.h | 8 ++++---- src/cb/argparser/argument_parser.cpp | 14 +++++++------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/include/cb/argparser/argument.h b/include/cb/argparser/argument.h index 67cb100..5ebbfc4 100644 --- a/include/cb/argparser/argument.h +++ b/include/cb/argparser/argument.h @@ -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); } diff --git a/include/cb/argparser/argument_parser.h b/include/cb/argparser/argument_parser.h index 8730416..f63ad0c 100644 --- a/include/cb/argparser/argument_parser.h +++ b/include/cb/argparser/argument_parser.h @@ -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[]); diff --git a/src/cb/argparser/argument_parser.cpp b/src/cb/argparser/argument_parser.cpp index 6b79518..b51783c 100644 --- a/src/cb/argparser/argument_parser.cpp +++ b/src/cb/argparser/argument_parser.cpp @@ -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); }