[libsigcplusplus] connection: Take the slot_base directly, without the intermediate slot_iterator.



commit 14e413a47bab2ba8e4892f0ba9493c2f8e0265d8
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Apr 21 17:33:51 2016 +0200

    connection: Take the slot_base directly, without the intermediate slot_iterator.

 sigc++/connection.cc |   10 +++--
 sigc++/connection.h  |   26 +---------------
 sigc++/signal.h      |   83 +++++--------------------------------------------
 3 files changed, 16 insertions(+), 103 deletions(-)
---
diff --git a/sigc++/connection.cc b/sigc++/connection.cc
index 58c2fe5..bbcfcb7 100644
--- a/sigc++/connection.cc
+++ b/sigc++/connection.cc
@@ -26,17 +26,19 @@ connection::connection() noexcept : slot_(nullptr)
 {
 }
 
-connection::connection(const connection& c) : slot_(c.slot_)
+connection::connection(slot_base* slot)
+: slot_(slot)
 {
-  // Let the connection forget about the signal handler when the handler object dies:
   if (slot_)
     slot_->add_destroy_notify_callback(this, &notify);
 }
 
-connection::connection(slot_base& sl) : slot_(&sl)
+
+connection::connection(const connection& c) : slot_(c.slot_)
 {
   // Let the connection forget about the signal handler when the handler object dies:
-  slot_->add_destroy_notify_callback(this, &notify);
+  if (slot_)
+    slot_->add_destroy_notify_callback(this, &notify);
 }
 
 connection&
diff --git a/sigc++/connection.h b/sigc++/connection.h
index cfcead2..54b462a 100644
--- a/sigc++/connection.h
+++ b/sigc++/connection.h
@@ -24,9 +24,6 @@
 namespace sigc
 {
 
-template <typename T_slot>
-struct slot_iterator;
-
 /** Convinience class for safe disconnection.
  * Iterators must not be used beyond the lifetime of the list
  * they work on. A connection object can be created from a
@@ -54,34 +51,13 @@ struct SIGC_API connection : public notifiable
   /** Constructs a connection object from a slot list iterator.
    * @param it The slot list iterator to take the slot from.
    */
-  template <typename T_slot>
-  connection(const slot_iterator<T_slot>& it) : slot_(&(*it))
-  {
-    if (slot_)
-      slot_->add_destroy_notify_callback(this, &notify);
-  }
-
-  /** Constructs a connection object from a slot object.
-   * This is only useful if you create your own slot list.
-   * @param sl The slot to operate on.
-   */
-  explicit connection(slot_base& sl);
+  explicit connection(slot_base* slot);
 
   /** Overrides this connection object copying another one.
    * @param c The connection object to make a copy from.
    */
   connection& operator=(const connection& c);
 
-  /** Overrides this connection object with another slot list iterator.
-   * @param it The new slot list iterator to take the slot from.
-   */
-  template <typename T_slot>
-  connection& operator=(const slot_iterator<T_slot>& it)
-  {
-    set_slot(&(*it));
-    return *this;
-  }
-
   ~connection();
 
   /** Returns whether the connection is still active.
diff --git a/sigc++/signal.h b/sigc++/signal.h
index 70748f8..5198405 100644
--- a/sigc++/signal.h
+++ b/sigc++/signal.h
@@ -33,66 +33,6 @@
 namespace sigc
 {
 
-/** STL-style iterator for slot_list.
- *
- * @ingroup signal
- */
-template <typename T_slot>
-struct slot_iterator
-{
-  using size_type = std::size_t;
-  using difference_type = std::ptrdiff_t;
-  using iterator_category = std::bidirectional_iterator_tag;
-
-  using slot_type = T_slot;
-
-  using value_type = T_slot;
-  using pointer = T_slot*;
-  using reference = T_slot&;
-
-  using iterator_type = typename internal::signal_impl::iterator_type;
-
-  slot_iterator() = default;
-
-  explicit slot_iterator(const iterator_type& i) : i_(i) {}
-
-  reference operator*() const { return static_cast<reference>(*i_); }
-
-  pointer operator->() const { return &(operator*()); }
-
-  slot_iterator& operator++()
-  {
-    ++i_;
-    return *this;
-  }
-
-  slot_iterator operator++(int)
-  {
-    slot_iterator tmp(*this);
-    ++i_;
-    return tmp;
-  }
-
-  slot_iterator& operator--()
-  {
-    --i_;
-    return *this;
-  }
-
-  slot_iterator operator--(int)
-  {
-    slot_iterator tmp(*this);
-    --i_;
-    return tmp;
-  }
-
-  bool operator==(const slot_iterator& other) const { return i_ == other.i_; }
-
-  bool operator!=(const slot_iterator& other) const { return i_ != other.i_; }
-
-  iterator_type i_;
-};
-
 namespace internal
 {
 
@@ -471,21 +411,12 @@ class signal_with_accumulator : public signal_base
 public:
   using slot_type = slot<T_return(T_arg...)>;
 
-private:
-  using iterator = slot_iterator<slot_type>;
-
-public:
-
-
   /** Add a slot to the list of slots.
    * Any functor or slot may be passed into connect().
    * It will be converted into a slot implicitly.
-   * The returned iterator may be stored for disconnection
+   * The returned connection may be stored for disconnection
    * of the slot at some later point. It stays valid until
-   * the slot is removed from the list of slots. The iterator
-   * can also be implicitly converted into a sigc::connection object
-   * that may be used safely beyond the life time of the slot.
-   *
+   * the slot is disconnected from the signal.
    * std::function<> and C++11 lambda expressions are functors.
    * These are examples of functors that can be connected to a signal.
    *
@@ -496,11 +427,13 @@ public:
    * to a std::function, you can connect the std::function to a signal.
    *
    * @param slot_ The slot to add to the list of slots.
-   * @return An iterator pointing to the new slot in the list.
+   * @return A connection.
    */
   connection connect(const slot_type& slot_)
   {
-    return connection(iterator(signal_base::connect(slot_)));
+    auto iter = signal_base::connect(slot_);
+    auto& slot_base = *iter;
+    return connection(&slot_base);
   }
 
   /** Add a slot to the list of slots.
@@ -510,7 +443,9 @@ public:
    */
   connection connect(slot_type&& slot_)
   {
-    return connection(iterator(signal_base::connect(std::move(slot_))));
+    auto iter = signal_base::connect(std::move(slot_));
+    auto& slot_base = *iter;
+    return connection(&slot_base);
   }
 
   /** Triggers the emission of the signal.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]