Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / mojo / public / cpp / bindings / callback.h
blob8d39b0231da927cdd068d3a19e5e3f3d94cb24ad
1 // This file was GENERATED by command:
2 // pump.py callback.h.pump
3 // DO NOT EDIT BY HAND!!!
7 // Copyright 2014 The Chromium Authors. All rights reserved.
8 // Use of this source code is governed by a BSD-style license that can be
9 // found in the LICENSE file.
11 #ifndef MOJO_PUBLIC_CPP_BINDINGS_CALLBACK_H_
12 #define MOJO_PUBLIC_CPP_BINDINGS_CALLBACK_H_
14 #include "mojo/public/cpp/bindings/lib/callback_internal.h"
15 #include "mojo/public/cpp/bindings/lib/shared_ptr.h"
16 #include "mojo/public/cpp/bindings/lib/template_util.h"
18 namespace mojo {
20 template <typename Sig>
21 class Callback;
23 template <>
24 class Callback<void()> {
25 public:
26 struct Runnable {
27 virtual ~Runnable() {}
28 virtual void Run() const = 0;
31 Callback() {}
33 // The Callback assumes ownership of |runnable|.
34 explicit Callback(Runnable* runnable) : sink_(runnable) {}
36 // Any class that is copy-constructable and has a compatible Run method may
37 // be adapted to a Callback using this constructor.
38 template <typename Sink>
39 Callback(const Sink& sink) : sink_(new Adapter<Sink>(sink)) {}
41 void Run() const {
42 if (sink_.get())
43 sink_->Run();
46 bool is_null() const {
47 return !sink_.get();
50 private:
51 template <typename Sink>
52 struct Adapter : public Runnable {
53 explicit Adapter(const Sink& sink) : sink(sink) {}
54 virtual void Run() const MOJO_OVERRIDE {
55 sink.Run();
57 Sink sink;
60 internal::SharedPtr<Runnable> sink_;
63 template <typename A1>
64 class Callback<void(A1)> {
65 public:
66 struct Runnable {
67 virtual ~Runnable() {}
68 virtual void Run(
69 typename internal::Callback_ParamTraits<A1>::ForwardType a1) const = 0;
72 Callback() {}
74 // The Callback assumes ownership of |runnable|.
75 explicit Callback(Runnable* runnable) : sink_(runnable) {}
77 // Any class that is copy-constructable and has a compatible Run method may
78 // be adapted to a Callback using this constructor.
79 template <typename Sink>
80 Callback(const Sink& sink) : sink_(new Adapter<Sink>(sink)) {}
82 void Run(typename internal::Callback_ParamTraits<A1>::ForwardType a1) const {
83 if (sink_.get())
84 sink_->Run(internal::Forward(a1));
87 bool is_null() const {
88 return !sink_.get();
91 private:
92 template <typename Sink>
93 struct Adapter : public Runnable {
94 explicit Adapter(const Sink& sink) : sink(sink) {}
95 virtual void Run(
96 typename internal::Callback_ParamTraits<A1>::ForwardType a1) const
97 MOJO_OVERRIDE {
98 sink.Run(internal::Forward(a1));
100 Sink sink;
103 internal::SharedPtr<Runnable> sink_;
106 template <typename A1, typename A2>
107 class Callback<void(A1, A2)> {
108 public:
109 struct Runnable {
110 virtual ~Runnable() {}
111 virtual void Run(
112 typename internal::Callback_ParamTraits<A1>::ForwardType a1,
113 typename internal::Callback_ParamTraits<A2>::ForwardType a2) const = 0;
116 Callback() {}
118 // The Callback assumes ownership of |runnable|.
119 explicit Callback(Runnable* runnable) : sink_(runnable) {}
121 // Any class that is copy-constructable and has a compatible Run method may
122 // be adapted to a Callback using this constructor.
123 template <typename Sink>
124 Callback(const Sink& sink) : sink_(new Adapter<Sink>(sink)) {}
126 void Run(
127 typename internal::Callback_ParamTraits<A1>::ForwardType a1,
128 typename internal::Callback_ParamTraits<A2>::ForwardType a2) const {
129 if (sink_.get())
130 sink_->Run(
131 internal::Forward(a1),
132 internal::Forward(a2));
135 bool is_null() const {
136 return !sink_.get();
139 private:
140 template <typename Sink>
141 struct Adapter : public Runnable {
142 explicit Adapter(const Sink& sink) : sink(sink) {}
143 virtual void Run(
144 typename internal::Callback_ParamTraits<A1>::ForwardType a1,
145 typename internal::Callback_ParamTraits<A2>::ForwardType a2) const
146 MOJO_OVERRIDE {
147 sink.Run(
148 internal::Forward(a1),
149 internal::Forward(a2));
151 Sink sink;
154 internal::SharedPtr<Runnable> sink_;
157 template <typename A1, typename A2, typename A3>
158 class Callback<void(A1, A2, A3)> {
159 public:
160 struct Runnable {
161 virtual ~Runnable() {}
162 virtual void Run(
163 typename internal::Callback_ParamTraits<A1>::ForwardType a1,
164 typename internal::Callback_ParamTraits<A2>::ForwardType a2,
165 typename internal::Callback_ParamTraits<A3>::ForwardType a3) const = 0;
168 Callback() {}
170 // The Callback assumes ownership of |runnable|.
171 explicit Callback(Runnable* runnable) : sink_(runnable) {}
173 // Any class that is copy-constructable and has a compatible Run method may
174 // be adapted to a Callback using this constructor.
175 template <typename Sink>
176 Callback(const Sink& sink) : sink_(new Adapter<Sink>(sink)) {}
178 void Run(
179 typename internal::Callback_ParamTraits<A1>::ForwardType a1,
180 typename internal::Callback_ParamTraits<A2>::ForwardType a2,
181 typename internal::Callback_ParamTraits<A3>::ForwardType a3) const {
182 if (sink_.get())
183 sink_->Run(
184 internal::Forward(a1),
185 internal::Forward(a2),
186 internal::Forward(a3));
189 bool is_null() const {
190 return !sink_.get();
193 private:
194 template <typename Sink>
195 struct Adapter : public Runnable {
196 explicit Adapter(const Sink& sink) : sink(sink) {}
197 virtual void Run(
198 typename internal::Callback_ParamTraits<A1>::ForwardType a1,
199 typename internal::Callback_ParamTraits<A2>::ForwardType a2,
200 typename internal::Callback_ParamTraits<A3>::ForwardType a3) const
201 MOJO_OVERRIDE {
202 sink.Run(
203 internal::Forward(a1),
204 internal::Forward(a2),
205 internal::Forward(a3));
207 Sink sink;
210 internal::SharedPtr<Runnable> sink_;
213 template <typename A1, typename A2, typename A3, typename A4>
214 class Callback<void(A1, A2, A3, A4)> {
215 public:
216 struct Runnable {
217 virtual ~Runnable() {}
218 virtual void Run(
219 typename internal::Callback_ParamTraits<A1>::ForwardType a1,
220 typename internal::Callback_ParamTraits<A2>::ForwardType a2,
221 typename internal::Callback_ParamTraits<A3>::ForwardType a3,
222 typename internal::Callback_ParamTraits<A4>::ForwardType a4) const = 0;
225 Callback() {}
227 // The Callback assumes ownership of |runnable|.
228 explicit Callback(Runnable* runnable) : sink_(runnable) {}
230 // Any class that is copy-constructable and has a compatible Run method may
231 // be adapted to a Callback using this constructor.
232 template <typename Sink>
233 Callback(const Sink& sink) : sink_(new Adapter<Sink>(sink)) {}
235 void Run(
236 typename internal::Callback_ParamTraits<A1>::ForwardType a1,
237 typename internal::Callback_ParamTraits<A2>::ForwardType a2,
238 typename internal::Callback_ParamTraits<A3>::ForwardType a3,
239 typename internal::Callback_ParamTraits<A4>::ForwardType a4) const {
240 if (sink_.get())
241 sink_->Run(
242 internal::Forward(a1),
243 internal::Forward(a2),
244 internal::Forward(a3),
245 internal::Forward(a4));
248 bool is_null() const {
249 return !sink_.get();
252 private:
253 template <typename Sink>
254 struct Adapter : public Runnable {
255 explicit Adapter(const Sink& sink) : sink(sink) {}
256 virtual void Run(
257 typename internal::Callback_ParamTraits<A1>::ForwardType a1,
258 typename internal::Callback_ParamTraits<A2>::ForwardType a2,
259 typename internal::Callback_ParamTraits<A3>::ForwardType a3,
260 typename internal::Callback_ParamTraits<A4>::ForwardType a4) const
261 MOJO_OVERRIDE {
262 sink.Run(
263 internal::Forward(a1),
264 internal::Forward(a2),
265 internal::Forward(a3),
266 internal::Forward(a4));
268 Sink sink;
271 internal::SharedPtr<Runnable> sink_;
274 template <typename A1, typename A2, typename A3, typename A4, typename A5>
275 class Callback<void(A1, A2, A3, A4, A5)> {
276 public:
277 struct Runnable {
278 virtual ~Runnable() {}
279 virtual void Run(
280 typename internal::Callback_ParamTraits<A1>::ForwardType a1,
281 typename internal::Callback_ParamTraits<A2>::ForwardType a2,
282 typename internal::Callback_ParamTraits<A3>::ForwardType a3,
283 typename internal::Callback_ParamTraits<A4>::ForwardType a4,
284 typename internal::Callback_ParamTraits<A5>::ForwardType a5) const = 0;
287 Callback() {}
289 // The Callback assumes ownership of |runnable|.
290 explicit Callback(Runnable* runnable) : sink_(runnable) {}
292 // Any class that is copy-constructable and has a compatible Run method may
293 // be adapted to a Callback using this constructor.
294 template <typename Sink>
295 Callback(const Sink& sink) : sink_(new Adapter<Sink>(sink)) {}
297 void Run(
298 typename internal::Callback_ParamTraits<A1>::ForwardType a1,
299 typename internal::Callback_ParamTraits<A2>::ForwardType a2,
300 typename internal::Callback_ParamTraits<A3>::ForwardType a3,
301 typename internal::Callback_ParamTraits<A4>::ForwardType a4,
302 typename internal::Callback_ParamTraits<A5>::ForwardType a5) const {
303 if (sink_.get())
304 sink_->Run(
305 internal::Forward(a1),
306 internal::Forward(a2),
307 internal::Forward(a3),
308 internal::Forward(a4),
309 internal::Forward(a5));
312 bool is_null() const {
313 return !sink_.get();
316 private:
317 template <typename Sink>
318 struct Adapter : public Runnable {
319 explicit Adapter(const Sink& sink) : sink(sink) {}
320 virtual void Run(
321 typename internal::Callback_ParamTraits<A1>::ForwardType a1,
322 typename internal::Callback_ParamTraits<A2>::ForwardType a2,
323 typename internal::Callback_ParamTraits<A3>::ForwardType a3,
324 typename internal::Callback_ParamTraits<A4>::ForwardType a4,
325 typename internal::Callback_ParamTraits<A5>::ForwardType a5) const
326 MOJO_OVERRIDE {
327 sink.Run(
328 internal::Forward(a1),
329 internal::Forward(a2),
330 internal::Forward(a3),
331 internal::Forward(a4),
332 internal::Forward(a5));
334 Sink sink;
337 internal::SharedPtr<Runnable> sink_;
340 template <typename A1, typename A2, typename A3, typename A4, typename A5,
341 typename A6>
342 class Callback<void(A1, A2, A3, A4, A5, A6)> {
343 public:
344 struct Runnable {
345 virtual ~Runnable() {}
346 virtual void Run(
347 typename internal::Callback_ParamTraits<A1>::ForwardType a1,
348 typename internal::Callback_ParamTraits<A2>::ForwardType a2,
349 typename internal::Callback_ParamTraits<A3>::ForwardType a3,
350 typename internal::Callback_ParamTraits<A4>::ForwardType a4,
351 typename internal::Callback_ParamTraits<A5>::ForwardType a5,
352 typename internal::Callback_ParamTraits<A6>::ForwardType a6) const = 0;
355 Callback() {}
357 // The Callback assumes ownership of |runnable|.
358 explicit Callback(Runnable* runnable) : sink_(runnable) {}
360 // Any class that is copy-constructable and has a compatible Run method may
361 // be adapted to a Callback using this constructor.
362 template <typename Sink>
363 Callback(const Sink& sink) : sink_(new Adapter<Sink>(sink)) {}
365 void Run(
366 typename internal::Callback_ParamTraits<A1>::ForwardType a1,
367 typename internal::Callback_ParamTraits<A2>::ForwardType a2,
368 typename internal::Callback_ParamTraits<A3>::ForwardType a3,
369 typename internal::Callback_ParamTraits<A4>::ForwardType a4,
370 typename internal::Callback_ParamTraits<A5>::ForwardType a5,
371 typename internal::Callback_ParamTraits<A6>::ForwardType a6) const {
372 if (sink_.get())
373 sink_->Run(
374 internal::Forward(a1),
375 internal::Forward(a2),
376 internal::Forward(a3),
377 internal::Forward(a4),
378 internal::Forward(a5),
379 internal::Forward(a6));
382 bool is_null() const {
383 return !sink_.get();
386 private:
387 template <typename Sink>
388 struct Adapter : public Runnable {
389 explicit Adapter(const Sink& sink) : sink(sink) {}
390 virtual void Run(
391 typename internal::Callback_ParamTraits<A1>::ForwardType a1,
392 typename internal::Callback_ParamTraits<A2>::ForwardType a2,
393 typename internal::Callback_ParamTraits<A3>::ForwardType a3,
394 typename internal::Callback_ParamTraits<A4>::ForwardType a4,
395 typename internal::Callback_ParamTraits<A5>::ForwardType a5,
396 typename internal::Callback_ParamTraits<A6>::ForwardType a6) const
397 MOJO_OVERRIDE {
398 sink.Run(
399 internal::Forward(a1),
400 internal::Forward(a2),
401 internal::Forward(a3),
402 internal::Forward(a4),
403 internal::Forward(a5),
404 internal::Forward(a6));
406 Sink sink;
409 internal::SharedPtr<Runnable> sink_;
412 template <typename A1, typename A2, typename A3, typename A4, typename A5,
413 typename A6, typename A7>
414 class Callback<void(A1, A2, A3, A4, A5, A6, A7)> {
415 public:
416 struct Runnable {
417 virtual ~Runnable() {}
418 virtual void Run(
419 typename internal::Callback_ParamTraits<A1>::ForwardType a1,
420 typename internal::Callback_ParamTraits<A2>::ForwardType a2,
421 typename internal::Callback_ParamTraits<A3>::ForwardType a3,
422 typename internal::Callback_ParamTraits<A4>::ForwardType a4,
423 typename internal::Callback_ParamTraits<A5>::ForwardType a5,
424 typename internal::Callback_ParamTraits<A6>::ForwardType a6,
425 typename internal::Callback_ParamTraits<A7>::ForwardType a7) const = 0;
428 Callback() {}
430 // The Callback assumes ownership of |runnable|.
431 explicit Callback(Runnable* runnable) : sink_(runnable) {}
433 // Any class that is copy-constructable and has a compatible Run method may
434 // be adapted to a Callback using this constructor.
435 template <typename Sink>
436 Callback(const Sink& sink) : sink_(new Adapter<Sink>(sink)) {}
438 void Run(
439 typename internal::Callback_ParamTraits<A1>::ForwardType a1,
440 typename internal::Callback_ParamTraits<A2>::ForwardType a2,
441 typename internal::Callback_ParamTraits<A3>::ForwardType a3,
442 typename internal::Callback_ParamTraits<A4>::ForwardType a4,
443 typename internal::Callback_ParamTraits<A5>::ForwardType a5,
444 typename internal::Callback_ParamTraits<A6>::ForwardType a6,
445 typename internal::Callback_ParamTraits<A7>::ForwardType a7) const {
446 if (sink_.get())
447 sink_->Run(
448 internal::Forward(a1),
449 internal::Forward(a2),
450 internal::Forward(a3),
451 internal::Forward(a4),
452 internal::Forward(a5),
453 internal::Forward(a6),
454 internal::Forward(a7));
457 bool is_null() const {
458 return !sink_.get();
461 private:
462 template <typename Sink>
463 struct Adapter : public Runnable {
464 explicit Adapter(const Sink& sink) : sink(sink) {}
465 virtual void Run(
466 typename internal::Callback_ParamTraits<A1>::ForwardType a1,
467 typename internal::Callback_ParamTraits<A2>::ForwardType a2,
468 typename internal::Callback_ParamTraits<A3>::ForwardType a3,
469 typename internal::Callback_ParamTraits<A4>::ForwardType a4,
470 typename internal::Callback_ParamTraits<A5>::ForwardType a5,
471 typename internal::Callback_ParamTraits<A6>::ForwardType a6,
472 typename internal::Callback_ParamTraits<A7>::ForwardType a7) const
473 MOJO_OVERRIDE {
474 sink.Run(
475 internal::Forward(a1),
476 internal::Forward(a2),
477 internal::Forward(a3),
478 internal::Forward(a4),
479 internal::Forward(a5),
480 internal::Forward(a6),
481 internal::Forward(a7));
483 Sink sink;
486 internal::SharedPtr<Runnable> sink_;
489 typedef Callback<void()> Closure;
491 } // namespace mojo
493 #endif // MOJO_PUBLIC_CPP_BINDINGS_CALLBACK_H_