From ce3c43eb9b3d8eb93030ca04608f732314e23719 Mon Sep 17 00:00:00 2001 From: Sean Robinson Date: Thu, 10 Feb 2022 09:41:20 -0700 Subject: [PATCH] Rename identifiers There are no functional changes in this commit. Signed-off-by: Sean Robinson --- .clang-tidy | 7 +- include/argparse/argparse.hpp | 475 +++++++++++++++++----------------- 2 files changed, 241 insertions(+), 241 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 88642ae0..d0b28f4f 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -10,11 +10,12 @@ CheckOptions: - { key: readability-identifier-naming.ConstexprVariableCase, value: lower_case } - { key: readability-identifier-naming.ConstexprVariableIgnoredRegexp, value: "^Is.+" } - { key: readability-identifier-naming.FunctionCase, value: lower_case } - - { key: readability-identifier-naming.LocalVariableIgnoredRegexp, value: "^[a-z][a-z_]+" } - { key: readability-identifier-naming.NamespaceCase, value: lower_case } - - { key: readability-identifier-naming.PrivateMemberPrefix, value: m } + - { key: readability-identifier-naming.ParameterCase, value: lower_case } + - { key: readability-identifier-naming.PrivateMemberCase, value: lower_case } + - { key: readability-identifier-naming.PrivateMemberPrefix, value: m_ } - { key: readability-identifier-naming.StructCase, value: CamelCase } - { key: readability-identifier-naming.StructIgnoredRegexp, value: "parse_number" } - - { key: readability-identifier-naming.VariableCase, value: camelBack } + - { key: readability-identifier-naming.VariableCase, value: lower_case } HeaderFilterRegex: '.*' diff --git a/include/argparse/argparse.hpp b/include/argparse/argparse.hpp index 21a2c11e..4cb17b80 100644 --- a/include/argparse/argparse.hpp +++ b/include/argparse/argparse.hpp @@ -350,11 +350,11 @@ class Argument { template explicit Argument(std::array &&a, std::index_sequence unused) - : mIsOptional((is_optional(a[I]) || ...)), mIsRequired(false), - mIsRepeatable(false), mIsUsed(false) { - ((void)mNames.emplace_back(a[I]), ...); + : m_is_optional((is_optional(a[I]) || ...)), m_is_required(false), + m_is_repeatable(false), m_is_used(false) { + ((void)m_names.emplace_back(a[I]), ...); std::sort( - mNames.begin(), mNames.end(), [](const auto &lhs, const auto &rhs) { + m_names.begin(), m_names.end(), [](const auto &lhs, const auto &rhs) { return lhs.size() == rhs.size() ? lhs < rhs : lhs.size() < rhs.size(); }); } @@ -364,41 +364,41 @@ class Argument { explicit Argument(std::array &&a) : Argument(std::move(a), std::make_index_sequence{}) {} - Argument &help(std::string aHelp) { - mHelp = std::move(aHelp); + Argument &help(std::string help_text) { + m_help = std::move(help_text); return *this; } - template Argument &default_value(T &&aDefaultValue) { - mDefaultValueRepr = details::repr(aDefaultValue); - mDefaultValue = std::forward(aDefaultValue); + template Argument &default_value(T &&value) { + m_default_value_repr = details::repr(value); + m_default_value = std::forward(value); return *this; } Argument &required() { - mIsRequired = true; + m_is_required = true; return *this; } - Argument &implicit_value(std::any aImplicitValue) { - mImplicitValue = std::move(aImplicitValue); - mNumArgs = 0; + Argument &implicit_value(std::any value) { + m_implicit_value = std::move(value); + m_num_args = 0; return *this; } template - auto action(F &&aAction, Args &&...aBound) + auto action(F &&callable, Args &&...bound_args) -> std::enable_if_t, Argument &> { using action_type = std::conditional_t< std::is_void_v>, void_action, valued_action>; if constexpr (sizeof...(Args) == 0) { - mAction.emplace(std::forward(aAction)); + m_action.emplace(std::forward(callable)); } else { - mAction.emplace( - [f = std::forward(aAction), - tup = std::make_tuple(std::forward(aBound)...)]( + m_action.emplace( + [f = std::forward(callable), + tup = std::make_tuple(std::forward(bound_args)...)]( std::string const &opt) mutable { return details::apply_plus_one(f, tup, opt); }); @@ -407,7 +407,7 @@ class Argument { } auto &append() { - mIsRepeatable = true; + m_is_repeatable = true; return *this; } @@ -451,33 +451,33 @@ class Argument { return *this; } - Argument &nargs(int aNumArgs) { - if (aNumArgs < 0) { + Argument &nargs(int num_args) { + if (num_args < 0) { throw std::logic_error("Number of arguments must be non-negative"); } - mNumArgs = aNumArgs; + m_num_args = num_args; return *this; } Argument &remaining() { - mNumArgs = -1; + m_num_args = -1; return *this; } template Iterator consume(Iterator start, Iterator end, - std::string_view usedName = {}) { - if (!mIsRepeatable && mIsUsed) { + std::string_view used_name = {}) { + if (!m_is_repeatable && m_is_used) { throw std::runtime_error("Duplicate argument"); } - mIsUsed = true; - mUsedName = usedName; - if (mNumArgs == 0) { - mValues.emplace_back(mImplicitValue); - std::visit([](const auto &aAction) { aAction({}); }, mAction); + m_is_used = true; + m_used_name = used_name; + if (m_num_args == 0) { + m_values.emplace_back(m_implicit_value); + std::visit([](const auto &f) { f({}); }, m_action); return start; } - if (mNumArgs <= std::distance(start, end)) { + if (m_num_args <= std::distance(start, end)) { if (auto expected = maybe_nargs()) { end = std::next(start, *expected); if (std::any_of(start, end, Argument::is_optional)) { @@ -487,14 +487,14 @@ class Argument { struct ActionApply { void operator()(valued_action &f) { - std::transform(first, last, std::back_inserter(self.mValues), f); + std::transform(first, last, std::back_inserter(self.m_values), f); } void operator()(void_action &f) { std::for_each(first, last, f); - if (!self.mDefaultValue.has_value()) { + if (!self.m_default_value.has_value()) { if (auto expected = self.maybe_nargs()) { - self.mValues.resize(*expected); + self.m_values.resize(*expected); } } } @@ -502,14 +502,14 @@ class Argument { Iterator first, last; Argument &self; }; - std::visit(ActionApply{start, end, *this}, mAction); + std::visit(ActionApply{start, end, *this}, m_action); return end; } - if (mDefaultValue.has_value()) { + if (m_default_value.has_value()) { return start; } throw std::runtime_error("Too few arguments for '" + - std::string(mUsedName) + "'."); + std::string(m_used_name) + "'."); } /* @@ -517,31 +517,31 @@ class Argument { */ void validate() const { if (auto expected = maybe_nargs()) { - if (mIsOptional) { - if (mIsUsed && mValues.size() != *expected && !mIsRepeatable && - !mDefaultValue.has_value()) { + if (m_is_optional) { + if (m_is_used && m_values.size() != *expected && !m_is_repeatable && + !m_default_value.has_value()) { std::stringstream stream; - stream << mUsedName << ": expected " << *expected << " argument(s). " - << mValues.size() << " provided."; + stream << m_used_name << ": expected " << *expected + << " argument(s). " << m_values.size() << " provided."; throw std::runtime_error(stream.str()); } // TODO: check if an implicit value was programmed for this argument - if (!mIsUsed && !mDefaultValue.has_value() && mIsRequired) { + if (!m_is_used && !m_default_value.has_value() && m_is_required) { std::stringstream stream; - stream << mNames[0] << ": required."; + stream << m_names[0] << ": required."; throw std::runtime_error(stream.str()); } - if (mIsUsed && mIsRequired && mValues.empty()) { + if (m_is_used && m_is_required && m_values.empty()) { std::stringstream stream; - stream << mUsedName << ": no value provided."; + stream << m_used_name << ": no value provided."; throw std::runtime_error(stream.str()); } - } else if (mValues.size() != expected && !mDefaultValue.has_value()) { + } else if (m_values.size() != expected && !m_default_value.has_value()) { std::stringstream stream; - if (!mUsedName.empty()) { - stream << mUsedName << ": "; + if (!m_used_name.empty()) { + stream << m_used_name << ": "; } - stream << *expected << " argument(s) expected. " << mValues.size() + stream << *expected << " argument(s) expected. " << m_values.size() << " provided."; throw std::runtime_error(stream.str()); } @@ -549,15 +549,15 @@ class Argument { } auto maybe_nargs() const -> std::optional { - if (mNumArgs < 0) { + if (m_num_args < 0) { return std::nullopt; } - return static_cast(mNumArgs); + return static_cast(m_num_args); } std::size_t get_arguments_length() const { - return std::accumulate(std::begin(mNames), std::end(mNames), std::size_t(0), - [](const auto &sum, const auto &s) { + return std::accumulate(std::begin(m_names), std::end(m_names), + std::size_t(0), [](const auto &sum, const auto &s) { return sum + s.size() + 1; // +1 for space between names }); @@ -565,17 +565,17 @@ class Argument { friend std::ostream &operator<<(std::ostream &stream, const Argument &argument) { - std::stringstream nameStream; - std::copy(std::begin(argument.mNames), std::end(argument.mNames), - std::ostream_iterator(nameStream, " ")); - stream << nameStream.str() << "\t" << argument.mHelp; - if (argument.mDefaultValue.has_value()) { - if (!argument.mHelp.empty()) { + std::stringstream name_stream; + std::copy(std::begin(argument.m_names), std::end(argument.m_names), + std::ostream_iterator(name_stream, " ")); + stream << name_stream.str() << "\t" << argument.m_help; + if (argument.m_default_value.has_value()) { + if (!argument.m_help.empty()) { stream << " "; } - stream << "[default: " << argument.mDefaultValueRepr << "]"; - } else if (argument.mIsRequired) { - if (!argument.mHelp.empty()) { + stream << "[default: " << argument.m_default_value_repr << "]"; + } else if (argument.m_is_required) { + if (!argument.m_help.empty()) { stream << " "; } stream << "[required]"; @@ -584,22 +584,22 @@ class Argument { return stream; } - template bool operator!=(const T &aRhs) const { - return !(*this == aRhs); + template bool operator!=(const T &rhs) const { + return !(*this == rhs); } /* * Compare to an argument value of known type * @throws std::logic_error in case of incompatible types */ - template bool operator==(const T &aRhs) const { + template bool operator==(const T &rhs) const { if constexpr (!details::IsContainer) { - return get() == aRhs; + return get() == rhs; } else { using ValueType = typename T::value_type; - auto tLhs = get(); - return std::equal(std::begin(tLhs), std::end(tLhs), std::begin(aRhs), - std::end(aRhs), [](const auto &lhs, const auto &rhs) { + auto lhs = get(); + return std::equal(std::begin(lhs), std::end(lhs), std::begin(rhs), + std::end(rhs), [](const auto &lhs, const auto &rhs) { return std::any_cast(lhs) == rhs; }); } @@ -754,8 +754,8 @@ class Argument { return false; } - static bool is_optional(std::string_view aName) { - return !is_positional(aName); + static bool is_optional(std::string_view name) { + return !is_positional(name); } /* @@ -765,16 +765,16 @@ class Argument { * '-' decimal-literal * !'-' anything */ - static bool is_positional(std::string_view aName) { - switch (lookahead(aName)) { + static bool is_positional(std::string_view name) { + switch (lookahead(name)) { case eof: return true; case '-': { - aName.remove_prefix(1); - if (aName.empty()) { + name.remove_prefix(1); + if (name.empty()) { return true; } - return is_decimal_literal(aName); + return is_decimal_literal(name); } default: return true; @@ -786,17 +786,17 @@ class Argument { * @throws std::logic_error in case of incompatible types */ template T get() const { - if (!mValues.empty()) { + if (!m_values.empty()) { if constexpr (details::IsContainer) { - return any_cast_container(mValues); + return any_cast_container(m_values); } else { - return std::any_cast(mValues.front()); + return std::any_cast(m_values.front()); } } - if (mDefaultValue.has_value()) { - return std::any_cast(mDefaultValue); + if (m_default_value.has_value()) { + return std::any_cast(m_default_value); } - throw std::logic_error("No value provided for '" + mNames.back() + "'."); + throw std::logic_error("No value provided for '" + m_names.back() + "'."); } /* @@ -805,55 +805,55 @@ class Argument { * @returns The stored value if any, std::nullopt otherwise. */ template auto present() const -> std::optional { - if (mDefaultValue.has_value()) { + if (m_default_value.has_value()) { throw std::logic_error("Argument with default value always presents"); } - if (mValues.empty()) { + if (m_values.empty()) { return std::nullopt; } if constexpr (details::IsContainer) { - return any_cast_container(mValues); + return any_cast_container(m_values); } - return std::any_cast(mValues.front()); + return std::any_cast(m_values.front()); } template - static auto any_cast_container(const std::vector &aOperand) -> T { + static auto any_cast_container(const std::vector &operand) -> T { using ValueType = typename T::value_type; - T tResult; + T result; std::transform( - std::begin(aOperand), std::end(aOperand), std::back_inserter(tResult), + std::begin(operand), std::end(operand), std::back_inserter(result), [](const auto &value) { return std::any_cast(value); }); - return tResult; + return result; } - std::vector mNames; - std::string_view mUsedName; - std::string mHelp; - std::any mDefaultValue; - std::string mDefaultValueRepr; - std::any mImplicitValue; + std::vector m_names; + std::string_view m_used_name; + std::string m_help; + std::any m_default_value; + std::string m_default_value_repr; + std::any m_implicit_value; using valued_action = std::function; using void_action = std::function; - std::variant mAction{ + std::variant m_action{ std::in_place_type, - [](const std::string &aValue) { return aValue; }}; - std::vector mValues; - int mNumArgs = 1; - bool mIsOptional : true; - bool mIsRequired : true; - bool mIsRepeatable : true; - bool mIsUsed : true; // True if the optional argument is used by user + [](const std::string &value) { return value; }}; + std::vector m_values; + int m_num_args = 1; + bool m_is_optional : true; + bool m_is_required : true; + bool m_is_repeatable : true; + bool m_is_used : true; // True if the optional argument is used by user }; class ArgumentParser { public: - explicit ArgumentParser(std::string aProgramName = {}, - std::string aVersion = "1.0", - default_arguments aArgs = default_arguments::all) - : mProgramName(std::move(aProgramName)), mVersion(std::move(aVersion)) { - if ((aArgs & default_arguments::help) == default_arguments::help) { + explicit ArgumentParser(std::string program_name = {}, + std::string version = "1.0", + default_arguments add_args = default_arguments::all) + : m_program_name(std::move(program_name)), m_version(std::move(version)) { + if ((add_args & default_arguments::help) == default_arguments::help) { add_argument("-h", "--help") .action([&](const auto &unused) { std::cout << help().str(); @@ -864,10 +864,10 @@ class ArgumentParser { .implicit_value(true) .nargs(0); } - if ((aArgs & default_arguments::version) == default_arguments::version) { + if ((add_args & default_arguments::version) == default_arguments::version) { add_argument("-v", "--version") .action([&](const auto &unused) { - std::cout << mVersion; + std::cout << m_version; std::exit(0); }) .default_value(false) @@ -881,19 +881,19 @@ class ArgumentParser { ArgumentParser &operator=(ArgumentParser &&) = default; ArgumentParser(const ArgumentParser &other) - : mProgramName(other.mProgramName), - mVersion(other.mVersion), - mDescription(other.mDescription), - mEpilog(other.mEpilog), - mIsParsed(other.mIsParsed), - mPositionalArguments(other.mPositionalArguments), - mOptionalArguments(other.mOptionalArguments) { - for (auto it = std::begin(mPositionalArguments); - it != std::end(mPositionalArguments); ++it) { + : m_program_name(other.m_program_name), + m_version(other.m_version), + m_description(other.m_description), + m_epilog(other.m_epilog), + m_is_parsed(other.m_is_parsed), + m_positional_arguments(other.m_positional_arguments), + m_optional_arguments(other.m_optional_arguments) { + for (auto it = std::begin(m_positional_arguments); + it != std::end(m_positional_arguments); ++it) { index_argument(it); } - for (auto it = std::begin(mOptionalArguments); - it != std::end(mOptionalArguments); ++it) { + for (auto it = std::begin(m_optional_arguments); + it != std::end(m_optional_arguments); ++it) { index_argument(it); } } @@ -908,46 +908,46 @@ class ArgumentParser { // Parameter packing // Call add_argument with variadic number of string arguments - template Argument &add_argument(Targs... Fargs) { + template Argument &add_argument(Targs... f_args) { using array_of_sv = std::array; - auto tArgument = mOptionalArguments.emplace(cend(mOptionalArguments), - array_of_sv{Fargs...}); + auto argument = m_optional_arguments.emplace(cend(m_optional_arguments), + array_of_sv{f_args...}); - if (!tArgument->mIsOptional) { - mPositionalArguments.splice(cend(mPositionalArguments), - mOptionalArguments, tArgument); + if (!argument->m_is_optional) { + m_positional_arguments.splice(cend(m_positional_arguments), + m_optional_arguments, argument); } - index_argument(tArgument); - return *tArgument; + index_argument(argument); + return *argument; } // Parameter packed add_parents method // Accepts a variadic number of ArgumentParser objects template - ArgumentParser &add_parents(const Targs &...Fargs) { - for (const ArgumentParser &tParentParser : {std::ref(Fargs)...}) { - for (const auto &tArgument : tParentParser.mPositionalArguments) { - auto it = - mPositionalArguments.insert(cend(mPositionalArguments), tArgument); + ArgumentParser &add_parents(const Targs &...f_args) { + for (const ArgumentParser &parent_parser : {std::ref(f_args)...}) { + for (const auto &argument : parent_parser.m_positional_arguments) { + auto it = m_positional_arguments.insert(cend(m_positional_arguments), + argument); index_argument(it); } - for (const auto &tArgument : tParentParser.mOptionalArguments) { + for (const auto &argument : parent_parser.m_optional_arguments) { auto it = - mOptionalArguments.insert(cend(mOptionalArguments), tArgument); + m_optional_arguments.insert(cend(m_optional_arguments), argument); index_argument(it); } } return *this; } - ArgumentParser &add_description(std::string aDescription) { - mDescription = std::move(aDescription); + ArgumentParser &add_description(std::string description) { + m_description = std::move(description); return *this; } - ArgumentParser &add_epilog(std::string aEpilog) { - mEpilog = std::move(aEpilog); + ArgumentParser &add_epilog(std::string epilog) { + m_epilog = std::move(epilog); return *this; } @@ -956,8 +956,8 @@ class ArgumentParser { * This variant is used mainly for testing * @throws std::runtime_error in case of any invalid argument */ - void parse_args(const std::vector &aArguments) { - parse_args_internal(aArguments); + void parse_args(const std::vector &arguments) { + parse_args_internal(arguments); parse_args_validate(); } @@ -978,12 +978,11 @@ class ArgumentParser { * @throws std::logic_error if the option has no value * @throws std::bad_any_cast if the option is not of type T */ - template - T get(std::string_view aArgumentName) const { - if (!mIsParsed) { + template T get(std::string_view arg_name) const { + if (!m_is_parsed) { throw std::logic_error("Nothing parsed, no arguments are available."); } - return (*this)[aArgumentName].get(); + return (*this)[arg_name].get(); } /* Getter for options without default values. @@ -992,81 +991,81 @@ class ArgumentParser { * @throws std::bad_any_cast if the option is not of type T */ template - auto present(std::string_view aArgumentName) const -> std::optional { - return (*this)[aArgumentName].present(); + auto present(std::string_view arg_name) const -> std::optional { + return (*this)[arg_name].present(); } /* Getter that returns true for user-supplied options. Returns false if not * user-supplied, even with a default value. */ - auto is_used(std::string_view aArgumentName) const { - return (*this)[aArgumentName].mIsUsed; + auto is_used(std::string_view arg_name) const { + return (*this)[arg_name].m_is_used; } /* Indexing operator. Return a reference to an Argument object * Used in conjuction with Argument.operator== e.g., parser["foo"] == true * @throws std::logic_error in case of an invalid argument name */ - Argument &operator[](std::string_view aArgumentName) const { - auto tIterator = mArgumentMap.find(aArgumentName); - if (tIterator != mArgumentMap.end()) { - return *(tIterator->second); - } - if (aArgumentName.front() != '-') { - std::string nameStr(aArgumentName); - // "-" + aArgumentName - nameStr = "-" + nameStr; - tIterator = mArgumentMap.find(nameStr); - if (tIterator != mArgumentMap.end()) { - return *(tIterator->second); + Argument &operator[](std::string_view arg_name) const { + auto it = m_argument_map.find(arg_name); + if (it != m_argument_map.end()) { + return *(it->second); + } + if (arg_name.front() != '-') { + std::string name(arg_name); + // "-" + arg_name + name = "-" + name; + it = m_argument_map.find(name); + if (it != m_argument_map.end()) { + return *(it->second); } - // "--" + aArgumentName - nameStr = "-" + nameStr; - tIterator = mArgumentMap.find(nameStr); - if (tIterator != mArgumentMap.end()) { - return *(tIterator->second); + // "--" + arg_name + name = "-" + name; + it = m_argument_map.find(name); + if (it != m_argument_map.end()) { + return *(it->second); } } - throw std::logic_error("No such argument: " + std::string(aArgumentName)); + throw std::logic_error("No such argument: " + std::string(arg_name)); } // Print help message friend auto operator<<(std::ostream &stream, const ArgumentParser &parser) -> std::ostream & { stream.setf(std::ios_base::left); - stream << "Usage: " << parser.mProgramName << " [options] "; - std::size_t tLongestArgumentLength = parser.get_length_of_longest_argument(); + stream << "Usage: " << parser.m_program_name << " [options] "; + std::size_t longest_arg_length = parser.get_length_of_longest_argument(); - for (const auto &argument : parser.mPositionalArguments) { - stream << argument.mNames.front() << " "; + for (const auto &argument : parser.m_positional_arguments) { + stream << argument.m_names.front() << " "; } stream << "\n\n"; - if (!parser.mDescription.empty()) { - stream << parser.mDescription << "\n\n"; + if (!parser.m_description.empty()) { + stream << parser.m_description << "\n\n"; } - if (!parser.mPositionalArguments.empty()) { + if (!parser.m_positional_arguments.empty()) { stream << "Positional arguments:\n"; } - for (const auto &mPositionalArgument : parser.mPositionalArguments) { - stream.width(tLongestArgumentLength); - stream << mPositionalArgument; + for (const auto &argument : parser.m_positional_arguments) { + stream.width(longest_arg_length); + stream << argument; } - if (!parser.mOptionalArguments.empty()) { - stream << (parser.mPositionalArguments.empty() ? "" : "\n") + if (!parser.m_optional_arguments.empty()) { + stream << (parser.m_positional_arguments.empty() ? "" : "\n") << "Optional arguments:\n"; } - for (const auto &mOptionalArgument : parser.mOptionalArguments) { - stream.width(tLongestArgumentLength); - stream << mOptionalArgument; + for (const auto &argument : parser.m_optional_arguments) { + stream.width(longest_arg_length); + stream << argument; } - if (!parser.mEpilog.empty()) { - stream << parser.mEpilog << "\n\n"; + if (!parser.m_epilog.empty()) { + stream << parser.m_epilog << "\n\n"; } return stream; @@ -1092,47 +1091,47 @@ class ArgumentParser { /* * @throws std::runtime_error in case of any invalid argument */ - void parse_args_internal(const std::vector &aArguments) { - if (mProgramName.empty() && !aArguments.empty()) { - mProgramName = aArguments.front(); - } - auto end = std::end(aArguments); - auto positionalArgumentIt = std::begin(mPositionalArguments); - for (auto it = std::next(std::begin(aArguments)); it != end;) { - const auto &tCurrentArgument = *it; - if (Argument::is_positional(tCurrentArgument)) { - if (positionalArgumentIt == std::end(mPositionalArguments)) { + void parse_args_internal(const std::vector &arguments) { + if (m_program_name.empty() && !arguments.empty()) { + m_program_name = arguments.front(); + } + auto end = std::end(arguments); + auto positional_argument_it = std::begin(m_positional_arguments); + for (auto it = std::next(std::begin(arguments)); it != end;) { + const auto ¤t_argument = *it; + if (Argument::is_positional(current_argument)) { + if (positional_argument_it == std::end(m_positional_arguments)) { throw std::runtime_error( "Maximum number of positional arguments exceeded"); } - auto tArgument = positionalArgumentIt++; - it = tArgument->consume(it, end); + auto argument = positional_argument_it++; + it = argument->consume(it, end); continue; } - auto tIterator = mArgumentMap.find(tCurrentArgument); - if (tIterator != mArgumentMap.end()) { - auto tArgument = tIterator->second; - it = tArgument->consume(std::next(it), end, tIterator->first); - } else if (const auto &tCompoundArgument = tCurrentArgument; - tCompoundArgument.size() > 1 && tCompoundArgument[0] == '-' && - tCompoundArgument[1] != '-') { + auto arg_map_it = m_argument_map.find(current_argument); + if (arg_map_it != m_argument_map.end()) { + auto argument = arg_map_it->second; + it = argument->consume(std::next(it), end, arg_map_it->first); + } else if (const auto &compound_arg = current_argument; + compound_arg.size() > 1 && compound_arg[0] == '-' && + compound_arg[1] != '-') { ++it; - for (std::size_t j = 1; j < tCompoundArgument.size(); j++) { - auto tHypotheticalArgument = std::string{'-', tCompoundArgument[j]}; - auto tIterator2 = mArgumentMap.find(tHypotheticalArgument); - if (tIterator2 != mArgumentMap.end()) { - auto tArgument = tIterator2->second; - it = tArgument->consume(it, end, tIterator2->first); + for (std::size_t j = 1; j < compound_arg.size(); j++) { + auto hypothetical_arg = std::string{'-', compound_arg[j]}; + auto arg_map_it2 = m_argument_map.find(hypothetical_arg); + if (arg_map_it2 != m_argument_map.end()) { + auto argument = arg_map_it2->second; + it = argument->consume(it, end, arg_map_it2->first); } else { - throw std::runtime_error("Unknown argument: " + tCurrentArgument); + throw std::runtime_error("Unknown argument: " + current_argument); } } } else { - throw std::runtime_error("Unknown argument: " + tCurrentArgument); + throw std::runtime_error("Unknown argument: " + current_argument); } } - mIsParsed = true; + m_is_parsed = true; } /* @@ -1140,44 +1139,44 @@ class ArgumentParser { */ void parse_args_validate() { // Check if all arguments are parsed - std::for_each(std::begin(mArgumentMap), std::end(mArgumentMap), - [](const auto &argPair) { - const auto &tArgument = argPair.second; - tArgument->validate(); + std::for_each(std::begin(m_argument_map), std::end(m_argument_map), + [](const auto &pair) { + const auto &argument = pair.second; + argument->validate(); }); } // Used by print_help. std::size_t get_length_of_longest_argument() const { - if (mArgumentMap.empty()) { + if (m_argument_map.empty()) { return 0; } - std::vector argumentLengths(mArgumentMap.size()); - std::transform(std::begin(mArgumentMap), std::end(mArgumentMap), - std::begin(argumentLengths), [](const auto &argPair) { - const auto &tArgument = argPair.second; - return tArgument->get_arguments_length(); + std::vector argument_lengths(m_argument_map.size()); + std::transform(std::begin(m_argument_map), std::end(m_argument_map), + std::begin(argument_lengths), [](const auto &pair) { + const auto &argument = pair.second; + return argument->get_arguments_length(); }); - return *std::max_element(std::begin(argumentLengths), - std::end(argumentLengths)); + return *std::max_element(std::begin(argument_lengths), + std::end(argument_lengths)); } using list_iterator = std::list::iterator; - void index_argument(list_iterator argIt) { - for (const auto &mName : std::as_const(argIt->mNames)) { - mArgumentMap.insert_or_assign(mName, argIt); + void index_argument(list_iterator it) { + for (const auto &name : std::as_const(it->m_names)) { + m_argument_map.insert_or_assign(name, it); } } - std::string mProgramName; - std::string mVersion; - std::string mDescription; - std::string mEpilog; - bool mIsParsed = false; - std::list mPositionalArguments; - std::list mOptionalArguments; - std::map> mArgumentMap; + std::string m_program_name; + std::string m_version; + std::string m_description; + std::string m_epilog; + bool m_is_parsed = false; + std::list m_positional_arguments; + std::list m_optional_arguments; + std::map> m_argument_map; }; } // namespace argparse