Scarab  v3.4.1
Project 8 C++ Utility Library
Public Types | Public Member Functions | Static Private Member Functions | List of all members
AsNumberWithUnit Class Reference

#include <CLI11.hpp>

Inheritance diagram for AsNumberWithUnit:
Inheritance graph

Public Types

enum  Options {
  CASE_SENSITIVE = 0, CASE_INSENSITIVE = 1, UNIT_OPTIONAL = 0, UNIT_REQUIRED = 2,
  DEFAULT = CASE_INSENSITIVE | UNIT_OPTIONAL
}
 

Public Member Functions

template<typename Number >
 AsNumberWithUnit (std::map< std::string, Number > mapping, Options opts=DEFAULT, const std::string &unit_name="UNIT")
 
- Public Member Functions inherited from Validator
 Validator ()=default
 
 Validator (std::string validator_desc)
 Construct a Validator with just the description string. More...
 
 Validator (std::function< std::string(std::string &)> op, std::string validator_desc, std::string validator_name="")
 
Validatoroperation (std::function< std::string(std::string &)> op)
 Set the Validator operation function. More...
 
std::string operator() (std::string &str) const
 
std::string operator() (const std::string &str) const
 
Validatordescription (std::string validator_desc)
 Specify the type string. More...
 
std::string get_description () const
 Generate type description information for the Validator. More...
 
Validatorname (std::string validator_name)
 Specify the type string. More...
 
const std::string & get_name () const
 Get the name of the Validator. More...
 
Validatoractive (bool active_val=true)
 Specify whether the Validator is active or not. More...
 
Validatornon_modifying (bool no_modify=true)
 Specify whether the Validator can be modifying or not. More...
 
bool get_active () const
 Get a boolean if the validator is active. More...
 
bool get_modifying () const
 Get a boolean if the validator is allowed to modify the input returns true if it can modify the input. More...
 
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. More...
 

Static Private Member Functions

template<typename Number >
static void validate_mapping (std::map< std::string, Number > &mapping, Options opts)
 
template<typename Number >
static std::string generate_description (const std::string &name, Options opts)
 Generate description like this: NUMBER [UNIT]. More...
 

Additional Inherited Members

- Protected Attributes inherited from Validator
std::function< std::string()> desc_function_ {[]() { return std::string{}; }}
 This is the description function, if empty the description_ will be used. More...
 
std::function< std::string(std::string &)> func_ {[](std::string &) { return std::string{}; }}
 
std::string name_
 The name for search purposes of the Validator. More...
 
bool active_ {true}
 Enable for Validator to allow it to be disabled if need be. More...
 
bool non_modifying_ {false}
 specify that a validator should not modify the input More...
 

Detailed Description

Multiply a number by a factor using given mapping. Can be used to write transforms for SIZE or DURATION inputs.

Example: With mapping = {"b"->1, "kb"->1024, "mb"->1024*1024} one can recognize inputs like "100", "12kb", "100 MB", that will be automatically transformed to 100, 14448, 104857600.

Output number type matches the type in the provided mapping. Therefore, if it is required to interpret real inputs like "0.42 s", the mapping should be of a type <string, float> or <string, double>.

Definition at line 2281 of file CLI11.hpp.

Member Enumeration Documentation

◆ Options

enum Options

Adjust AsNumberWithUnit behavior. CASE_SENSITIVE/CASE_INSENSITIVE controls how units are matched. UNIT_OPTIONAL/UNIT_REQUIRED throws ValidationError if UNIT_REQUIRED is set and unit literal is not found.

Enumerator
CASE_SENSITIVE 
CASE_INSENSITIVE 
UNIT_OPTIONAL 
UNIT_REQUIRED 
DEFAULT 

Definition at line 2287 of file CLI11.hpp.

Constructor & Destructor Documentation

◆ AsNumberWithUnit()

AsNumberWithUnit ( std::map< std::string, Number mapping,
Options  opts = DEFAULT,
const std::string &  unit_name = "UNIT" 
)
inlineexplicit

Definition at line 2296 of file CLI11.hpp.

Member Function Documentation

◆ generate_description()

static std::string generate_description ( const std::string &  name,
Options  opts 
)
inlinestaticprivate

Generate description like this: NUMBER [UNIT].

Definition at line 2387 of file CLI11.hpp.

◆ validate_mapping()

static void validate_mapping ( std::map< std::string, Number > &  mapping,
Options  opts 
)
inlinestaticprivate

Check that mapping contains valid units. Update mapping for CASE_INSENSITIVE mode.

Definition at line 2362 of file CLI11.hpp.


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