]> git.lyx.org Git - lyx.git/blob - boost/boost/signals/detail/named_slot_map.hpp
update to boost 1.32.0
[lyx.git] / boost / boost / signals / detail / named_slot_map.hpp
1 // Boost.Signals library
2
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)
7
8 // For more information, see http://www.boost.org
9
10 #ifndef BOOST_SIGNALS_NAMED_SLOT_MAP_HPP
11 #define BOOST_SIGNALS_NAMED_SLOT_MAP_HPP
12
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>
21 #include <memory>
22 #include <utility>
23
24 namespace boost { namespace BOOST_SIGNALS_NAMESPACE {
25
26 enum connect_position { at_back, at_front };
27
28 namespace detail {
29
30 typedef function2<bool, any, any> compare_type;
31
32 // Used to delimit the front and back of the list for O(1) insertion.
33 struct front_type {};
34 struct back_type {};
35
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 {
41 public:
42   typedef bool result_type;
43   typedef const any& first_argument_type;
44   typedef const any& second_argument_type;
45
46   any_bridge_compare(const Compare& c) : comp(c) {}
47
48   bool operator()(const any& k1, const any& k2) const
49   {
50     if (k1.type() == typeid(front_type))
51       return !(k2.type() == typeid(front_type));
52     if (k1.type() == typeid(back_type))
53       return false;
54     if (k2.type() == typeid(front_type))
55       return false;
56     if (k2.type() == typeid(back_type))
57       return true;
58
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));
63   }
64
65 private:
66   Compare comp;
67 };
68
69 class BOOST_SIGNALS_DECL named_slot_map_iterator :
70   public iterator_facade<named_slot_map_iterator,
71                          connection_slot_pair,
72                          forward_traversal_tag>
73 {
74   class impl;
75
76   typedef iterator_facade<named_slot_map_iterator,
77                           connection_slot_pair,
78                           forward_traversal_tag> inherited;
79 public:
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);
84
85   connection_slot_pair& dereference() const;
86   void increment();
87   bool equal(const named_slot_map_iterator& other) const;
88
89 #if BOOST_WORKAROUND(BOOST_MSVC, <= 0x1701)
90   void decrement();
91   void advance(difference_type);
92 #endif
93
94 private:
95   named_slot_map_iterator(std::auto_ptr<impl>);
96
97 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
98   shared_ptr<impl> impl_;
99 #else
100   scoped_ptr<impl> impl_;
101 #endif
102
103   friend class named_slot_map;
104 };
105
106 class BOOST_SIGNALS_DECL named_slot_map
107 {
108 public:
109   typedef named_slot_map_iterator iterator;
110
111   named_slot_map(const compare_type& compare);
112   ~named_slot_map();
113
114   void clear();
115   iterator begin();
116   iterator end();
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();
122
123 private:
124   class impl;
125
126 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
127   shared_ptr<impl> impl_;
128 #else
129   scoped_ptr<impl> impl_;
130 #endif
131 };
132
133 } } }
134
135 #endif // BOOST_SIGNALS_NAMED_SLOT_MAP_HPP