ROSE  0.11.96.11
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 <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  Preferred {
  NO,
  YES
}
 
using Ptr = Sawyer::SharedPointer< SuffixMultiplierParser >
 Shared-ownership pointer to a SuffixMultiplierParser. More...
 
- 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. More...
 
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. More...
 
bool extendedSyntax () const
 Property: Allow extended syntax for numberic values. More...
 
Ptr extendedSyntax (bool b)
 Property: Allow extended syntax for numberic values. More...
 
- Public Member Functions inherited from Sawyer::CommandLine::ValueParser
ParsedValue matchString (const std::string &)
 Parse the entire string and return a value. More...
 
ParsedValue match (Cursor &)
 Parse a value from the beginning of the specified string. More...
 
Ptr valueSaver (const ValueSaver::Ptr &f)
 Property: functor responsible for saving a parsed value in user storage. More...
 
const ValueSaver::Ptr valueSaver () const
 Property: functor responsible for saving a parsed value in user storage. More...
 
- Public Member Functions inherited from Sawyer::SharedObject
 SharedObject ()
 Default constructor. More...
 
 SharedObject (const SharedObject &)
 Copy constructor. More...
 
virtual ~SharedObject ()
 Virtual destructor. More...
 
SharedObjectoperator= (const SharedObject &)
 Assignment. More...
 
- Public Member Functions inherited from Sawyer::SharedFromThis< ValueParser >
SharedPointer< ValueParser > sharedFromThis ()
 Create a shared pointer from this. More...
 
SharedPointer< const ValueParser > sharedFromThis () const
 Create a shared pointer from this. More...
 

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. More...
 
 ValueParser (const ValueSaver::Ptr &valueSaver)
 Constructor for derived classes. More...
 

Member Typedef Documentation

◆ Ptr

Shared-ownership pointer to a SuffixMultiplierParser.

See Shared ownership.

Definition at line 58 of file SuffixMultiplierParser.h.

Member Function Documentation

◆ 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.

◆ 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.

◆ 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.


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