aboutsummaryrefslogtreecommitdiff
path: root/args.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'args.hxx')
-rw-r--r--args.hxx108
1 files changed, 84 insertions, 24 deletions
diff --git a/args.hxx b/args.hxx
index 5aee038..22f1170 100644
--- a/args.hxx
+++ b/args.hxx
@@ -27,9 +27,18 @@
#include <tuple>
#include <vector>
#include <unordered_set>
+#include <type_traits>
namespace args
{
+ /** Getter to grab the value reference
+ */
+ template <typename Arg>
+ auto get(Arg &arg) -> decltype(arg.Get())
+ {
+ return arg.Get();
+ }
+
/** (INTERNAL) Count UTF-8 glyphs
*
* This is not reliable, and will fail for combinatory glyphs, but it's
@@ -613,6 +622,13 @@ namespace args
return validator(*this);
}
+ /** Get validation
+ */
+ bool Get() const
+ {
+ return Matched();
+ }
+
/** Get all the child descriptions for help generation
*/
std::vector<std::tuple<std::string, std::string, unsigned int>> GetChildDescriptions(const std::string &shortPrefix, const std::string &longPrefix, const std::string &shortSeparator, const std::string &longSeparator, unsigned int indent = 0) const
@@ -1199,6 +1215,13 @@ namespace args
}
virtual ~Flag() {}
+
+ /** Get whether this was matched
+ */
+ bool Get() const
+ {
+ return Matched();
+ }
};
/** Help flag class
@@ -1229,17 +1252,25 @@ namespace args
}
return nullptr;
}
+
+ /** Get whether this was matched
+ */
+ bool Get() const noexcept
+ {
+ return Matched();
+ }
};
/** A flag class that simply counts the number of times it's matched
*/
class Counter : public Flag
{
- public:
- /** The public count variable. Can be changed at will, but probably shouldn't be.
- */
+ friend int get(Counter &);
+
+ private:
int count;
+ public:
Counter(Group &group, const std::string &name, const std::string &help, Matcher &&matcher, const int startcount = 0): Flag(group, name, help, std::move(matcher)), count(startcount) {}
virtual ~Counter() {}
@@ -1263,6 +1294,13 @@ namespace args
}
return me;
}
+
+ /** Get the count
+ */
+ int &Get() noexcept
+ {
+ return count;
+ }
};
/** A default Reader function for argument classes
@@ -1303,13 +1341,13 @@ namespace args
template <typename T, void (*Reader)(const std::string &, const std::string &, T&) = ArgReader<T>>
class ArgFlag : public ArgFlagBase
{
- public:
- /** The publicly accessible value member
- *
- * You can change this, but you probably shouldn't.
- */
+ friend T &get(ArgFlag &);
+
+ private:
T value;
+ public:
+
ArgFlag(Group &group, const std::string &name, const std::string &help, Matcher &&matcher, const T &defaultValue = T()): ArgFlagBase(name, help, std::move(matcher)), value(defaultValue)
{
group.Add(*this);
@@ -1321,6 +1359,13 @@ namespace args
{
Reader(name, value, this->value);
}
+
+ /** Get the value
+ */
+ T &Get() noexcept
+ {
+ return value;
+ }
};
/** An argument-accepting flag class that pushes the found values into a list
@@ -1335,13 +1380,12 @@ namespace args
void (*Reader)(const std::string &, const std::string &, T&) = ArgReader<T>>
class ArgFlagList : public ArgFlagBase
{
- public:
- /** The publicly accessible value member list
- *
- * You can change this, but you probably shouldn't.
- */
+ friend List &get(ArgFlagList &);
+ private:
List values;
+ public:
+
ArgFlagList(Group &group, const std::string &name, const std::string &help, Matcher &&matcher, const List &defaultValues = List()): ArgFlagBase(name, help, std::move(matcher)), values(defaultValues)
{
group.Add(*this);
@@ -1354,6 +1398,13 @@ namespace args
values.emplace_back();
Reader(name, value, values.back());
}
+
+ /** Get the values
+ */
+ List &Get() noexcept
+ {
+ return values;
+ }
};
/** A positional argument class
@@ -1364,13 +1415,10 @@ namespace args
template <typename T, void (*Reader)(const std::string &, const std::string &, T&) = ArgReader<T>>
class PosArg : public PosBase
{
- public:
- /** The publicly accessible value member
- *
- * You can change this, but you probably shouldn't.
- */
+ friend T &get(PosArg &);
+ private:
T value;
-
+ public:
PosArg(Group &group, const std::string &name, const std::string &help, const T &defaultValue = T()): PosBase(name, help), value(defaultValue)
{
group.Add(*this);
@@ -1384,6 +1432,13 @@ namespace args
ready = false;
matched = true;
}
+
+ /** Get the value
+ */
+ T &Get() noexcept
+ {
+ return value;
+ }
};
/** A positional argument class that pushes the found values into a list
@@ -1398,13 +1453,11 @@ namespace args
void (*Reader)(const std::string &, const std::string &, T&) = ArgReader<T>>
class PosArgList : public PosBase
{
- public:
- /** The publicly accessible value member list
- *
- * You can change this, but you probably shouldn't.
- */
+ friend List &get(PosArgList &);
+ private:
List values;
+ public:
PosArgList(Group &group, const std::string &name, const std::string &help, const List &defaultValues = List()): PosBase(name, help), values(defaultValues)
{
group.Add(*this);
@@ -1423,5 +1476,12 @@ namespace args
{
return name + std::string("...");
}
+
+ /** Get the values
+ */
+ List &Get() noexcept
+ {
+ return values;
+ }
};
}