clang-tags
C/C++ source code indexing tool based on libclang
 All Classes Functions Variables Typedefs Groups Pages
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Request::CommandParser Class Reference

Base class for command parsers. More...

#include <request.hxx>

Inheritance diagram for Request::CommandParser:
Inheritance graph
[legend]

Public Member Functions

 CommandParser (std::string name, std::string description="")
 Constructor.
void parse (std::istream &cin, std::ostream &cout, bool echo=false)
 Parse an input stream and handle key arguments.
void parseJson (const Json::Value &request, std::ostream &cout)
 Parse an input stream and handle key arguments.

Protected Member Functions

const std::string & name ()
 Get the command name.
void setDescription (std::string description)
 Set the command description.
virtual void defaults ()
 Set default values for keys.
virtual void run (std::ostream &cout)=0
 Run the command.
CommandParseradd (KeyParserBase *key)
 Add a key parser to the list of parameters.

Protected Attributes

std::string prompt_
 Prompt used for interactive plain-text requests.

Friends

class Parser

Detailed Description

Base class for command parsers.

Parses the keys associated to a command, and run it.

Custom commands should be implemented through user-defined functors deriving from CommandParser.

Constructor & Destructor Documentation

Request::CommandParser::CommandParser ( std::string  name,
std::string  description = "" 
)
inline

Constructor.

Parameters
nameCommand name
descriptionCommand description

Member Function Documentation

CommandParser& Request::CommandParser::add ( KeyParserBase key)
inlineprotected

Add a key parser to the list of parameters.

Parameters
keykey parser
Returns
the command parser itself
virtual void Request::CommandParser::defaults ( )
inlineprotectedvirtual

Set default values for keys.

This method should be specialized to specify default key values.

Reimplemented in CompleteCommand, GrepCommand, FindCommand, IndexCommand, UpdateCommand, Repeat, and CompilationDatabaseCommand.

const std::string& Request::CommandParser::name ( )
inlineprotected

Get the command name.

Returns
the command name, as a string
void Request::CommandParser::parse ( std::istream &  cin,
std::ostream &  cout,
bool  echo = false 
)
inline

Parse an input stream and handle key arguments.

Parse all key arguments provided to the command, and handle them. Also run the command and output results to the provided stream. This method is used for plain-text requests.

Parameters
cininput stream, where the request will be read
coutoutput stream
See Also
parseJson()
void Request::CommandParser::parseJson ( const Json::Value &  request,
std::ostream &  cout 
)
inline

Parse an input stream and handle key arguments.

Parse all key arguments provided to the command, and handle them. Also run the command and output results to the provided stream. This method is used for JSON-formatted requests.

Parameters
requestJSON request
coutoutput stream
See Also
parseJson()
virtual void Request::CommandParser::run ( std::ostream &  cout)
protectedpure virtual

Run the command.

This typically is a user-defined function. It should use key values and write results on the provided output stream.

Parameters
coutoutput stream for results

Implemented in ExitCommand, CompleteCommand, GrepCommand, FindCommand, IndexCommand, UpdateCommand, Repeat, and CompilationDatabaseCommand.

void Request::CommandParser::setDescription ( std::string  description)
inlineprotected

Set the command description.

This description will be used for help messages.

Parameters
descriptioncommand description

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