From 5955ec1992fbad26d89b9e3030276350708362c7 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 20 Jun 2022 10:17:22 -0400 Subject: cmArgumentParser: Store keyword action map with explicit name --- Source/cmArgumentParser.cxx | 8 ++++---- Source/cmArgumentParser.h | 22 +++++++++++++++------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Source/cmArgumentParser.cxx b/Source/cmArgumentParser.cxx index df008a2..c997933 100644 --- a/Source/cmArgumentParser.cxx +++ b/Source/cmArgumentParser.cxx @@ -8,7 +8,7 @@ namespace ArgumentParser { -auto ActionMap::Emplace(cm::string_view name, Action action) +auto KeywordActionMap::Emplace(cm::string_view name, KeywordAction action) -> std::pair { auto const it = @@ -21,7 +21,7 @@ auto ActionMap::Emplace(cm::string_view name, Action action) : std::make_pair(this->emplace(it, name, std::move(action)), true); } -auto ActionMap::Find(cm::string_view name) const -> const_iterator +auto KeywordActionMap::Find(cm::string_view name) const -> const_iterator { auto const it = std::lower_bound(this->begin(), this->end(), name, @@ -76,8 +76,8 @@ void Instance::Bind(std::vector>& val) void Instance::Consume(cm::string_view arg) { - auto const it = this->Bindings.Find(arg); - if (it != this->Bindings.end()) { + auto const it = this->Bindings.Keywords.Find(arg); + if (it != this->Bindings.Keywords.end()) { this->FinishKeyword(); this->Keyword = it->first; if (this->ParsedKeywords != nullptr) { diff --git a/Source/cmArgumentParser.h b/Source/cmArgumentParser.h index 75f7a82..4079946 100644 --- a/Source/cmArgumentParser.h +++ b/Source/cmArgumentParser.h @@ -22,16 +22,24 @@ class cmArgumentParser; // IWYU pragma: keep namespace ArgumentParser { class Instance; -using Action = std::function; +using KeywordAction = std::function; -// using ActionMap = cm::flat_map; -class ActionMap : public std::vector> +// using KeywordActionMap = cm::flat_map; +class KeywordActionMap + : public std::vector> { public: - std::pair Emplace(cm::string_view name, Action action); + std::pair Emplace(cm::string_view name, + KeywordAction action); const_iterator Find(cm::string_view name) const; }; +class ActionMap +{ +public: + KeywordActionMap Keywords; +}; + class Base { public: @@ -39,12 +47,12 @@ public: ArgumentParser::ActionMap Bindings; - bool MaybeBind(cm::string_view name, Action action) + bool MaybeBind(cm::string_view name, KeywordAction action) { - return this->Bindings.Emplace(name, std::move(action)).second; + return this->Bindings.Keywords.Emplace(name, std::move(action)).second; } - void Bind(cm::string_view name, Action action) + void Bind(cm::string_view name, KeywordAction action) { bool const inserted = this->MaybeBind(name, std::move(action)); assert(inserted); -- cgit v0.12