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

Base class for key parsers. More...

#include <request.hxx>

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

Public Member Functions

 KeyParserBase (std::string name)
 Constructor.
const std::string & name () const
 Get the key name.
void display (std::ostream &cout) const
 Display help about the key.
KeyParserBasemetavar (std::string metavar)
 Set the meta variable name for the key.
KeyParserBasedescription (std::string description)
 Set the description string for the key.
KeyParserBaserequired (bool req=true)
 Sets whether the key is optional or required.
virtual bool isVector () const
 Tell whether the key takes more than one value.
virtual void parse (std::istream &cin)=0
 Parse an input stream and handle the key value.
virtual void set (const Json::Value &json)=0
 Retrieve the key value from a JSON value and handle it.

Protected Attributes

std::string default_
 Description of the default key value.

Detailed Description

Base class for key parsers.

A key is a named parameter taking a typed value.

Constructor & Destructor Documentation

Request::KeyParserBase::KeyParserBase ( std::string  name)
inline

Constructor.

Parameters
namekey name

Member Function Documentation

KeyParserBase* Request::KeyParserBase::description ( std::string  description)
inline

Set the description string for the key.

The description string is included in the help message output by the display() method.

Returns the key itself to allow chaining mutator calls.

Parameters
descriptionnew value for the key description
Returns
the key itself
void Request::KeyParserBase::display ( std::ostream &  cout) const
inline

Display help about the key.

Display the key name, along with indications about its usage. Such indications include, when available:

  • expected values
  • a description of the key meaning
  • a default value taken if the key is not provided in the request
  • whether the key is optional or required
  • whether the key can take multiple values
Parameters
coutI/O stream where help will be printed
virtual bool Request::KeyParserBase::isVector ( ) const
inlinevirtual

Tell whether the key takes more than one value.

A scalar key can take only one argument. If it is present multiple times in the request, only the last value will be used. A vector key takes multiple values : each occurence of the key in the request adds the correponding value to a list. In JSON-formatted requests, vector keys are associated to an array of values.

Returns
true if the key takes multiple values, false otherwise

Reimplemented in Request::Key< std::vector< T > >.

KeyParserBase* Request::KeyParserBase::metavar ( std::string  metavar)
inline

Set the meta variable name for the key.

The meta variable name is a generic name used as a placeholder for the value taken by the key in the documentation. For example, the meta variable name for a "fileName" key could be "PATH", indicating that the value provided to the key should be a filesystem path. The meta variable name is included in the help message printed by the display() method.

Returns the key itself to allow chaining mutator calls.

Parameters
metavarnew value for the meta variable name
Returns
the key itself
const std::string& Request::KeyParserBase::name ( ) const
inline

Get the key name.

Returns
the key name, as a string
virtual void Request::KeyParserBase::parse ( std::istream &  cin)
pure virtual

Parse an input stream and handle the key value.

Parse the key value in an input text stream and store it. This method is used for plain-text requests. Values associated to vector keys are appended to the list of previously read values.

Parameters
cininput stream

Implemented in Request::Key< std::vector< T > >, and Request::Key< T >.

KeyParserBase* Request::KeyParserBase::required ( bool  req = true)
inline

Sets whether the key is optional or required.

If a required key is missing in a request, an error message will be output. Optional keys can take default values when missing in the request.

Returns the key itself to allow chaining mutator calls.

Parameters
reqtrue if the key should be required
Returns
the key itself
virtual void Request::KeyParserBase::set ( const Json::Value &  json)
pure virtual

Retrieve the key value from a JSON value and handle it.

This method is used for JSON-formatted requests.

Parameters
jsonJSON request

Implemented in Request::Key< std::vector< T > >, and Request::Key< T >.

Member Data Documentation

std::string Request::KeyParserBase::default_
protected

Description of the default key value.

Used for the help message


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