advgetopt 2.0.47
Parse complex command line arguments and configuration files in C++.
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
advgetopt::validator_integer Class Reference

#include <validator_integer.h>

Inheritance diagram for advgetopt::validator_integer:
Inheritance graph
[legend]
Collaboration diagram for advgetopt::validator_integer:
Collaboration graph
[legend]

Classes

struct  range_t
 

Public Types

typedef std::shared_ptr< validatorpointer_t
 
typedef bool(* to_integer_t) (std::string const &number, std::int64_t &result)
 
typedef std::vector< pointer_tvector_t
 

Public Member Functions

 validator_integer (string_list_t const &data)
 Initialize the integer validator.
 
virtual std::string name () const override
 Return the name of this validator.
 
virtual bool validate (std::string const &value) const override
 Determine whether value is an integer.
 

Static Public Member Functions

static bool convert_string (std::string const &number, std::int64_t &result)
 Convert a string to an std::int64_t value.
 
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

range_t::vector_t f_allowed_values = range_t::vector_t()
 

Detailed Description

Definition at line 49 of file validator_integer.h.

Member Typedef Documentation

◆ pointer_t

Definition at line 64 of file validator.h.

◆ to_integer_t

typedef bool(* advgetopt::validator_integer::to_integer_t) (std::string const &number, std::int64_t &result)

Definition at line 53 of file validator_integer.h.

◆ vector_t

Definition at line 65 of file validator.h.

Constructor & Destructor Documentation

◆ validator_integer()

advgetopt::validator_integer::validator_integer ( string_list_t const range_list)

The constructor accepts a string with values and ranges which are used to limit the values that can be used with this parameter.

Remember that the default does not have to be included in these values. It will still be viewed as valid.

The string uses the following format:

| start ',' range
| number '...' number
number: [-+]?(0[bdox])?[0-9]+
constexpr flag_t option_flags_merge()
Definition flags.h:87

Note that a single number is considered to be a range and is managed the exact same way. A value which matches any of the ranges is considered valid.

The start and end values of a range are optional. If not specified, the start value is set to the minimum int64_t value. If the not specified, the end value is set to the maximum int64_t value.

Examples:

"-100...100,-1000"

This example allows all values between -100 and +100 inclusive and also allows the value -1000.

"1..."

This example allows all positive values.

Parameters
[in]rangesThe ranges used to limit the integer.

Definition at line 151 of file validator_integer.cpp.

References convert_string(), f_allowed_values, and advgetopt::option_flags_merge().

Member Function Documentation

◆ convert_string()

bool advgetopt::validator_integer::convert_string ( std::string const value,
std::int64_t &  result 
)
static

This function is used to convert a string to an integer with full boundary verification.

Warning
There is no range checks in this function since it does not have access to the ranges (i.e. it is static).
Parameters
[in]valueThe value to be converted to an integer.
[out]resultThe resulting integer.
Returns
true if the conversion succeeded.

Definition at line 289 of file validator_integer.cpp.

References advgetopt::option_flags_merge().

Referenced by validator_integer(), advgetopt::validator_length::validator_length(), advgetopt::option_info_ref::get_long(), advgetopt::option_info::get_long(), advgetopt::getopt::get_long(), and validate().

◆ create() [1/2]

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

◆ create() [2/2]

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

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 override
Return the name of this validator.

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.

Parameters
[in]name_and_paramsThe validator name and parameters.

Definition at line 626 of file validator.cpp.

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

◆ name()

std::string advgetopt::validator_integer::name ( ) const
overridevirtual

This function returns "integer".

Returns
"integer".

Implements advgetopt::validator.

Definition at line 225 of file validator_integer.cpp.

◆ register_validator()

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

Definition at line 571 of file validator.cpp.

References advgetopt::option_flags_merge().

◆ validate()

bool advgetopt::validator_integer::validate ( std::string const value) const
overridevirtual

This function verifies that the specified value is a valid integer.

It makes sures that the value is only composed of digits ([0-9]+). It may also start with a sign ([-+]?).

The function also makes sure that the value fits in an int64_t value.

If ranges were defined, then the function also verifies that the value is within at least one of the ranges.

Todo:
Add support for binary, octal, hexadecimal.
Parameters
[in]valueThe value to validate.
Returns
true if the value validates.

Implements advgetopt::validator.

Definition at line 250 of file validator_integer.cpp.

References convert_string(), f_allowed_values, and advgetopt::option_flags_merge().

Member Data Documentation

◆ f_allowed_values

range_t::vector_t advgetopt::validator_integer::f_allowed_values = range_t::vector_t()
private

Definition at line 75 of file validator_integer.h.

Referenced by validator_integer(), and validate().


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.