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

SgGtpCommands Class Reference

General utility GTP commands. More...

#include <SgGtpCommands.h>

List of all members.

Public Member Functions

 SgGtpCommands (GtpEngine &engine, const char *programPath=0)
 Constructor.
virtual ~SgGtpCommands ()
void AddGoGuiAnalyzeCommands (GtpCommand &cmd)
void Register (GtpEngine &engine)
 Register commands at engine.
Command Callbacks

virtual void CmdCompareFloat (GtpCommand &)
 Run another GTP command and compare its response against a float value.
virtual void CmdCompareInt (GtpCommand &)
 Run another GTP command and compare its response against an integer value.
virtual void CmdCpuTime (GtpCommand &)
 Return process time.
virtual void CmdCpuTimeReset (GtpCommand &)
 Reset process time.
virtual void CmdDebugger (GtpCommand &)
 Run a debugger and attach it to the current program.
virtual void CmdEcho (GtpCommand &)
 Echo command argument line as response.
virtual void CmdEchoErr (GtpCommand &)
 Echo command argument line to std::cerr.
virtual void CmdExec (GtpCommand &)
 Execute GTP commands from a file.
virtual void CmdGetRandomSeed (GtpCommand &)
 Return the current random seed.
virtual void CmdParam (GtpCommand &)
 Set global parameters used in module SmartGame.
virtual void CmdPid (GtpCommand &)
 Return the process ID.
virtual void CmdSetRandomSeed (GtpCommand &)
 Set and store random seed.
virtual void CmdQuiet (GtpCommand &)
 Switch debug logging on/off.

Private Attributes

const char * m_programPath
GtpEnginem_engine
std::map< std::string, double > m_cpuTimes
 Cputimes for cputime and cputime_reset commands.

Detailed Description

General utility GTP commands.

Implements generally useful command, which do not require a board or player. Uses functionality from module SmartGo. This class can be used in GTP engines.

Note:
You should make it a member of your engine to ensure that its lifetime is as long as the engine's lifetime, otherwise the pointers in GtpCallback will point to freed memory.
See also:
SgGtpCommands Commands

Definition at line 22 of file SgGtpCommands.h.


Constructor & Destructor Documentation

SgGtpCommands::SgGtpCommands ( GtpEngine engine,
const char *  programPath = 0 
)

Constructor.

Parameters:
engine The GTP engine (needed for wrapper commands that invoke arbitrary other engine commands like sg_compare_float)
programPath The path to the executable for the engine for sg_debug, 0 if unknown

Definition at line 60 of file SgGtpCommands.cpp.

SgGtpCommands::~SgGtpCommands (  )  [virtual]

Definition at line 66 of file SgGtpCommands.cpp.


Member Function Documentation

void SgGtpCommands::AddGoGuiAnalyzeCommands ( GtpCommand cmd  ) 

Definition at line 70 of file SgGtpCommands.cpp.

void SgGtpCommands::CmdCompareFloat ( GtpCommand cmd  )  [virtual]

Run another GTP command and compare its response against a float value.

Arguments: float command [arg...]
Returns: -1 if response is smaller than float; 1 otherwise.

Definition at line 79 of file SgGtpCommands.cpp.

References GtpCommand::Arg(), GtpEngine::ExecuteCommand(), m_engine, and GtpCommand::RemainingLine().

Referenced by Register().

void SgGtpCommands::CmdCompareInt ( GtpCommand cmd  )  [virtual]

Run another GTP command and compare its response against an integer value.

Arguments: int command [arg...]
Returns: -1 if response is smaller than int; 0 if it is equal; 1 if it is greater

Definition at line 95 of file SgGtpCommands.cpp.

References GtpCommand::Arg(), GtpEngine::ExecuteCommand(), m_engine, and GtpCommand::RemainingLine().

Referenced by Register().

void SgGtpCommands::CmdCpuTime ( GtpCommand cmd  )  [virtual]

Return process time.

An optional string argument can be used as an ID for a timer. Default ID is "total". Other IDs are only allowed if cputime_reset was called with this ID before.

Definition at line 118 of file SgGtpCommands.cpp.

References SgTime::Get(), m_cpuTimes, and SG_TIME_CPU.

Referenced by Register().

void SgGtpCommands::CmdCpuTimeReset ( GtpCommand cmd  )  [virtual]

Reset process time.

An optional string argument can be used as an ID for a timer. Default ID is "total".

Definition at line 137 of file SgGtpCommands.cpp.

References SgTime::Get(), m_cpuTimes, and SG_TIME_CPU.

Referenced by Register().

void SgGtpCommands::CmdDebugger ( GtpCommand cmd  )  [virtual]

Run a debugger and attach it to the current program.

Arguments: debugger-type
Currently implemented debugger types:

  • gdb_kde GDB in KDE terminal
  • gdb_gnome GDB in GNOME terminal

Definition at line 149 of file SgGtpCommands.cpp.

References GtpCommand::Arg(), m_programPath, and SgDebug().

Referenced by Register().

void SgGtpCommands::CmdEcho ( GtpCommand cmd  )  [virtual]

Echo command argument line as response.

This command is compatible with GNU Go's 'echo' command.

Definition at line 175 of file SgGtpCommands.cpp.

References GtpCommand::ArgLine().

Referenced by Register().

void SgGtpCommands::CmdEchoErr ( GtpCommand cmd  )  [virtual]

Echo command argument line to std::cerr.

This command is compatible with GNU Go's 'echo_err' command.

Definition at line 182 of file SgGtpCommands.cpp.

References GtpCommand::ArgLine(), and cerr.

Referenced by Register().

void SgGtpCommands::CmdExec ( GtpCommand cmd  )  [virtual]

Execute GTP commands from a file.

Argument: filename
Aborts on the first command that fails. Responses to the commands in the file are written to SgDebug()

See also:
GtpEngine::ExecuteFile

Definition at line 194 of file SgGtpCommands.cpp.

References GtpCommand::Arg(), GtpEngine::ExecuteFile(), m_engine, and SgDebug().

Referenced by Register().

void SgGtpCommands::CmdGetRandomSeed ( GtpCommand cmd  )  [virtual]

Return the current random seed.

See SgRandom::SetSeed(int) for the special meaning of zero and negative values.

Definition at line 202 of file SgGtpCommands.cpp.

References GtpCommand::CheckArgNone(), and SgRandom::Seed().

Referenced by Register().

void SgGtpCommands::CmdParam ( GtpCommand cmd  )  [virtual]

Set global parameters used in module SmartGame.

Parameters:

  • time_mode cpu|real See SgTime

Definition at line 211 of file SgGtpCommands.cpp.

References GtpCommand::Arg(), GtpCommand::CheckNuArgLessEqual(), SgTime::DefaultMode(), GtpCommand::NuArg(), and SgTime::SetDefaultMode().

Referenced by Register().

void SgGtpCommands::CmdPid ( GtpCommand cmd  )  [virtual]

Return the process ID.

Definition at line 234 of file SgGtpCommands.cpp.

References GtpCommand::CheckArgNone().

Referenced by Register().

void SgGtpCommands::CmdQuiet ( GtpCommand cmd  )  [virtual]

Switch debug logging on/off.

Definition at line 254 of file SgGtpCommands.cpp.

References GtpCommand::Arg(), cerr, SgDebugToNull(), and SgSwapDebugStr().

Referenced by Register().

void SgGtpCommands::CmdSetRandomSeed ( GtpCommand cmd  )  [virtual]

Set and store random seed.

Arguments: seed
See SgRandom::SetSeed(int) for the special meaning of zero and negative values.

Definition at line 248 of file SgGtpCommands.cpp.

References GtpCommand::Arg(), and SgRandom::SetSeed().

Referenced by Register().

void SgGtpCommands::Register ( GtpEngine engine  ) 

Register commands at engine.

Make sure that this object lives as long as the GtpEngine, for example by making it a member of the engine.

Definition at line 262 of file SgGtpCommands.cpp.

References CmdCompareFloat(), CmdCompareInt(), CmdCpuTime(), CmdCpuTimeReset(), CmdDebugger(), CmdEcho(), CmdEchoErr(), CmdExec(), CmdGetRandomSeed(), CmdParam(), CmdPid(), CmdQuiet(), CmdSetRandomSeed(), and GtpEngine::Register().


Member Data Documentation

std::map<std::string,double> SgGtpCommands::m_cpuTimes [private]

Cputimes for cputime and cputime_reset commands.

Definition at line 78 of file SgGtpCommands.h.

Referenced by CmdCpuTime(), and CmdCpuTimeReset().

Definition at line 75 of file SgGtpCommands.h.

Referenced by CmdCompareFloat(), CmdCompareInt(), and CmdExec().

const char* SgGtpCommands::m_programPath [private]

Definition at line 73 of file SgGtpCommands.h.

Referenced by CmdDebugger().


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


Sun Mar 13 2011 Doxygen 1.7.1