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

Description

template<typename T>
class Sawyer::CommandLine::AnyParser< T >

Parses any argument as plain text.

This parser consumes the entire following string and then attempts to convert it to type T, or throw an std::runtime_error. This differs from most other parsers which consume only those characters they recognize. For instance:

int i;
IntegerParser< T >::Ptr integerParser()
Factory for value parsers.
AnyParser< T >::Ptr anyParser()
Factory for value parsers.

The anyParser(i) will throw an error for a command line like -n123x, but the integerParser(i) will consume only the "123" and leave "x" alone (which is presumably the "-x" nestled short switch). The integerParser will also provide more informative error messages for overflows.

This parser is primarily intended for parsing arbitrary strings as std::string, and uses that type when no other type is provided by template argument or constructor argument.

The boost::lexical_cast package is used for the conversion, but boost::bad_lexical_cast exceptions are caught and rethrown as std::runtime_error as required by the ValueParser interface.

See also
anyParser factory method, and Command line parser factories

Definition at line 865 of file Sawyer/CommandLine.h.

#include <Sawyer/CommandLine.h>

Inheritance diagram for Sawyer::CommandLine::AnyParser< T >:
Inheritance graph
[legend]
Collaboration diagram for Sawyer::CommandLine::AnyParser< T >:
Collaboration graph
[legend]

Public Types

typedef SharedPointer< AnyParserPtr
 Reference counting pointer for this class.
 
- Public Types inherited from Sawyer::CommandLine::ValueParser
typedef SharedPointer< ValueParserPtr
 Reference counting pointer for this class.
 

Static Public Member Functions

static Ptr instance ()
 Allocating constructor.
 
static Ptr instance (const ValueSaver::Ptr &valueSaver)
 Allocating constructor.
 

Protected Member Functions

 AnyParser ()
 Constructor for derived classes.
 
 AnyParser (const ValueSaver::Ptr &valueSaver)
 Constructor for derived classes.
 
- Protected Member Functions inherited from Sawyer::CommandLine::ValueParser
 ValueParser ()
 Constructor for derived classes.
 
 ValueParser (const ValueSaver::Ptr &valueSaver)
 Constructor for derived classes.
 

Additional Inherited Members

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

Member Typedef Documentation

◆ Ptr

template<typename T >
typedef SharedPointer<AnyParser> Sawyer::CommandLine::AnyParser< T >::Ptr

Reference counting pointer for this class.

Definition at line 874 of file Sawyer/CommandLine.h.

Constructor & Destructor Documentation

◆ AnyParser() [1/2]

template<typename T >
Sawyer::CommandLine::AnyParser< T >::AnyParser ( )
inlineprotected

Constructor for derived classes.

Non-subclass users should use instance instead.

Definition at line 868 of file Sawyer/CommandLine.h.

Referenced by Sawyer::CommandLine::AnyParser< T >::instance().

◆ AnyParser() [2/2]

template<typename T >
Sawyer::CommandLine::AnyParser< T >::AnyParser ( const ValueSaver::Ptr valueSaver)
inlineprotected

Constructor for derived classes.

Non-subclass users should use instance instead.

Definition at line 871 of file Sawyer/CommandLine.h.

Member Function Documentation

◆ instance() [1/2]

template<typename T >
static Ptr Sawyer::CommandLine::AnyParser< T >::instance ( )
inlinestatic

Allocating constructor.

Returns a pointer to a new AnyParser object. Uses will most likely want to use the anyParser factory instead, which requires less typing.

See also
Command line parser factories

Definition at line 879 of file Sawyer/CommandLine.h.

Referenced by Sawyer::CommandLine::anyParser(), and Sawyer::CommandLine::anyParser().

◆ instance() [2/2]

template<typename T >
static Ptr Sawyer::CommandLine::AnyParser< T >::instance ( const ValueSaver::Ptr valueSaver)
inlinestatic

Allocating constructor.

Returns a pointer to a new AnyParser object. Uses will most likely want to use the anyParser factory instead, which takes the same arguments, but requires less typing.

See also
Command line parser factories

Definition at line 884 of file Sawyer/CommandLine.h.

References Sawyer::CommandLine::AnyParser< T >::AnyParser(), and Sawyer::CommandLine::ValueParser::valueSaver().


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