| OLD | NEW |
| 1 $$ This is a pump file for generating file templates. Pump is a python | 1 $$ This is a pump file for generating file templates. Pump is a python |
| 2 $$ script that is part of the Google Test suite of utilities. Description | 2 $$ script that is part of the Google Test suite of utilities. Description |
| 3 $$ can be found here: | 3 $$ can be found here: |
| 4 $$ | 4 $$ |
| 5 $$ http://code.google.com/p/googletest/wiki/PumpManual | 5 $$ http://code.google.com/p/googletest/wiki/PumpManual |
| 6 $$ | 6 $$ |
| 7 | 7 |
| 8 $$ See comment for MAX_ARITY in base/bind.h.pump. | 8 $$ See comment for MAX_ARITY in base/bind.h.pump. |
| 9 $var MAX_ARITY = 7 | 9 $var MAX_ARITY = 7 |
| 10 | 10 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 // RegisterCallback(const OnFooCallback& cb) { | 43 // RegisterCallback(const OnFooCallback& cb) { |
| 44 // return callback_list_.Add(cb); | 44 // return callback_list_.Add(cb); |
| 45 // } | 45 // } |
| 46 // | 46 // |
| 47 // private: | 47 // private: |
| 48 // void NotifyFoo(const Foo& foo) { | 48 // void NotifyFoo(const Foo& foo) { |
| 49 // callback_list_.Notify(foo); | 49 // callback_list_.Notify(foo); |
| 50 // } | 50 // } |
| 51 // | 51 // |
| 52 // base::CallbackList<void(const Foo&)> callback_list_; | 52 // base::CallbackList<void(const Foo&)> callback_list_; |
| 53 // |
| 54 // DISALLOW_COPY_AND_ASSIGN(MyWidget); |
| 53 // }; | 55 // }; |
| 54 // | 56 // |
| 55 // | 57 // |
| 56 // class MyWidgetListener { | 58 // class MyWidgetListener { |
| 57 // public: | 59 // public: |
| 58 // MyWidgetListener::MyWidgetListener() { | 60 // MyWidgetListener::MyWidgetListener() { |
| 59 // foo_subscription_ = MyWidget::GetCurrent()->RegisterCallback( | 61 // foo_subscription_ = MyWidget::GetCurrent()->RegisterCallback( |
| 60 // base::Bind(&MyWidgetListener::OnFoo, this))); | 62 // base::Bind(&MyWidgetListener::OnFoo, this))); |
| 61 // } | 63 // } |
| 62 // | 64 // |
| 63 // MyWidgetListener::~MyWidgetListener() { | 65 // MyWidgetListener::~MyWidgetListener() { |
| 64 // // Subscription gets deleted automatically and will deregister | 66 // // Subscription gets deleted automatically and will deregister |
| 65 // // the callback in the process. | 67 // // the callback in the process. |
| 66 // } | 68 // } |
| 67 // | 69 // |
| 68 // private: | 70 // private: |
| 69 // void OnFoo(const Foo& foo) { | 71 // void OnFoo(const Foo& foo) { |
| 70 // // Do something. | 72 // // Do something. |
| 71 // } | 73 // } |
| 72 // | 74 // |
| 73 // scoped_ptr<base::CallbackList<void(const Foo&)>::Subscription> | 75 // scoped_ptr<base::CallbackList<void(const Foo&)>::Subscription> |
| 74 // foo_subscription_; | 76 // foo_subscription_; |
| 77 // |
| 78 // DISALLOW_COPY_AND_ASSIGN(MyWidgetListener); |
| 75 // }; | 79 // }; |
| 76 | 80 |
| 77 namespace base { | 81 namespace base { |
| 78 | 82 |
| 79 namespace internal { | 83 namespace internal { |
| 80 | 84 |
| 81 template <typename CallbackType> | 85 template <typename CallbackType> |
| 82 class CallbackListBase { | 86 class CallbackListBase { |
| 83 public: | 87 public: |
| 84 class Subscription { | 88 class Subscription { |
| 85 public: | 89 public: |
| 86 Subscription(CallbackListBase<CallbackType>* list, | 90 Subscription(CallbackListBase<CallbackType>* list, |
| 87 typename std::list<CallbackType>::iterator iter) | 91 typename std::list<CallbackType>::iterator iter) |
| 88 : list_(list), | 92 : list_(list), |
| 89 iter_(iter) {} | 93 iter_(iter) { |
| 94 } |
| 90 | 95 |
| 91 ~Subscription() { | 96 ~Subscription() { |
| 92 if (list_->active_iterator_count_) | 97 if (list_->active_iterator_count_) |
| 93 (*iter_).Reset(); | 98 iter_->Reset(); |
| 94 else | 99 else |
| 95 list_->callbacks_.erase(iter_); | 100 list_->callbacks_.erase(iter_); |
| 96 } | 101 } |
| 97 | 102 |
| 98 private: | 103 private: |
| 99 CallbackListBase<CallbackType>* list_; | 104 CallbackListBase<CallbackType>* list_; |
| 100 typename std::list<CallbackType>::iterator iter_; | 105 typename std::list<CallbackType>::iterator iter_; |
| 101 | 106 |
| 102 DISALLOW_COPY_AND_ASSIGN(Subscription); | 107 DISALLOW_COPY_AND_ASSIGN(Subscription); |
| 103 }; | 108 }; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 ++list_iter_; | 148 ++list_iter_; |
| 144 } | 149 } |
| 145 return cb; | 150 return cb; |
| 146 } | 151 } |
| 147 | 152 |
| 148 private: | 153 private: |
| 149 CallbackListBase<CallbackType>* list_; | 154 CallbackListBase<CallbackType>* list_; |
| 150 typename std::list<CallbackType>::iterator list_iter_; | 155 typename std::list<CallbackType>::iterator list_iter_; |
| 151 }; | 156 }; |
| 152 | 157 |
| 153 CallbackListBase() | 158 CallbackListBase() : active_iterator_count_(0) {} |
| 154 : active_iterator_count_(0) {} | |
| 155 | 159 |
| 156 ~CallbackListBase() { | 160 ~CallbackListBase() { |
| 157 DCHECK_EQ(0, active_iterator_count_); | 161 DCHECK_EQ(0, active_iterator_count_); |
| 158 DCHECK_EQ(0U, callbacks_.size()); | 162 DCHECK_EQ(0U, callbacks_.size()); |
| 159 } | 163 } |
| 160 | 164 |
| 161 // Returns an instance of a CallbackListBase::Iterator which can be used | 165 // Returns an instance of a CallbackListBase::Iterator which can be used |
| 162 // to run callbacks. | 166 // to run callbacks. |
| 163 Iterator GetIterator() { | 167 Iterator GetIterator() { |
| 164 return Iterator(this); | 168 return Iterator(this); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 239 |
| 236 private: | 240 private: |
| 237 DISALLOW_COPY_AND_ASSIGN(CallbackList); | 241 DISALLOW_COPY_AND_ASSIGN(CallbackList); |
| 238 }; | 242 }; |
| 239 | 243 |
| 240 | 244 |
| 241 ]] $$ for ARITY | 245 ]] $$ for ARITY |
| 242 } // namespace base | 246 } // namespace base |
| 243 | 247 |
| 244 #endif // BASE_CALLBACK_LIST_H_ | 248 #endif // BASE_CALLBACK_LIST_H_ |
| OLD | NEW |