Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: base/callback_list.h

Issue 23645019: C++ Readability Review for caitkp (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/callback_list.h.pump » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // This file was GENERATED by command: 1 // This file was GENERATED by command:
2 // pump.py callback_list.h.pump 2 // pump.py callback_list.h.pump
3 // DO NOT EDIT BY HAND!!! 3 // DO NOT EDIT BY HAND!!!
4 4
5 5
6 // Copyright 2013 The Chromium Authors. All rights reserved. 6 // Copyright 2013 The Chromium Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be 7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file. 8 // found in the LICENSE file.
9 9
10 #ifndef BASE_CALLBACK_LIST_H_ 10 #ifndef BASE_CALLBACK_LIST_H_
(...skipping 27 matching lines...) Expand all
38 // RegisterCallback(const OnFooCallback& cb) { 38 // RegisterCallback(const OnFooCallback& cb) {
39 // return callback_list_.Add(cb); 39 // return callback_list_.Add(cb);
40 // } 40 // }
41 // 41 //
42 // private: 42 // private:
43 // void NotifyFoo(const Foo& foo) { 43 // void NotifyFoo(const Foo& foo) {
44 // callback_list_.Notify(foo); 44 // callback_list_.Notify(foo);
45 // } 45 // }
46 // 46 //
47 // base::CallbackList<void(const Foo&)> callback_list_; 47 // base::CallbackList<void(const Foo&)> callback_list_;
48 //
49 // DISALLOW_COPY_AND_ASSIGN(MyWidget);
48 // }; 50 // };
49 // 51 //
50 // 52 //
51 // class MyWidgetListener { 53 // class MyWidgetListener {
52 // public: 54 // public:
53 // MyWidgetListener::MyWidgetListener() { 55 // MyWidgetListener::MyWidgetListener() {
54 // foo_subscription_ = MyWidget::GetCurrent()->RegisterCallback( 56 // foo_subscription_ = MyWidget::GetCurrent()->RegisterCallback(
55 // base::Bind(&MyWidgetListener::OnFoo, this))); 57 // base::Bind(&MyWidgetListener::OnFoo, this)));
56 // } 58 // }
57 // 59 //
58 // MyWidgetListener::~MyWidgetListener() { 60 // MyWidgetListener::~MyWidgetListener() {
59 // // Subscription gets deleted automatically and will deregister 61 // // Subscription gets deleted automatically and will deregister
60 // // the callback in the process. 62 // // the callback in the process.
61 // } 63 // }
62 // 64 //
63 // private: 65 // private:
64 // void OnFoo(const Foo& foo) { 66 // void OnFoo(const Foo& foo) {
65 // // Do something. 67 // // Do something.
66 // } 68 // }
67 // 69 //
68 // scoped_ptr<base::CallbackList<void(const Foo&)>::Subscription> 70 // scoped_ptr<base::CallbackList<void(const Foo&)>::Subscription>
69 // foo_subscription_; 71 // foo_subscription_;
72 //
73 // DISALLOW_COPY_AND_ASSIGN(MyWidgetListener);
70 // }; 74 // };
71 75
72 namespace base { 76 namespace base {
73 77
74 namespace internal { 78 namespace internal {
75 79
76 template <typename CallbackType> 80 template <typename CallbackType>
77 class CallbackListBase { 81 class CallbackListBase {
78 public: 82 public:
79 class Subscription { 83 class Subscription {
80 public: 84 public:
81 Subscription(CallbackListBase<CallbackType>* list, 85 Subscription(CallbackListBase<CallbackType>* list,
82 typename std::list<CallbackType>::iterator iter) 86 typename std::list<CallbackType>::iterator iter)
83 : list_(list), 87 : list_(list),
84 iter_(iter) {} 88 iter_(iter) {
89 }
85 90
86 ~Subscription() { 91 ~Subscription() {
87 if (list_->active_iterator_count_) 92 if (list_->active_iterator_count_)
88 (*iter_).Reset(); 93 iter_->Reset();
89 else 94 else
90 list_->callbacks_.erase(iter_); 95 list_->callbacks_.erase(iter_);
91 } 96 }
92 97
93 private: 98 private:
94 CallbackListBase<CallbackType>* list_; 99 CallbackListBase<CallbackType>* list_;
95 typename std::list<CallbackType>::iterator iter_; 100 typename std::list<CallbackType>::iterator iter_;
96 101
97 DISALLOW_COPY_AND_ASSIGN(Subscription); 102 DISALLOW_COPY_AND_ASSIGN(Subscription);
98 }; 103 };
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 ++list_iter_; 143 ++list_iter_;
139 } 144 }
140 return cb; 145 return cb;
141 } 146 }
142 147
143 private: 148 private:
144 CallbackListBase<CallbackType>* list_; 149 CallbackListBase<CallbackType>* list_;
145 typename std::list<CallbackType>::iterator list_iter_; 150 typename std::list<CallbackType>::iterator list_iter_;
146 }; 151 };
147 152
148 CallbackListBase() 153 CallbackListBase() : active_iterator_count_(0) {}
149 : active_iterator_count_(0) {}
150 154
151 ~CallbackListBase() { 155 ~CallbackListBase() {
152 DCHECK_EQ(0, active_iterator_count_); 156 DCHECK_EQ(0, active_iterator_count_);
153 DCHECK_EQ(0U, callbacks_.size()); 157 DCHECK_EQ(0U, callbacks_.size());
154 } 158 }
155 159
156 // Returns an instance of a CallbackListBase::Iterator which can be used 160 // Returns an instance of a CallbackListBase::Iterator which can be used
157 // to run callbacks. 161 // to run callbacks.
158 Iterator GetIterator() { 162 Iterator GetIterator() {
159 return Iterator(this); 163 return Iterator(this);
(...skipping 27 matching lines...) Expand all
187 : public internal::CallbackListBase<Callback<void(void)> > { 191 : public internal::CallbackListBase<Callback<void(void)> > {
188 public: 192 public:
189 typedef Callback<void(void)> CallbackType; 193 typedef Callback<void(void)> CallbackType;
190 194
191 CallbackList() {} 195 CallbackList() {}
192 196
193 void Notify() { 197 void Notify() {
194 internal::CallbackListBase<CallbackType>::Iterator it = 198 internal::CallbackListBase<CallbackType>::Iterator it =
195 this->GetIterator(); 199 this->GetIterator();
196 CallbackType* cb; 200 CallbackType* cb;
197 while((cb = it.GetNext()) != NULL) { 201 while ((cb = it.GetNext()) != NULL) {
198 cb->Run(); 202 cb->Run();
199 } 203 }
200 } 204 }
201 205
202 private: 206 private:
203 DISALLOW_COPY_AND_ASSIGN(CallbackList); 207 DISALLOW_COPY_AND_ASSIGN(CallbackList);
204 }; 208 };
205 209
206 template <typename A1> 210 template <typename A1>
207 class CallbackList<void(A1)> 211 class CallbackList<void(A1)>
208 : public internal::CallbackListBase< 212 : public internal::CallbackListBase<Callback<void(A1)> > {
209 Callback<void(A1)> > {
210 public: 213 public:
211 typedef Callback<void(A1)> CallbackType; 214 typedef Callback<void(A1)> CallbackType;
212 215
213 CallbackList() {} 216 CallbackList() {}
214 217
215 void Notify(typename internal::CallbackParamTraits<A1>::ForwardType a1) { 218 void Notify(typename internal::CallbackParamTraits<A1>::ForwardType a1) {
216 typename internal::CallbackListBase<CallbackType>::Iterator it = 219 typename internal::CallbackListBase<CallbackType>::Iterator it =
217 this->GetIterator(); 220 this->GetIterator();
218 CallbackType* cb; 221 CallbackType* cb;
219 while((cb = it.GetNext()) != NULL) { 222 while ((cb = it.GetNext()) != NULL) {
220 cb->Run(a1); 223 cb->Run(a1);
221 } 224 }
222 } 225 }
223 226
224 private: 227 private:
225 DISALLOW_COPY_AND_ASSIGN(CallbackList); 228 DISALLOW_COPY_AND_ASSIGN(CallbackList);
226 }; 229 };
227 230
228 template <typename A1, typename A2> 231 template <typename A1, typename A2>
229 class CallbackList<void(A1, A2)> 232 class CallbackList<void(A1, A2)>
230 : public internal::CallbackListBase< 233 : public internal::CallbackListBase<Callback<void(A1, A2)> > {
231 Callback<void(A1, A2)> > {
232 public: 234 public:
233 typedef Callback<void(A1, A2)> CallbackType; 235 typedef Callback<void(A1, A2)> CallbackType;
234 236
235 CallbackList() {} 237 CallbackList() {}
236 238
237 void Notify(typename internal::CallbackParamTraits<A1>::ForwardType a1, 239 void Notify(typename internal::CallbackParamTraits<A1>::ForwardType a1,
238 typename internal::CallbackParamTraits<A2>::ForwardType a2) { 240 typename internal::CallbackParamTraits<A2>::ForwardType a2) {
239 typename internal::CallbackListBase<CallbackType>::Iterator it = 241 typename internal::CallbackListBase<CallbackType>::Iterator it =
240 this->GetIterator(); 242 this->GetIterator();
241 CallbackType* cb; 243 CallbackType* cb;
242 while((cb = it.GetNext()) != NULL) { 244 while ((cb = it.GetNext()) != NULL) {
243 cb->Run(a1, a2); 245 cb->Run(a1, a2);
244 } 246 }
245 } 247 }
246 248
247 private: 249 private:
248 DISALLOW_COPY_AND_ASSIGN(CallbackList); 250 DISALLOW_COPY_AND_ASSIGN(CallbackList);
249 }; 251 };
250 252
251 template <typename A1, typename A2, typename A3> 253 template <typename A1, typename A2, typename A3>
252 class CallbackList<void(A1, A2, A3)> 254 class CallbackList<void(A1, A2, A3)>
253 : public internal::CallbackListBase< 255 : public internal::CallbackListBase<Callback<void(A1, A2, A3)> > {
254 Callback<void(A1, A2, A3)> > {
255 public: 256 public:
256 typedef Callback<void(A1, A2, A3)> CallbackType; 257 typedef Callback<void(A1, A2, A3)> CallbackType;
257 258
258 CallbackList() {} 259 CallbackList() {}
259 260
260 void Notify(typename internal::CallbackParamTraits<A1>::ForwardType a1, 261 void Notify(typename internal::CallbackParamTraits<A1>::ForwardType a1,
261 typename internal::CallbackParamTraits<A2>::ForwardType a2, 262 typename internal::CallbackParamTraits<A2>::ForwardType a2,
262 typename internal::CallbackParamTraits<A3>::ForwardType a3) { 263 typename internal::CallbackParamTraits<A3>::ForwardType a3) {
263 typename internal::CallbackListBase<CallbackType>::Iterator it = 264 typename internal::CallbackListBase<CallbackType>::Iterator it =
264 this->GetIterator(); 265 this->GetIterator();
265 CallbackType* cb; 266 CallbackType* cb;
266 while((cb = it.GetNext()) != NULL) { 267 while ((cb = it.GetNext()) != NULL) {
267 cb->Run(a1, a2, a3); 268 cb->Run(a1, a2, a3);
268 } 269 }
269 } 270 }
270 271
271 private: 272 private:
272 DISALLOW_COPY_AND_ASSIGN(CallbackList); 273 DISALLOW_COPY_AND_ASSIGN(CallbackList);
273 }; 274 };
274 275
275 template <typename A1, typename A2, typename A3, typename A4> 276 template <typename A1, typename A2, typename A3, typename A4>
276 class CallbackList<void(A1, A2, A3, A4)> 277 class CallbackList<void(A1, A2, A3, A4)>
277 : public internal::CallbackListBase< 278 : public internal::CallbackListBase<Callback<void(A1, A2, A3, A4)> > {
278 Callback<void(A1, A2, A3, A4)> > {
279 public: 279 public:
280 typedef Callback<void(A1, A2, A3, A4)> CallbackType; 280 typedef Callback<void(A1, A2, A3, A4)> CallbackType;
281 281
282 CallbackList() {} 282 CallbackList() {}
283 283
284 void Notify(typename internal::CallbackParamTraits<A1>::ForwardType a1, 284 void Notify(typename internal::CallbackParamTraits<A1>::ForwardType a1,
285 typename internal::CallbackParamTraits<A2>::ForwardType a2, 285 typename internal::CallbackParamTraits<A2>::ForwardType a2,
286 typename internal::CallbackParamTraits<A3>::ForwardType a3, 286 typename internal::CallbackParamTraits<A3>::ForwardType a3,
287 typename internal::CallbackParamTraits<A4>::ForwardType a4) { 287 typename internal::CallbackParamTraits<A4>::ForwardType a4) {
288 typename internal::CallbackListBase<CallbackType>::Iterator it = 288 typename internal::CallbackListBase<CallbackType>::Iterator it =
289 this->GetIterator(); 289 this->GetIterator();
290 CallbackType* cb; 290 CallbackType* cb;
291 while((cb = it.GetNext()) != NULL) { 291 while ((cb = it.GetNext()) != NULL) {
292 cb->Run(a1, a2, a3, a4); 292 cb->Run(a1, a2, a3, a4);
293 } 293 }
294 } 294 }
295 295
296 private: 296 private:
297 DISALLOW_COPY_AND_ASSIGN(CallbackList); 297 DISALLOW_COPY_AND_ASSIGN(CallbackList);
298 }; 298 };
299 299
300 template <typename A1, typename A2, typename A3, typename A4, typename A5> 300 template <typename A1, typename A2, typename A3, typename A4, typename A5>
301 class CallbackList<void(A1, A2, A3, A4, A5)> 301 class CallbackList<void(A1, A2, A3, A4, A5)>
302 : public internal::CallbackListBase< 302 : public internal::CallbackListBase<Callback<void(A1, A2, A3, A4, A5)> > {
303 Callback<void(A1, A2, A3, A4, A5)> > {
304 public: 303 public:
305 typedef Callback<void(A1, A2, A3, A4, A5)> CallbackType; 304 typedef Callback<void(A1, A2, A3, A4, A5)> CallbackType;
306 305
307 CallbackList() {} 306 CallbackList() {}
308 307
309 void Notify(typename internal::CallbackParamTraits<A1>::ForwardType a1, 308 void Notify(typename internal::CallbackParamTraits<A1>::ForwardType a1,
310 typename internal::CallbackParamTraits<A2>::ForwardType a2, 309 typename internal::CallbackParamTraits<A2>::ForwardType a2,
311 typename internal::CallbackParamTraits<A3>::ForwardType a3, 310 typename internal::CallbackParamTraits<A3>::ForwardType a3,
312 typename internal::CallbackParamTraits<A4>::ForwardType a4, 311 typename internal::CallbackParamTraits<A4>::ForwardType a4,
313 typename internal::CallbackParamTraits<A5>::ForwardType a5) { 312 typename internal::CallbackParamTraits<A5>::ForwardType a5) {
314 typename internal::CallbackListBase<CallbackType>::Iterator it = 313 typename internal::CallbackListBase<CallbackType>::Iterator it =
315 this->GetIterator(); 314 this->GetIterator();
316 CallbackType* cb; 315 CallbackType* cb;
317 while((cb = it.GetNext()) != NULL) { 316 while ((cb = it.GetNext()) != NULL) {
318 cb->Run(a1, a2, a3, a4, a5); 317 cb->Run(a1, a2, a3, a4, a5);
319 } 318 }
320 } 319 }
321 320
322 private: 321 private:
323 DISALLOW_COPY_AND_ASSIGN(CallbackList); 322 DISALLOW_COPY_AND_ASSIGN(CallbackList);
324 }; 323 };
325 324
326 template <typename A1, typename A2, typename A3, typename A4, typename A5, 325 template <typename A1, typename A2, typename A3, typename A4, typename A5,
327 typename A6> 326 typename A6>
328 class CallbackList<void(A1, A2, A3, A4, A5, A6)> 327 class CallbackList<void(A1, A2, A3, A4, A5, A6)>
329 : public internal::CallbackListBase< 328 : public internal::CallbackListBase<Callback<void(A1, A2, A3, A4, A5,
330 Callback<void(A1, A2, A3, A4, A5, A6)> > { 329 A6)> > {
331 public: 330 public:
332 typedef Callback<void(A1, A2, A3, A4, A5, A6)> CallbackType; 331 typedef Callback<void(A1, A2, A3, A4, A5, A6)> CallbackType;
333 332
334 CallbackList() {} 333 CallbackList() {}
335 334
336 void Notify(typename internal::CallbackParamTraits<A1>::ForwardType a1, 335 void Notify(typename internal::CallbackParamTraits<A1>::ForwardType a1,
337 typename internal::CallbackParamTraits<A2>::ForwardType a2, 336 typename internal::CallbackParamTraits<A2>::ForwardType a2,
338 typename internal::CallbackParamTraits<A3>::ForwardType a3, 337 typename internal::CallbackParamTraits<A3>::ForwardType a3,
339 typename internal::CallbackParamTraits<A4>::ForwardType a4, 338 typename internal::CallbackParamTraits<A4>::ForwardType a4,
340 typename internal::CallbackParamTraits<A5>::ForwardType a5, 339 typename internal::CallbackParamTraits<A5>::ForwardType a5,
341 typename internal::CallbackParamTraits<A6>::ForwardType a6) { 340 typename internal::CallbackParamTraits<A6>::ForwardType a6) {
342 typename internal::CallbackListBase<CallbackType>::Iterator it = 341 typename internal::CallbackListBase<CallbackType>::Iterator it =
343 this->GetIterator(); 342 this->GetIterator();
344 CallbackType* cb; 343 CallbackType* cb;
345 while((cb = it.GetNext()) != NULL) { 344 while ((cb = it.GetNext()) != NULL) {
346 cb->Run(a1, a2, a3, a4, a5, a6); 345 cb->Run(a1, a2, a3, a4, a5, a6);
347 } 346 }
348 } 347 }
349 348
350 private: 349 private:
351 DISALLOW_COPY_AND_ASSIGN(CallbackList); 350 DISALLOW_COPY_AND_ASSIGN(CallbackList);
352 }; 351 };
353 352
354 template <typename A1, typename A2, typename A3, typename A4, typename A5, 353 template <typename A1, typename A2, typename A3, typename A4, typename A5,
355 typename A6, typename A7> 354 typename A6, typename A7>
356 class CallbackList<void(A1, A2, A3, A4, A5, A6, A7)> 355 class CallbackList<void(A1, A2, A3, A4, A5, A6, A7)>
357 : public internal::CallbackListBase< 356 : public internal::CallbackListBase<Callback<void(A1, A2, A3, A4, A5, A6,
358 Callback<void(A1, A2, A3, A4, A5, A6, A7)> > { 357 A7)> > {
359 public: 358 public:
360 typedef Callback<void(A1, A2, A3, A4, A5, A6, A7)> CallbackType; 359 typedef Callback<void(A1, A2, A3, A4, A5, A6, A7)> CallbackType;
361 360
362 CallbackList() {} 361 CallbackList() {}
363 362
364 void Notify(typename internal::CallbackParamTraits<A1>::ForwardType a1, 363 void Notify(typename internal::CallbackParamTraits<A1>::ForwardType a1,
365 typename internal::CallbackParamTraits<A2>::ForwardType a2, 364 typename internal::CallbackParamTraits<A2>::ForwardType a2,
366 typename internal::CallbackParamTraits<A3>::ForwardType a3, 365 typename internal::CallbackParamTraits<A3>::ForwardType a3,
367 typename internal::CallbackParamTraits<A4>::ForwardType a4, 366 typename internal::CallbackParamTraits<A4>::ForwardType a4,
368 typename internal::CallbackParamTraits<A5>::ForwardType a5, 367 typename internal::CallbackParamTraits<A5>::ForwardType a5,
369 typename internal::CallbackParamTraits<A6>::ForwardType a6, 368 typename internal::CallbackParamTraits<A6>::ForwardType a6,
370 typename internal::CallbackParamTraits<A7>::ForwardType a7) { 369 typename internal::CallbackParamTraits<A7>::ForwardType a7) {
371 typename internal::CallbackListBase<CallbackType>::Iterator it = 370 typename internal::CallbackListBase<CallbackType>::Iterator it =
372 this->GetIterator(); 371 this->GetIterator();
373 CallbackType* cb; 372 CallbackType* cb;
374 while((cb = it.GetNext()) != NULL) { 373 while ((cb = it.GetNext()) != NULL) {
375 cb->Run(a1, a2, a3, a4, a5, a6, a7); 374 cb->Run(a1, a2, a3, a4, a5, a6, a7);
376 } 375 }
377 } 376 }
378 377
379 private: 378 private:
380 DISALLOW_COPY_AND_ASSIGN(CallbackList); 379 DISALLOW_COPY_AND_ASSIGN(CallbackList);
381 }; 380 };
382 381
383 } // namespace base 382 } // namespace base
384 383
385 #endif // BASE_CALLBACK_LIST_H_ 384 #endif // BASE_CALLBACK_LIST_H_
OLDNEW
« no previous file with comments | « no previous file | base/callback_list.h.pump » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698