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

translate named items to other or a value set More...

#include <CLI11.hpp>

Inheritance diagram for CLI::CheckedTransformer:
Collaboration diagram for CLI::CheckedTransformer:

Public Types

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

Public Member Functions

template<typename... Args>
 CheckedTransformer (std::initializer_list< std::pair< std::string, std::string > > values, Args &&... args)
 This allows in-place construction.
 
template<typename T >
 CheckedTransformer (T mapping)
 direct map of std::string to std::string
 
template<typename T , typename F >
 CheckedTransformer (T mapping, F filter_function)
 
template<typename T , typename... Args>
 CheckedTransformer (T &&mapping, 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.
 
- 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 2841 of file CLI11.hpp.

Member Typedef Documentation

◆ filter_fn_t

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

Definition at line 2843 of file CLI11.hpp.

Constructor & Destructor Documentation

◆ CheckedTransformer() [1/4]

template<typename... Args>
CLI::CheckedTransformer::CheckedTransformer ( std::initializer_list< std::pair< std::string, std::string > > values,
Args &&... args )
inline

Definition at line 2847 of file CLI11.hpp.

2848 : CheckedTransformer(TransformPairs<std::string>(values), std::forward<Args>(args)...) {}
CheckedTransformer(std::initializer_list< std::pair< std::string, std::string > > values, Args &&... args)
This allows in-place construction.
Definition CLI11.hpp:2847
std::vector< std::pair< std::string, T > > TransformPairs
definition of the default transformation object
Definition CLI11.hpp:2780

◆ CheckedTransformer() [2/4]

template<typename T >
CLI::CheckedTransformer::CheckedTransformer ( T mapping)
inlineexplicit

Definition at line 2851 of file CLI11.hpp.

2851: CheckedTransformer(std::move(mapping), nullptr) {}

◆ CheckedTransformer() [3/4]

template<typename T , typename F >
CLI::CheckedTransformer::CheckedTransformer ( T mapping,
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 2855 of file CLI11.hpp.

2855 {
2856
2857 static_assert(detail::pair_adaptor<typename detail::element_type<T>::type>::value,
2858 "mapping must produce value pairs");
2859 // Get the type of the contained item - requires a container have ::value_type
2860 // if the type does not have first_type and second_type, these are both value_type
2861 using element_t = typename detail::element_type<T>::type; // Removes (smart) pointers if needed
2862 using item_t = typename detail::pair_adaptor<element_t>::first_type; // Is value_type if not a map
2863 using local_item_t = typename IsMemberType<item_t>::type; // This will convert bad types to good ones
2864 // (const char * to std::string)
2865 using iteration_type_t = typename detail::pair_adaptor<element_t>::value_type; // the type of the object pair //
2866 // the type of the object pair
2867
2868 // Make a local copy of the filter function, using a std::function if not one already
2869 std::function<local_item_t(local_item_t)> filter_fn = filter_function;
2870
2871 auto tfunc = [mapping]() {
2872 std::string out("value in ");
2873 out += detail::generate_map(detail::smart_deref(mapping)) + " OR {";
2874 out += detail::join(
2875 detail::smart_deref(mapping),
2876 [](const iteration_type_t &v) { return detail::to_string(detail::pair_adaptor<element_t>::second(v)); },
2877 ",");
2878 out.push_back('}');
2879 return out;
2880 };
2881
2882 desc_function_ = tfunc;
2883
2884 func_ = [mapping, tfunc, filter_fn](std::string &input) {
2885 local_item_t b;
2886 bool converted = detail::lexical_cast(input, b);
2887 if(converted) {
2888 if(filter_fn) {
2889 b = filter_fn(b);
2890 }
2891 auto res = detail::search(mapping, b, filter_fn);
2892 if(res.first) {
2894 return std::string{};
2895 }
2896 }
2897 for(const auto &v : detail::smart_deref(mapping)) {
2899 if(output_string == input) {
2900 return std::string();
2901 }
2902 }
2903
2904 return "Check " + input + " " + tfunc() + " FAILED";
2905 };
2906 }
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
auto to_string(T &&value) -> decltype(std::forward< T >(value))
Convert an object to a string (directly forward if this can become a string)
Definition CLI11.hpp:1053
std::string generate_map(const T &map, bool key_only=false)
Generate a string representation of a map.
Definition CLI11.hpp:2597
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
std::string join(const T &v, std::string delim=",")
Simple function to join a string.
Definition CLI11.hpp:196
#define value
Definition pkcs11.h:157
typename T::value_type value_type
Definition CLI11.hpp:930
static auto second(Q &&pair_value) -> decltype(std::forward< Q >(pair_value))
Get the second value (really just the underlying value)
Definition CLI11.hpp:939
typename std::remove_const< value_type >::type first_type
Definition CLI11.hpp:931
Here is the call graph for this function:

◆ CheckedTransformer() [4/4]

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

Definition at line 2910 of file CLI11.hpp.

2912 std::forward<T>(mapping),
2913 [filter_fn_1, filter_fn_2](std::string a) { return filter_fn_2(filter_fn_1(a)); },
2914 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: