- Your Widget Set For OpenGL
Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | Related Pages

ufunctionslot.hpp

00001 /*************************************************************************** 00002 LibUFO - UI For OpenGL 00003 copyright : (C) 2001-2005 by Johannes Schmidt 00004 email : schmidtjf at users.sourceforge.net 00005 ------------------- 00006 00007 file : include/ufo/signals/ufunctionslots.hpp 00008 begin : Thu Jul 18 2002 00009 $Id: ufunctionslot.hpp,v 1.9 2005/02/13 17:49:29 schmidtjf Exp $ 00010 ***************************************************************************/ 00011 00012 /*************************************************************************** 00013 * This library is free software; you can redistribute it and/or * 00014 * modify it under the terms of the GNU Lesser General Public * 00015 * License as published by the Free Software Foundation; either * 00016 * version 2.1 of the License, or (at your option) any later version. * 00017 * * 00018 * This library is distributed in the hope that it will be useful, * 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00021 * Lesser General Public License for more details. * 00022 * * 00023 * You should have received a copy of the GNU Lesser General Public * 00024 * License along with this library; if not, write to the Free Software * 00025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 00026 ***************************************************************************/ 00027 00028 // ripped from sigc++/slot.h 00029 // Copyright 2000, Karl Einar Nelson 00030 00031 #ifndef UFUNCTIONSLOTS_HPP 00032 #define UFUNCTIONSLOTS_HPP 00033 00034 #include "uslot.hpp" 00035 00036 namespace ufo { 00037 00038 struct UFuncSlotNode : public USlotNode { 00039 FuncPtr _func; 00040 UFuncSlotNode(ProxyPtr proxy, FuncPtr func) : USlotNode(proxy), _func(func) {} 00041 virtual ~UFuncSlotNode() {} 00042 00043 virtual bool equals(const USlotNode * node) const { 00044 if (const UFuncSlotNode * fnode = dynamic_cast<const UFuncSlotNode*>(node)) { 00045 return (_func == fnode->_func); 00046 } else { 00047 return false; 00048 } 00049 } 00050 }; 00051 00052 // 00053 // 0 params 00054 // 00055 00056 struct UFuncSlot0 { 00057 typedef void (*Callback)(); 00058 00059 static void proxy(void *s) { 00060 ((Callback)(((UFuncSlotNode*)s)->_func))(); 00061 } 00062 }; 00063 00064 inline USlot0 slot(void (*func)()) { 00065 return new UFuncSlotNode((ProxyPtr) &UFuncSlot0::proxy, (FuncPtr) func); 00066 } 00067 00068 // 00069 // 1 param 00070 // 00071 00072 template <typename P1> 00073 struct UFuncSlot1 { 00074 typedef void (*Callback)(P1 p1); 00075 00076 static void proxy(typename UTrait<P1>::ref p1, void *s) { 00077 ((Callback)(((UFuncSlotNode*)s)->_func))(p1); 00078 } 00079 }; 00080 00081 template <typename P1> 00082 USlot1<P1> slot(void (*func)(P1)) { 00083 return new UFuncSlotNode((ProxyPtr) &UFuncSlot1<P1>::proxy, (FuncPtr) func); 00084 } 00085 00086 00087 // 00088 // 2 params 00089 // 00090 00091 template <typename P1, typename P2> 00092 struct UFuncSlot2 { 00093 typedef void (*Callback)(P1 p1, P2 p2); 00094 00095 static void proxy( 00096 typename UTrait<P1>::ref p1, 00097 typename UTrait<P2>::ref p2, 00098 void *s) { 00099 ((Callback)(((UFuncSlotNode*)s)->_func))(p1, p2); 00100 } 00101 }; 00102 00103 template <typename P1, typename P2> 00104 USlot2<P1, P2> slot(void (*func)(P1, P2)) { 00105 return new UFuncSlotNode((ProxyPtr) &UFuncSlot2<P1, P2>::proxy, (FuncPtr) func); 00106 } 00107 00108 00109 00110 // 00111 // 3 params 00112 // 00113 00114 template <typename P1, typename P2, typename P3> 00115 struct UFuncSlot3 { 00116 typedef void (*Callback)(P1 p1, P2 p2, P3 p3); 00117 00118 static void proxy( 00119 typename UTrait<P1>::ref p1, 00120 typename UTrait<P2>::ref p2, 00121 typename UTrait<P3>::ref p3, 00122 void *s) { 00123 ((Callback)(((UFuncSlotNode*)s)->_func))(p1, p2, p3); 00124 } 00125 }; 00126 00127 template <typename P1, typename P2, typename P3> 00128 USlot3<P1, P2, P3> slot(void (*func)(P1, P2, P3)) { 00129 return new UFuncSlotNode((ProxyPtr) &UFuncSlot3<P1, P2, P3>::proxy, (FuncPtr) func); 00130 } 00131 00132 00133 // 00134 // 4 params 00135 // 00136 00137 template <typename P1, typename P2, typename P3, typename P4> 00138 struct UFuncSlot4 { 00139 typedef void (*Callback)(P1 p1, P2 p2, P3 p3, P4 p4); 00140 00141 static void proxy( 00142 typename UTrait<P1>::ref p1, 00143 typename UTrait<P2>::ref p2, 00144 typename UTrait<P3>::ref p3, 00145 typename UTrait<P4>::ref p4, 00146 void *s) { 00147 ((Callback)(((UFuncSlotNode*)s)->_func))(p1, p2, p3, p4); 00148 } 00149 }; 00150 00151 template <typename P1, typename P2, typename P3, typename P4> 00152 USlot4<P1, P2, P3, P4> slot(void (*func)(P1, P2, P3, P4)) { 00153 return new UFuncSlotNode((ProxyPtr) &UFuncSlot4<P1, P2, P3, P4>::proxy, (FuncPtr) func); 00154 } 00155 00156 } // namespace ufo 00157 00158 #endif // UFUNCTIONSLOTS_HPP

The libUFO Project - written by Johannes Schmidt