diff options
author | Brad King <brad.king@kitware.com> | 2022-06-20 14:12:04 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-07-27 11:03:32 (GMT) |
commit | 078e2aec8f7a0e6d0be91d0fd565d6c22032f666 (patch) | |
tree | 3bc04a620c5234b6daea0e4f2366ffa6951b8e1d /Source/cmArgumentParser.h | |
parent | 77fcb00a2b76518c0db861a96a8f4857a50b140e (diff) | |
download | CMake-078e2aec8f7a0e6d0be91d0fd565d6c22032f666.zip CMake-078e2aec8f7a0e6d0be91d0fd565d6c22032f666.tar.gz CMake-078e2aec8f7a0e6d0be91d0fd565d6c22032f666.tar.bz2 |
cmArgumentParser: Generalize internal state tracking
Use a `std::function` to support general actions on value arguments.
Diffstat (limited to 'Source/cmArgumentParser.h')
-rw-r--r-- | Source/cmArgumentParser.h | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Source/cmArgumentParser.h b/Source/cmArgumentParser.h index 33b8fff..a417eb4 100644 --- a/Source/cmArgumentParser.h +++ b/Source/cmArgumentParser.h @@ -62,6 +62,12 @@ AsParseResultPtr(Result&) return nullptr; } +enum class Continue +{ + No, + Yes, +}; + class Instance; using KeywordAction = std::function<void(Instance&)>; using KeywordNameAction = std::function<void(Instance&, cm::string_view)>; @@ -87,6 +93,7 @@ public: class Base { public: + using Continue = ArgumentParser::Continue; using Instance = ArgumentParser::Instance; using ParseResult = ArgumentParser::ParseResult; @@ -129,6 +136,7 @@ public: { } + void Bind(std::function<Continue(cm::string_view)> f); void Bind(bool& val); void Bind(std::string& val); void Bind(Maybe<std::string>& val); @@ -162,8 +170,7 @@ private: void* Result = nullptr; cm::string_view Keyword; - std::string* CurrentString = nullptr; - std::vector<std::string>* CurrentList = nullptr; + std::function<Continue(cm::string_view)> KeywordValueFunc; bool ExpectValue = false; void Consume(cm::string_view arg); |