nslot1.hpp

Go to the documentation of this file.
00001 // LICENSE: (Please see the file COPYING for details)
00002 //
00003 // NUS - Nemesis Utilities System: A C++ application development framework 
00004 // Copyright (C) 2006, 2008 Otavio Rodolfo Piske
00005 //
00006 //  This file is part of NUS
00007 //
00008 //  This library is free software; you can redistribute it and/or
00009 //  modify it under the terms of the GNU Lesser General Public
00010 //  License as published by the Free Software Foundation version 2.1
00011 //  of the License.
00012 //
00013 //  This library is distributed in the hope that it will be useful,
00014 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 //  Lesser General Public License for more details.
00017 //
00018 //  You should have received a copy of the GNU Lesser General Public
00019 //  License along with this library; if not, write to the Free Software
00020 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00021 //
00022 #ifndef NSLOT1_HPP
00023 #define NSLOT1_HPP
00024 
00035 template <typename ParamT>
00036 class NSlotBase1 {
00037       public:
00041             virtual ~NSlotBase1(void) {};
00042             
00048             virtual int connect(NEvent1<ParamT>* event) = 0;
00049             
00053             virtual void disconnect() = 0;
00054 };
00055 
00056 
00062 template <typename ListenerT, typename ParamT>
00063 class NSlot1: public NSlotBase1<ParamT> {
00064       public:
00065       
00066             typedef void (ListenerT::*PtrMember)(ParamT);  
00073             NSlot1(ListenerT* object, PtrMember member);
00074             
00078             ~NSlot1();
00079       
00080             
00086             int connect(NEvent1<ParamT>* event);
00087             
00091             void disconnect();
00092 
00093       private:
00094             ListenerT* m_object;
00095             PtrMember m_member;
00096 
00097             NEventId m_handle;
00098             NEvent1<ParamT>* m_cpp_event;
00099       
00100             NSlot1(const NSlot1<ListenerT, ParamT> &other);
00101             NSlot1<ListenerT, ParamT> 
00102                         operator=(const NSlot1<ListenerT, ParamT> &other);
00103 };
00104 
00105 
00106 template <typename ListenerT, typename ParamT>
00107 NSlot1<ListenerT, ParamT>::NSlot1(ListenerT* object, PtrMember member)
00108             : m_object(object), 
00109             m_member(member),
00110             m_handle(0), 
00111             m_cpp_event(NULL)
00112 {
00113       assert(object && member);
00114 }
00115 
00116 
00117 template <typename ListenerT, typename ParamT>
00118 NSlot1<ListenerT, ParamT>::~NSlot1() {
00119       
00120       if(m_cpp_event != NULL) {
00121             m_cpp_event->detach(m_handle);
00122       }
00123 }
00124 
00125 
00126 template <typename ListenerT, typename ParamT>
00127 int NSlot1<ListenerT, ParamT>::connect(NEvent1<ParamT>* event) {
00128       m_cpp_event = event;
00129       m_handle = event->attach(m_object, m_member);
00130             
00131       return m_handle;
00132 }
00133 
00134 
00135 template <typename ListenerT, typename ParamT>
00136 void NSlot1<ListenerT, ParamT>::disconnect() {
00137       m_cpp_event = NULL;
00138 }
00139 
00140 #endif // NSLOT1_HPP

Generated on Wed Mar 5 23:10:36 2008 for NemesisUtilitiesSystem by  doxygen 1.5.4