Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgGtpClient.h

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file SgGtpClient.h */
00003 //----------------------------------------------------------------------------
00004 
00005 #ifndef SG_GTPCLIENT_H
00006 #define SG_GTPCLIENT_H
00007 
00008 #include <iostream>
00009 #include <string>
00010 #include "SgException.h"
00011 
00012 //----------------------------------------------------------------------------
00013 
00014 /** Error thrown by SgGtpClient::Send() if command fails or connection is
00015     broken. */
00016 class SgGtpFailure
00017     : public SgException
00018 {
00019 public:
00020     /** Constructor.
00021         @param message The failure response of the command or other error
00022         message. */
00023     SgGtpFailure(const std::string& message);
00024 };
00025 
00026 //----------------------------------------------------------------------------
00027 
00028 /** Client connection to an external GTP engine.
00029     Usage example:
00030 @code
00031     // Run GNU Go and send a GTP command
00032     try
00033     {
00034         SgProcess process("gnugo --mode gtp");
00035         SgGtpClient gtp(process.Input(), process.Output());
00036         string result = gtp.Send("version");
00037         SgDebug() << "Success response: " << result << '\n';
00038     }
00039     catch (const SgGtpFailure& e)
00040     {
00041         SgDebug() << "Error response: " << e.what() << '\n';
00042     }
00043     catch (const SgException& e)
00044     {
00045         SgDebug() << "Error running GNU Go: " << e.what() << '\n';
00046     }
00047 
00048 @endcode */
00049 class SgGtpClient
00050 {
00051 public:
00052     /** Constructor.
00053         @param in Input stream.
00054         @param out Output stream.
00055         @param verbose Log stream to SgDebug() */
00056     SgGtpClient(std::istream& in, std::ostream& out, bool verbose = false);
00057 
00058     virtual ~SgGtpClient();
00059 
00060     /** Send a command.
00061         @return The response if command succeeds (without status character
00062         and whitespace after status character)
00063         @throws SgGtpFailure If command fails or connection is broken. */
00064     std::string Send(const std::string& command);
00065 
00066 private:
00067     bool m_verbose;
00068 
00069     std::istream& m_in;
00070 
00071     std::ostream& m_out;
00072 };
00073 
00074 //----------------------------------------------------------------------------
00075 
00076 #endif // SG_GTPCLIENT_H


Sun Mar 13 2011 Doxygen 1.7.1