Loading...
Searching...
No Matches
Validator Class Reference

Some validators that are provided. More...

#include <CLI11.h>

+ Inheritance diagram for Validator:

Public Member Functions

 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
 This is the required operator for a Validator - provided to help users (CLI11 uses the member func directly)
 
std::string operator() (const std::string &str) const
 This is the required operator for a Validator - provided to help users (CLI11 uses the member func directly)
 
Validatordescription (std::string validator_desc)
 Specify the type string.
 
CLI11_NODISCARD Validator description (std::string validator_desc) const
 Specify the type string.
 
CLI11_NODISCARD std::string get_description () const
 Generate type description information for the Validator.
 
Validatorname (std::string validator_name)
 Specify the type string.
 
CLI11_NODISCARD Validator name (std::string validator_name) const
 Specify the type string.
 
CLI11_NODISCARD 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.
 
CLI11_NODISCARD 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.
 
CLI11_NODISCARD Validator application_index (int app_index) const
 Specify the application index of a validator.
 
CLI11_NODISCARD int get_application_index () const
 Get the current value of the application index.
 
CLI11_NODISCARD bool get_active () const
 Get a boolean if the validator is active.
 
CLI11_NODISCARD 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
 Combining validators is a new validator.
 
Validator operator| (const Validator &other) const
 Combining validators is a new validator.
 
Validator operator! () const
 Create a validator that fails when a given validator succeeds.
 

Protected Member Functions

 Validator (std::string validator_desc, std::function< std::string(std::string &)> func)
 

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{}; }}
 This is the base function that is to be called.
 
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

Some validators that are provided.

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 2830 of file CLI11.h.

Constructor & Destructor Documentation

◆ Validator() [1/3]

Validator ( std::string  validator_desc,
std::function< std::string(std::string &)>  func 
)
inlineprotected

Definition at line 2847 of file CLI11.h.

◆ Validator() [2/3]

Validator ( std::string  validator_desc)
inlineexplicit

Construct a Validator with just the description string.

Definition at line 2853 of file CLI11.h.

◆ Validator() [3/3]

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

Construct Validator from basic information.

Definition at line 2855 of file CLI11.h.

Member Function Documentation

◆ active() [1/2]

Validator & active ( bool  active_val = true)
inline

Specify whether the Validator is active or not.

Definition at line 2903 of file CLI11.h.

◆ active() [2/2]

CLI11_NODISCARD Validator active ( bool  active_val = true) const
inline

Specify whether the Validator is active or not.

Definition at line 2908 of file CLI11.h.

◆ application_index() [1/2]

Validator & application_index ( int  app_index)
inline

Specify the application index of a validator.

Definition at line 2920 of file CLI11.h.

◆ application_index() [2/2]

CLI11_NODISCARD Validator application_index ( int  app_index) const
inline

Specify the application index of a validator.

Definition at line 2925 of file CLI11.h.

◆ description() [1/2]

Validator & description ( std::string  validator_desc)
inline

Specify the type string.

Definition at line 2875 of file CLI11.h.

◆ description() [2/2]

CLI11_NODISCARD CLI11_INLINE Validator description ( std::string  validator_desc) const

Specify the type string.

Definition at line 3668 of file CLI11.h.

◆ get_active()

CLI11_NODISCARD bool get_active ( ) const
inline

Get a boolean if the validator is active.

Definition at line 2933 of file CLI11.h.

◆ get_application_index()

CLI11_NODISCARD int get_application_index ( ) const
inline

Get the current value of the application index.

Definition at line 2931 of file CLI11.h.

◆ get_description()

CLI11_NODISCARD std::string get_description ( ) const
inline

Generate type description information for the Validator.

Definition at line 2883 of file CLI11.h.

◆ get_modifying()

CLI11_NODISCARD bool get_modifying ( ) const
inline

Get a boolean if the validator is allowed to modify the input returns true if it can modify the input.

Definition at line 2936 of file CLI11.h.

◆ get_name()

CLI11_NODISCARD const std::string & get_name ( ) const
inline

Get the name of the Validator.

Definition at line 2901 of file CLI11.h.

◆ name() [1/2]

Validator & name ( std::string  validator_name)
inline

Specify the type string.

Definition at line 2890 of file CLI11.h.

◆ name() [2/2]

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

Specify the type string.

Definition at line 2895 of file CLI11.h.

◆ non_modifying()

Validator & non_modifying ( bool  no_modify = true)
inline

Specify whether the Validator can be modifying or not.

Definition at line 2915 of file CLI11.h.

◆ operation()

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

Set the Validator operation function.

Definition at line 2859 of file CLI11.h.

◆ operator!()

CLI11_INLINE Validator operator! ( ) const

Create a validator that fails when a given validator succeeds.

Definition at line 3718 of file CLI11.h.

◆ operator&()

CLI11_INLINE Validator operator& ( const Validator other) const

Combining validators is a new validator.

Type comes from left validator if function, otherwise only set if the same.

Definition at line 3674 of file CLI11.h.

◆ operator()() [1/2]

std::string 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 2869 of file CLI11.h.

◆ operator()() [2/2]

CLI11_INLINE std::string operator() ( std::string &  str) const

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

Definition at line 3655 of file CLI11.h.

◆ operator|()

CLI11_INLINE Validator operator| ( const Validator other) const

Combining validators is a new validator.

Type comes from left validator if function, otherwise only set if the same.

Definition at line 3696 of file CLI11.h.

Member Data Documentation

◆ active_

bool active_ {true}
protected

Enable for Validator to allow it to be disabled if need be.

Definition at line 2843 of file CLI11.h.

◆ application_index_

int application_index_ = -1
protected

A Validator will only apply to an indexed value (-1 is all elements)

Definition at line 2841 of file CLI11.h.

◆ desc_function_

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

This is the description function, if empty the description_ will be used.

Definition at line 2833 of file CLI11.h.

◆ func_

std::function<std::string(std::string &)> 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 2837 of file CLI11.h.

◆ name_

std::string name_ {}
protected

The name for search purposes of the Validator.

Definition at line 2839 of file CLI11.h.

◆ non_modifying_

bool non_modifying_ {false}
protected

specify that a validator should not modify the input

Definition at line 2845 of file CLI11.h.


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