From a47095016bf1e96ffc66986cf744cd5baa3839d2 Mon Sep 17 00:00:00 2001 From: Alfredo Luque Date: Fri, 15 Jul 2016 22:59:31 -0400 Subject: validators must be defined earlier --- args.hxx | 102 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/args.hxx b/args.hxx index fa38aab..8deb71b 100644 --- a/args.hxx +++ b/args.hxx @@ -585,6 +585,57 @@ namespace args std::function validator; public: + /** Default validators + */ + struct Validators + { + static bool Xor(const Group &group) + { + return group.MatchedChildren() == 1; + } + + static bool AtLeastOne(const Group &group) + { + return group.MatchedChildren() >= 1; + } + + static bool AtMostOne(const Group &group) + { + return group.MatchedChildren() <= 1; + } + + static bool All(const Group &group) + { + return group.Children().size() == group.MatchedChildren(); + } + + static bool AllOrNone(const Group &group) + { + return (All(group) || None(group)); + } + + static bool AllChildGroups(const Group &group) + { + return std::find_if(std::begin(group.Children()), std::end(group.Children()), [](const Base* child) -> bool { + return dynamic_cast(child) && !child->Matched(); + }) == std::end(group.Children()); + } + + static bool DontCare(const Group &group) + { + return true; + } + + static bool CareTooMuch(const Group &group) + { + return false; + } + + static bool None(const Group &group) + { + return group.MatchedChildren() == 0; + } + }; /// If help is empty, this group will not be printed in help output Group(const std::string &help = std::string(), const std::function &validator = Validators::DontCare) : Base(help), validator(validator) {} /// If help is empty, this group will not be printed in help output @@ -784,57 +835,6 @@ namespace args } #endif - /** Default validators - */ - struct Validators - { - static bool Xor(const Group &group) - { - return group.MatchedChildren() == 1; - } - - static bool AtLeastOne(const Group &group) - { - return group.MatchedChildren() >= 1; - } - - static bool AtMostOne(const Group &group) - { - return group.MatchedChildren() <= 1; - } - - static bool All(const Group &group) - { - return group.Children().size() == group.MatchedChildren(); - } - - static bool AllOrNone(const Group &group) - { - return (All(group) || None(group)); - } - - static bool AllChildGroups(const Group &group) - { - return std::find_if(std::begin(group.Children()), std::end(group.Children()), [](const Base* child) -> bool { - return dynamic_cast(child) && !child->Matched(); - }) == std::end(group.Children()); - } - - static bool DontCare(const Group &group) - { - return true; - } - - static bool CareTooMuch(const Group &group) - { - return false; - } - - static bool None(const Group &group) - { - return group.MatchedChildren() == 0; - } - }; }; /** The main user facing command line argument parser class -- cgit v1.2.1