| OLD | NEW |
| (Empty) |
| 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 | |
| 3 $$ can be found here: | |
| 4 $$ | |
| 5 $$ http://code.google.com/p/googletest/wiki/PumpManual | |
| 6 $$ | |
| 7 | |
| 8 $var MAX_ARITY = 7 | |
| 9 | |
| 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. | |
| 13 | |
| 14 #ifndef MOJO_PUBLIC_BINDINGS_CALLBACK_H_ | |
| 15 #define MOJO_PUBLIC_BINDINGS_CALLBACK_H_ | |
| 16 | |
| 17 #include "mojo/public/bindings/lib/callback_internal.h" | |
| 18 #include "mojo/public/bindings/lib/shared_ptr.h" | |
| 19 | |
| 20 namespace mojo { | |
| 21 | |
| 22 template <typename Sig> | |
| 23 class Callback; | |
| 24 | |
| 25 $range ARITY 0..MAX_ARITY | |
| 26 $for ARITY [[ | |
| 27 $range ARG 1..ARITY | |
| 28 | |
| 29 template <$for ARG , [[typename A$(ARG)]]> | |
| 30 class Callback<void($for ARG , [[A$(ARG)]])> { | |
| 31 public: | |
| 32 struct Runnable { | |
| 33 virtual ~Runnable() {} | |
| 34 virtual void Run( | |
| 35 $for ARG , | |
| 36 [[typename internal::Callback_ParamTraits<A$(ARG)>::ForwardType a$(ARG)]
]) const = 0; | |
| 37 }; | |
| 38 | |
| 39 Callback() {} | |
| 40 | |
| 41 // The Callback assumes ownership of |runnable|. | |
| 42 explicit Callback(Runnable* runnable) : sink_(runnable) {} | |
| 43 | |
| 44 // Any class that is copy-constructable and has a compatible Run method may | |
| 45 // be adapted to a Callback using this constructor. | |
| 46 template <typename Sink> | |
| 47 Callback(const Sink& sink) : sink_(new Adapter<Sink>(sink)) {} | |
| 48 | |
| 49 void Run( | |
| 50 $for ARG , | |
| 51 [[typename internal::Callback_ParamTraits<A$(ARG)>::ForwardType a$(ARG)]])
const { | |
| 52 if (sink_.get()) | |
| 53 sink_->Run( | |
| 54 $for ARG , | |
| 55 [[internal::Callback_Forward(a$(ARG))]]); | |
| 56 } | |
| 57 | |
| 58 private: | |
| 59 template <typename Sink> | |
| 60 struct Adapter : public Runnable { | |
| 61 explicit Adapter(const Sink& sink) : sink(sink) {} | |
| 62 virtual void Run( | |
| 63 $for ARG , | |
| 64 [[typename internal::Callback_ParamTraits<A$(ARG)>::ForwardType a$(ARG)]
]) const MOJO_OVERRIDE { | |
| 65 sink.Run( | |
| 66 $for ARG , | |
| 67 [[internal::Callback_Forward(a$(ARG))]]); | |
| 68 } | |
| 69 Sink sink; | |
| 70 }; | |
| 71 | |
| 72 internal::SharedPtr<Runnable> sink_; | |
| 73 }; | |
| 74 | |
| 75 ]] $$ for ARITY | |
| 76 | |
| 77 } // namespace mojo | |
| 78 | |
| 79 #endif // MOJO_PUBLIC_BINDINGS_CALLBACK_H_ | |
| OLD | NEW |