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

Description

template<class Functor>
class Sawyer::CommandLine::UserAction< Functor >

Wrapper around a user functor.

User code doesn't often use reference counting smart pointers for functors, but more often creates functors in global data or on the stack. The purpose of UserAction is to be a wrapper around these functors, to be a bridge between the world of reference counting pointers and objects or object references. For example, say the user has a function like this:

void showRawManPage(const ParserResult *cmdline) {
std::cout <<cmdline->parser()->manpage();
exit(0);
}
The result from parsing a command line.
const Parser & parser() const
That parser that created this result.

Then the functor/function can be used like this:

switchGroup.insert(Switch("raw-man")
.action(userAction(showRawManPage))
.doc("Prints the raw nroff man page to standard output."));
Describes one command-line switch.
UserAction< Functor >::Ptr userAction(const Functor &functor)
Factory for switch action.

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

#include <Sawyer/CommandLine.h>

Inheritance diagram for Sawyer::CommandLine::UserAction< Functor >:
Inheritance graph
[legend]
Collaboration diagram for Sawyer::CommandLine::UserAction< Functor >:
Collaboration graph
[legend]

Public Types

typedef SharedPointer< class UserActionPtr
 Reference counting pointer for this class.
 
- Public Types inherited from Sawyer::CommandLine::SwitchAction
typedef SharedPointer< SwitchActionPtr
 Reference counting pointer for this class.
 

Static Public Member Functions

static Ptr instance (Functor &f)
 Allocating constructor.
 

Protected Member Functions

 UserAction (Functor &f)
 Constructor for derived classes.
 
virtual void operator() (const ParserResult &parserResult)
 

Additional Inherited Members

- Public Member Functions inherited from Sawyer::CommandLine::SwitchAction
void run (const ParserResult &parserResult)
 Runs the action.
 
- Public Member Functions inherited from Sawyer::SharedObject
 SharedObject ()
 Default constructor.
 
 SharedObject (const SharedObject &)
 Copy constructor.
 
virtual ~SharedObject ()
 Virtual destructor.
 
SharedObjectoperator= (const SharedObject &)
 Assignment.
 

Member Typedef Documentation

◆ Ptr

template<class Functor >
typedef SharedPointer<class UserAction> Sawyer::CommandLine::UserAction< Functor >::Ptr

Reference counting pointer for this class.

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

Constructor & Destructor Documentation

◆ UserAction()

template<class Functor >
Sawyer::CommandLine::UserAction< Functor >::UserAction ( Functor &  f)
inlineprotected

Constructor for derived classes.

Non-subclass users should use instance instead.

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

Member Function Documentation

◆ instance()

template<class Functor >
static Ptr Sawyer::CommandLine::UserAction< Functor >::instance ( Functor &  f)
inlinestatic

Allocating constructor.

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

See also
Command line action factories, and the SwitchAction class.

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

Referenced by Sawyer::CommandLine::userAction().

◆ operator()()

template<class Functor >
virtual void Sawyer::CommandLine::UserAction< Functor >::operator() ( const ParserResult parserResult)
inlineprotectedvirtual

Implements Sawyer::CommandLine::SwitchAction.

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


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