Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  
Classes | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Related Functions

GtpCommand Class Reference

GTP command. More...

#include <GtpEngine.h>

List of all members.

Classes

struct  Argument
 Argument in command line. More...

Public Member Functions

 GtpCommand ()
 Construct empty command.
 GtpCommand (const std::string &line)
 Construct with a command line.
 operator std::ostream & ()
 Conversion to output stream.
const std::string & Arg (std::size_t number) const
 Get argument.
const std::string & Arg () const
 Get single argument.
std::string ArgToLower (std::size_t number) const
 Get argument converted to lowercase.
template<typename T >
Arg (std::size_t i) const
 Get argument converted to a type.
template<typename T >
Arg () const
 Get single argument converted to a type.
template<typename T >
ArgMin (std::size_t i, const T &min) const
 Get argument converted to a type and check for a minimum value.
template<typename T >
ArgMinMax (std::size_t i, const T &min, const T &max) const
 Get argument converted to a type and check for a range.
void CheckArgNone () const
 Check that command has no arguments.
void CheckNuArg (std::size_t number) const
 Check number of arguments.
void CheckNuArgLessEqual (std::size_t number) const
 Check maximum number of arguments.
std::string ID () const
 Get command ID.
void Init (const std::string &line)
 Initialize with a command line.
std::string ArgLine () const
 Get argument line.
const std::string & Line () const
 Get command line.
const std::string & Name () const
 Get argument name.
std::size_t NuArg () const
 Get number of arguments.
std::string RemainingLine (std::size_t number) const
 Return remaining line after argument.
std::string Response () const
 Get response.
std::ostringstream & ResponseStream ()
 Get internal response string stream.
void SetResponse (const std::string &response)
 Set response.
void SetResponseBool (bool value)
 Set response to "true" or "false".
Deprecated functions

Will be removed in the future.

bool BoolArg (std::size_t number) const
 Deprecated.
double FloatArg (std::size_t number) const
 Deprecated.
int IntArg (std::size_t number) const
 Deprecated.
int IntArg (std::size_t number, int min) const
 Deprecated.
int IntArg (std::size_t number, int min, int max) const
 Deprecated.
std::size_t SizeTypeArg (std::size_t number) const
 Deprecated.
std::size_t SizeTypeArg (std::size_t number, std::size_t min) const
 Deprecated.

Private Member Functions

void ParseCommandId ()
void SplitLine (const std::string &line)
 Split line into arguments.

Private Attributes

std::string m_id
 ID of command or empty string, if command has no ID.
std::string m_line
 Full command line.
std::ostringstream m_response
 Response stream.
std::vector< Argumentm_arguments
 Arguments of command.

Static Private Attributes

static std::ostringstream s_dummy
 Dummy stream for copying default formatting settings.

Related Functions

(Note that these are not member functions.)



template<typename TYPE >
GtpCommandoperator<< (GtpCommand &cmd, const TYPE &type)
template<typename TYPE >
GtpCommandoperator<< (GtpCommand &cmd, TYPE &type)

Detailed Description

GTP command.

GtpCommands are passed to command handlers. They can be queried for arguments and used for writing the response to.

Arguments can contain spaces if they are double quoted, for instance:

loadsgf "My File.sgf" 

Double quotes in a quoted argument have to be escaped with '\'.

The response message format does not have any special requirement, it will be sanitized by GtpEngine before writing to form a valid GTP response (see GtpEngine::MainLoop).

Definition at line 159 of file GtpEngine.h.


Constructor & Destructor Documentation

GtpCommand (  ) 

Construct empty command.

Warning:
An empty command cannot be used, before Init() was called. This constructor exists only to reuse instances.

Definition at line 385 of file GtpEngine.h.

GtpCommand ( const std::string &  line  ) 

Construct with a command line.

See also:
Init()

Definition at line 389 of file GtpEngine.h.

References Init().


Member Function Documentation

T Arg ( std::size_t  number  )  const

Get argument.

Parameters:
number Argument index starting with 0
Returns:
Argument value
Exceptions:
GtpFailure If no such argument

Definition at line 421 of file GtpEngine.cpp.

References m_arguments, and NuArg().

Referenced by GtpEngine::CmdKnownCommand().

T Arg ( std::size_t  i  )  const

Get argument converted to a type.

This function allows to parse any argument type that implements operator<<(istream).

Parameters:
i Argument index starting with 0
Returns:
The converted argument
Exceptions:
Failure If no such argument, or argument cannot be converted
T Arg (  )  const

Get single argument.

Returns:
Argument value
Exceptions:
GtpFailure If no such argument or command has more than one arguments

Definition at line 429 of file GtpEngine.cpp.

References CheckNuArg().

Referenced by ArgToLower().

T Arg (  )  const

Get single argument converted to a type.

This function allows to parse any argument type that implements operator<<(istream).

Returns:
The converted argument
Exceptions:
Failure If no such argument, argument cannot be converted or command has more than one arguments
std::string ArgLine (  )  const

Get argument line.

Get all arguments as a line. No modfications to the line were made apart from trimmimg leading and trailing white spaces.

Definition at line 455 of file GtpEngine.cpp.

References m_arguments, and m_line.

T ArgMin ( std::size_t  i,
const T &  min 
) const

Get argument converted to a type and check for a minimum value.

This function allows to parse any argument type that implements operator<<(istream).

Parameters:
i Argument index starting with 0
min The minimum value
Returns:
The converted argument
Exceptions:
Failure If no such argument, argument cannot be converted, or is less than the minimum value

Definition at line 430 of file GtpEngine.h.

Referenced by ArgMinMax().

T ArgMinMax ( std::size_t  i,
const T &  min,
const T &  max 
) const

Get argument converted to a type and check for a range.

This function allows to parse any argument type that implements operator<<(istream).

Parameters:
i Argument index starting with 0
min The minimum value of the range
max The maximum value of the range
Returns:
The converted argument
Exceptions:
Failure If no such argument, argument cannot be converted, or is not contained in the range.

Definition at line 440 of file GtpEngine.h.

References ArgMin().

string ArgToLower ( std::size_t  number  )  const

Get argument converted to lowercase.

Parameters:
number Argument index starting with 0
Returns:
Copy of argument value converted to lowercase
Exceptions:
GtpFailure If no such argument

Definition at line 462 of file GtpEngine.cpp.

References Arg().

bool BoolArg ( std::size_t  number  )  const

Deprecated.

Deprecated:
Use Arg<bool>() instead

Definition at line 470 of file GtpEngine.cpp.

void CheckArgNone (  )  const

Check that command has no arguments.

Exceptions:
GtpFailure If command has arguments

Definition at line 449 of file GtpEngine.h.

References CheckNuArg().

Referenced by GtpEngine::CmdListCommands(), GtpEngine::CmdName(), GtpEngine::CmdProtocolVersion(), GtpEngine::CmdQuit(), and GtpEngine::CmdVersion().

void CheckNuArg ( std::size_t  number  )  const

Check number of arguments.

Parameters:
number Expected number of arguments
Exceptions:
GtpFailure If command has a different number of arguments

Definition at line 475 of file GtpEngine.cpp.

References NuArg().

Referenced by Arg(), and CheckArgNone().

void CheckNuArgLessEqual ( std::size_t  number  )  const

Check maximum number of arguments.

Parameters:
number Expected maximum number of arguments
Exceptions:
GtpFailure If command has more arguments

Definition at line 487 of file GtpEngine.cpp.

References NuArg().

double FloatArg ( std::size_t  number  )  const

Deprecated.

Deprecated:
Use Arg<double>() instead

Definition at line 497 of file GtpEngine.cpp.

std::string ID (  )  const

Get command ID.

Returns:
ID or empty string, if command has no ID

Definition at line 454 of file GtpEngine.h.

References m_id.

Referenced by GtpEngine::HandleCommand().

void Init ( const std::string &  line  ) 

Initialize with a command line.

The line should be not empty, not contain only whitespaces and not be a comment line. It will be split into the optional numeric command ID, the command name, and arguments.

Definition at line 517 of file GtpEngine.cpp.

References m_arguments, m_line, m_response, ParseCommandId(), s_dummy, and SplitLine().

Referenced by GtpEngine::ExecuteCommand(), GtpEngine::ExecuteFile(), and GtpCommand().

int IntArg ( std::size_t  number  )  const

Deprecated.

Deprecated:
Use Arg<int>() instead

Definition at line 502 of file GtpEngine.cpp.

int IntArg ( std::size_t  number,
int  min 
) const

Deprecated.

Deprecated:
Use ArgMin<int>() instead

Definition at line 507 of file GtpEngine.cpp.

int IntArg ( std::size_t  number,
int  min,
int  max 
) const

Deprecated.

Deprecated:
Use ArgMinMax<int>() instead

Definition at line 512 of file GtpEngine.cpp.

const std::string & Line (  )  const

Get command line.

Returns full command line as given to the constructor or GtpCommand::Init. No modfications to the line were made apart from trimmimg leading and trailing white spaces.

Definition at line 459 of file GtpEngine.h.

References m_line.

Referenced by GtpEngine::ExecuteCommand(), and GtpEngine::ExecuteFile().

const std::string & Name (  )  const

Get argument name.

Definition at line 464 of file GtpEngine.h.

References m_arguments.

Referenced by GtpEngine::HandleCommand().

std::size_t NuArg (  )  const

Get number of arguments.

Definition at line 469 of file GtpEngine.h.

References m_arguments.

Referenced by Arg(), CheckNuArg(), CheckNuArgLessEqual(), and RemainingLine().

operator std::ostream & (  ) 

Conversion to output stream.

Returns reference to response stream.

Definition at line 394 of file GtpEngine.h.

References ResponseStream().

void ParseCommandId (  )  [private]

Definition at line 529 of file GtpEngine.cpp.

References m_arguments, and m_id.

Referenced by Init().

string RemainingLine ( std::size_t  number  )  const

Return remaining line after argument.

Parameters:
number Argument index starting with 0
Returns:
The remaining line after the given argument, unmodified apart from leading and trailing whitespaces, which are trimmed. Quotation marks are not handled.
Exceptions:
GtpFailure If no such argument

Definition at line 544 of file GtpEngine.cpp.

References m_arguments, m_line, and NuArg().

std::string Response (  )  const

Get response.

Returns:
A copy of the internal response string stream

Definition at line 474 of file GtpEngine.h.

References m_response.

Referenced by GtpEngine::ExecuteCommand(), and GtpEngine::HandleCommand().

std::ostringstream & ResponseStream (  ) 

Get internal response string stream.

Definition at line 479 of file GtpEngine.h.

References m_response.

Referenced by operator std::ostream &(), and operator<<().

void SetResponse ( const std::string &  response  ) 

Set response.

Definition at line 554 of file GtpEngine.cpp.

References m_response.

void SetResponseBool ( bool  value  ) 

Set response to "true" or "false".

Definition at line 559 of file GtpEngine.cpp.

References m_response.

Referenced by GtpEngine::CmdKnownCommand().

std::size_t SizeTypeArg ( std::size_t  number  )  const

Deprecated.

Deprecated:
Use Arg<size_t>() instead

Definition at line 564 of file GtpEngine.cpp.

std::size_t SizeTypeArg ( std::size_t  number,
std::size_t  min 
) const

Deprecated.

Deprecated:
Use ArgMin<size_t>() instead

Definition at line 569 of file GtpEngine.cpp.

void SplitLine ( const std::string &  line  )  [private]

Split line into arguments.

Arguments are words separated by whitespaces. Arguments with whitespaces can be quoted with quotation marks ('"'). Characters can be escaped with a backslash ('\').

Parameters:
line The line to split.

Definition at line 579 of file GtpEngine.cpp.

References m_arguments.

Referenced by Init().


Friends And Related Function Documentation

GtpCommand & operator<< ( GtpCommand cmd,
const TYPE &  type 
) [related]

Definition at line 371 of file GtpEngine.h.

References ResponseStream().

GtpCommand & operator<< ( GtpCommand cmd,
TYPE &  type 
) [related]

Definition at line 379 of file GtpEngine.h.

References ResponseStream().


Member Data Documentation

std::vector<Argument> m_arguments [private]

Arguments of command.

Definition at line 362 of file GtpEngine.h.

Referenced by Arg(), ArgLine(), Init(), Name(), NuArg(), ParseCommandId(), RemainingLine(), and SplitLine().

std::string m_id [private]

ID of command or empty string, if command has no ID.

Definition at line 353 of file GtpEngine.h.

Referenced by ID(), and ParseCommandId().

std::string m_line [private]

Full command line.

Definition at line 356 of file GtpEngine.h.

Referenced by ArgLine(), Init(), Line(), and RemainingLine().

std::ostringstream m_response [private]

Response stream.

Definition at line 359 of file GtpEngine.h.

Referenced by Init(), Response(), ResponseStream(), SetResponse(), and SetResponseBool().

ostringstream s_dummy [static, private]

Dummy stream for copying default formatting settings.

Definition at line 350 of file GtpEngine.h.

Referenced by Init().


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


Sun Mar 13 2011 Doxygen 1.7.1