Index: mojo/public/bindings/callback.h.pump |
diff --git a/mojo/public/bindings/callback.h.pump b/mojo/public/bindings/callback.h.pump |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2ba1dfcd12c6683538dddf47033a1e1df7f69289 |
--- /dev/null |
+++ b/mojo/public/bindings/callback.h.pump |
@@ -0,0 +1,79 @@ |
+$$ This is a pump file for generating file templates. Pump is a python |
+$$ script that is part of the Google Test suite of utilities. Description |
+$$ can be found here: |
+$$ |
+$$ http://code.google.com/p/googletest/wiki/PumpManual |
+$$ |
+ |
+$var MAX_ARITY = 7 |
+ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MOJO_PUBLIC_BINDINGS_CALLBACK_H_ |
+#define MOJO_PUBLIC_BINDINGS_CALLBACK_H_ |
+ |
+#include "mojo/public/bindings/lib/callback_internal.h" |
+#include "mojo/public/bindings/lib/shared_ptr.h" |
+ |
+namespace mojo { |
+ |
+template <typename Sig> |
+class Callback; |
+ |
+$range ARITY 0..MAX_ARITY |
+$for ARITY [[ |
+$range ARG 1..ARITY |
+ |
+template <$for ARG , [[typename A$(ARG)]]> |
+class Callback<void($for ARG , [[A$(ARG)]])> { |
+ public: |
+ struct Runnable { |
+ virtual ~Runnable() {} |
+ virtual void Run( |
+ $for ARG , |
+ [[typename internal::Callback_ParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) const = 0; |
+ }; |
+ |
+ Callback() {} |
+ |
+ // The Callback assumes ownership of |runnable|. |
+ explicit Callback(Runnable* runnable) : sink_(runnable) {} |
+ |
+ // Any class that is copy-constructable and has a compatible Run method may |
+ // be adapted to a Callback using this constructor. |
+ template <typename Sink> |
+ Callback(const Sink& sink) : sink_(new Adapter<Sink>(sink)) {} |
+ |
+ void Run( |
+ $for ARG , |
+ [[typename internal::Callback_ParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) const { |
+ if (sink_.get()) |
+ sink_->Run( |
+ $for ARG , |
+ [[internal::Callback_Forward(a$(ARG))]]); |
+ } |
+ |
+ private: |
+ template <typename Sink> |
+ struct Adapter : public Runnable { |
+ explicit Adapter(const Sink& sink) : sink(sink) {} |
+ virtual void Run( |
+ $for ARG , |
+ [[typename internal::Callback_ParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) const MOJO_OVERRIDE { |
+ sink.Run( |
+ $for ARG , |
+ [[internal::Callback_Forward(a$(ARG))]]); |
+ } |
+ Sink sink; |
+ }; |
+ |
+ internal::SharedPtr<Runnable> sink_; |
+}; |
+ |
+]] $$ for ARITY |
+ |
+} // namespace mojo |
+ |
+#endif // MOJO_PUBLIC_BINDINGS_CALLBACK_H_ |