diff options
author | Brad King <brad.king@kitware.com> | 2022-06-20 14:17:22 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-07-22 14:32:17 (GMT) |
commit | 5955ec1992fbad26d89b9e3030276350708362c7 (patch) | |
tree | ef84e9cbda8d8e569f82bd50e14e73615fb3b066 | |
parent | 119e1f7fbc6a8244bd93ce54aa265c303395cfbc (diff) | |
download | CMake-5955ec1992fbad26d89b9e3030276350708362c7.zip CMake-5955ec1992fbad26d89b9e3030276350708362c7.tar.gz CMake-5955ec1992fbad26d89b9e3030276350708362c7.tar.bz2 |
cmArgumentParser: Store keyword action map with explicit name
-rw-r--r-- | Source/cmArgumentParser.cxx | 8 | ||||
-rw-r--r-- | 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<iterator, bool> { 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<std::vector<std::string>>& 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<void(Instance&)>; +using KeywordAction = std::function<void(Instance&)>; -// using ActionMap = cm::flat_map<cm::string_view, Action>; -class ActionMap : public std::vector<std::pair<cm::string_view, Action>> +// using KeywordActionMap = cm::flat_map<cm::string_view, KeywordAction>; +class KeywordActionMap + : public std::vector<std::pair<cm::string_view, KeywordAction>> { public: - std::pair<iterator, bool> Emplace(cm::string_view name, Action action); + std::pair<iterator, bool> 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); |