Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
CLI::Validator Class Reference

Some validators that are provided. More...

#include <CLI11.hpp>

Inheritance diagram for CLI::Validator:
Collaboration diagram for CLI::Validator:

Public Member Functions

 Validator ()=default
 
 Validator (std::string validator_desc)
 Construct a Validator with just the description string.
 
 Validator (std::function< std::string(std::string &)> op, std::string validator_desc, std::string validator_name="")
 Construct Validator from basic information.
 
Validatoroperation (std::function< std::string(std::string &)> op)
 Set the Validator operation function.
 
std::string operator() (std::string &str) const
 
std::string operator() (const std::string &str) const
 
Validatordescription (std::string validator_desc)
 Specify the type string.
 
Validator description (std::string validator_desc) const
 Specify the type string.
 
std::string get_description () const
 Generate type description information for the Validator.
 
Validatorname (std::string validator_name)
 Specify the type string.
 
Validator name (std::string validator_name) const
 Specify the type string.
 
const std::string & get_name () const
 Get the name of the Validator.
 
Validatoractive (bool active_val=true)
 Specify whether the Validator is active or not.
 
Validator active (bool active_val=true) const
 Specify whether the Validator is active or not.
 
Validatornon_modifying (bool no_modify=true)
 Specify whether the Validator can be modifying or not.
 
Validatorapplication_index (int app_index)
 Specify the application index of a validator.
 
Validator application_index (int app_index) const
 Specify the application index of a validator.
 
int get_application_index () const
 Get the current value of the application index.
 
bool get_active () const
 Get a boolean if the validator is active.
 
bool get_modifying () const
 Get a boolean if the validator is allowed to modify the input returns true if it can modify the input.
 
Validator operator& (const Validator &other) const
 
Validator operator| (const Validator &other) const
 
Validator operator! () const
 Create a validator that fails when a given validator succeeds.
 

Protected Attributes

std::function< std::string()> desc_function_ {[]() { return std::string{}; }}
 This is the description function, if empty the description_ will be used.
 
std::function< std::string(std::string &)> func_ {[](std::string &) { return std::string{}; }}
 
std::string name_ {}
 The name for search purposes of the Validator.
 
int application_index_ = -1
 A Validator will only apply to an indexed value (-1 is all elements)
 
bool active_ {true}
 Enable for Validator to allow it to be disabled if need be.
 
bool non_modifying_ {false}
 specify that a validator should not modify the input
 

Detailed Description

These are simple std::string(const std::string&) validators that are useful. They return a string if the validation fails. A custom struct is provided, as well, with the same user semantics, but with the ability to provide a new type name.

Definition at line 2089 of file CLI11.hpp.

Constructor & Destructor Documentation

◆ Validator() [1/3]

CLI::Validator::Validator ( )
default

◆ Validator() [2/3]

CLI::Validator::Validator ( std::string validator_desc)
inlineexplicit

Definition at line 2109 of file CLI11.hpp.

2109: desc_function_([validator_desc]() { return validator_desc; }) {}
std::function< std::string()> desc_function_
This is the description function, if empty the description_ will be used.
Definition CLI11.hpp:2092

◆ Validator() [3/3]

CLI::Validator::Validator ( std::function< std::string(std::string &)> op,
std::string validator_desc,
std::string validator_name = "" )
inline

Definition at line 2111 of file CLI11.hpp.

2112 : desc_function_([validator_desc]() { return validator_desc; }), func_(std::move(op)),
2113 name_(std::move(validator_name)) {}
std::function< std::string(std::string &)> func_
Definition CLI11.hpp:2096
std::string name_
The name for search purposes of the Validator.
Definition CLI11.hpp:2098

Member Function Documentation

◆ active() [1/2]

Validator & CLI::Validator::active ( bool active_val = true)
inline

Definition at line 2173 of file CLI11.hpp.

2173 {
2174 active_ = active_val;
2175 return *this;
2176 }
bool active_
Enable for Validator to allow it to be disabled if need be.
Definition CLI11.hpp:2102

◆ active() [2/2]

Validator CLI::Validator::active ( bool active_val = true) const
inline

Definition at line 2178 of file CLI11.hpp.

2178 {
2179 Validator newval(*this);
2180 newval.active_ = active_val;
2181 return newval;
2182 }
Validator()=default

◆ application_index() [1/2]

Validator & CLI::Validator::application_index ( int app_index)
inline

Definition at line 2190 of file CLI11.hpp.

2190 {
2191 application_index_ = app_index;
2192 return *this;
2193 };
int application_index_
A Validator will only apply to an indexed value (-1 is all elements)
Definition CLI11.hpp:2100
Here is the caller graph for this function:

◆ application_index() [2/2]

Validator CLI::Validator::application_index ( int app_index) const
inline

Definition at line 2195 of file CLI11.hpp.

2195 {
2196 Validator newval(*this);
2197 newval.application_index_ = app_index;
2198 return newval;
2199 };

◆ description() [1/2]

Validator & CLI::Validator::description ( std::string validator_desc)
inline

Definition at line 2142 of file CLI11.hpp.

2142 {
2143 desc_function_ = [validator_desc]() { return validator_desc; };
2144 return *this;
2145 }
Here is the caller graph for this function:

◆ description() [2/2]

Validator CLI::Validator::description ( std::string validator_desc) const
inline

Definition at line 2147 of file CLI11.hpp.

2147 {
2148 Validator newval(*this);
2149 newval.desc_function_ = [validator_desc]() { return validator_desc; };
2150 return newval;
2151 }

◆ get_active()

bool CLI::Validator::get_active ( ) const
inline

Definition at line 2203 of file CLI11.hpp.

2203{ return active_; }

◆ get_application_index()

int CLI::Validator::get_application_index ( ) const
inline

Definition at line 2201 of file CLI11.hpp.

2201{ return application_index_; }

◆ get_description()

std::string CLI::Validator::get_description ( ) const
inline

Definition at line 2153 of file CLI11.hpp.

2153 {
2154 if(active_) {
2155 return desc_function_();
2156 }
2157 return std::string{};
2158 }
Here is the caller graph for this function:

◆ get_modifying()

bool CLI::Validator::get_modifying ( ) const
inline

Definition at line 2206 of file CLI11.hpp.

2206{ return !non_modifying_; }
bool non_modifying_
specify that a validator should not modify the input
Definition CLI11.hpp:2104

◆ get_name()

const std::string & CLI::Validator::get_name ( ) const
inline

Definition at line 2171 of file CLI11.hpp.

2171{ return name_; }
Here is the caller graph for this function:

◆ name() [1/2]

Validator & CLI::Validator::name ( std::string validator_name)
inline

Definition at line 2160 of file CLI11.hpp.

2160 {
2161 name_ = std::move(validator_name);
2162 return *this;
2163 }
Here is the caller graph for this function:

◆ name() [2/2]

Validator CLI::Validator::name ( std::string validator_name) const
inline

Definition at line 2165 of file CLI11.hpp.

2165 {
2166 Validator newval(*this);
2167 newval.name_ = std::move(validator_name);
2168 return newval;
2169 }

◆ non_modifying()

Validator & CLI::Validator::non_modifying ( bool no_modify = true)
inline

Definition at line 2185 of file CLI11.hpp.

2185 {
2186 non_modifying_ = no_modify;
2187 return *this;
2188 }
Here is the caller graph for this function:

◆ operation()

Validator & CLI::Validator::operation ( std::function< std::string(std::string &)> op)
inline

Definition at line 2115 of file CLI11.hpp.

2115 {
2116 func_ = std::move(op);
2117 return *this;
2118 }

◆ operator!()

Validator CLI::Validator::operator! ( ) const
inline

Definition at line 2258 of file CLI11.hpp.

2258 {
2259 Validator newval;
2260 const std::function<std::string()> &dfunc1 = desc_function_;
2261 newval.desc_function_ = [dfunc1]() {
2262 auto str = dfunc1();
2263 return (!str.empty()) ? std::string("NOT ") + str : std::string{};
2264 };
2265 // Give references (will make a copy in lambda function)
2266 const std::function<std::string(std::string & res)> &f1 = func_;
2267
2268 newval.func_ = [f1, dfunc1](std::string &test) -> std::string {
2269 std::string s1 = f1(test);
2270 if(s1.empty()) {
2271 return std::string("check ") + dfunc1() + " succeeded improperly";
2272 }
2273 return std::string{};
2274 };
2275 newval.active_ = active_;
2276 newval.application_index_ = application_index_;
2277 return newval;
2278 }
return str
Definition CLI11.hpp:1359
const T1 & f1
@ test
Unit testing utility error code.
Definition error.hpp:96

◆ operator&()

Validator CLI::Validator::operator& ( const Validator & other) const
inline

Combining validators is a new validator. Type comes from left validator if function, otherwise only set if the same.

Definition at line 2210 of file CLI11.hpp.

2210 {
2211 Validator newval;
2212
2213 newval._merge_description(*this, other, " AND ");
2214
2215 // Give references (will make a copy in lambda function)
2216 const std::function<std::string(std::string & filename)> &f1 = func_;
2217 const std::function<std::string(std::string & filename)> &f2 = other.func_;
2218
2219 newval.func_ = [f1, f2](std::string &input) {
2220 std::string s1 = f1(input);
2221 std::string s2 = f2(input);
2222 if(!s1.empty() && !s2.empty())
2223 return std::string("(") + s1 + ") AND (" + s2 + ")";
2224 else
2225 return s1 + s2;
2226 };
2227
2228 newval.active_ = (active_ & other.active_);
2229 newval.application_index_ = application_index_;
2230 return newval;
2231 }
const T1 const T2 & f2

◆ operator()() [1/2]

std::string CLI::Validator::operator() ( const std::string & str) const
inline

This is the required operator for a Validator - provided to help users (CLI11 uses the member func directly)

Definition at line 2136 of file CLI11.hpp.

2136 {
2137 std::string value = str;
2138 return (active_) ? func_(value) : std::string{};
2139 };
Definition name.hpp:106
#define value
Definition pkcs11.h:157

◆ operator()() [2/2]

std::string CLI::Validator::operator() ( std::string & str) const
inline

This is the required operator for a Validator - provided to help users (CLI11 uses the member func directly)

Definition at line 2121 of file CLI11.hpp.

2121 {
2122 std::string retstring;
2123 if(active_) {
2124 if(non_modifying_) {
2125 std::string value = str;
2126 retstring = func_(value);
2127 } else {
2128 retstring = func_(str);
2129 }
2130 }
2131 return retstring;
2132 };

◆ operator|()

Validator CLI::Validator::operator| ( const Validator & other) const
inline

Combining validators is a new validator. Type comes from left validator if function, otherwise only set if the same.

Definition at line 2235 of file CLI11.hpp.

2235 {
2236 Validator newval;
2237
2238 newval._merge_description(*this, other, " OR ");
2239
2240 // Give references (will make a copy in lambda function)
2241 const std::function<std::string(std::string &)> &f1 = func_;
2242 const std::function<std::string(std::string &)> &f2 = other.func_;
2243
2244 newval.func_ = [f1, f2](std::string &input) {
2245 std::string s1 = f1(input);
2246 std::string s2 = f2(input);
2247 if(s1.empty() || s2.empty())
2248 return std::string();
2249
2250 return std::string("(") + s1 + ") OR (" + s2 + ")";
2251 };
2252 newval.active_ = (active_ & other.active_);
2253 newval.application_index_ = application_index_;
2254 return newval;
2255 }

Member Data Documentation

◆ active_

bool CLI::Validator::active_ {true}
protected

Definition at line 2102 of file CLI11.hpp.

2102{true};

◆ application_index_

int CLI::Validator::application_index_ = -1
protected

Definition at line 2100 of file CLI11.hpp.

◆ desc_function_

std::function<std::string()> CLI::Validator::desc_function_ {[]() { return std::string{}; }}
protected

Definition at line 2092 of file CLI11.hpp.

2092{[]() { return std::string{}; }};

◆ func_

std::function<std::string(std::string &)> CLI::Validator::func_ {[](std::string &) { return std::string{}; }}
protected

This is the base function that is to be called. Returns a string error message if validation fails.

Definition at line 2096 of file CLI11.hpp.

2096{[](std::string &) { return std::string{}; }};

◆ name_

std::string CLI::Validator::name_ {}
protected

Definition at line 2098 of file CLI11.hpp.

2098{};

◆ non_modifying_

bool CLI::Validator::non_modifying_ {false}
protected

Definition at line 2104 of file CLI11.hpp.

2104{false};

The documentation for this class was generated from the following file: