advgetopt 2.0.49
Parse complex command line arguments and configuration files in C++.
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
advgetopt::validator Class Referenceabstract

#include <validator.h>

Inheritance diagram for advgetopt::validator:
Inheritance graph
[legend]

Public Types

typedef std::shared_ptr< validatorpointer_t
 
typedef std::vector< pointer_tvector_t
 

Public Member Functions

virtual ~validator ()
 The validator destructor to support virtuals.
 
std::string constget_error () const
 
virtual std::string name () const =0
 Return the name of the validator.
 
void set_error (std::string const &msg) const
 
virtual bool validate (std::string const &value) const =0
 Return true if value validates against this validator.
 

Static Public Member Functions

static pointer_t create (std::string const &name, string_list_t const &data)
 
static pointer_t create (std::string const &name_and_params)
 Set the validator for this option.
 
static void register_validator (validator_factory const &factory)
 

Private Attributes

std::string f_error = std::string("<error undefined>")
 

Detailed Description

Definition at line 61 of file validator.h.

Member Typedef Documentation

◆ pointer_t

Definition at line 64 of file validator.h.

◆ vector_t

Definition at line 65 of file validator.h.

Constructor & Destructor Documentation

◆ ~validator()

advgetopt::validator::~validator ( )
virtual

This destructor is defined so virtual functions work as expected including the deleter.

Definition at line 541 of file validator.cpp.

Member Function Documentation

◆ create() [1/2]

validator::pointer_t advgetopt::validator::create ( std::string const name,
string_list_t const data 
)
static

Definition at line 605 of file validator.cpp.

References name(), and advgetopt::option_flags_merge().

Referenced by create(), and advgetopt::option_info::set_validator().

◆ create() [2/2]

validator::pointer_t advgetopt::validator::create ( std::string const name_and_params)
static

This function parses the specified name and optional parameters and create a corresponding validator for this option.

The name_and_params string can be defined as:

virtual std::string name() const =0
Return the name of the validator.
constexpr flag_t option_flags_merge()
Definition flags.h:87

The list of parameters is optional. There may be an empty, just one, or any number of parameters. How the parameters are parsed is left to the validator to decide.

If the input string is empty, the current validator, if one is installed, gets removed.

The complete grammar of the name_and_params name and parameters can be written as a comma separated list of function calls, we have a special case for regex which do not require the function call. thing is pretty much anything other than the few special characters (comma, space, parenthesis, and quotes). To include a special character in thing either use a string or escape the character.

| '/' ... '/' // regex special case
name: [a-zA-Z_][a-zA-Z_0-9]*
params: (thing - [,()'" ])
| '\'' (thing - '\'') '\''
| '"' (thing - '"') '"'
thing: [^ -~]*
| '\\' [ -~]
Parameters
[in]name_and_paramsThe validator name and parameters.

Definition at line 666 of file validator.cpp.

References create(), and advgetopt::option_flags_merge().

◆ get_error()

std::string const & advgetopt::validator::get_error ( ) const

Definition at line 581 of file validator.cpp.

References f_error.

◆ name()

std::string const & advgetopt::validator::name ( ) const
pure virtual

The name() function is used to get the name of the validator. Validators are recognized by name and added to your options using their name.

Note that when an option specifies a validator which it can't find, then an error occurs.

Returns
The name of the validator.

Implemented in advgetopt::validator_double, advgetopt::validator_duration, advgetopt::validator_email, advgetopt::validator_integer, advgetopt::validator_keywords, advgetopt::validator_length, advgetopt::validator_list, advgetopt::validator_regex, and advgetopt::validator_size.

Referenced by create().

◆ register_validator()

void advgetopt::validator::register_validator ( validator_factory const factory)
static

Definition at line 587 of file validator.cpp.

References advgetopt::option_flags_merge().

◆ set_error()

void advgetopt::validator::set_error ( std::string const msg) const

◆ validate()

bool advgetopt::validator::validate ( std::string const value) const
pure virtual

The function parses the value parameter and if it matches the allowed parameters, then it returns true.

The validator may save an error message when the validation fails. See the set_error() and get_error() functions.

Parameters
[in]valueThe value to validate.
Returns
true if the value validates.

Implemented in advgetopt::validator_double, advgetopt::validator_duration, advgetopt::validator_email, advgetopt::validator_integer, advgetopt::validator_keywords, advgetopt::validator_length, advgetopt::validator_list, advgetopt::validator_regex, and advgetopt::validator_size.

Member Data Documentation

◆ f_error

std::string advgetopt::validator::f_error = std::string("<error undefined>")
mutableprivate

Definition at line 82 of file validator.h.

Referenced by get_error(), and set_error().


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

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.