ROSE 0.11.145.147
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
Rose::CommandLine::SuffixMultiplierParser< T > Class Template Reference

Description

template<class T>
class Rose::CommandLine::SuffixMultiplierParser< T >

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>

Inheritance diagram for Rose::CommandLine::SuffixMultiplierParser< T >:
Inheritance graph
[legend]
Collaboration diagram for Rose::CommandLine::SuffixMultiplierParser< T >:
Collaboration graph
[legend]

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< ValueParserPtr
 Reference counting pointer for this class.
 

Public Member Functions

parse (const char *input, const char **rest)
 Parse from a C string.
 
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.
 
SharedObjectoperator= (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.
 

Member Typedef Documentation

◆ Ptr

Shared-ownership pointer to a Rose::CommandLine::SuffixMultiplierParser.

See Shared ownership.

Definition at line 58 of file SuffixMultiplierParser.h.

Member Enumeration Documentation

◆ Preferred

template<class T >
enum class Rose::CommandLine::SuffixMultiplierParser::Preferred
strong

Definition at line 36 of file SuffixMultiplierParser.h.

Constructor & Destructor Documentation

◆ SuffixMultiplierParser() [1/2]

template<class T >
Rose::CommandLine::SuffixMultiplierParser< T >::SuffixMultiplierParser ( )
inlineprotected

Definition at line 49 of file SuffixMultiplierParser.h.

◆ SuffixMultiplierParser() [2/2]

template<class T >
Rose::CommandLine::SuffixMultiplierParser< T >::SuffixMultiplierParser ( const Sawyer::CommandLine::ValueSaver::Ptr valueSaver)
inlineprotected

Definition at line 51 of file SuffixMultiplierParser.h.

Member Function Documentation

◆ instance() [1/2]

template<class T >
static Ptr Rose::CommandLine::SuffixMultiplierParser< T >::instance ( )
inlinestatic

Default allocating constructor.

Definition at line 61 of file SuffixMultiplierParser.h.

◆ instance() [2/2]

template<class T >
static Ptr Rose::CommandLine::SuffixMultiplierParser< T >::instance ( const Sawyer::CommandLine::ValueSaver::Ptr valueSaver)
inlinestatic

Allocating constructor.

Definition at line 66 of file SuffixMultiplierParser.h.

References Sawyer::CommandLine::ValueParser::valueSaver().

◆ with() [1/2]

template<class T >
Ptr Rose::CommandLine::SuffixMultiplierParser< T >::with ( const std::string &  suffix,
multiplier,
Preferred  preferred = Preferred::YES 
)
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().

◆ with() [2/2]

template<class T >
Ptr Rose::CommandLine::SuffixMultiplierParser< T >::with ( const std::string &  suffix,
multiplier,
const std::string &  alias1,
const std::string &  alias2 = "",
const std::string &  alias3 = "",
const std::string &  alias4 = "" 
)
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().

◆ extendedSyntax() [1/2]

template<class T >
bool Rose::CommandLine::SuffixMultiplierParser< T >::extendedSyntax ( ) const
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.

◆ extendedSyntax() [2/2]

template<class T >
Ptr Rose::CommandLine::SuffixMultiplierParser< T >::extendedSyntax ( bool  b)
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().

◆ parse() [1/2]

template<class T >
T Rose::CommandLine::SuffixMultiplierParser< T >::parse ( const char *  input,
const char **  rest 
)
inline

Parse from a C string.

Definition at line 123 of file SuffixMultiplierParser.h.

Referenced by Rose::CommandLine::SuffixMultiplierParser< T >::parse().

◆ parse() [2/2]

template<class T >
T Rose::CommandLine::SuffixMultiplierParser< T >::parse ( const std::string &  input)
inline

Parse from a C++ string.

Definition at line 156 of file SuffixMultiplierParser.h.

References Rose::StringUtility::cEscape(), and Rose::CommandLine::SuffixMultiplierParser< T >::parse().

◆ quotientRemainder() [1/2]

template<class T >
static std::pair< T, T > Rose::CommandLine::SuffixMultiplierParser< T >::quotientRemainder ( product,
divisor,
uint64_t   
)
inlinestatic

Definition at line 166 of file SuffixMultiplierParser.h.

◆ quotientRemainder() [2/2]

template<class T >
static std::pair< T, T > Rose::CommandLine::SuffixMultiplierParser< T >::quotientRemainder ( product,
divisor,
double   
)
inlinestatic

Definition at line 178 of file SuffixMultiplierParser.h.

◆ toString()

template<class T >
std::string Rose::CommandLine::SuffixMultiplierParser< T >::toString ( value)
inline

Unparse to a string.

Definition at line 195 of file SuffixMultiplierParser.h.


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