![]() |
advgetopt 2.0.49
Parse complex command line arguments and configuration files in C++.
|
#include <validator_size.h>
Public Types | |
typedef std::uint32_t | flag_t |
typedef std::shared_ptr< validator > | pointer_t |
typedef std::vector< pointer_t > | vector_t |
Public Member Functions | |
validator_size (string_list_t const &data) | |
Initialize the size 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 a valid size. | |
Static Public Member Functions | |
static bool | convert_string (std::string const &size, flag_t flags, __int128 &result) |
Convert a string to a large integer (128 bits) value representing a size. | |
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) |
Static Public Attributes | |
static constexpr flag_t | VALIDATOR_SIZE_DEFAULT_FLAGS = 0x00 |
static constexpr flag_t | VALIDATOR_SIZE_POWER_OF_TWO = 0x01 |
Private Attributes | |
flag_t | f_flags = VALIDATOR_SIZE_DEFAULT_FLAGS |
Definition at line 48 of file validator_size.h.
typedef std::uint32_t advgetopt::validator_size::flag_t |
Definition at line 52 of file validator_size.h.
|
inherited |
Definition at line 64 of file validator.h.
|
inherited |
Definition at line 65 of file validator.h.
advgetopt::validator_size::validator_size | ( | string_list_t const & | flag_list | ) |
The constructor accepts a string defining the acceptable sizes.
The string uses the following format:
'si' stands for "Systeme International" (French for International System of Units); this means "1kB" will stand for "1000 bytes".
'legacy' means that one kilo bytes will be represented by 1024 bytes. So "1kB" with the legacy flag turned on represents "1024 bytes".
The 'si' and 'legacy' flags are exclusive, the last one will be effective.
[in] | flag_list | The flags used to define how to interpret the data. |
Definition at line 129 of file validator_size.cpp.
References f_flags, advgetopt::option_flags_merge(), and VALIDATOR_SIZE_POWER_OF_TWO.
|
static |
This function is used to convert a string to a double representing a size. The size can be specified with one of the following suffixes:
The suffix capitalization is not important since we can always distinguish both types (power of 1000 or 1024). The 'B' represents bytes either way so it does not need to be dinstinguished.
In legacy mode (VALIDATOR_SIZE_POWER_OF_TWO flag set), the 1024 power is always used.
The final result is an integer representing bytes. If you use a decimal number, it will be rounded down (floor). So "1.9B" returns 1. A decimal number is practical for larger sizes such as "1.3GiB".
[in] | value | The value to be converted to a size. |
[in] | flags | The flags to determine how to interpret the suffix. |
[out] | result | The resulting size in bits or bytes. |
Definition at line 244 of file validator_size.cpp.
References advgetopt::validator_double::convert_string(), advgetopt::option_flags_merge(), and VALIDATOR_SIZE_POWER_OF_TWO.
Referenced by validate().
|
staticinherited |
Definition at line 589 of file validator.cpp.
References advgetopt::validator::name(), and advgetopt::option_flags_merge().
Referenced by advgetopt::validator::create(), and advgetopt::option_info::set_validator().
|
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:
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.
[in] | name_and_params | The validator name and parameters. |
Definition at line 626 of file validator.cpp.
References advgetopt::validator::create(), and advgetopt::option_flags_merge().
|
overridevirtual |
This function returns "size".
Implements advgetopt::validator.
Definition at line 159 of file validator_size.cpp.
|
staticinherited |
Definition at line 571 of file validator.cpp.
References advgetopt::option_flags_merge().
This function verifies that the specified value is a valid size.
It makes sures that the value is a valid decimal number which optionally starts with a sign ([-+]?
) and is optionally followed by a known measurement suffix.
[in] | value | The value to validate. |
Implements advgetopt::validator.
Definition at line 179 of file validator_size.cpp.
References convert_string(), f_flags, and advgetopt::option_flags_merge().
|
private |
Definition at line 72 of file validator_size.h.
Referenced by validator_size(), and validate().
Definition at line 54 of file validator_size.h.
Definition at line 55 of file validator_size.h.
Referenced by validator_size(), and convert_string().
This document is part of the Snap! Websites Project.
Copyright by Made to Order Software Corp.