Re: [Housebot-developers] SF.net SVN: housebot: [466]trunk/housebot/src
Status: Alpha
Brought to you by:
j_house
|
From: Phil G <go...@th...> - 2007-02-08 05:47:20
|
> I'll accept all the hits as to how horrible GTPFunctionObjectTemplate.hpp= is, but I'll =0A> also argue that it's as elegant as you can get with resp= ect to the C++ language =0A> and this type of feature. Repetitively typing= the same code over and over again =0A> is error prone and tough to maintai= n. I guess it's possible to add more extensive =0A> commentary to it? I l= ooked at the implementation of boost::function and the =0A> macro based thi= ng is the way that they did it.=0A =0AThe root of the problem is mapping va= rying number of and differently typed arguments to C++ =0Afunction method c= alls. Since we both admit that C++ is not built for this, I would suggest = =0Awe approached the problem in a different way by simply passing whole arg= ument =0Alist as a single parameter to the function and let the function do= the parsing with helper =0Amethods. Similar to my 2nd iteration of GTP for= HouseBot, except we add boost functions. =0AI think this helps get around = the object base to derived class convertion. =0A =0AAnd I still think it's = a good idea to always pass the "interface" to the "GoBoard" to every =0AGTP= function, regardless if it used or not. In essence, I'm arguing to use the= "Facade" =0Astructural design pattern to reduce complexity between compone= nts. =0A=0AOn another note, I'm getting ready to take converting Point to p= osition. =0A=0APhil=0A =0A=0A=0A=0AFrom: housebot-developers-bounces@lists.= sourceforge.net [mailto:hou...@li...] = On Behalf Of Phil G=0ASent: Wednesday, February 07, 2007 10:08 PM=0ATo: Dis= cussion with/among housebot developers=0ASubject: Re: [Housebot-developers]= SF.net SVN: housebot: [466]trunk/housebot/src=0A=0A=0A =0AJason:=0A =0AI j= ust reviewed the "GTPFunctionObjectTemplate.hpp". It is a fine example of m= acro expansion using the c++ preprocessor. However, are you sure you want t= o go in this direction? This is an awfully complex (and obtuse) coding styl= e - more macro rather than object oriented. It also has limitations on the = number of arguments. I'm worried about code maintainability and readability= . =0A =0AOn another note for correctness, I think you wish to include "b" a= nd "B" as Black and "W" and "w" for White, in the code below, or better yet= , just check the first character.=0A =0A+ template<> inline=0A+ color_t c= onverter(SmartString &x){=0A+ if (x=3D=3D"black" || x=3D=3D"Black" || x= =3D=3D"BLACK")=0A+ return black;=0A+ if (x=3D=3D"white" || x=3D=3D"= White" || x=3D=3D"WHITE")=0A+ return white;=0A+ assert(false);=0A+ = }=0A =0APhil=0A =0A----- Original Message ----=0AFrom: "j_...@us...= ceforge.net" <j_...@us...>=0ATo: housebot-developers@list= s.sourceforge.net=0ASent: Tuesday, February 6, 2007 4:16:25 PM=0ASubject: [= Housebot-developers] SF.net SVN: housebot: [466] trunk/housebot/src=0A=0A= =0ARevision: 466=0A http://svn.sourceforge.net/housebot/?rev=3D466= &view=3Drev=0AAuthor: j_house=0ADate: 2007-02-06 16:16:24 -0800 (Tue,= 06 Feb 2007)=0A=0ALog Message:=0A-----------=0AA truly generic and functio= nal GTP command registration=0ASadly, most uses are commented out right now= :(=0AOn a positive note, they work if you uncomment them...=0A=0AModified = Paths:=0A--------------=0A trunk/housebot/src/brains.cpp=0A trunk/hou= sebot/src/gtp/GTPBoard.h=0A trunk/housebot/src/gtp/GTPFunctionObject.h= =0A trunk/housebot/src/housebot.cpp=0A=0AAdded Paths:=0A-----------=0A = trunk/housebot/src/gtp/GTPFunctionObjectTemplate.hpp=0A=0AModified: trunk= /housebot/src/brains.cpp=0A=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=0A--- trunk/housebot/src/brains.cpp 2007-02-07 00:15:28 UTC (rev 465= )=0A+++ trunk/housebot/src/brains.cpp 2007-02-07 00:16:24 UTC (rev 466)= =0A@@ -580,14 +580,12 @@=0A=0Avoid =0Acollective::register_gtp(GTPBoard >= p_engine){=0A-/// \bug since these command bypass the GoBoardInterface and = other data structures, like the GameTree, are not updated and causes the pr= ogram to crash.=0A-=0A-// gtp_engine.RegisterCommand("boardsize", GTPCom= mandCallBack(new boost::function<void (int)> (boost::lambda::bind(boost::m= em_fn(&collective::reinitialize), (collective*)this, boost::lambda::_1))));= =0A-// gtp_engine.RegisterCommand("clear_board", GTPCommandCallBack(new bo= ost::function<void ()> (boost::lambda::bind(boost::mem_fn(&collective::= clear), (collective*)this))));=0A-// gtp_engine.RegisterCommand("komi", = GTPCommandCallBack(new boost::function<void (float)>(boost::lambda::bi= nd(boost::mem_fn(&collective::set_komi), (collective*)this, boost::lamb= da::_1))));=0A-// gtp_engine.RegisterCommand("undo", GTPCommandCallBack(ne= w boost::function<void ()> (boost::lambda::bind(boost::mem_fn(&collecti= ve::undo), (collective*)this))));=0A- //gtp_engine.RegisterCommand("time_l= eft", GTPCommandCallBack(new boost::function<void (color_t, int, int)>(bo= ost::lambda::bind(boost::mem_fn(&collective::time_left), (collective*)this,= boost::lambda::_1, boost::lambda::_2, boost::lambda::_3))));=0A-=0A+ /// = \bug since these command bypass the GoBoardInterface and other data structu= res, like the GameTree, are not updated and causes the program to crash.=0A= +// gtp_engine.RegisterCommand("boardsize", GTPCommandCallBack1(new boos= t::function1<void, int> (boost::lambda::bind(boost::mem_fn(&collective::re= initialize), (collective*)this, boost::lambda::_1))));=0A+// gtp_engine.Re= gisterCommand("clear_board", GTPCommandCallBack0(new boost::function0<void>= (boost::lambda::bind(boost::mem_fn(&collective::clear), (collective*= )this))));=0A+// gtp_engine.RegisterCommand("komi", GTPCommandCallB= ack1(new boost::function1<void, float>(boost::lambda::bind(boost::mem_fn(&c= ollective::set_komi), (collective*)this, boost::lambda::_1))));=0A+// = gtp_engine.RegisterCommand("time_left", GTPCommandCallBack3(new boost::fu= nction3<void, color_t, int, int>(boost::lambda::bind(boost::mem_fn(&collect= ive::time_left), (collective*)this, boost::lambda::_1, boost::lambda::_2, b= oost::lambda::_3))));=0A+// gtp_engine.RegisterCommand("undo", GTPCommandC= allBack0(new boost::function0<void> (boost::lambda::bind(boost= ::mem_fn(&collective::undo), (collective*)this))));=0A}=0A=0Abool=0A=0AModi= fied: trunk/housebot/src/gtp/GTPBoard.h=0A=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=0A--- trunk/housebot/src/gtp/GTPBoard.h 2007-02-07 00= :15:28 UTC (rev 465)=0A+++ trunk/housebot/src/gtp/GTPBoard.h 2007-02-07 = 00:16:24 UTC (rev 466)=0A@@ -140,7 +140,7 @@=0A// RegisterCommand("known= _command", >PBoard::GTPKnownComand);=0A RegisterCommand("list_command= s", GTPListCommands);=0A RegisterCommand("cputime", >PCPUTime);=0A- = RegisterCommand("echo", GTPCommandCallBack(GTPBoard::GTPEcho));=0A+ Re= gisterCommand("echo", GTPCommandCallBack1(new boost::function1<std::string,= std::string>(GTPBoard::GTPEcho)));=0A RegisterCommand("quit", >PBoa= rd::GTPQuit);=0A RegisterCommand("timer_start", >PTimerStart);=0A = RegisterCommand("timer_now", >PTimerNow);=0A=0AModified: trunk/housebot/= src/gtp/GTPFunctionObject.h=0A=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=0A--- trunk/housebot/src/gtp/GTPFunctionObject.h 2007-02-07 00:15= :28 UTC (rev 465)=0A+++ trunk/housebot/src/gtp/GTPFunctionObject.h 2007-= 02-07 00:16:24 UTC (rev 466)=0A@@ -4,20 +4,27 @@=0A#include "GTPInternalRes= ponse.h"=0A#include "GTPCommand.h"=0A=0A+/// \bug This should be made indpe= ndent of the housebot core=0A+#include "go_board.hpp" // for color_t=0A+=0A= #include <boost/function.hpp>=0A#include <boost/lambda/bind.hpp>=0A#include= <assert.h>=0A#include <list>=0A=0A+#include <boost/static_assert.hpp>=0A+#= include <boost/preprocessor/enum_params.hpp> // expands= for 0 ... N-1=0A+#include <boost/preprocessor/repetition/enum_shifted_para= ms.hpp> // expands for 1 ... N-1=0A+=0Atypedef boost::function<GTPInternal= Response (GTPCommand)> GTPFunctionObject;=0A=0Anamespace gtp_detail{=0A-=0A= /// \bug Not very general purpose at this time=0A /// \bug Having to d= eclare this inline is an anti-ld-error feature...=0A template<typename in= putType, typename outputType> inline=0A outputType converter(inputType x)= {=0A outputType y =3D (outputType) x;=0A+ //BOOST_STATIC_ASSERT(fals= e);=0A return y;=0A }=0A =0A@@ -51,6 +58,15 @@=0A return x.GetA= sFloat();=0A }=0A=0A+ template<> inline=0A+ color_t converter(SmartStri= ng &x){=0A+ if (x=3D=3D"black" || x=3D=3D"Black" || x=3D=3D"BLACK")=0A+ = return black;=0A+ if (x=3D=3D"white" || x=3D=3D"White" || x=3D=3D"W= HITE")=0A+ return white;=0A+ assert(false);=0A+ }=0A+=0A templat= e<typename inputType> inline=0A inputType extract(GTPCommand &x, unsigned= int &position){=0A SmartString arg =3D x.GetArgument(position++);=0A@@= -67,122 +83,22 @@=0A return return_val;=0A }=0A=0A- template <typen= ame inputType, typename outputType> inline=0A- GTPInternalResponse type_wr= apper(boost::function<outputType (inputType)> *callback_function, GTPComman= d cmd){=0A- unsigned int position =3D 0;=0A- inputType arg =3D extrac= t<inputType>(cmd, position);=0A- assert(position =3D=3D cmd.GetArgumentC= ount());=0A- return converter<outputType, GTPInternalResponse>( (*callba= ck_function)(arg) );=0A- }=0A-=0A- // If there's no input argument, speci= al handling is required=0A- template<typename outputType> inline =0A- GTP= InternalResponse type_wrapper(boost::function<outputType (void)> *callback_= function, GTPCommand cmd){=0A- assert(cmd.GetArgumentCount()=3D=3D0);=0A= - return converter<outputType, GTPInternalResponse>( (*callback_function= )() );=0A- }=0A-=0A- // If there's no output argument, special handling i= s required=0A- template<typename inputType> inline=0A- GTPInternalRespons= e type_wrapper(boost::function<void (inputType)> *callback_function, GTPCom= mand cmd){=0A- unsigned int position =3D 0;=0A- inputType arg =3D ext= ract<inputType>(cmd, position);=0A- assert(position =3D=3D cmd.GetArgume= ntCount());=0A- (*callback_function)(arg);=0A- return GTPInternalResp= onse(true, "");=0A- }=0A-=0A- // If neither... you get the idea...=0A- t= emplate<> inline=0A- GTPInternalResponse type_wrapper(boost::function<void= ()> *callback_function, GTPCommand cmd){=0A- assert(cmd.GetArgumentCoun= t() =3D=3D 0);=0A- (*callback_function)();=0A- return GTPInternalResp= onse(true, "");=0A- }=0A- /*=0A- template<typename inputType1, typename = inputType2, typename outputType> inline=0A- GTPInternalResponse type_wrapp= er(boost::function<outputType (inputType1, inputType2)> *callback_function,= GTPCommand cmd){=0A- unsigned int position =3D 0;=0A- assert (positi= on < cmd.GetArgumentCount());=0A- inputType1 arg1 =3D extract<inputType1= >(cmd, position);=0A- assert(position < cmd.GetArgumentCount());=0A- = inputType2 arg2 =3D extract<inputType2>(cmd, position);=0A- assert(posit= ion =3D=3D cmd.GetArgumentCount());=0A- return converter<outputType, GTP= InternalResponse>( (*callback_function)(arg1, arg2) );=0A- }=0A-=0A- temp= late<typename inputType1, typename inputType2> inline=0A- GTPInternalRespo= nse type_wrapper(boost::function<void (inputType1, inputType2)> *callback_f= unction, GTPCommand cmd){=0A- unsigned int position =3D 0;=0A- assert= (position < cmd.GetArgumentCount());=0A- inputType1 arg1 =3D extract<in= putType1>(cmd, position);=0A- assert(position < cmd.GetArgumentCount());= =0A- inputType2 arg2 =3D extract<inputType2>(cmd, position);=0A- asse= rt(position =3D=3D cmd.GetArgumentCount());=0A- (*callback_function)(arg= 1,arg2);=0A- return GTPInternalResponse (true, "");=0A- }=0A- */=0A-= =0A};=0A=0A-template <typename inputType, typename outputType> inline=0A-GT= PFunctionObject* GTPCommandCallBack(boost::function<outputType (inputType)>= *callback_function){=0A- GTPInternalResponse (*type_wrapper)(boost::funct= ion<outputType (inputType)>*, GTPCommand) =3D gtp_detail::type_wrapper<inpu= tType,outputType>;=0A- return new GTPFunctionObject(boost::lambda::bind(ty= pe_wrapper, callback_function, boost::lambda::_1));=0A-}=0A+#define GTP_PAR= AM_COUNT 0=0A+#include "GTPFunctionObjectTemplate.hpp"=0A+#undef GTP_PARAM= _COUNT=0A=0A-template <typename inputType> inline=0A-GTPFunctionObject* GTP= CommandCallBack(boost::function<void (inputType)> *callback_function){=0A- = GTPInternalResponse (*type_wrapper)(boost::function<void (inputType)>*, GT= PCommand) =3D gtp_detail::type_wrapper<inputType>;=0A- return new GTPFunct= ionObject(boost::lambda::bind(type_wrapper, callback_function, boost::lambd= a::_1));=0A-}=0A+#define GTP_PARAM_COUNT 1=0A+#include "GTPFunctionObjectTe= mplate.hpp"=0A+#undef GTP_PARAM_COUNT=0A=0A-template <typename outputType> = inline=0A-GTPFunctionObject* GTPCommandCallBack(boost::function<outputType = ()> *callback_function){=0A- GTPInternalResponse (*type_wrapper)(boost::fu= nction<outputType ()>*, GTPCommand) =3D gtp_detail::type_wrapper<outputType= >;=0A- return new GTPFunctionObject(boost::lambda::bind(type_wrapper, call= back_function, boost::lambda::_1));=0A-}=0A+#define GTP_PARAM_COUNT 2=0A+#i= nclude "GTPFunctionObjectTemplate.hpp"=0A+#undef GTP_PARAM_COUNT=0A=0A-temp= late <typename inputType1, typename inputType2, typename outputType>=0A-GTP= FunctionObject* GTPCommandCallBack(boost::function<outputType(inputType1, i= nputType2)> *callback_function){=0A- GTPInternalResponse (*type_wrapper)(b= oost::function<outputType (inputType1,inputType2)>*, GTPCommand) =3D gtp_de= tail::type_wrapper<inputType1, inputType2, outputType>;=0A- return new GTP= FunctionObject(boost::lambda::bind(type_wrapper, callback_function, boost::= lambda::_1));=0A-}=0A-/*=0A-template <typename inputType1, typename inputTy= pe2, typename inputType3, typename outputType>=0A-GTPFunctionObject* GTPCom= mandCallBack(boost::function<outputType(inputType1, inputType2, inputType3)= > *callback_function){=0A- GTPInternalResponse (*type_wrapper)(boost::func= tion<outputType (inputType1,inputType2,inputType3)>*, GTPCommand) =3D gtp_d= etail::type_wrapper<inputType1, inputType2, inputType3, outputType>;=0A- r= eturn new GTPFunctionObject(boost::lambda::bind(type_wrapper, callback_func= tion, boost::lambda::_1));=0A-}=0A+#define GTP_PARAM_COUNT 3=0A+#include "G= TPFunctionObjectTemplate.hpp"=0A+#undef GTP_PARAM_COUNT=0A=0A-template <typ= ename inputType1, typename inputType2, typename inputType3>=0A-GTPFunctionO= bject* GTPCommandCallBack(boost::function<void (inputType1, inputType2, inp= utType3)> *callback_function){=0A- GTPInternalResponse (*type_wrapper)(boo= st::function<void (inputType1,inputType2,inputType3)>*, GTPCommand) =3D gtp= _detail::type_wrapper<inputType1, inputType2, inputType3>;=0A- return new = GTPFunctionObject(boost::lambda::bind(type_wrapper, callback_function, boos= t::lambda::_1));=0A-}=0A-*/=0A-=0A-////////////////////////=0A-=0A-template= <typename inputType, typename outputType> inline=0A-GTPFunctionObject* GTP= CommandCallBack(outputType (*callback_function)(inputType)){=0A- return GT= PCommandCallBack(new boost::function<outputType (inputType)>(callback_funct= ion));=0A-}=0A-=0A-template <typename inputType> inline=0A-GTPFunctionObjec= t* GTPCommandCallBAck(void (*callback_function)(inputType)){=0A- return GT= PCommandCallBack(new boost::function<void (inputType)>(callback_function));= =0A-}=0A-=0A-template <typename outputType> inline=0A-GTPFunctionObject* GT= PCommandCallBack(outputType (*callback_function)()){=0A- return GTPCommand= CallBack(new boost::function<outputType ()>(callback_function));=0A-}=0A-= =0A-template <typename inputType1, typename inputType2, typename outputType= >=0A-GTPFunctionObject* GTPCommandCallBack(outputType(*callback_function)(i= nputType1, inputType2)){=0A- return GTPCommandCallBack(new boost::function= <outputType (inputType1, inputType2)>(callback_function));=0A-}=0A-=0A#endi= f=0A=0AAdded: trunk/housebot/src/gtp/GTPFunctionObjectTemplate.hpp=0A=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A--- trunk/housebot/src/gtp/= GTPFunctionObjectTemplate.hpp (rev 0)=0A+++ trun= k/housebot/src/gtp/GTPFunctionObjectTemplate.hpp 2007-02-07 00:16:24 UTC= (rev 466)=0A@@ -0,0 +1,113 @@=0A+#if GTP_PARAM_COUNT =3D=3D 0=0A+# define= GTP_OPTIONAL_COMMA=0A+#else=0A+# define GTP_OPTIONAL_COMMA ,=0A+#endif=0A= +=0A+=0A+// GTP_PARMS expands to " typename T0, typename T1, typename T2" i= f GTP_PARAM_COUNT is 3=0A+#define GTP_TEMPLATE_PARAMS BOOST_PP_ENUM_PARAMS(= GTP_PARAM_COUNT, typename T)=0A+=0A+// expands to "typename R0 , typename T= 0, typename T1, typename T2" if GTP_PARAM_COUNT is 3=0A+#define GTP_FULL_TE= MPLATE_PARAMS typename R0 GTP_OPTIONAL_COMMA GTP_TEMPLATE_PARAMS=0A+=0A+// = GTP_PARAM expands to " T3 a3" if INDEX is 3=0A+#define GTP_PARAM(UNKNOWN1,I= NDEX,UNKNOWN2) BOOST_PP_CAT(T,I) BOOST_PP_CAT(a,I)=0A+=0A+// GTP_PARAMS exp= ands to " T0 a0, T1 a1, T2 a2" if GTP_PARAM_COUNT is 3=0A+#define GTP_PARAM= S BOOST_PP_ENUM(GTP_PARAM_COUNT,GTP_PARAM,BOOST_PP_EMPTY)=0A+=0A+// GTP_PAR= AM_TYPES expands to " T0, T1, T2" if GTP_PARAM_COUNT is 3=0A+#define GTP_PA= RAM_TYPES BOOST_PP_ENUM_PARAMS(GTP_PARAM_COUNT, T)=0A+=0A+// expands to "R0= , T0, T1, T2" if GTP_PARAM_COUNT is 3=0A+#define GTP_FULL_PARAM_TYPES R0 G= TP_OPTIONAL_COMMA GTP_PARAM_TYPES=0A+=0A+// GTP_PARAM_NAMES expands to " a0= , a1, a2" if GTP_PARAM_COUNT is 3=0A+#define GTP_PARAM_NAMES BOOST_PP_ENUM_= PARAMS(GTP_PARAM_COUNT, a)=0A+=0A+// expands to "boost::function3 < R0 , T= 0, T1, T2 >" when GTP_PARAM_COUNT is 3=0A+#define GTP_BOOST_FUNCTION BOOST_= PP_CAT(boost::function,GTP_PARAM_COUNT) < GTP_FULL_PARAM_TYPES >=0A+=0A+// = expands to "boost::function3 < void , T0, T1, T2 >" when GTP_PARAM_COUNT i= s 3=0A+#define GTP_BOOST_FUNCTION_VOID BOOST_PP_CAT(boost::function,GTP_PAR= AM_COUNT) < void GTP_OPTIONAL_COMMA GTP_PARAM_TYPES >=0A+=0A+// expands to = type_wrapper3 when GTP_PARAM_COUNT is 3=0A+#define GTP_TYPE_WRAPPER BOOST_P= P_CAT(type_wrapper,GTP_PARAM_COUNT)=0A+=0A+////////////////////////////////= //////////////////////////////=0A+// gtp_detail::type_wrapper for convertin= g all input arguments=0A+namespace gtp_detail{=0A+=0A+ template < GTP_FULL= _TEMPLATE_PARAMS >=0A+ struct GTP_TYPE_WRAPPER{=0A+ static GTPInternalR= esponse wrap(GTP_BOOST_FUNCTION *(callback_function), GTPCommand cmd){=0A+ = unsigned int position =3D 0;=0A+ /// \bug Must figure out how to = auto generate this repetative body=0A+#if GTP_PARAM_COUNT >=3D 1=0A+ a= ssert(position < cmd.GetArgumentCount());=0A+ T0 a0 =3D extract<T0>(cm= d, position);=0A+#endif=0A+#if GTP_PARAM_COUNT >=3D 2=0A+ assert(posit= ion < cmd.GetArgumentCount());=0A+ T1 a1 =3D extract<T1>(cmd,position)= ;=0A+#endif=0A+#if GTP_PARAM_COUNT >=3D 3=0A+ assert(position < cmd.Ge= tArgumentCount());=0A+ T2 a2 =3D extract<T2>(cmd,position);=0A+#endif= =0A+ assert(position =3D=3D cmd.GetArgumentCount());=0A+ return c= onverter<R0, GTPInternalResponse>( (*callback_function)(GTP_PARAM_NAMES) );= =0A+ }=0A+ };=0A+=0A+ template < GTP_TEMPLATE_PARAMS >=0A+ struct GTP= _TYPE_WRAPPER < void GTP_OPTIONAL_COMMA GTP_PARAM_TYPES >{=0A+ static GT= PInternalResponse wrap(GTP_BOOST_FUNCTION_VOID *(callback_function), GTPCom= mand cmd){=0A+ unsigned int position =3D 0;=0A+ /// \bug Must fig= ure out how to auto generate this repetative body=0A+#if GTP_PARAM_COUNT >= =3D 1=0A+ assert(position < cmd.GetArgumentCount());=0A+ T0 a0 = =3D extract<T0>(cmd, position);=0A+#endif=0A+#if GTP_PARAM_COUNT >=3D 2=0A+= assert(position < cmd.GetArgumentCount());=0A+ T1 a1 =3D extract= <T1>(cmd,position);=0A+#endif=0A+#if GTP_PARAM_COUNT >=3D 3=0A+ assert= (position < cmd.GetArgumentCount());=0A+ T2 a2 =3D extract<T2>(cmd,pos= ition);=0A+#endif=0A+ assert(position =3D=3D cmd.GetArgumentCount());= =0A+ (*callback_function)(GTP_PARAM_NAMES);=0A+ return GTPInterna= lResponse();=0A+ }=0A+ };=0A+=0A+};=0A+=0A+////////////////////////////= ///////////////////////////=0A+// GTPCommandCallBack accepting a boost func= tion object=0A+=0A+// expands to GTPFunctionObject3 when GTP_PARAM_COUNT is= 3=0A+#define GTP_COMMAND_CALLBACK BOOST_PP_CAT(GTPCommandCallBack,GTP_PARA= M_COUNT)=0A+=0A+template< GTP_FULL_TEMPLATE_PARAMS > inline=0A+GTPFunctionO= bject* GTP_COMMAND_CALLBACK(GTP_BOOST_FUNCTION *callback_function){=0A+ re= turn new GTPFunctionObject(boost::lambda::bind((>p_detail::GTP_TYPE_WRAPP= ER<GTP_FULL_PARAM_TYPES>::wrap), callback_function, boost::lambda::_1));=0A= +}=0A+=0A+///////////////////////////////////////////////////////=0A+// Cle= anup=0A+=0A+#undef GTP_OPTIONAL_COMMA=0A+#undef GTP_TEMPLATE_PARAMS=0A+#und= ef GTP_FULL_TEMPLATE_PARAMS=0A+#undef GTP_PARAM=0A+#undef GTP_PARAMS=0A+#un= def GTP_PARAM_TYPES=0A+#undef GTP_PARAM_NAMES=0A+#undef GTP_BOOST_FUNCTION= =0A+#undef GTP_BOOST_FUNCTION_VOID=0A+#undef GTP_TYPE_WRAPPER=0A+#undef GTP= _COMMAND_CALLBACK=0A=0AModified: trunk/housebot/src/housebot.cpp=0A=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A--- trunk/housebot/src/hous= ebot.cpp 2007-02-07 00:15:28 UTC (rev 465)=0A+++ trunk/housebot/src/hous= ebot.cpp 2007-02-07 00:16:24 UTC (rev 466)=0A@@ -83,10 +83,10 @@=0A=0A = the_collective.register_gtp(lGTPGoBoard);=0A=0A- lGTPGoBoard.RegisterComm= and("name", GTPCommandCallBack(name));=0A- lGTPGoBoard.RegisterCo= mmand("version", GTPCommandCallBack(version));=0A- lGTPGoBoard.Regis= terCommand("kgs-game_over", GTPCommandCallBack(consider_shutdown));=0A- lG= TPGoBoard.RegisterCommand("kgs-chat", GTPCommandCallBack(chat));=0A+ = lGTPGoBoard.RegisterCommand("name", GTPCommandCallBack0(new boost:= :function0<std::string>(name)));=0A+ lGTPGoBoard.RegisterCommand("version"= , GTPCommandCallBack0(new boost::function0<std::string>(version)));= =0A+ lGTPGoBoard.RegisterCommand("kgs-game_over", GTPCommandCallBack0(new = boost::function0<void>(consider_shutdown)));=0A+ lGTPGoBoard.RegisterComma= nd("kgs-chat", GTPCommandCallBack1(new boost::function1<std::string,st= d::list<std::string> >(chat)));=0A=0A GTPCommStream lComm(&std::cin,&std:= :cout);=0A GTPEngine lGTPEngine(lGTPGoBoard, lComm);=0A=0A=0AThis was sen= t by the SourceForge.net collaborative development platform, the world's la= rgest Open Source development site.=0A=0A----------------------------------= ---------------------------------------=0AUsing Tomcat but need to do more?= Need to support web services, security?=0AGet stuff done quickly with pre-= integrated technology to make your job easier.=0ADownload IBM WebSphere App= lication Server v.1.0.1 based on Apache Geronimo=0Ahttp://sel.as-us.falkag.= net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat=3D121642=0A________________= _______________________________=0AHousebot-developers mailing list=0AHouseb= ot-...@li...=0Ahttps://lists.sourceforge.net/lists/l= istinfo/housebot-developers=0A=0A=0A---------------------------------------= ----------------------------------=0AUsing Tomcat but need to do more? Need= to support web services, security?=0AGet stuff done quickly with pre-integ= rated technology to make your job easier.=0ADownload IBM WebSphere Applicat= ion Server v.1.0.1 based on Apache Geronimo=0Ahttp://sel.as-us.falkag.net/s= el?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat=3D121642=0A_____________________= __________________________=0AHousebot-developers mailing list=0AHousebot-de= vel...@li...=0Ahttps://lists.sourceforge.net/lists/listin= fo/housebot-developers |