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 #ifndef BOOST_SIGNALS_NAMED_SLOT_MAP_HPP
11 #define BOOST_SIGNALS_NAMED_SLOT_MAP_HPP
13 #include <boost/signals/detail/config.hpp>
14 #include <boost/signals/detail/signals_common.hpp>
15 #include <boost/signals/connection.hpp>
16 #include <boost/smart_ptr.hpp>
17 #include <boost/any.hpp>
18 #include <boost/utility.hpp>
19 #include <boost/function/function2.hpp>
20 #include <boost/iterator/iterator_facade.hpp>
24 namespace boost { namespace BOOST_SIGNALS_NAMESPACE {
26 enum connect_position { at_back, at_front };
30 typedef function2<bool, any, any> compare_type;
32 // Used to delimit the front and back of the list for O(1) insertion.
36 // This function object bridges from a pair of any objects that hold
37 // values of type Key to the underlying function object that compares
38 // values of type Key.
39 template<typename Compare, typename Key>
40 class any_bridge_compare {
42 typedef bool result_type;
43 typedef const any& first_argument_type;
44 typedef const any& second_argument_type;
46 any_bridge_compare(const Compare& c) : comp(c) {}
48 bool operator()(const any& k1, const any& k2) const
50 if (k1.type() == typeid(front_type))
51 return !(k2.type() == typeid(front_type));
52 if (k1.type() == typeid(back_type))
54 if (k2.type() == typeid(front_type))
56 if (k2.type() == typeid(back_type))
59 // Neither is empty, so compare their values to order them
60 // The strange */& is so that we will get a reference to the
61 // value stored in the any object instead of a copy
62 return comp(*any_cast<Key>(&k1), *any_cast<Key>(&k2));
69 class BOOST_SIGNALS_DECL named_slot_map_iterator :
70 public iterator_facade<named_slot_map_iterator,
72 forward_traversal_tag>
76 typedef iterator_facade<named_slot_map_iterator,
78 forward_traversal_tag> inherited;
80 named_slot_map_iterator();
81 named_slot_map_iterator(const named_slot_map_iterator& other);
82 ~named_slot_map_iterator();
83 named_slot_map_iterator& operator=(const named_slot_map_iterator& other);
85 connection_slot_pair& dereference() const;
87 bool equal(const named_slot_map_iterator& other) const;
89 #if BOOST_WORKAROUND(BOOST_MSVC, <= 0x1701)
91 void advance(difference_type);
95 named_slot_map_iterator(std::auto_ptr<impl>);
97 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
98 shared_ptr<impl> impl_;
100 scoped_ptr<impl> impl_;
103 friend class named_slot_map;
106 class BOOST_SIGNALS_DECL named_slot_map
109 typedef named_slot_map_iterator iterator;
111 named_slot_map(const compare_type& compare);
117 iterator insert(const any& name, const connection& con, const any& slot,
118 connect_position at);
119 void disconnect(const any& name);
120 void erase(iterator pos);
121 void remove_disconnected_slots();
126 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
127 shared_ptr<impl> impl_;
129 scoped_ptr<impl> impl_;
135 #endif // BOOST_SIGNALS_NAMED_SLOT_MAP_HPP