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 27 matching lines...) Expand all Loading... |
192 $for ARITY [[ | 196 $for ARITY [[ |
193 $range ARG 1..ARITY | 197 $range ARG 1..ARITY |
194 | 198 |
195 $if ARITY == 0 [[ | 199 $if ARITY == 0 [[ |
196 template <> | 200 template <> |
197 class CallbackList<void(void)> | 201 class CallbackList<void(void)> |
198 : public internal::CallbackListBase<Callback<void(void)> > { | 202 : public internal::CallbackListBase<Callback<void(void)> > { |
199 ]] $else [[ | 203 ]] $else [[ |
200 template <$for ARG , [[typename A$(ARG)]]> | 204 template <$for ARG , [[typename A$(ARG)]]> |
201 class CallbackList<void($for ARG , [[A$(ARG)]])> | 205 class CallbackList<void($for ARG , [[A$(ARG)]])> |
202 : public internal::CallbackListBase< | 206 : public internal::CallbackListBase<Callback<void($for ARG , [[A$(ARG)]])> >
{ |
203 Callback<void($for ARG , [[A$(ARG)]])> > { | |
204 ]] | 207 ]] |
205 | 208 |
206 public: | 209 public: |
207 $if ARITY == 0 [[ | 210 $if ARITY == 0 [[ |
208 | 211 |
209 typedef Callback<void(void)> CallbackType; | 212 typedef Callback<void(void)> CallbackType; |
210 ]] $else [[ | 213 ]] $else [[ |
211 | 214 |
212 typedef Callback<void($for ARG , [[A$(ARG)]])> CallbackType; | 215 typedef Callback<void($for ARG , [[A$(ARG)]])> CallbackType; |
213 ]] | 216 ]] |
214 | 217 |
215 | 218 |
216 CallbackList() {} | 219 CallbackList() {} |
217 | 220 |
218 void Notify($for ARG , | 221 void Notify($for ARG , |
219 [[typename internal::CallbackParamTraits<A$(ARG)>::ForwardType a$(
ARG)]]) { | 222 [[typename internal::CallbackParamTraits<A$(ARG)>::ForwardType a$(
ARG)]]) { |
220 $if ARITY == 0 [[ | 223 $if ARITY == 0 [[ |
221 | 224 |
222 internal::CallbackListBase<CallbackType>::Iterator it = | 225 internal::CallbackListBase<CallbackType>::Iterator it = |
223 this->GetIterator(); | 226 this->GetIterator(); |
224 ]] $else [[ | 227 ]] $else [[ |
225 | 228 |
226 typename internal::CallbackListBase<CallbackType>::Iterator it = | 229 typename internal::CallbackListBase<CallbackType>::Iterator it = |
227 this->GetIterator(); | 230 this->GetIterator(); |
228 ]] | 231 ]] |
229 | 232 |
230 CallbackType* cb; | 233 CallbackType* cb; |
231 while((cb = it.GetNext()) != NULL) { | 234 while ((cb = it.GetNext()) != NULL) { |
232 cb->Run($for ARG , [[a$(ARG)]]); | 235 cb->Run($for ARG , [[a$(ARG)]]); |
233 } | 236 } |
234 } | 237 } |
235 | 238 |
236 private: | 239 private: |
237 DISALLOW_COPY_AND_ASSIGN(CallbackList); | 240 DISALLOW_COPY_AND_ASSIGN(CallbackList); |
238 }; | 241 }; |
239 | 242 |
240 | 243 |
241 ]] $$ for ARITY | 244 ]] $$ for ARITY |
242 } // namespace base | 245 } // namespace base |
243 | 246 |
244 #endif // BASE_CALLBACK_LIST_H_ | 247 #endif // BASE_CALLBACK_LIST_H_ |
OLD | NEW |