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

uslot.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/uslot.hpp 00008 begin : Thu Jul 18 2002 00009 $Id: uslot.hpp,v 1.14 2005/09/30 12:36:27 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 #ifndef USLOT_HPP 00029 #define USLOT_HPP 00030 00031 // ripped from sigc++/slot.h (created by m4 macro) 00032 // Copyright 2000, Karl Einar Nelson 00033 00034 #include "../ufo_global.hpp" 00035 #include "../utrait.hpp" 00036 #include "../usharedptr.hpp" 00037 00038 namespace ufo { 00039 00040 // implementation 00041 typedef void (*ProxyPtr)(void*); 00042 typedef void (*FuncPtr)(void*); 00043 00044 struct UFO_EXPORT USlotNode { 00045 USlotNode() : m_died(false) {} 00046 USlotNode(FuncPtr proxy) : _proxy(proxy), m_died(false) {} 00047 virtual ~USlotNode() {} 00048 00049 // message from child that it has died and we should start 00050 // our shut down. If from_child is true, we do not need 00051 // to clean up the child links. 00052 virtual void notify(bool /* from_child */) { 00053 m_died = true; 00054 } 00055 virtual bool died() { return m_died; } 00056 00057 virtual bool equals(const USlotNode * /* node */) const { return false; } 00058 00059 bool connected() { return _proxy != NULL; } 00060 00061 public: // Public attributes 00065 ProxyPtr _proxy; 00066 private: // Private attributes 00067 bool m_died; 00068 }; 00069 00074 class UFO_EXPORT USlotBase { 00075 public: 00076 USlotBase() : _node(0) {} 00077 USlotBase(USlotNode * node) : _node(node) {} 00078 ~USlotBase() {} 00079 00081 USlotNode * node() { return _node; } 00082 const USlotNode * node() const { return _node; } 00083 00084 bool operator ==(const USlotBase & slot) const { 00085 //return (*_impl == *(slot._impl)); 00086 return _node->equals(slot._node); 00087 } 00088 bool equals(const USlotBase * slot) const { 00089 return _node->equals(slot->_node); 00090 } 00091 00092 void assign(USlotNode * node) { 00093 _node = node; 00094 } 00095 00096 private: 00098 USharedPtr<USlotNode> _node; 00099 }; 00100 00101 00102 // 00103 // only void returns are supported 00104 // 00105 00106 class UFO_EXPORT USlot0 : public USlotBase { 00107 public: 00108 //typedef typename Trait<R>::type RType; 00109 typedef void (*Callback)(); 00110 typedef void (*Proxy)(void*); 00111 00112 void operator()() { 00113 if (!node()) return; 00114 //if (!node_->valid()) { clear(); return RType(); } 00115 ((Proxy)(node()->_proxy))(node()); 00116 } 00117 00118 USlot0(USlotNode * node = NULL) : USlotBase(node) {} 00119 }; 00120 00121 template <typename P1> 00122 class UFO_EXPORT USlot1 : public USlotBase { 00123 public: 00124 typedef void (*Proxy)(typename UTrait<P1>::ref, void*); 00125 00126 void operator ()(typename UTrait<P1>::ref p1) { 00127 if (!node()) return; 00128 //if (!node_->valid()) { clear(); return RType(); } 00129 ((Proxy)(node()->_proxy))(p1, node()); 00130 } 00131 00132 USlot1(USlotNode * node = NULL) : USlotBase(node) {} 00133 }; 00134 00135 template <typename P1, typename P2> 00136 class UFO_EXPORT USlot2 : public USlotBase { 00137 public: 00138 typedef void (*Proxy)(typename UTrait<P1>::ref, typename UTrait<P2>::ref, void*); 00139 00140 void operator ()(typename UTrait<P1>::ref p1, typename UTrait<P2>::ref p2) { 00141 if (!node()) return; 00142 //if (!node_->valid()) { clear(); return RType(); } 00143 ((Proxy)(node()->_proxy))(p1, p2, node()); 00144 } 00145 00146 USlot2(USlotNode * node = NULL) : USlotBase(node) {} 00147 }; 00148 00149 00150 template <typename P1, typename P2, typename P3> 00151 class UFO_EXPORT USlot3 : public USlotBase { 00152 public: 00153 typedef void (*Proxy)(typename UTrait<P1>::ref, typename UTrait<P2>::ref, 00154 typename UTrait<P3>::ref, void*); 00155 00156 void operator ()(typename UTrait<P1>::ref p1, typename UTrait<P2>::ref p2, 00157 typename UTrait<P3>::ref p3) { 00158 if (!node()) return; 00159 //if (!node_->valid()) { clear(); return RType(); } 00160 ((Proxy)(node()->_proxy))(p1, p2, p3, node()); 00161 } 00162 00163 USlot3(USlotNode * node = NULL) : USlotBase(node) {} 00164 }; 00165 00166 00167 template <typename P1, typename P2, typename P3, typename P4> 00168 class UFO_EXPORT USlot4 : public USlotBase { 00169 public: 00170 typedef void (*Proxy)(typename UTrait<P1>::ref, typename UTrait<P2>::ref, 00171 typename UTrait<P3>::ref, typename UTrait<P4>::ref, void*); 00172 00173 void operator ()(typename UTrait<P1>::ref p1, typename UTrait<P2>::ref p2, 00174 typename UTrait<P3>::ref p3, typename UTrait<P4>::ref p4) { 00175 if (!node()) return; 00176 //if (!node_->valid()) { clear(); return RType(); } 00177 ((Proxy)(node()->_proxy))(p1, p2, p3, p4, node()); 00178 } 00179 00180 USlot4(USlotNode * node = NULL) : USlotBase(node) {} 00181 }; 00182 00183 } // namespace ufo 00184 00185 #endif // USLOT_HPP

The libUFO Project - written by Johannes Schmidt