1 // Boost.Signals library
3 // Copyright Douglas Gregor 2001-2004. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // For more information, see http://www.boost.org
10 #define BOOST_SIGNALS_SOURCE
12 #include <boost/signals/detail/named_slot_map.hpp>
18 namespace boost { namespace BOOST_SIGNALS_NAMESPACE { namespace detail {
20 typedef std::list<connection_slot_pair> group_list;
21 typedef group_list::iterator slot_pair_iterator;
22 typedef std::map<stored_group, group_list, compare_type> slot_container_type;
23 typedef slot_container_type::iterator group_iterator;
24 typedef slot_container_type::const_iterator const_group_iterator;
27 #if BOOST_WORKAROUND(_MSC_VER, <= 1400)
28 void named_slot_map_iterator::decrement() { assert(false); }
29 void named_slot_map_iterator::advance(difference_type) { assert(false); }
32 named_slot_map::named_slot_map(const compare_type& compare) : groups(compare)
37 void named_slot_map::clear()
40 groups[stored_group(stored_group::sk_front)];
41 groups[stored_group(stored_group::sk_back)];
46 named_slot_map::iterator named_slot_map::begin()
48 return named_slot_map::iterator(groups.begin(), groups.end());
51 named_slot_map::iterator named_slot_map::end()
53 return named_slot_map::iterator(groups.end(), groups.end());
56 named_slot_map::iterator
57 named_slot_map::insert(const stored_group& name, const connection& con,
58 const any& slot, connect_position at)
63 case at_front: group = groups.begin(); break;
64 case at_back: group = back; break;
67 group = groups.find(name);
68 if (group == groups.end()) {
69 slot_container_type::value_type v(name, group_list());
70 group = groups.insert(v).first;
75 it.last_group = groups.end();
79 group->second.push_back(connection_slot_pair(con, slot));
80 it.slot_ = group->second.end();
81 it.slot_assigned = true;
86 group->second.push_front(connection_slot_pair(con, slot));
87 it.slot_ = group->second.begin();
88 it.slot_assigned = true;
94 void named_slot_map::disconnect(const stored_group& name)
96 group_iterator group = groups.find(name);
97 if (group != groups.end()) {
98 slot_pair_iterator i = group->second.begin();
99 while (i != group->second.end()) {
100 slot_pair_iterator next = i;
102 i->first.disconnect();
109 void named_slot_map::erase(iterator pos)
112 pos.slot_->first.disconnect();
113 pos.group->second.erase(pos.slot_);
116 void named_slot_map::remove_disconnected_slots()
118 // Remove any disconnected slots
119 group_iterator g = groups.begin();
120 while (g != groups.end()) {
121 slot_pair_iterator s = g->second.begin();
122 while (s != g->second.end()) {
123 if (s->first.connected()) ++s;
124 else g->second.erase(s++);
127 // Clear out empty groups
128 if (empty(g)) groups.erase(g++);