ROSE 0.11.145.147
|
Parse values followed by unit names.
Parses one or more multiplicative terms and sums them to obtain a numeric value. A term is a number followed by an optional unit name. For instance, a time duration could have units "h" (hours), "m" (minutes), and "s" (seconds) and be specified as "3h2m1s" where the terms are "3h" (3*3600) plus "2m" (2*60) plus "1s" (1*1) for a total of 10921.
The numbers used in the terms are parsed as either integers or floating point depending on the template argument. For integers, the usual C/C++ syntax for hexadecimal, octal, and binary parsing are available if configured, and floating point exponential parsing is also conditionally available.
The unit names and multipliers are specified by the user. Any number of names and multipliers are allowed, and longer names are matched preferentially before shorter names so that, for example, "hour" is parsed before "h". One of the unit names my also be the empty string, which can only apply to the final term.
Definition at line 34 of file SuffixMultiplierParser.h.
#include <Rose/CommandLine/SuffixMultiplierParser.h>
Public Types | |
enum class | Preferred { NO , YES } |
using | Ptr = Sawyer::SharedPointer< SuffixMultiplierParser > |
Shared-ownership pointer to a Rose::CommandLine::SuffixMultiplierParser. | |
Public Types inherited from Sawyer::CommandLine::ValueParser | |
typedef SharedPointer< ValueParser > | Ptr |
Reference counting pointer for this class. | |
Public Member Functions | |
T | parse (const char *input, const char **rest) |
Parse from a C string. | |
T | parse (const std::string &input) |
Parse from a C++ string. | |
std::string | toString (T value) |
Unparse to a string. | |
Ptr | with (const std::string &suffix, T multiplier, Preferred preferred=Preferred::YES) |
Insert a suffix definition. | |
Ptr | with (const std::string &suffix, T multiplier, const std::string &alias1, const std::string &alias2="", const std::string &alias3="", const std::string &alias4="") |
Insert a suffix definition. | |
bool | extendedSyntax () const |
Property: Allow extended syntax for numberic values. | |
Ptr | extendedSyntax (bool b) |
Property: Allow extended syntax for numberic values. | |
Public Member Functions inherited from Sawyer::CommandLine::ValueParser | |
ParsedValue | matchString (const std::string &) |
Parse the entire string and return a value. | |
ParsedValue | match (Cursor &) |
Parse a value from the beginning of the specified string. | |
Ptr | valueSaver (const ValueSaver::Ptr &f) |
Property: functor responsible for saving a parsed value in user storage. | |
const ValueSaver::Ptr | valueSaver () const |
Property: functor responsible for saving a parsed value in user storage. | |
Public Member Functions inherited from Sawyer::SharedObject | |
SharedObject () | |
Default constructor. | |
SharedObject (const SharedObject &) | |
Copy constructor. | |
virtual | ~SharedObject () |
Virtual destructor. | |
SharedObject & | operator= (const SharedObject &) |
Assignment. | |
Public Member Functions inherited from Sawyer::SharedFromThis< ValueParser > | |
SharedPointer< ValueParser > | sharedFromThis () |
Create a shared pointer from this . | |
SharedPointer< const ValueParser > | sharedFromThis () const |
Create a shared pointer from this . | |
Static Public Member Functions | |
static Ptr | instance () |
Default allocating constructor. | |
static Ptr | instance (const Sawyer::CommandLine::ValueSaver::Ptr &valueSaver) |
Allocating constructor. | |
static std::pair< T, T > | quotientRemainder (T product, T divisor, uint64_t) |
static std::pair< T, T > | quotientRemainder (T product, T divisor, double) |
Protected Member Functions | |
SuffixMultiplierParser (const Sawyer::CommandLine::ValueSaver::Ptr &valueSaver) | |
Protected Member Functions inherited from Sawyer::CommandLine::ValueParser | |
ValueParser () | |
Constructor for derived classes. | |
ValueParser (const ValueSaver::Ptr &valueSaver) | |
Constructor for derived classes. | |
using Rose::CommandLine::SuffixMultiplierParser< T >::Ptr = Sawyer::SharedPointer<SuffixMultiplierParser> |
Shared-ownership pointer to a Rose::CommandLine::SuffixMultiplierParser.
See Shared ownership.
Definition at line 58 of file SuffixMultiplierParser.h.
|
strong |
Definition at line 36 of file SuffixMultiplierParser.h.
|
inlineprotected |
Definition at line 49 of file SuffixMultiplierParser.h.
|
inlineprotected |
Definition at line 51 of file SuffixMultiplierParser.h.
|
inlinestatic |
Default allocating constructor.
Definition at line 61 of file SuffixMultiplierParser.h.
|
inlinestatic |
Allocating constructor.
Definition at line 66 of file SuffixMultiplierParser.h.
References Sawyer::CommandLine::ValueParser::valueSaver().
|
inline |
Insert a suffix definition.
If preferred
is set, then this suffix can be used when converting a value to a string. Alternatively, all suffixes with the same multiplier can be specified in a single with call and the first one can be used in string conversion.
Definition at line 77 of file SuffixMultiplierParser.h.
References Sawyer::SharedFromThis< ValueParser >::sharedFromThis().
|
inline |
Insert a suffix definition.
If preferred
is set, then this suffix can be used when converting a value to a string. Alternatively, all suffixes with the same multiplier can be specified in a single with call and the first one can be used in string conversion.
Definition at line 82 of file SuffixMultiplierParser.h.
References Sawyer::SharedFromThis< ValueParser >::sharedFromThis().
|
inline |
Property: Allow extended syntax for numberic values.
If clear, then integers and floating-point value syntax is simple. For integers, the syntax is a sequence of one or more digits interpreted as a decimal integer; and for floating point the syntax is a simple integer followed by an optional decimal point and simple integer.
If set, then integers and floating-point values have a more complicated syntax. Integers can be specified as hexadecimal with a leading "0x", binary with a leading "0b", octal with a leading "0" (not followed by "x" or "b"), and decimal in other cases. Care must be taken with hexadecimal since the letters "a" through "f" (lower and upper case) would be interpreted as part of the integer rather than the beginning of a suffix unit name. Extended floating-point syntax is a simple floating point value followed by an optional exponent. An exponent is the letter "e" or "E", an optional "+" or "-" sign, followed by an integer.
The default is to use simple syntax.
Definition at line 113 of file SuffixMultiplierParser.h.
|
inline |
Property: Allow extended syntax for numberic values.
If clear, then integers and floating-point value syntax is simple. For integers, the syntax is a sequence of one or more digits interpreted as a decimal integer; and for floating point the syntax is a simple integer followed by an optional decimal point and simple integer.
If set, then integers and floating-point values have a more complicated syntax. Integers can be specified as hexadecimal with a leading "0x", binary with a leading "0b", octal with a leading "0" (not followed by "x" or "b"), and decimal in other cases. Care must be taken with hexadecimal since the letters "a" through "f" (lower and upper case) would be interpreted as part of the integer rather than the beginning of a suffix unit name. Extended floating-point syntax is a simple floating point value followed by an optional exponent. An exponent is the letter "e" or "E", an optional "+" or "-" sign, followed by an integer.
The default is to use simple syntax.
Definition at line 116 of file SuffixMultiplierParser.h.
References Sawyer::SharedFromThis< ValueParser >::sharedFromThis().
|
inline |
Parse from a C string.
Definition at line 123 of file SuffixMultiplierParser.h.
Referenced by Rose::CommandLine::SuffixMultiplierParser< T >::parse().
|
inline |
Parse from a C++ string.
Definition at line 156 of file SuffixMultiplierParser.h.
References Rose::StringUtility::cEscape(), and Rose::CommandLine::SuffixMultiplierParser< T >::parse().
|
inlinestatic |
Definition at line 166 of file SuffixMultiplierParser.h.
|
inlinestatic |
Definition at line 178 of file SuffixMultiplierParser.h.
|
inline |
Unparse to a string.
Definition at line 195 of file SuffixMultiplierParser.h.