#include <GtpEngine.h>
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"
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 168 of file GtpEngine.h.
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. | |
| bool | BoolArg (std::size_t number) const |
| Get integer argument converted boolean. | |
| 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. | |
| double | FloatArg (std::size_t number) const |
| Get argument converted to double. | |
| std::string | ID () const |
| Get command ID. | |
| void | Init (const std::string &line) |
| Initialize with a command line. | |
| int | IntArg (std::size_t number) const |
| Get argument converted to integer. | |
| int | IntArg (std::size_t number, int min) const |
| Get argument converted to integer in a range with lower limit. | |
| int | IntArg (std::size_t number, int min, int max) const |
| Get argument converted to integer in a range with lower and upper limit. | |
| 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". | |
| std::size_t | SizeTypeArg (std::size_t number) const |
| Get argument converted to std::size_t. | |
| std::size_t | SizeTypeArg (std::size_t number, std::size_t min) const |
| Get argument converted to std::size_t with lower limit. | |
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) |
Classes | |
| struct | Argument |
| Argument in command line. More... | |
| GtpCommand | ( | ) |
Construct empty command.
Definition at line 390 of file GtpEngine.h.
| GtpCommand | ( | const std::string & | line | ) |
Construct with a command line.
Definition at line 394 of file GtpEngine.h.
References Init().
| const string & Arg | ( | ) | const |
Get single argument.
| GtpFailure | If no such argument or command has more than one arguments |
Definition at line 437 of file GtpEngine.cpp.
References CheckNuArg().
Referenced by ArgToLower(), BoolArg(), FloatArg(), IntArg(), and SizeTypeArg().
| const string & Arg | ( | std::size_t | number | ) | const |
Get argument.
| number | Argument index starting with 0 |
| GtpFailure | If no such argument |
Definition at line 429 of file GtpEngine.cpp.
References m_arguments, and NuArg().
Referenced by GtpEngine::CmdKnownCommand().
| 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 443 of file GtpEngine.cpp.
References m_arguments, m_line, and Trim().
| 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 450 of file GtpEngine.cpp.
References Arg().
| bool BoolArg | ( | std::size_t | number | ) | const |
Get integer argument converted boolean.
| number | Argument index starting with 0 |
| GtpFailure | If no such argument, or argument has other value |
Definition at line 458 of file GtpEngine.cpp.
References Arg().
| void CheckArgNone | ( | ) | const |
Check that command has no arguments.
| GtpFailure | If command has arguments |
Definition at line 404 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 468 of file GtpEngine.cpp.
References NuArg().
Referenced by Arg(), CheckArgNone(), and GtpEngine::CmdKnownCommand().
| 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 480 of file GtpEngine.cpp.
References NuArg().
| double FloatArg | ( | std::size_t | number | ) | const |
Get argument converted to double.
| number | Argument index starting with 0 |
| GtpFailure | If no such argument, or argument is not a double |
Definition at line 490 of file GtpEngine.cpp.
References Arg().
| std::string ID | ( | ) | const |
Get command ID.
Definition at line 409 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 533 of file GtpEngine.cpp.
References m_arguments, m_line, m_response, ParseCommandId(), s_dummy, SplitLine(), and Trim().
Referenced by GtpEngine::ExecuteCommand(), GtpEngine::ExecuteFile(), and GtpCommand().
| int IntArg | ( | std::size_t | number, | |
| int | min, | |||
| int | max | |||
| ) | const |
Get argument converted to integer in a range with lower and upper limit.
| number | Argument index starting with 0 | |
| min | Minimum allowed value | |
| max | Maximum allowed value |
| GtpFailure | If no such argument, argument is not an integer, or not in range |
Definition at line 521 of file GtpEngine.cpp.
References IntArg().
| int IntArg | ( | std::size_t | number, | |
| int | min | |||
| ) | const |
Get argument converted to integer in a range with lower limit.
| number | Argument index starting with 0 | |
| min | Minimum allowed value |
| GtpFailure | If no such argument, argument is not an integer, or not in range |
Definition at line 512 of file GtpEngine.cpp.
References IntArg().
| int IntArg | ( | std::size_t | number | ) | const |
Get argument converted to integer.
| number | Argument index starting with 0 |
| GtpFailure | If no such argument, or argument is not an integer |
Definition at line 501 of file GtpEngine.cpp.
References Arg().
Referenced by IntArg().
| 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 414 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 419 of file GtpEngine.h.
References m_arguments.
Referenced by GtpEngine::HandleCommand().
| std::size_t NuArg | ( | ) | const |
Get number of arguments.
Definition at line 424 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 399 of file GtpEngine.h.
References ResponseStream().
| void ParseCommandId | ( | ) | [private] |
Definition at line 545 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 560 of file GtpEngine.cpp.
References m_arguments, m_line, NuArg(), and Trim().
| std::string Response | ( | ) | const |
Get response.
Definition at line 429 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 434 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 575 of file GtpEngine.cpp.
References m_response.
Referenced by GtpEngine::CmdKnownCommand().
| std::size_t SizeTypeArg | ( | std::size_t | number, | |
| std::size_t | min | |||
| ) | const |
Get argument converted to std::size_t with lower limit.
| number | Argument index starting with 0 | |
| min | Minimum allowed value |
| GtpFailure | If no such argument, or argument is not a size_t |
Definition at line 600 of file GtpEngine.cpp.
References SizeTypeArg().
| std::size_t SizeTypeArg | ( | std::size_t | number | ) | const |
Get argument converted to std::size_t.
| number | Argument index starting with 0 |
| GtpFailure | If no such argument, or argument is not a size_t |
Definition at line 580 of file GtpEngine.cpp.
References Arg().
Referenced by SizeTypeArg().
| 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 615 of file GtpEngine.cpp.
References m_arguments.
Referenced by Init().
| GtpCommand & operator<< | ( | GtpCommand & | cmd, | |
| TYPE & | type | |||
| ) | [related] |
| GtpCommand & operator<< | ( | GtpCommand & | cmd, | |
| const TYPE & | type | |||
| ) | [related] |
std::vector<Argument> m_arguments [private] |
Arguments of command.
Definition at line 367 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 358 of file GtpEngine.h.
Referenced by ID(), and ParseCommandId().
std::string m_line [private] |
Full command line.
Definition at line 361 of file GtpEngine.h.
Referenced by ArgLine(), Init(), Line(), and RemainingLine().
std::ostringstream m_response [private] |
Response stream.
Definition at line 364 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 355 of file GtpEngine.h.
Referenced by Init().