00001 /* 00002 * Copyright (C) Sergey P. Derevyago, 2003-2004. 00003 * 00004 * Permission to copy, use, modify, sell and distribute this software is granted 00005 * provided this copyright notice appears in all copies. 00006 * This software is provided "as is" without express or implied warranty, and 00007 * with no claim as to its suitability for any purpose. 00008 * 00009 */ 00010 00015 #include "pubsub.hpp" 00016 00017 bool PubSub_private::PubImpl::subscribe(void* sub) 00018 { 00019 if (isSubscribed(sub)) return 0; 00020 00021 subs.push_back(sub); 00022 return 1; 00023 } 00024 00025 bool PubSub_private::PubImpl::unsubscribe(void* sub) 00026 { 00027 for (list_type::iterator it=subs.begin(), end=subs.end(); it!=end; ++it) { 00028 if (*it==sub) { 00029 subs.erase(it); 00030 return 1; 00031 } 00032 } 00033 00034 return 0; 00035 } 00036 00037 bool PubSub_private::PubImpl::isSubscribed(void* sub) const 00038 { 00039 for (list_type::const_iterator cit=subs.begin(), cend=subs.end(); cit!=cend; 00040 ++cit) { 00041 if (*cit==sub) return 1; 00042 } 00043 00044 return 0; 00045 }