Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

pgsigconvert.h

Go to the documentation of this file.
00001 /*
00002         libSigCX -libSigC++ Extras 
00003  
00004  
00005 Distribution of library and components is under the LGPL as listed in the
00006 file COPYING.  Examples and tests are Public Domain.
00007  
00008 Contact info:
00009   Maintainer:   mailto: rottmann@users.sourceforge.net
00010   Mailing List: mailto: libsigx-main@lists.sourceforge.net
00011   Homepage:     http://libsigx.sourceforge.net
00012   Download:     http://sourceforge.net/project/showfiles.php?group_id=58659
00013 */
00014 
00015 #ifndef   SIGC_CONVERT_H
00016 #define   SIGC_CONVERT_H
00017 #include <sigc++/adaptor.h>
00018 #include "SDL.h"
00019 
00020 /*
00021   SigC::convert
00022   -------------
00023   convert() alters a Slot by assigning a conversion function 
00024   which can completely alter the parameter types of a slot. 
00025  
00026   Only convert functions for changing with same number of
00027   arguments is compiled by default.
00028  
00029   Sample usage:
00030     int my_string_to_char(Slot2<int,const char*> &d,const string &s)
00031     int f(const char*);
00032     string s=hello;
00033  
00034  
00035     Slot1<int,const string &>  s2=convert(slot(&f),my_string_to_char);
00036     s2(s);  
00037  
00038 */
00039 
00040 #ifdef SIGC_CXX_NAMESPACES
00041 namespace SigCX {
00042 #endif
00043 
00044 // (internal)
00045 struct AdaptorConvertSlotNode : public SigC::AdaptorSlotNode {
00046         SigC::FuncPtr convert_func_;
00047 
00048         AdaptorConvertSlotNode(SigC::FuncPtr proxy, const SigC::Node& s, SigC::FuncPtr dtor);
00049 
00050         virtual ~AdaptorConvertSlotNode();
00051 };
00052 
00053 
00054 
00055 
00056 
00057 template <class R,class T>
00058 struct AdaptorConvertSlot0_ {
00059         typedef typename SigC::Trait<R>::type RType;
00060         typedef R (*ConvertFunc)(T&);
00061         static RType proxy(void *data) {
00062                 AdaptorConvertSlotNode& node=*(AdaptorConvertSlotNode*)(data);
00063                 T &slot_=(T&)(node.slot_);
00064                 return ((ConvertFunc)(node.convert_func_))
00065                        (slot_);
00066         }
00067 };
00068 
00069 template <class R,class T>
00070 SigC::Slot0<R>
00071 convert(const T& slot_, R (*convert_func)(T&)) {
00072         return new AdaptorConvertSlotNode((SigC::FuncPtr)(&AdaptorConvertSlot0_<R,T>::proxy),
00073                                           slot_,
00074                                           (SigC::FuncPtr)(convert_func));
00075 }
00076 
00077 
00078 template <class R,class P1,class T>
00079 struct AdaptorConvertSlot1_ {
00080         typedef typename SigC::Trait<R>::type RType;
00081         typedef R (*ConvertFunc)(T&,P1);
00082         static RType proxy(typename SigC::Trait<P1>::ref p1,void *data) {
00083                 AdaptorConvertSlotNode& node=*(AdaptorConvertSlotNode*)(data);
00084                 T &slot_=(T&)(node.slot_);
00085                 return ((ConvertFunc)(node.convert_func_))
00086                        (slot_,p1);
00087         }
00088 };
00089 
00090 template <class R,class P1,class T>
00091 SigC::Slot1<R,P1>
00092 convert(const T& slot_, R (*convert_func)(T&,P1)) {
00093         return new AdaptorConvertSlotNode((SigC::FuncPtr)(&AdaptorConvertSlot1_<R,P1,T>::proxy),
00094                                           slot_,
00095                                           (SigC::FuncPtr)(convert_func));
00096 }
00097 
00098 
00099 template <class R,class P1,class P2,class T>
00100 struct AdaptorConvertSlot2_ {
00101         typedef typename SigC::Trait<R>::type RType;
00102         typedef R (*ConvertFunc)(T&,P1,P2);
00103         static RType proxy(typename SigC::Trait<P1>::ref p1,typename SigC::Trait<P2>::ref p2,void *data) {
00104                 AdaptorConvertSlotNode& node=*(AdaptorConvertSlotNode*)(data);
00105                 T &slot_=(T&)(node.slot_);
00106                 return ((ConvertFunc)(node.convert_func_))
00107                        (slot_,p1,p2);
00108         }
00109 };
00110 
00111 template <class R,class P1,class P2,class T>
00112 SigC::Slot2<R,P1,P2>
00113 convert(const T& slot_, R (*convert_func)(T&,P1,P2)) {
00114         return new AdaptorConvertSlotNode((SigC::FuncPtr)(&AdaptorConvertSlot2_<R,P1,P2,T>::proxy),
00115                                           slot_,
00116                                           (SigC::FuncPtr)(convert_func));
00117 }
00118 
00119 
00120 template <class R,class P1,class P2,class P3,class T>
00121 struct AdaptorConvertSlot3_ {
00122         typedef typename SigC::Trait<R>::type RType;
00123         typedef R (*ConvertFunc)(T&,P1,P2,P3);
00124         static RType proxy(typename SigC::Trait<P1>::ref p1,typename SigC::Trait<P2>::ref p2,typename SigC::Trait<P3>::ref p3,void *data) {
00125                 AdaptorConvertSlotNode& node=*(AdaptorConvertSlotNode*)(data);
00126                 T &slot_=(T&)(node.slot_);
00127                 return ((ConvertFunc)(node.convert_func_))
00128                        (slot_,p1,p2,p3);
00129         }
00130 };
00131 
00132 template <class R,class P1,class P2,class P3,class T>
00133 SigC::Slot3<R,P1,P2,P3>
00134 convert(const T& slot_, R (*convert_func)(T&,P1,P2,P3)) {
00135         return new AdaptorConvertSlotNode((SigC::FuncPtr)(&AdaptorConvertSlot3_<R,P1,P2,P3,T>::proxy),
00136                                           slot_,
00137                                           (SigC::FuncPtr)(convert_func));
00138 }
00139 
00140 
00141 template <class R,class P1,class P2,class P3,class P4,class T>
00142 struct AdaptorConvertSlot4_ {
00143         typedef typename SigC::Trait<R>::type RType;
00144         typedef R (*ConvertFunc)(T&,P1,P2,P3,P4);
00145         static RType proxy(typename SigC::Trait<P1>::ref p1,typename SigC::Trait<P2>::ref p2,typename SigC::Trait<P3>::ref p3,typename SigC::Trait<P4>::ref p4,void *data) {
00146                 AdaptorConvertSlotNode& node=*(AdaptorConvertSlotNode*)(data);
00147                 T &slot_=(T&)(node.slot_);
00148                 return ((ConvertFunc)(node.convert_func_))
00149                        (slot_,p1,p2,p3,p4);
00150         }
00151 };
00152 
00153 template <class R,class P1,class P2,class P3,class P4,class T>
00154 SigC::Slot4<R,P1,P2,P3,P4>
00155 convert(const T& slot_, R (*convert_func)(T&,P1,P2,P3,P4)) {
00156         return new AdaptorConvertSlotNode((SigC::FuncPtr)(&AdaptorConvertSlot4_<R,P1,P2,P3,P4,T>::proxy),
00157                                           slot_,
00158                                           (SigC::FuncPtr)(convert_func));
00159 }
00160 
00161 
00162 template <class R,class P1,class P2,class P3,class P4,class P5,class T>
00163 struct AdaptorConvertSlot5_ {
00164         typedef typename SigC::Trait<R>::type RType;
00165         typedef R (*ConvertFunc)(T&,P1,P2,P3,P4,P5);
00166         static RType proxy(typename SigC::Trait<P1>::ref p1,typename SigC::Trait<P2>::ref p2,typename SigC::Trait<P3>::ref p3,typename SigC::Trait<P4>::ref p4,typename SigC::Trait<P5>::ref p5,void *data) {
00167                 AdaptorConvertSlotNode& node=*(AdaptorConvertSlotNode*)(data);
00168                 T &slot_=(T&)(node.slot_);
00169                 return ((ConvertFunc)(node.convert_func_))
00170                        (slot_,p1,p2,p3,p4,p5);
00171         }
00172 };
00173 
00174 template <class R,class P1,class P2,class P3,class P4,class P5,class T>
00175 SigC::Slot5<R,P1,P2,P3,P4,P5>
00176 convert(const T& slot_, R (*convert_func)(T&,P1,P2,P3,P4,P5)) {
00177         return new AdaptorConvertSlotNode((SigC::FuncPtr)(&AdaptorConvertSlot5_<R,P1,P2,P3,P4,P5,T>::proxy),
00178                                           slot_,
00179                                           (SigC::FuncPtr)(convert_func));
00180 }
00181 
00182 
00183 template <class R,class P1,class P2,class P3,class P4,class P5,class P6,class T>
00184 struct AdaptorConvertSlot6_ {
00185         typedef typename SigC::Trait<R>::type RType;
00186         typedef R (*ConvertFunc)(T&,P1,P2,P3,P4,P5,P6);
00187         static RType proxy(typename SigC::Trait<P1>::ref p1,typename SigC::Trait<P2>::ref p2,typename SigC::Trait<P3>::ref p3,typename SigC::Trait<P4>::ref p4,typename SigC::Trait<P5>::ref p5,typename SigC::Trait<P6>::ref p6,void *data) {
00188                 AdaptorConvertSlotNode& node=*(AdaptorConvertSlotNode*)(data);
00189                 T &slot_=(T&)(node.slot_);
00190                 return ((ConvertFunc)(node.convert_func_))
00191                        (slot_,p1,p2,p3,p4,p5,p6);
00192         }
00193 };
00194 
00195 template <class R,class P1,class P2,class P3,class P4,class P5,class P6,class T>
00196 SigC::Slot6<R,P1,P2,P3,P4,P5,P6>
00197 convert(const T& slot_, R (*convert_func)(T&,P1,P2,P3,P4,P5,P6)) {
00198         return new AdaptorConvertSlotNode((SigC::FuncPtr)(&AdaptorConvertSlot6_<R,P1,P2,P3,P4,P5,P6,T>::proxy),
00199                                           slot_,
00200                                           (SigC::FuncPtr)(convert_func));
00201 }
00202 
00203 
00204 
00205 #ifdef SIGC_CXX_NAMESPACES
00206 }
00207 #endif
00208 
00209 
00210 
00211 #endif // SIGC_CONVERT_H

Generated on Tue Jun 24 01:27:49 2008 for Advanced Strategic Command by  doxygen 1.4.2