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

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

#include <CLI11.hpp>

Inheritance diagram for CLI::Transformer:
Collaboration diagram for CLI::Transformer:

Public Types

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

Public Member Functions

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

Member Typedef Documentation

◆ filter_fn_t

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

Definition at line 2785 of file CLI11.hpp.

Constructor & Destructor Documentation

◆ Transformer() [1/4]

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

Definition at line 2789 of file CLI11.hpp.

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

◆ Transformer() [2/4]

template<typename T >
CLI::Transformer::Transformer ( T && mapping)
inlineexplicit

Definition at line 2793 of file CLI11.hpp.

2793: Transformer(std::forward<T>(mapping), nullptr) {}

◆ Transformer() [3/4]

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

2797 {
2798
2799 static_assert(detail::pair_adaptor<typename detail::element_type<T>::type>::value,
2800 "mapping must produce value pairs");
2801 // Get the type of the contained item - requires a container have ::value_type
2802 // if the type does not have first_type and second_type, these are both value_type
2803 using element_t = typename detail::element_type<T>::type; // Removes (smart) pointers if needed
2804 using item_t = typename detail::pair_adaptor<element_t>::first_type; // Is value_type if not a map
2805 using local_item_t = typename IsMemberType<item_t>::type; // This will convert bad types to good ones
2806 // (const char * to std::string)
2807
2808 // Make a local copy of the filter function, using a std::function if not one already
2809 std::function<local_item_t(local_item_t)> filter_fn = filter_function;
2810
2811 // This is the type name for help, it will take the current version of the set contents
2812 desc_function_ = [mapping]() { return detail::generate_map(detail::smart_deref(mapping)); };
2813
2814 func_ = [mapping, filter_fn](std::string &input) {
2815 local_item_t b;
2816 if(!detail::lexical_cast(input, b)) {
2817 return std::string();
2818 // there is no possible way we can match anything in the mapping if we can't convert so just return
2819 }
2820 if(filter_fn) {
2821 b = filter_fn(b);
2822 }
2823 auto res = detail::search(mapping, b, filter_fn);
2824 if(res.first) {
2826 }
2827 return std::string{};
2828 };
2829 }
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_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
#define value
Definition pkcs11.h:157
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:

◆ Transformer() [4/4]

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

Definition at line 2833 of file CLI11.hpp.

2834 : Transformer(
2835 std::forward<T>(mapping),
2836 [filter_fn_1, filter_fn_2](std::string a) { return filter_fn_2(filter_fn_1(a)); },
2837 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: