nsignal1.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 NSIGNAL1_HPP
00023 #define NSIGNAL1_HPP
00024 
00034 template <typename Param1>
00035 class NSignal1: public NEvent1<Param1> {
00036       typedef NMap<int, NSlotBase1<Param1> *> SlotHandlersMap;
00037       
00038       public:
00042             NSignal1();
00043             
00047             ~NSignal1();
00048 
00053             bool connect(NSlotBase1<Param1>* slot);
00054 
00058             bool emit_sig(Param1 param) const;
00059 
00060       private:
00061             SlotHandlersMap m_slots;
00062 };
00063 
00064 
00065 template <typename Param1>
00066 NSignal1<Param1>::NSignal1(void)
00067       : m_slots()
00068 {
00069 }
00070 
00071 
00072 // disconnect all connected slots
00073 template <typename Param1>
00074 NSignal1<Param1>::~NSignal1(void) {
00075       for(typename SlotHandlersMap::iterator it = m_slots.begin(); 
00076                it != m_slots.end(); 
00077                it++)
00078       {
00079             if(isAttached(it.key())) {
00080                   it.value()->disconnect();
00081             }
00082       }
00083 }
00084 
00085 // connect slot to the signal
00086 template <typename Param1>
00087 bool NSignal1<Param1>::connect(NSlotBase1<Param1>* slot) {
00088       int handle = -1;
00089       
00090       if (!slot) { 
00091             return false;
00092       }
00093       
00094       handle = slot->connect(this);
00095       m_slots.insert(handle, slot);
00096       
00097       return true;
00098 }
00099 
00100       
00101 template <typename Param1>
00102 bool NSignal1<Param1>::emit_sig(Param1 param) const {
00103       notify(param);
00104       return true;
00105 }
00106 
00107 #endif // NSIGNAL1_HPP

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