diff options
author | Murray Cumming <murrayc@murrayc.com> | 2016-03-30 16:04:56 +0200 |
---|---|---|
committer | Murray Cumming <murrayc@murrayc.com> | 2016-03-30 16:04:56 +0200 |
commit | 6964db1f78e2a0900a4eca36f87ffdb9bb5c3954 (patch) | |
tree | 15ea5ebb46941c825b529e80403534b6423d2ffb | |
parent | 9656bc2c0ead7e2155d5df701ca5ce34f2b00f49 (diff) | |
download | sigc++-6964db1f78e2a0900a4eca36f87ffdb9bb5c3954.tar.gz |
Reformat .cc files with clang-format.
-rw-r--r-- | sigc++/connection.cc | 50 | ||||
-rw-r--r-- | sigc++/functors/slot.cc | 4 | ||||
-rw-r--r-- | sigc++/functors/slot_base.cc | 106 | ||||
-rw-r--r-- | sigc++/signal.cc | 4 | ||||
-rw-r--r-- | sigc++/signal_base.cc | 131 | ||||
-rw-r--r-- | sigc++/trackable.cc | 70 |
6 files changed, 208 insertions, 157 deletions
diff --git a/sigc++/connection.cc b/sigc++/connection.cc index 228952b..6772276 100644 --- a/sigc++/connection.cc +++ b/sigc++/connection.cc @@ -19,28 +19,28 @@ #include <sigc++/connection.h> -namespace sigc { +namespace sigc +{ -connection::connection() noexcept -: slot_(nullptr) -{} +connection::connection() noexcept : slot_(nullptr) +{ +} -connection::connection(const connection& c) -: slot_(c.slot_) +connection::connection(const connection& c) : slot_(c.slot_) { - //Let the connection forget about the signal handler when the handler object dies: + // Let the connection forget about the signal handler when the handler object dies: if (slot_) slot_->add_destroy_notify_callback(this, ¬ify); } -connection::connection(slot_base& sl) -: slot_(&sl) +connection::connection(slot_base& sl) : slot_(&sl) { - //Let the connection forget about the signal handler when the handler object dies: + // Let the connection forget about the signal handler when the handler object dies: slot_->add_destroy_notify_callback(this, ¬ify); } -connection& connection::operator=(const connection& c) +connection& +connection::operator=(const connection& c) { set_slot(c.slot_); return *this; @@ -52,43 +52,50 @@ connection::~connection() slot_->remove_destroy_notify_callback(this); } -bool connection::empty() const noexcept +bool +connection::empty() const noexcept { return (!slot_ || slot_->empty()); } -bool connection::connected() const noexcept +bool +connection::connected() const noexcept { return !empty(); } -bool connection::blocked() const noexcept +bool +connection::blocked() const noexcept { return (slot_ ? slot_->blocked() : false); } -bool connection::block(bool should_block) noexcept +bool +connection::block(bool should_block) noexcept { return (slot_ ? slot_->block(should_block) : false); } -bool connection::unblock() noexcept +bool +connection::unblock() noexcept { return (slot_ ? slot_->unblock() : false); } -void connection::disconnect() +void +connection::disconnect() { if (slot_) slot_->disconnect(); // This notifies slot_'s parent. -} +} connection::operator bool() const noexcept { return !empty(); } - -void connection::set_slot(slot_base* sl) + +void +connection::set_slot(slot_base* sl) { if (slot_) slot_->remove_destroy_notify_callback(this); @@ -99,7 +106,8 @@ void connection::set_slot(slot_base* sl) slot_->add_destroy_notify_callback(this, ¬ify); } -void connection::notify(notifiable* data) +void +connection::notify(notifiable* data) { auto self = reinterpret_cast<connection*>(data); self->slot_ = nullptr; diff --git a/sigc++/functors/slot.cc b/sigc++/functors/slot.cc index 5b9c92e..fe308db 100644 --- a/sigc++/functors/slot.cc +++ b/sigc++/functors/slot.cc @@ -19,7 +19,7 @@ */ #include <sigc++/functors/slot.h> -namespace sigc { - +namespace sigc +{ } /* namespace sigc */ diff --git a/sigc++/functors/slot_base.cc b/sigc++/functors/slot_base.cc index a0c4f7d..f57a337 100644 --- a/sigc++/functors/slot_base.cc +++ b/sigc++/functors/slot_base.cc @@ -25,7 +25,7 @@ namespace // notified, if the slot_rep is deleted when they call disconnect(). struct destroy_notify_struct : public sigc::notifiable { - destroy_notify_struct() noexcept : deleted_(false) { } + destroy_notify_struct() noexcept : deleted_(false) {} static void notify(notifiable* data) noexcept { @@ -43,18 +43,21 @@ namespace internal { // only MSVC needs this to guarantee that all new/delete are executed from the DLL module #ifdef SIGC_NEW_DELETE_IN_LIBRARY_ONLY -void* slot_rep::operator new(size_t size_) +void* +slot_rep::operator new(size_t size_) { return malloc(size_); } -void slot_rep::operator delete(void* p) +void +slot_rep::operator delete(void* p) { free(p); } #endif -void slot_rep::disconnect() +void +slot_rep::disconnect() { // Invalidate the slot. // _Must_ be done here because parent_ might defer the actual @@ -67,18 +70,19 @@ void slot_rep::disconnect() if (parent_) { auto data_ = parent_; - parent_ = nullptr; // Just a precaution. - (cleanup_)(data_); // Notify the parent (might lead to destruction of this!). + parent_ = nullptr; // Just a precaution. + (cleanup_)(data_); // Notify the parent (might lead to destruction of this!). } } -//static -void slot_rep::notify(notifiable* data) +// static +void +slot_rep::notify(notifiable* data) { auto self_ = reinterpret_cast<slot_rep*>(data); self_->call_ = nullptr; // Invalidate the slot. - + // Make sure we are notified if disconnect() deletes self_, which is trackable. destroy_notify_struct notifier; self_->add_destroy_notify_callback(¬ifier, destroy_notify_struct::notify); @@ -87,44 +91,40 @@ void slot_rep::notify(notifiable* data) if (!notifier.deleted_) { self_->remove_destroy_notify_callback(¬ifier); - self_->destroy(); // Detach the stored functor from the other referred trackables and destroy it. - // destroy() might lead to deletion of self_. Bug #564005. + self_ + ->destroy(); // Detach the stored functor from the other referred trackables and destroy it. + // destroy() might lead to deletion of self_. Bug #564005. } } } // namespace internal - -slot_base::slot_base() noexcept -: rep_(nullptr), - blocked_(false) -{} - -slot_base::slot_base(rep_type* rep) noexcept -: rep_(rep), - blocked_(false) -{} - -slot_base::slot_base(const slot_base& src) -: rep_(nullptr), - blocked_(src.blocked_) + +slot_base::slot_base() noexcept : rep_(nullptr), blocked_(false) +{ +} + +slot_base::slot_base(rep_type* rep) noexcept : rep_(rep), blocked_(false) +{ +} + +slot_base::slot_base(const slot_base& src) : rep_(nullptr), blocked_(src.blocked_) { if (src.rep_) { - //Check call_ so we can ignore invalidated slots. - //Otherwise, destroyed bound reference parameters (whose destruction caused the slot's invalidation) may be used during dup(). - //Note: I'd prefer to check somewhere during dup(). murrayc. + // Check call_ so we can ignore invalidated slots. + // Otherwise, destroyed bound reference parameters (whose destruction caused the slot's + // invalidation) may be used during dup(). + // Note: I'd prefer to check somewhere during dup(). murrayc. if (src.rep_->call_) rep_ = src.rep_->dup(); else { - *this = slot_base(); //Return the default invalid slot. + *this = slot_base(); // Return the default invalid slot. } } } -slot_base::slot_base(slot_base&& src) -: rep_(nullptr), - blocked_(src.blocked_) +slot_base::slot_base(slot_base&& src) : rep_(nullptr), blocked_(src.blocked_) { if (src.rep_) { @@ -133,13 +133,13 @@ slot_base::slot_base(slot_base&& src) // src is connected to a parent, e.g. a sigc::signal. // Copy, don't move! See https://bugzilla.gnome.org/show_bug.cgi?id=756484 - //Check call_ so we can ignore invalidated slots. - //Otherwise, destroyed bound reference parameters (whose destruction - //caused the slot's invalidation) may be used during dup(). + // Check call_ so we can ignore invalidated slots. + // Otherwise, destroyed bound reference parameters (whose destruction + // caused the slot's invalidation) may be used during dup(). if (src.rep_->call_) rep_ = src.rep_->dup(); else - blocked_ = false; //Return the default invalid slot. + blocked_ = false; // Return the default invalid slot. } else { @@ -147,7 +147,7 @@ slot_base::slot_base(slot_base&& src) src.rep_->notify_callbacks(); rep_ = src.rep_; - //Wipe src: + // Wipe src: src.rep_ = nullptr; src.blocked_ = false; } @@ -165,7 +165,8 @@ slot_base::operator bool() const noexcept return rep_ != nullptr; } -void slot_base::delete_rep_with_check() +void +slot_base::delete_rep_with_check() { if (!rep_) return; @@ -188,7 +189,8 @@ void slot_base::delete_rep_with_check() } } -slot_base& slot_base::operator=(const slot_base& src) +slot_base& +slot_base::operator=(const slot_base& src) { if (src.rep_ == rep_) { @@ -217,7 +219,8 @@ slot_base& slot_base::operator=(const slot_base& src) return *this; } -slot_base& slot_base::operator=(slot_base&& src) +slot_base& +slot_base::operator=(slot_base&& src) { if (src.rep_ == rep_) { @@ -245,7 +248,7 @@ slot_base& slot_base::operator=(slot_base&& src) src.rep_->notify_callbacks(); new_rep_ = src.rep_; - //Wipe src: + // Wipe src: src.rep_ = nullptr; src.blocked_ = false; } @@ -259,43 +262,48 @@ slot_base& slot_base::operator=(slot_base&& src) return *this; } -void slot_base::set_parent(notifiable* parent, notifiable::func_destroy_notify cleanup) const noexcept +void +slot_base::set_parent(notifiable* parent, notifiable::func_destroy_notify cleanup) const noexcept { if (rep_) rep_->set_parent(parent, cleanup); } -void slot_base::add_destroy_notify_callback(notifiable* data, func_destroy_notify func) const +void +slot_base::add_destroy_notify_callback(notifiable* data, func_destroy_notify func) const { if (rep_) rep_->add_destroy_notify_callback(data, func); } -void slot_base::remove_destroy_notify_callback(notifiable* data) const +void +slot_base::remove_destroy_notify_callback(notifiable* data) const { if (rep_) rep_->remove_destroy_notify_callback(data); } -bool slot_base::block(bool should_block) noexcept +bool +slot_base::block(bool should_block) noexcept { bool old = blocked_; blocked_ = should_block; return old; } -bool slot_base::unblock() noexcept +bool +slot_base::unblock() noexcept { return block(false); } -void slot_base::disconnect() +void +slot_base::disconnect() { if (rep_) rep_->disconnect(); } - /*bool slot_base::empty() const // having this function not inline is killing performance !!! { if (rep_ && !rep_->call_) @@ -306,4 +314,4 @@ void slot_base::disconnect() return (rep_ == nullptr); }*/ -} //namespace sigc +} // namespace sigc diff --git a/sigc++/signal.cc b/sigc++/signal.cc index 993eee4..23a3ec8 100644 --- a/sigc++/signal.cc +++ b/sigc++/signal.cc @@ -19,7 +19,7 @@ */ #include <sigc++/signal.h> -namespace sigc { - +namespace sigc +{ } /* sigc */ diff --git a/sigc++/signal_base.cc b/sigc++/signal_base.cc index 1bf12c4..254a90f 100644 --- a/sigc++/signal_base.cc +++ b/sigc++/signal_base.cc @@ -18,8 +18,10 @@ #include <sigc++/signal_base.h> #include <memory> // std::unique_ptr -namespace sigc { -namespace internal { +namespace sigc +{ +namespace internal +{ // Data sent from signal_impl::insert() to slot_rep::set_parent() when a slot is // connected, and then sent from slot_rep::disconnect() to signal_impl::notify() @@ -29,13 +31,12 @@ struct self_and_iter : public notifiable signal_impl* self_; signal_impl::iterator_type iter_; - self_and_iter(signal_impl* self, signal_impl::iterator_type iter) - : self_(self), iter_(iter) {} + self_and_iter(signal_impl* self, signal_impl::iterator_type iter) : self_(self), iter_(iter) {} }; -signal_impl::signal_impl() -: ref_count_(0), exec_count_(0), deferred_(false) -{} +signal_impl::signal_impl() : ref_count_(0), exec_count_(0), deferred_(false) +{ +} signal_impl::~signal_impl() { @@ -52,18 +53,21 @@ signal_impl::~signal_impl() // only MSVC needs this to guarantee that all new/delete are executed from the DLL module #ifdef SIGC_NEW_DELETE_IN_LIBRARY_ONLY -void* signal_impl::operator new(size_t size_) +void* +signal_impl::operator new(size_t size_) { return malloc(size_); } -void signal_impl::operator delete(void* p) +void +signal_impl::operator delete(void* p) { free(p); } #endif -void signal_impl::clear() +void +signal_impl::clear() { // Don't let signal_impl::notify() erase the slots. It would invalidate the // iterator in the following loop. @@ -80,12 +84,14 @@ void signal_impl::clear() slots_.clear(); } -signal_impl::size_type signal_impl::size() const noexcept +signal_impl::size_type +signal_impl::size() const noexcept { return slots_.size(); } -bool signal_impl::blocked() const noexcept +bool +signal_impl::blocked() const noexcept { for (const auto& slot : const_cast<const std::list<slot_base>&>(slots_)) { @@ -95,7 +101,8 @@ bool signal_impl::blocked() const noexcept return true; } -void signal_impl::block(bool should_block) noexcept +void +signal_impl::block(bool should_block) noexcept { for (auto& slot : slots_) { @@ -103,17 +110,20 @@ void signal_impl::block(bool should_block) noexcept } } -signal_impl::iterator_type signal_impl::connect(const slot_base& slot_) +signal_impl::iterator_type +signal_impl::connect(const slot_base& slot_) { return insert(slots_.end(), slot_); } -signal_impl::iterator_type signal_impl::connect(slot_base&& slot_) +signal_impl::iterator_type +signal_impl::connect(slot_base&& slot_) { return insert(slots_.end(), std::move(slot_)); } -signal_impl::iterator_type signal_impl::erase(iterator_type i) +signal_impl::iterator_type +signal_impl::erase(iterator_type i) { // Don't let signal_impl::notify() erase the slot. It would be more // difficult to get the correct return value from signal_impl::erase(). @@ -128,8 +138,9 @@ signal_impl::iterator_type signal_impl::erase(iterator_type i) return slots_.erase(i); } - -signal_impl::iterator_type signal_impl::insert(signal_impl::iterator_type i, const slot_base& slot_) + +signal_impl::iterator_type +signal_impl::insert(signal_impl::iterator_type i, const slot_base& slot_) { auto temp = slots_.insert(i, slot_); auto si = new self_and_iter(this, temp); @@ -137,7 +148,8 @@ signal_impl::iterator_type signal_impl::insert(signal_impl::iterator_type i, con return temp; } -signal_impl::iterator_type signal_impl::insert(signal_impl::iterator_type i, slot_base&& slot_) +signal_impl::iterator_type +signal_impl::insert(signal_impl::iterator_type i, slot_base&& slot_) { auto temp = slots_.insert(i, std::move(slot_)); auto si = new self_and_iter(this, temp); @@ -145,7 +157,8 @@ signal_impl::iterator_type signal_impl::insert(signal_impl::iterator_type i, slo return temp; } -void signal_impl::sweep() +void +signal_impl::sweep() { // The deletion of a slot may cause the deletion of a signal_base, // a decrementation of ref_count_, and the deletion of this. @@ -161,8 +174,9 @@ void signal_impl::sweep() ++i; } -//static -void signal_impl::notify(notifiable* d) +// static +void +signal_impl::notify(notifiable* d) { std::unique_ptr<self_and_iter> si(static_cast<self_and_iter*>(d)); @@ -174,28 +188,25 @@ void signal_impl::notify(notifiable* d) signal_exec exec(si->self_); si->self_->slots_.erase(si->iter_); } - else // This is occuring during signal emission or slot erasure. - si->self_->deferred_ = true; // => sweep() will be called from ~signal_exec() after signal emission. - // This is safer because we don't have to care about our - // iterators in emit(), clear(), and erase(). + else // This is occuring during signal emission or slot erasure. + si->self_->deferred_ = + true; // => sweep() will be called from ~signal_exec() after signal emission. + // This is safer because we don't have to care about our + // iterators in emit(), clear(), and erase(). } } /* namespace internal */ -signal_base::signal_base() noexcept -: impl_(nullptr) -{} +signal_base::signal_base() noexcept : impl_(nullptr) +{ +} -signal_base::signal_base(const signal_base& src) noexcept -: trackable(), - impl_(src.impl()) +signal_base::signal_base(const signal_base& src) noexcept : trackable(), impl_(src.impl()) { impl_->reference(); } -signal_base::signal_base(signal_base&& src) -: trackable(std::move(src)), - impl_(std::move(src.impl_)) +signal_base::signal_base(signal_base&& src) : trackable(std::move(src)), impl_(std::move(src.impl_)) { src.impl_ = nullptr; } @@ -208,62 +219,74 @@ signal_base::~signal_base() } } -void signal_base::clear() +void +signal_base::clear() { if (impl_) impl_->clear(); } -signal_base::size_type signal_base::size() const noexcept +signal_base::size_type +signal_base::size() const noexcept { return (impl_ ? impl_->size() : 0); } -bool signal_base::blocked() const noexcept +bool +signal_base::blocked() const noexcept { return (impl_ ? impl_->blocked() : true); } -void signal_base::block(bool should_block) noexcept +void +signal_base::block(bool should_block) noexcept { if (impl_) impl_->block(should_block); } -void signal_base::unblock() noexcept +void +signal_base::unblock() noexcept { if (impl_) impl_->block(false); } -signal_base::iterator_type signal_base::connect(const slot_base& slot_) +signal_base::iterator_type +signal_base::connect(const slot_base& slot_) { return impl()->connect(slot_); } -signal_base::iterator_type signal_base::connect(slot_base&& slot_) +signal_base::iterator_type +signal_base::connect(slot_base&& slot_) { return impl()->connect(std::move(slot_)); } -signal_base::iterator_type signal_base::insert(iterator_type i, const slot_base& slot_) +signal_base::iterator_type +signal_base::insert(iterator_type i, const slot_base& slot_) { return impl()->insert(i, slot_); } -signal_base::iterator_type signal_base::insert(iterator_type i, slot_base&& slot_) +signal_base::iterator_type +signal_base::insert(iterator_type i, slot_base&& slot_) { return impl()->insert(i, std::move(slot_)); } -signal_base::iterator_type signal_base::erase(iterator_type i) +signal_base::iterator_type +signal_base::erase(iterator_type i) { return impl()->erase(i); } -signal_base& signal_base::operator=(const signal_base& src) +signal_base& +signal_base::operator=(const signal_base& src) { - if (src.impl_ == impl_) return *this; + if (src.impl_ == impl_) + return *this; if (impl_) { @@ -275,9 +298,11 @@ signal_base& signal_base::operator=(const signal_base& src) return *this; } -signal_base& signal_base::operator=(signal_base&& src) +signal_base& +signal_base::operator=(signal_base&& src) { - if (src.impl_ == impl_) return *this; + if (src.impl_ == impl_) + return *this; if (impl_) { @@ -291,11 +316,13 @@ signal_base& signal_base::operator=(signal_base&& src) return *this; } -internal::signal_impl* signal_base::impl() const +internal::signal_impl* +signal_base::impl() const { - if (!impl_) { + if (!impl_) + { impl_ = new internal::signal_impl; - impl_->reference(); // start with a reference count of 1 + impl_->reference(); // start with a reference count of 1 } return impl_; } diff --git a/sigc++/trackable.cc b/sigc++/trackable.cc index 7c492ea..510ac18 100644 --- a/sigc++/trackable.cc +++ b/sigc++/trackable.cc @@ -22,15 +22,15 @@ namespace sigc { -trackable::trackable() noexcept -: callback_list_(nullptr) -{} +trackable::trackable() noexcept : callback_list_(nullptr) +{ +} /* Don't copy the notification list. The objects watching src don't need to be notified when the new object dies. */ -trackable::trackable(const trackable& /*src*/) noexcept -: callback_list_(nullptr) -{} +trackable::trackable(const trackable& /*src*/) noexcept : callback_list_(nullptr) +{ +} // Don't move the notification list. // The objects watching src don't need to be notified when the new object dies. @@ -38,25 +38,26 @@ trackable::trackable(const trackable& /*src*/) noexcept // // If trackable's move constructor is modified, check if Glib::Object's // move constructor should be modified similarly. -trackable::trackable(trackable&& src) -: callback_list_(nullptr) +trackable::trackable(trackable&& src) : callback_list_(nullptr) { src.notify_callbacks(); } -trackable& trackable::operator=(const trackable& src) +trackable& +trackable::operator=(const trackable& src) { - if(this != &src) - notify_callbacks(); //Make sure that we have finished with existing stuff before replacing it. - + if (this != &src) + notify_callbacks(); // Make sure that we have finished with existing stuff before replacing it. + return *this; } -trackable& trackable::operator=(trackable&& src) +trackable& +trackable::operator=(trackable&& src) { - if(this != &src) + if (this != &src) { - notify_callbacks(); //Make sure that we have finished with existing stuff before replacing it. + notify_callbacks(); // Make sure that we have finished with existing stuff before replacing it. src.notify_callbacks(); // src probably becomes useless. } return *this; @@ -67,25 +68,29 @@ trackable::~trackable() notify_callbacks(); } -void trackable::add_destroy_notify_callback(notifiable* data, func_destroy_notify func) const +void +trackable::add_destroy_notify_callback(notifiable* data, func_destroy_notify func) const { callback_list()->add_callback(data, func); } -void trackable::remove_destroy_notify_callback(notifiable* data) const +void +trackable::remove_destroy_notify_callback(notifiable* data) const { callback_list()->remove_callback(data); } -void trackable::notify_callbacks() +void +trackable::notify_callbacks() { if (callback_list_) - delete callback_list_; //This invokes all of the callbacks. + delete callback_list_; // This invokes all of the callbacks. callback_list_ = nullptr; } -internal::trackable_callback_list* trackable::callback_list() const +internal::trackable_callback_list* +trackable::callback_list() const { if (!callback_list_) callback_list_ = new internal::trackable_callback_list; @@ -93,7 +98,6 @@ internal::trackable_callback_list* trackable::callback_list() const return callback_list_; } - namespace internal { @@ -106,20 +110,23 @@ trackable_callback_list::~trackable_callback_list() callback.func_(callback.data_); } -void trackable_callback_list::add_callback(notifiable* data, func_destroy_notify func) +void +trackable_callback_list::add_callback(notifiable* data, func_destroy_notify func) { - if (!clearing_) // TODO: Is it okay to silently ignore attempts to add dependencies when the list is being cleared? - // I'd consider this a serious application bug, since the app is likely to segfault. - // But then, how should we handle it? Throw an exception? Martin. + if (!clearing_) // TODO: Is it okay to silently ignore attempts to add dependencies when the list + // is being cleared? + // I'd consider this a serious application bug, since the app is likely to segfault. + // But then, how should we handle it? Throw an exception? Martin. callbacks_.push_back(trackable_callback(data, func)); } -void trackable_callback_list::clear() +void +trackable_callback_list::clear() { clearing_ = true; for (auto& callback : callbacks_) - if (callback.func_) + if (callback.func_) callback.func_(callback.data_); callbacks_.clear(); @@ -127,16 +134,17 @@ void trackable_callback_list::clear() clearing_ = false; } -void trackable_callback_list::remove_callback(notifiable* data) +void +trackable_callback_list::remove_callback(notifiable* data) { for (callback_list::iterator i = callbacks_.begin(); i != callbacks_.end(); ++i) { auto& callback = *i; if (callback.data_ == data && callback.func_ != nullptr) { - //Don't remove a list element while the list is being cleared. - //It could invalidate the iterator in ~trackable_callback_list() or clear(). - //But it may be necessary to invalidate the callback. See bug 589202. + // Don't remove a list element while the list is being cleared. + // It could invalidate the iterator in ~trackable_callback_list() or clear(). + // But it may be necessary to invalidate the callback. See bug 589202. if (clearing_) callback.func_ = nullptr; else |