3 * Copyright 2003, The libsigc++ Development Team
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <sigc++/signal_base.h>
25 signal_impl::signal_impl()
26 : ref_count_(0), exec_count_(0), deferred_(0)
29 // only MSVC needs this to guarantee that all new/delete are executed from the DLL module
30 #ifdef SIGC_NEW_DELETE_IN_LIBRARY_ONLY
31 void* signal_impl::operator new(size_t size_
)
36 void signal_impl::operator delete(void* p
)
42 void signal_impl::clear()
47 signal_impl::size_type
signal_impl::size() const
52 signal_impl::iterator_type
signal_impl::connect(const slot_base
& slot_
)
54 return insert(slots_
.end(), slot_
);
57 signal_impl::iterator_type
signal_impl::erase(iterator_type i
)
59 return slots_
.erase(i
);
62 signal_impl::iterator_type
signal_impl::insert(signal_impl::iterator_type i
, const slot_base
& slot_
)
64 iterator_type temp
= slots_
.insert(i
, slot_
);
65 temp
->set_parent(this, ¬ify
);
69 void signal_impl::sweep()
72 iterator_type i
= slots_
.begin();
73 while (i
!= slots_
.end())
80 void* signal_impl::notify(void* d
)
82 signal_impl
* self
= reinterpret_cast<signal_impl
*>(d
);
83 if (self
->exec_count_
== 0)
85 else // This is occuring during signal emission.
86 self
->deferred_
= true; // => sweep() will be called from ~signal_exec().
87 return 0; // This is safer because we don't have to care about our iterators in emit().
90 } /* namespace internal */
92 signal_base::signal_base()
96 signal_base::signal_base(const signal_base
& src
)
103 signal_base::~signal_base()
106 impl_
->unreference();
109 void signal_base::clear()
115 signal_base::size_type
signal_base::size() const
117 return (impl_
? impl_
->size() : 0);
120 signal_base::iterator_type
signal_base::connect(const slot_base
& slot_
)
122 return impl()->connect(slot_
);
125 signal_base::iterator_type
signal_base::insert(iterator_type i
, const slot_base
& slot_
)
127 return impl()->insert(i
, slot_
);
130 signal_base::iterator_type
signal_base::erase(iterator_type i
)
132 return impl()->erase(i
);
135 signal_base
& signal_base::operator = (const signal_base
& src
)
137 if (impl_
) impl_
->unreference();
143 internal::signal_impl
* signal_base::impl() const
146 impl_
= new internal::signal_impl
;
147 impl_
->reference(); // start with a reference count of 1