|
libpsynth 0.2.1
|
00001 00014 /* 00015 * Copyright (C) 2009 Juan Pedro BolĂvar Puente 00016 * 00017 * This file is part of Psychosynth. 00018 * 00019 * Psychosynth is free software: you can redistribute it and/or modify 00020 * it under the terms of the GNU General Public License as published by 00021 * the Free Software Foundation, either version 3 of the License, or 00022 * (at your option) any later version. 00023 * 00024 * Psychosynth is distributed in the hope that it will be useful, 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00027 * GNU General Public License for more details. 00028 * 00029 * You should have received a copy of the GNU General Public License 00030 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00031 * 00032 */ 00033 00034 #ifndef PSYNTH_OBSERVER_H_ 00035 #define PSYNTH_OBSERVER_H_ 00036 00037 #include <boost/bind.hpp> 00038 #include <boost/signal.hpp> 00039 #include <boost/signals/trackable.hpp> 00040 00041 namespace psynth 00042 { 00043 namespace base 00044 { 00045 00046 #if 0 00047 00051 template <typename ...Types> 00052 class signal : public sigc::signal <Types...> { }; 00053 #endif 00054 00063 class listener_base : public boost::signals::trackable 00064 { 00065 public: 00067 virtual ~listener_base () 00068 {} 00069 00079 void disconnect_all () 00080 { 00081 listener_base empty; 00082 boost::signals::trackable::operator= (empty); 00083 } 00084 00085 protected: 00086 }; 00087 00094 template <class Listener> 00095 class subject_base 00096 { 00097 public: 00099 virtual ~subject_base () 00100 {} 00101 00107 virtual void add_listener (Listener& l) = 0; 00108 00113 virtual void del_listener (Listener& l) = 0; 00114 00115 protected: 00126 template <class Signal, class Slot> 00127 void remove_slot (Signal& sig, const Slot& s); 00128 }; 00129 00130 template <class Listener> 00131 template <class Signal, class Slot> 00132 void subject_base<Listener>::remove_slot (Signal& sig, 00133 const Slot& s) 00134 { 00135 sig.disconnect (s); 00136 } 00137 00138 } /* namespace base */ 00139 } /* namespace psynth */ 00140 00141 #endif /* PSYNTH_OBSERVER_H_ */
1.7.4