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
5 $$ http://code.google.com/p/googletest/wiki/PumpManual
10 // Copyright 2014 The Chromium Authors. All rights reserved.
11 // Use of this source code is governed by a BSD-style license that can be
12 // found in the LICENSE file.
14 #ifndef MOJO_PUBLIC_CPP_BINDINGS_CALLBACK_H_
15 #define MOJO_PUBLIC_CPP_BINDINGS_CALLBACK_H_
17 #include "mojo/public/cpp/bindings/lib/callback_internal.h"
18 #include "mojo/public/cpp/bindings/lib/shared_ptr.h"
19 #include "mojo/public/cpp/bindings/lib/template_util.h"
23 template <typename Sig>
26 $range ARITY 0..MAX_ARITY
30 template <$for ARG , [[typename A$(ARG)]]>
31 class Callback<void($for ARG , [[A$(ARG)]])> {
34 virtual ~Runnable() {}
35 virtual void Run($if ARITY > 0 [[
38 [[typename internal::Callback_ParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) const = 0;
43 // The Callback assumes ownership of |runnable|.
44 explicit Callback(Runnable* runnable) : sink_(runnable) {}
46 // Any class that is copy-constructable and has a compatible Run method may
47 // be adapted to a Callback using this constructor.
48 template <typename Sink>
49 Callback(const Sink& sink) : sink_(new Adapter<Sink>(sink)) {}
51 void Run($if ARITY > 1 [[
54 [[typename internal::Callback_ParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) const {
56 sink_->Run($if ARITY > 1 [[
59 [[internal::Forward(a$(ARG))]]);
62 bool is_null() const {
67 template <typename Sink>
68 struct Adapter : public Runnable {
69 explicit Adapter(const Sink& sink) : sink(sink) {}
70 virtual void Run($if ARITY > 0 [[
73 [[typename internal::Callback_ParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) const MOJO_OVERRIDE {
74 sink.Run($if ARITY > 1 [[
77 [[internal::Forward(a$(ARG))]]);
82 internal::SharedPtr<Runnable> sink_;
87 typedef Callback<void()> Closure;
91 #endif // MOJO_PUBLIC_CPP_BINDINGS_CALLBACK_H_