GTP command. More...
#include <GtpEngine.h>
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 > | |
T | Arg (std::size_t i) const |
Get argument converted to a type. | |
template<typename T > | |
T | Arg () const |
Get single argument converted to a type. | |
template<typename T > | |
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 > | |
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 | |
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< Argument > | m_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 > | |
GtpCommand & | operator<< (GtpCommand &cmd, const TYPE &type) |
template<typename TYPE > | |
GtpCommand & | operator<< (GtpCommand &cmd, TYPE &type) |
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.
GtpCommand | ( | ) |
Construct empty command.
Definition at line 385 of file GtpEngine.h.
GtpCommand | ( | const std::string & | line | ) |
Construct with a command line.
Definition at line 389 of file GtpEngine.h.
References Init().
T Arg | ( | std::size_t | number | ) | const |
Get argument.
number | Argument index starting with 0 |
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)
.
i | Argument index starting with 0 |
Failure | If no such argument, or argument cannot be converted |
T Arg | ( | ) | const |
Get single argument.
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)
.
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)
.
i | Argument index starting with 0 | |
min | The minimum value |
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)
.
i | Argument index starting with 0 | |
min | The minimum value of the range | |
max | The maximum value of the range |
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.
number | Argument index starting with 0 |
GtpFailure | If no such argument |
Definition at line 462 of file GtpEngine.cpp.
References Arg().
bool BoolArg | ( | std::size_t | number | ) | const |
void CheckArgNone | ( | ) | const |
Check that command has no arguments.
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.
number | Expected number of arguments |
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.
number | Expected maximum number of arguments |
GtpFailure | If command has more arguments |
Definition at line 487 of file GtpEngine.cpp.
References NuArg().
double FloatArg | ( | std::size_t | number | ) | const |
std::string ID | ( | ) | const |
Get command 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 |
int IntArg | ( | std::size_t | number, | |
int | min | |||
) | const |
int IntArg | ( | std::size_t | number, | |
int | min, | |||
int | max | |||
) | const |
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.
number | Argument index starting with 0 |
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.
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 | ) |
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 |
std::size_t SizeTypeArg | ( | std::size_t | number, | |
std::size_t | min | |||
) | const |
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 ('\').
line | The line to split. |
Definition at line 579 of file GtpEngine.cpp.
References m_arguments.
Referenced by Init().
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().
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().