annotate DEPENDENCIES/generic/include/boost/signals/detail/named_slot_map.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 // Boost.Signals library
Chris@16 2
Chris@16 3 // Copyright Douglas Gregor 2001-2004. Use, modification and
Chris@16 4 // distribution is subject to the Boost Software License, Version
Chris@16 5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 6 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 7
Chris@16 8 // For more information, see http://www.boost.org
Chris@16 9
Chris@16 10 #ifndef BOOST_SIGNALS_NAMED_SLOT_MAP_HPP
Chris@16 11 #define BOOST_SIGNALS_NAMED_SLOT_MAP_HPP
Chris@16 12
Chris@16 13 #include <boost/signals/detail/config.hpp>
Chris@16 14 #include <boost/signals/detail/signals_common.hpp>
Chris@16 15 #include <boost/signals/connection.hpp>
Chris@16 16 #include <boost/shared_ptr.hpp>
Chris@16 17 #include <boost/function/function2.hpp>
Chris@16 18 #include <boost/iterator/iterator_facade.hpp>
Chris@16 19 #include <map>
Chris@16 20 #include <memory>
Chris@16 21 #include <utility>
Chris@16 22
Chris@16 23 namespace boost { namespace BOOST_SIGNALS_NAMESPACE {
Chris@16 24
Chris@16 25 enum connect_position { at_back, at_front };
Chris@16 26
Chris@16 27 namespace detail {
Chris@16 28
Chris@16 29 class stored_group
Chris@16 30 {
Chris@16 31 public:
Chris@16 32 enum storage_kind { sk_empty, sk_front, sk_back, sk_group };
Chris@16 33
Chris@16 34 stored_group(storage_kind p_kind = sk_empty) : kind(p_kind), group() { }
Chris@16 35
Chris@16 36 template<typename T>
Chris@16 37 stored_group(const T& p_group) : kind(sk_group), group(new T(p_group)) { }
Chris@16 38
Chris@16 39 bool is_front() const { return kind == sk_front; }
Chris@16 40 bool is_back() const { return kind == sk_back; }
Chris@16 41 bool empty() const { return kind == sk_empty; }
Chris@16 42
Chris@16 43 void* get() const { return group.get(); }
Chris@16 44
Chris@16 45 private:
Chris@16 46 storage_kind kind;
Chris@16 47 shared_ptr<void> group;
Chris@16 48 };
Chris@16 49
Chris@16 50 typedef function2<bool, stored_group, stored_group> compare_type;
Chris@16 51
Chris@16 52 // This function object bridges from a pair of any objects that hold
Chris@16 53 // values of type Key to the underlying function object that compares
Chris@16 54 // values of type Key.
Chris@16 55 template<typename Compare, typename Key>
Chris@16 56 class group_bridge_compare {
Chris@16 57 public:
Chris@16 58 typedef bool result_type;
Chris@16 59 typedef const stored_group& first_argument_type;
Chris@16 60 typedef const stored_group& second_argument_type;
Chris@16 61
Chris@101 62 group_bridge_compare(const Compare& c) : comp(c)
Chris@16 63 { }
Chris@16 64
Chris@16 65 bool operator()(const stored_group& k1, const stored_group& k2) const
Chris@16 66 {
Chris@16 67 if (k1.is_front()) return !k2.is_front();
Chris@16 68 if (k1.is_back()) return false;
Chris@16 69 if (k2.is_front()) return false;
Chris@16 70 if (k2.is_back()) return true;
Chris@16 71
Chris@16 72 // Neither is empty, so compare their values to order them
Chris@16 73 return comp(*static_cast<Key*>(k1.get()), *static_cast<Key*>(k2.get()));
Chris@16 74 }
Chris@16 75
Chris@16 76 private:
Chris@16 77 Compare comp;
Chris@16 78 };
Chris@16 79
Chris@16 80 class BOOST_SIGNALS_DECL named_slot_map_iterator :
Chris@16 81 public iterator_facade<named_slot_map_iterator,
Chris@16 82 connection_slot_pair,
Chris@16 83 forward_traversal_tag>
Chris@16 84 {
Chris@16 85 typedef std::list<connection_slot_pair> group_list;
Chris@16 86 typedef group_list::iterator slot_pair_iterator;
Chris@16 87 typedef std::map<stored_group, group_list, compare_type> slot_container_type;
Chris@16 88 typedef slot_container_type::iterator group_iterator;
Chris@16 89 typedef slot_container_type::const_iterator const_group_iterator;
Chris@16 90
Chris@16 91 typedef iterator_facade<named_slot_map_iterator,
Chris@16 92 connection_slot_pair,
Chris@16 93 forward_traversal_tag> inherited;
Chris@16 94 public:
Chris@101 95 named_slot_map_iterator() : slot_assigned(false)
Chris@16 96 { }
Chris@101 97 named_slot_map_iterator(const named_slot_map_iterator& other)
Chris@16 98 : group(other.group), last_group(other.last_group),
Chris@16 99 slot_assigned(other.slot_assigned)
Chris@16 100 {
Chris@16 101 if (slot_assigned) slot_ = other.slot_;
Chris@16 102 }
Chris@101 103 named_slot_map_iterator& operator=(const named_slot_map_iterator& other)
Chris@16 104 {
Chris@16 105 slot_assigned = other.slot_assigned;
Chris@16 106 group = other.group;
Chris@16 107 last_group = other.last_group;
Chris@16 108 if (slot_assigned) slot_ = other.slot_;
Chris@16 109 return *this;
Chris@16 110 }
Chris@101 111 connection_slot_pair& dereference() const
Chris@16 112 {
Chris@16 113 return *slot_;
Chris@16 114 }
Chris@101 115 void increment()
Chris@16 116 {
Chris@16 117 ++slot_;
Chris@16 118 if (slot_ == group->second.end()) {
Chris@16 119 ++group;
Chris@16 120 init_next_group();
Chris@16 121 }
Chris@16 122 }
Chris@16 123 bool equal(const named_slot_map_iterator& other) const {
Chris@16 124 return (group == other.group
Chris@16 125 && (group == last_group
Chris@16 126 || slot_ == other.slot_));
Chris@16 127 }
Chris@16 128
Chris@101 129 #if BOOST_WORKAROUND(_MSC_VER, <= 1900)
Chris@16 130 void decrement();
Chris@16 131 void advance(difference_type);
Chris@16 132 #endif
Chris@16 133
Chris@16 134 private:
Chris@16 135 named_slot_map_iterator(group_iterator giter, group_iterator last) :
Chris@16 136 group(giter), last_group(last), slot_assigned(false)
Chris@16 137 { init_next_group(); }
Chris@16 138 named_slot_map_iterator(group_iterator giter, group_iterator last,
Chris@16 139 slot_pair_iterator slot) :
Chris@16 140 group(giter), last_group(last), slot_(slot), slot_assigned(true)
Chris@16 141 { }
Chris@16 142
Chris@16 143 void init_next_group()
Chris@16 144 {
Chris@16 145 while (group != last_group && group->second.empty()) ++group;
Chris@16 146 if (group != last_group) {
Chris@16 147 slot_ = group->second.begin();
Chris@16 148 slot_assigned = true;
Chris@16 149 }
Chris@16 150 }
Chris@16 151
Chris@16 152 group_iterator group;
Chris@16 153 group_iterator last_group;
Chris@16 154 slot_pair_iterator slot_;
Chris@16 155 bool slot_assigned;
Chris@16 156
Chris@16 157 friend class named_slot_map;
Chris@16 158 };
Chris@16 159
Chris@16 160 class BOOST_SIGNALS_DECL named_slot_map
Chris@16 161 {
Chris@16 162 public:
Chris@16 163 typedef named_slot_map_iterator iterator;
Chris@16 164
Chris@16 165 named_slot_map(const compare_type& compare);
Chris@16 166
Chris@16 167 void clear();
Chris@16 168 iterator begin();
Chris@16 169 iterator end();
Chris@16 170 iterator insert(const stored_group& name, const connection& con,
Chris@16 171 const any& slot, connect_position at);
Chris@16 172 void disconnect(const stored_group& name);
Chris@16 173 void erase(iterator pos);
Chris@16 174 void remove_disconnected_slots();
Chris@16 175
Chris@16 176 private:
Chris@16 177 typedef std::list<connection_slot_pair> group_list;
Chris@16 178 typedef std::map<stored_group, group_list, compare_type> slot_container_type;
Chris@16 179 typedef slot_container_type::iterator group_iterator;
Chris@16 180 typedef slot_container_type::const_iterator const_group_iterator;
Chris@16 181
Chris@16 182 bool empty(const_group_iterator group) const
Chris@16 183 {
Chris@16 184 return (group->second.empty() && group != groups.begin() && group != back);
Chris@16 185 }
Chris@16 186 slot_container_type groups;
Chris@16 187 group_iterator back;
Chris@16 188 };
Chris@16 189
Chris@16 190 } } }
Chris@16 191
Chris@16 192 #endif // BOOST_SIGNALS_NAMED_SLOT_MAP_HPP