Parsnip
parsing library
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes
Parsnip::Dispatcher< DispatchReturnType, DispatchContextType > Class Template Reference

Public Types

using ReturnType = DispatchReturnType
 
using ContextType = DispatchContextType
 
using ExecutorType = std::function< ReturnType(Parser::CommandId, const Parsnip::Data &, ContextType)>
 

Public Member Functions

 Dispatcher (const ParserRef &parser)
 Construct a dispatcher.
 
void addHandler (const Parser::Definitions &defs, const ExecutorType &handler)
 Register handlers with the dispatcher.
 
void addHandler (const Parser::Definitions &defs, Interpreter< DispatchReturnType, DispatchContextType > *interpreter)
 Register handlers with the dispatcher.
 
void addStatements (const Parser::Definitions &defs, ExecutorType handler)
 Add statements to the parser and register their related handler.
 
ReturnType operator() (Parser::CommandId command_id, const Parsnip::Data &parameters, DispatchContextType context) const
 Dispatch a command to the executor/handler function.
 
ReturnType operator() (Parser::StringType command, ContextType context) const
 Parse and dispatch a command to the executor/handler function.
 

Protected Attributes

const ParserRef parser
 

Constructor & Destructor Documentation

◆ Dispatcher()

template<typename DispatchReturnType , typename DispatchContextType >
Parsnip::Dispatcher< DispatchReturnType, DispatchContextType >::Dispatcher ( const ParserRef &  par)

Construct a dispatcher.

Parameters
parA parser for evaluating command lines to be dispatched.

Member Function Documentation

◆ addHandler() [1/2]

template<typename DispatchReturnType , typename DispatchContextType >
void Parsnip::Dispatcher< DispatchReturnType, DispatchContextType >::addHandler ( const Parser::Definitions &  defs,
const ExecutorType &  handler 
)

Register handlers with the dispatcher.

If assertions aren't enabled, keeps a secondary map to ensure statements are not redefined with different handlers.

Parameters
defsThe statements handled by the handler.
handlerSomething to call when dispatching to defined statements.

◆ addHandler() [2/2]

template<typename DispatchReturnType , typename DispatchContextType >
void Parsnip::Dispatcher< DispatchReturnType, DispatchContextType >::addHandler ( const Parser::Definitions &  defs,
Interpreter< DispatchReturnType, DispatchContextType > *  interpreter 
)
inline

Register handlers with the dispatcher.

Parameters
defsThe statements handled by the handler.
interpreterAn Interpreter whose interpret routine will be used as the handler.

◆ addStatements()

template<typename DispatchReturnType , typename DispatchContextType >
void Parsnip::Dispatcher< DispatchReturnType, DispatchContextType >::addStatements ( const Parser::Definitions &  defs,
ExecutorType  handler 
)

Add statements to the parser and register their related handler.

Parameters
defsThe statements to add and register.
handlerSomething to call when dispatching to defined statements.

◆ operator()() [1/2]

template<typename DispatchReturnType , typename DispatchContextType >
DispatchReturnType Parsnip::Dispatcher< DispatchReturnType, DispatchContextType >::operator() ( Parser::CommandId  command_id,
const Parsnip::Data parameters,
DispatchContextType  context 
) const

Dispatch a command to the executor/handler function.

Parameters
command_idIdentifier for the requested handler.
parametersDetails passed to the handler.
contextThe caller's context.
Returns
Whatever value is returned by the handler.

◆ operator()() [2/2]

template<typename DispatchReturnType , typename DispatchContextType >
DispatchReturnType Parsnip::Dispatcher< DispatchReturnType, DispatchContextType >::operator() ( Parser::StringType  command,
ContextType  context 
) const

Parse and dispatch a command to the executor/handler function.

Parameters
commandThe command line to parse & execute.
contextThe caller's context.
Returns
Whatever value is returned by the handler.

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