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

Verify items are in a set. More...

#include <CLI11.hpp>

Inheritance diagram for CLI::IsMember:
Collaboration diagram for CLI::IsMember:

Public Types

using filter_fn_t = std::function<std::string(std::string)>
 

Public Member Functions

template<typename T , typename... Args>
 IsMember (std::initializer_list< T > values, Args &&... args)
 This allows in-place construction using an initializer list.
 
template<typename T >
 IsMember (T &&set)
 This checks to see if an item is in a set (empty function)
 
template<typename T , typename F >
 IsMember (T set, F filter_function)
 
template<typename T , typename... Args>
 IsMember (T &&set, filter_fn_t filter_fn_1, filter_fn_t filter_fn_2, Args &&... other)
 You can pass in as many filter functions as you like, they nest (string only currently)
 
- Public Member Functions inherited from CLI::Validator
 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.
 

Additional Inherited Members

- Protected Attributes inherited from CLI::Validator
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

Definition at line 2712 of file CLI11.hpp.

Member Typedef Documentation

◆ filter_fn_t

using CLI::IsMember::filter_fn_t = std::function<std::string(std::string)>

Definition at line 2714 of file CLI11.hpp.

Constructor & Destructor Documentation

◆ IsMember() [1/4]

template<typename T , typename... Args>
CLI::IsMember::IsMember ( std::initializer_list< T > values,
Args &&... args )
inline

Definition at line 2718 of file CLI11.hpp.

2719 : IsMember(std::vector<T>(values), std::forward<Args>(args)...) {}
IsMember(std::initializer_list< T > values, Args &&... args)
This allows in-place construction using an initializer list.
Definition CLI11.hpp:2718

◆ IsMember() [2/4]

template<typename T >
CLI::IsMember::IsMember ( T && set)
inlineexplicit

Definition at line 2722 of file CLI11.hpp.

2722: IsMember(std::forward<T>(set), nullptr) {}

◆ IsMember() [3/4]

template<typename T , typename F >
CLI::IsMember::IsMember ( T set,
F filter_function )
inlineexplicit

This checks to see if an item is in a set: pointer or copy version. You can pass in a function that will filter both sides of the comparison before computing the comparison.

Definition at line 2726 of file CLI11.hpp.

2726 {
2727
2728 // Get the type of the contained item - requires a container have ::value_type
2729 // if the type does not have first_type and second_type, these are both value_type
2730 using element_t = typename detail::element_type<T>::type; // Removes (smart) pointers if needed
2731 using item_t = typename detail::pair_adaptor<element_t>::first_type; // Is value_type if not a map
2732
2733 using local_item_t = typename IsMemberType<item_t>::type; // This will convert bad types to good ones
2734 // (const char * to std::string)
2735
2736 // Make a local copy of the filter function, using a std::function if not one already
2737 std::function<local_item_t(local_item_t)> filter_fn = filter_function;
2738
2739 // This is the type name for help, it will take the current version of the set contents
2741
2742 // This is the function that validates
2743 // It stores a copy of the set pointer-like, so shared_ptr will stay alive
2744 func_ = [set, filter_fn](std::string &input) {
2745 local_item_t b;
2746 if(!detail::lexical_cast(input, b)) {
2747 throw ValidationError(input); // name is added later
2748 }
2749 if(filter_fn) {
2750 b = filter_fn(b);
2751 }
2752 auto res = detail::search(set, b, filter_fn);
2753 if(res.first) {
2754 // Make sure the version in the input string is identical to the one in the set
2755 if(filter_fn) {
2757 }
2758
2759 // Return empty error string (success)
2760 return std::string{};
2761 }
2762
2763 // If you reach this point, the result was not found
2764 std::string out(" not in ");
2766 return out;
2767 };
2768 }
std::function< std::string()> desc_function_
This is the description function, if empty the description_ will be used.
Definition CLI11.hpp:2092
std::function< std::string(std::string &)> func_
Definition CLI11.hpp:2096
auto smart_deref(T value) -> decltype(*value)
Definition CLI11.hpp:2573
std::string generate_set(const T &set)
Generate a string representation of a set.
Definition CLI11.hpp:2584
std::string value_string(const T &value)
get a string as a convertible value for arithmetic types
Definition CLI11.hpp:1112
auto search(const T &set, const V &val) -> std::pair< bool, decltype(std::begin(detail::smart_deref(set)))>
A search function.
Definition CLI11.hpp:2628
typename std::remove_const< value_type >::type first_type
Definition CLI11.hpp:931
static auto first(Q &&pair_value) -> decltype(std::forward< Q >(pair_value))
Get the first value (really just the underlying value)
Definition CLI11.hpp:935
bool set
Here is the call graph for this function:

◆ IsMember() [4/4]

template<typename T , typename... Args>
CLI::IsMember::IsMember ( T && set,
filter_fn_t filter_fn_1,
filter_fn_t filter_fn_2,
Args &&... other )
inline

Definition at line 2772 of file CLI11.hpp.

2773 : IsMember(
2774 std::forward<T>(set),
2775 [filter_fn_1, filter_fn_2](std::string a) { return filter_fn_2(filter_fn_1(a)); },
2776 other...) {}
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181

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