summaryrefslogtreecommitdiff
path: root/Source/cmArgumentParser.h
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-06-20 10:12:04 -0400
committerBrad King <brad.king@kitware.com>2022-07-27 07:03:32 -0400
commit078e2aec8f7a0e6d0be91d0fd565d6c22032f666 (patch)
tree3bc04a620c5234b6daea0e4f2366ffa6951b8e1d /Source/cmArgumentParser.h
parent77fcb00a2b76518c0db861a96a8f4857a50b140e (diff)
downloadcmake-078e2aec8f7a0e6d0be91d0fd565d6c22032f666.tar.gz
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.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/Source/cmArgumentParser.h b/Source/cmArgumentParser.h
index 33b8fff310..a417eb44ab 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);