summaryrefslogtreecommitdiffstats
path: root/Source/cmArgumentParser.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmArgumentParser.h')
-rw-r--r--Source/cmArgumentParser.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/Source/cmArgumentParser.h b/Source/cmArgumentParser.h
index fdf54fb..b35d7f3 100644
--- a/Source/cmArgumentParser.h
+++ b/Source/cmArgumentParser.h
@@ -7,6 +7,7 @@
#include <cassert>
#include <cstddef>
#include <functional>
+#include <iterator>
#include <map>
#include <string>
#include <utility>
@@ -176,6 +177,17 @@ public:
void Bind(MaybeEmpty<std::vector<std::string>>& val);
void Bind(NonEmpty<std::vector<std::string>>& val);
void Bind(std::vector<std::vector<std::string>>& val);
+ template <typename U>
+ void Bind(NonEmpty<std::vector<std::pair<std::string, U>>>& val,
+ U const& context)
+ {
+ this->Bind(
+ [&val, &context](cm::string_view arg) -> Continue {
+ val.emplace_back(std::string(arg), context);
+ return Continue::Yes;
+ },
+ ExpectAtLeast{ 1 });
+ }
// cm::optional<> records the presence the keyword to which it binds.
template <typename T>
@@ -187,6 +199,15 @@ public:
this->Bind(*optVal);
}
+ template <typename T, typename U>
+ void Bind(cm::optional<T>& optVal, U const& context)
+ {
+ if (!optVal) {
+ optVal.emplace();
+ }
+ this->Bind(*optVal, context);
+ }
+
template <typename Range>
void Parse(Range const& args, std::size_t pos = 0)
{
@@ -232,6 +253,17 @@ public:
return *this;
}
+ template <typename T, typename U>
+ cmArgumentParser& BindWithContext(cm::static_string_view name,
+ T Result::*member, U Result::*context)
+ {
+ this->Base::Bind(name, [member, context](Instance& instance) {
+ auto* result = static_cast<Result*>(instance.Result);
+ instance.Bind(result->*member, result->*context);
+ });
+ return *this;
+ }
+
cmArgumentParser& Bind(cm::static_string_view name,
Continue (Result::*member)(cm::string_view),
ExpectAtLeast expect = { 1 })