blob: 53dcbd3a618c71a9336e44563e92645c8c6eca38 [file] [log] [blame]
ajwong@chromium.orge2cca632011-02-15 10:27:38 +09001$$ 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
ajwong@chromium.org6f015bd2011-11-29 07:13:54 +09008$$ See comment for MAX_ARITY in base/bind.h.pump.
9$var MAX_ARITY = 7
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +090010$range ARITY 0..MAX_ARITY
ajwong@chromium.orge2cca632011-02-15 10:27:38 +090011
12// Copyright (c) 2011 The Chromium Authors. All rights reserved.
13// Use of this source code is governed by a BSD-style license that can be
14// found in the LICENSE file.
15
16#ifndef BASE_BIND_INTERNAL_H_
17#define BASE_BIND_INTERNAL_H_
18#pragma once
19
20#include "base/bind_helpers.h"
ajwong@chromium.orgfa0ff432011-02-19 08:29:31 +090021#include "base/callback_internal.h"
ajwong@chromium.org27e56852011-10-01 15:31:41 +090022#include "base/memory/raw_scoped_refptr_mismatch_checker.h"
ajwong@chromium.orgc711b822011-05-17 07:35:14 +090023#include "base/memory/weak_ptr.h"
ajwong@chromium.orge2cca632011-02-15 10:27:38 +090024#include "base/template_util.h"
ajwong@chromium.orgcb175342011-02-27 10:25:59 +090025#include "build/build_config.h"
26
27#if defined(OS_WIN)
28#include "base/bind_internal_win.h"
29#endif
ajwong@chromium.orge2cca632011-02-15 10:27:38 +090030
31namespace base {
32namespace internal {
33
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +090034// CONCEPTS:
35// Runnable -- A type (really a type class) that has a single Run() method
36// and a RunType typedef that corresponds to the type of Run().
37// A Runnable can declare that it should treated like a method
38// call by including a typedef named IsMethod. The value of
39// this typedef is NOT inspected, only the existence. When a
40// Runnable declares itself a method, Bind() will enforce special
41// refcounting + WeakPtr handling semantics for the first
42// parameter which is expected to be an object.
43// Functor -- A copyable type representing something that should be called.
44// All function pointers, Callback<>, and Runnables are functors
45// even if the invocation syntax differs.
46// RunType -- A function type (as opposed to function _pointer_ type) for
47// a Run() function. Usually just a convenience typedef.
48// (Bound)ArgsType -- A function type that is being (ab)used to store the
49// types of set of arguments. The "return" type is always
50// void here. We use this hack so that we do not need
51// a new type name for each arity of type. (eg.,
52// BindState1, BindState2). This makes forward
53// declarations and friending much much easier.
ajwong@chromium.orge2cca632011-02-15 10:27:38 +090054//
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +090055// Types:
56// RunnableAdapter<> -- Wraps the various "function" pointer types into an
57// object that adheres to the Runnable interface.
58// There are |3*ARITY| RunnableAdapter types.
59// FunctionTraits<> -- Type traits that unwrap a function signature into a
60// a set of easier to use typedefs. Used mainly for
61// compile time asserts.
62// There are |ARITY| FunctionTraits types.
63// ForceVoidReturn<> -- Helper class for translating function signatures to
64// equivalent forms with a "void" return type.
65// There are |ARITY| ForceVoidReturn types.
66// FunctorTraits<> -- Type traits used determine the correct RunType and
67// RunnableType for a Functor. This is where function
68// signature adapters are applied.
69// There are |ARITY| ForceVoidReturn types.
70// MakeRunnable<> -- Takes a Functor and returns an object in the Runnable
71// type class that represents the underlying Functor.
72// There are |O(1)| MakeRunnable types.
73// InvokeHelper<> -- Take a Runnable + arguments and actully invokes it.
74// Handle the differing syntaxes needed for WeakPtr<> support,
75// and for ignoring return values. This is separate from
76// Invoker to avoid creating multiple version of Invoker<>
77// which grows at O(n^2) with the arity.
78// There are |k*ARITY| InvokeHelper types.
79// Invoker<> -- Unwraps the curried parameters and executes the Runnable.
80// There are |(ARITY^2 + ARITY)/2| Invoketypes.
81// BindState<> -- Stores the curried parameters, and is the main entry point
82// into the Bind() system, doing most of the type resolution.
83// There are ARITY BindState types.
ajwong@chromium.orge0648232011-02-19 09:52:15 +090084
jeremya@chromium.orgd71e8fe2011-12-22 08:37:57 +090085
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +090086// RunnableAdapter<>
ajwong@chromium.orge0648232011-02-19 09:52:15 +090087//
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +090088// The RunnableAdapter<> templates provide a uniform interface for invoking
89// a function pointer, method pointer, or const method pointer. The adapter
90// exposes a Run() method with an appropriate signature. Using this wrapper
91// allows for writing code that supports all three pointer types without
92// undue repetition. Without it, a lot of code would need to be repeated 3
93// times.
ajwong@chromium.orge0648232011-02-19 09:52:15 +090094//
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +090095// For method pointers and const method pointers the first argument to Run()
96// is considered to be the received of the method. This is similar to STL's
97// mem_fun().
ajwong@chromium.orge0648232011-02-19 09:52:15 +090098//
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +090099// This class also exposes a RunType typedef that is the function type of the
100// Run() function.
ajwong@chromium.orge0648232011-02-19 09:52:15 +0900101//
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900102// If and only if the wrapper contains a method or const method pointer, an
103// IsMethod typedef is exposed. The existence of this typedef (NOT the value)
104// marks that the wrapper should be considered a method wrapper.
ajwong@chromium.orge0648232011-02-19 09:52:15 +0900105
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900106template <typename Functor>
107class RunnableAdapter;
ajwong@chromium.orge0648232011-02-19 09:52:15 +0900108
ajwong@chromium.orge0648232011-02-19 09:52:15 +0900109$for ARITY [[
110$range ARG 1..ARITY
111
112// Function: Arity $(ARITY).
113template <typename R[[]]
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900114$if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]>
115class RunnableAdapter<R(*)($for ARG , [[A$(ARG)]])> {
116 public:
117 typedef R (RunType)($for ARG , [[A$(ARG)]]);
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900118
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900119 explicit RunnableAdapter(R(*function)($for ARG , [[A$(ARG)]]))
120 : function_(function) {
121 }
ajwong@chromium.orgc711b822011-05-17 07:35:14 +0900122
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900123 R Run($for ARG , [[typename CallbackParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) {
jeremya@chromium.orgd71e8fe2011-12-22 08:37:57 +0900124 return function_($for ARG , [[a$(ARG)]]);
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900125 }
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900126
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900127 private:
128 R (*function_)($for ARG , [[A$(ARG)]]);
ajwong@chromium.orge0648232011-02-19 09:52:15 +0900129};
130
131// Method: Arity $(ARITY).
132template <typename R, typename T[[]]
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900133$if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]>
134class RunnableAdapter<R(T::*)($for ARG , [[A$(ARG)]])> {
135 public:
136 typedef R (RunType)(T*[[]]
137$if ARITY > 0[[, ]] $for ARG , [[A$(ARG)]]);
ajwong@chromium.orgcb175342011-02-27 10:25:59 +0900138 typedef true_type IsMethod;
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900139
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900140 explicit RunnableAdapter(R(T::*method)($for ARG , [[A$(ARG)]]))
141 : method_(method) {
142 }
ajwong@chromium.orgc711b822011-05-17 07:35:14 +0900143
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900144 R Run(T* object[[]]
145$if ARITY > 0[[, ]] $for ARG, [[typename CallbackParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) {
jeremya@chromium.orgd71e8fe2011-12-22 08:37:57 +0900146 return (object->*method_)($for ARG , [[a$(ARG)]]);
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900147 }
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900148
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900149 private:
150 R (T::*method_)($for ARG , [[A$(ARG)]]);
ajwong@chromium.orge0648232011-02-19 09:52:15 +0900151};
152
153// Const Method: Arity $(ARITY).
154template <typename R, typename T[[]]
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900155$if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]>
156class RunnableAdapter<R(T::*)($for ARG , [[A$(ARG)]]) const> {
157 public:
158 typedef R (RunType)(const T*[[]]
159$if ARITY > 0[[, ]] $for ARG , [[A$(ARG)]]);
ajwong@chromium.orgcb175342011-02-27 10:25:59 +0900160 typedef true_type IsMethod;
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900161
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900162 explicit RunnableAdapter(R(T::*method)($for ARG , [[A$(ARG)]]) const)
163 : method_(method) {
164 }
ajwong@chromium.orgc711b822011-05-17 07:35:14 +0900165
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900166 R Run(const T* object[[]]
167$if ARITY > 0[[, ]] $for ARG, [[typename CallbackParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) {
jeremya@chromium.orgd71e8fe2011-12-22 08:37:57 +0900168 return (object->*method_)($for ARG , [[a$(ARG)]]);
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900169 }
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900170
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900171 private:
172 R (T::*method_)($for ARG , [[A$(ARG)]]) const;
173};
174
175]] $$ for ARITY
176
177
178// FunctionTraits<>
179//
180// Breaks a function signature apart into typedefs for easier introspection.
181template <typename Sig>
182struct FunctionTraits;
183
184$for ARITY [[
185$range ARG 1..ARITY
186
187template <typename R[[]]
188$if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]>
189struct FunctionTraits<R($for ARG , [[A$(ARG)]])> {
190 typedef R ReturnType;
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900191$for ARG [[
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900192
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900193 typedef A$(ARG) A$(ARG)Type;
194]]
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900195
ajwong@chromium.orge0648232011-02-19 09:52:15 +0900196};
197
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900198]]
ajwong@chromium.orge0648232011-02-19 09:52:15 +0900199
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900200
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900201// ForceVoidReturn<>
202//
203// Set of templates that support forcing the function return type to void.
204template <typename Sig>
205struct ForceVoidReturn;
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900206
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900207$for ARITY [[
208$range ARG 1..ARITY
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900209
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900210template <typename R[[]]
211$if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]>
212struct ForceVoidReturn<R($for ARG , [[A$(ARG)]])> {
213 typedef void(RunType)($for ARG , [[A$(ARG)]]);
214};
215
216]] $$ for ARITY
217
218
219// FunctorTraits<>
220//
221// See description at top of file.
222template <typename T>
223struct FunctorTraits {
224 typedef RunnableAdapter<T> RunnableType;
225 typedef typename RunnableType::RunType RunType;
226};
227
228template <typename T>
229struct FunctorTraits<IgnoreResultHelper<T> > {
230 typedef typename FunctorTraits<T>::RunnableType RunnableType;
231 typedef typename ForceVoidReturn<
232 typename RunnableType::RunType>::RunType RunType;
233};
234
235template <typename T>
236struct FunctorTraits<Callback<T> > {
237 typedef Callback<T> RunnableType;
238 typedef typename Callback<T>::RunType RunType;
239};
240
241
242// MakeRunnable<>
243//
244// Converts a passed in functor to a RunnableType using type inference.
245
246template <typename T>
247typename FunctorTraits<T>::RunnableType MakeRunnable(const T& t) {
248 return RunnableAdapter<T>(t);
249}
250
251template <typename T>
252typename FunctorTraits<T>::RunnableType
253MakeRunnable(const IgnoreResultHelper<T>& t) {
254 return MakeRunnable(t.functor_);
255}
256
257template <typename T>
258const typename FunctorTraits<Callback<T> >::RunnableType&
259MakeRunnable(const Callback<T>& t) {
260 return t;
261}
262
263
264// InvokeHelper<>
265//
266// There are 3 logical InvokeHelper<> specializations: normal, void-return,
267// WeakCalls.
268//
269// The normal type just calls the underlying runnable.
270//
271// We need a InvokeHelper to handle void return types in order to support
272// IgnoreResult(). Normally, if the Runnable's RunType had a void return,
273// the template system would just accept "return functor.Run()" ignoring
274// the fact that a void function is being used with return. This piece of
275// sugar breaks though when the Runnable's RunType is not void. Thus, we
276// need a partial specialization to change the syntax to drop the "return"
277// from the invocation call.
278//
279// WeakCalls similarly need special syntax that is applied to the first
280// argument to check if they should no-op themselves.
281template <bool IsWeakCall, typename ReturnType, typename Runnable,
282 typename ArgsType>
283struct InvokeHelper;
284
285$for ARITY [[
286$range ARG 1..ARITY
287
288template <typename ReturnType, typename Runnable[[]]
289$if ARITY > 0 [[,]] $for ARG , [[typename A$(ARG)]]>
290struct InvokeHelper<false, ReturnType, Runnable,
291 void($for ARG , [[A$(ARG)]])> {
292 static ReturnType MakeItSo(Runnable runnable[[]]
293$if ARITY > 0[[, ]] $for ARG , [[A$(ARG) a$(ARG)]]) {
jeremya@chromium.orgd71e8fe2011-12-22 08:37:57 +0900294 return runnable.Run($for ARG , [[a$(ARG)]]);
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900295 }
296};
297
298template <typename Runnable[[]]
299$if ARITY > 0 [[,]] $for ARG , [[typename A$(ARG)]]>
300struct InvokeHelper<false, void, Runnable,
301 void($for ARG , [[A$(ARG)]])> {
302 static void MakeItSo(Runnable runnable[[]]
303$if ARITY > 0[[, ]] $for ARG , [[A$(ARG) a$(ARG)]]) {
jeremya@chromium.orgd71e8fe2011-12-22 08:37:57 +0900304 runnable.Run($for ARG , [[a$(ARG)]]);
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900305 }
306};
307
308$if ARITY > 0 [[
309
310template <typename Runnable[[]], $for ARG , [[typename A$(ARG)]]>
311struct InvokeHelper<true, void, Runnable,
312 void($for ARG , [[A$(ARG)]])> {
313 static void MakeItSo(Runnable runnable[[]]
314$if ARITY > 0[[, ]] $for ARG , [[A$(ARG) a$(ARG)]]) {
315 if (!a1.get()) {
316 return;
317 }
318
jeremya@chromium.orgd71e8fe2011-12-22 08:37:57 +0900319 runnable.Run($for ARG , [[a$(ARG)]]);
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900320 }
321};
322
323]]
324
325]] $$ for ARITY
326
327#if !defined(_MSC_VER)
328
329template <typename ReturnType, typename Runnable, typename ArgsType>
330struct InvokeHelper<true, ReturnType, Runnable, ArgsType> {
331 // WeakCalls are only supported for functions with a void return type.
332 // Otherwise, the function result would be undefined if the the WeakPtr<>
333 // is invalidated.
334 COMPILE_ASSERT(is_void<ReturnType>::value,
335 weak_ptrs_can_only_bind_to_methods_without_return_values);
336};
337
338#endif
339
340// Invoker<>
341//
342// See description at the top of the file.
343template <int NumBound, typename Storage, typename RunType>
344struct Invoker;
345
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900346$for ARITY [[
347
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900348$$ Number of bound arguments.
349$range BOUND 0..ARITY
350$for BOUND [[
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900351
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900352$var UNBOUND = ARITY - BOUND
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900353$range ARG 1..ARITY
354$range BOUND_ARG 1..BOUND
355$range UNBOUND_ARG (ARITY - UNBOUND + 1)..ARITY
356
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900357// Arity $(ARITY) -> $(UNBOUND).
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900358template <typename StorageType, typename R[[]]
359$if ARITY > 0 [[,]][[]]
360$for ARG , [[typename X$(ARG)]]>
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900361struct Invoker<$(BOUND), StorageType, R($for ARG , [[X$(ARG)]])> {
362 typedef R(RunType)(BindStateBase*[[]]
ajwong@chromium.orgec1750a2011-06-27 01:22:50 +0900363$if UNBOUND != 0 [[, ]]
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900364$for UNBOUND_ARG , [[typename CallbackParamTraits<X$(UNBOUND_ARG)>::ForwardType]]);
ajwong@chromium.orgec1750a2011-06-27 01:22:50 +0900365
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900366 typedef R(UnboundRunType)($for UNBOUND_ARG , [[X$(UNBOUND_ARG)]]);
367
368 static R Run(BindStateBase* base[[]]
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900369$if UNBOUND != 0 [[, ]][[]]
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900370$for UNBOUND_ARG , [[
371typename CallbackParamTraits<X$(UNBOUND_ARG)>::ForwardType x$(UNBOUND_ARG)
372]][[]]
373) {
374 StorageType* storage = static_cast<StorageType*>(base);
375
376 // Local references to make debugger stepping easier. If in a debugger,
377 // you really want to warp ahead and step through the
378 // InvokeHelper<>::MakeItSo() call below.
379$for BOUND_ARG
380[[
381
382 typedef typename StorageType::Bound$(BOUND_ARG)UnwrapTraits Bound$(BOUND_ARG)UnwrapTraits;
383]]
384
385
386$for BOUND_ARG
387[[
388
389 typename Bound$(BOUND_ARG)UnwrapTraits::ForwardType x$(BOUND_ARG) =
390 Bound$(BOUND_ARG)UnwrapTraits::Unwrap(storage->p$(BOUND_ARG)_);
391]]
392
393 return InvokeHelper<StorageType::IsWeakCall::value, R,
394 typename StorageType::RunnableType,
395 void(
396$for BOUND_ARG , [[
397typename Bound$(BOUND_ARG)UnwrapTraits::ForwardType
398]]
399
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900400$if UNBOUND > 0 [[$if BOUND > 0 [[, ]]]][[]]
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900401
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900402$for UNBOUND_ARG , [[
403typename CallbackParamTraits<X$(UNBOUND_ARG)>::ForwardType x$(UNBOUND_ARG)
ajwong@chromium.orgc711b822011-05-17 07:35:14 +0900404]]
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900405)>
406 ::MakeItSo(storage->runnable_
jeremya@chromium.orgd71e8fe2011-12-22 08:37:57 +0900407$if ARITY > 0[[, ]] $for ARG , [[x$(ARG)]]);
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900408 }
409};
ajwong@chromium.orgc711b822011-05-17 07:35:14 +0900410
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900411]] $$ for BOUND
412]] $$ for ARITY
413
414
415// BindState<>
416//
417// This stores all the state passed into Bind() and is also where most
418// of the template resolution magic occurs.
419//
420// Runnable is the functor we are binding arguments to.
421// RunType is type of the Run() function that the Invoker<> should use.
422// Normally, this is the same as the RunType of the Runnable, but it can
423// be different if an adapter like IgnoreResult() has been used.
424//
425// BoundArgsType contains the storage type for all the bound arguments by
426// (ab)using a function type.
427template <typename Runnable, typename RunType, typename BoundArgsType>
428struct BindState;
429
430$for ARITY [[
431$range ARG 1..ARITY
432
433template <typename Runnable, typename RunType[[]]
434$if ARITY > 0[[, ]] $for ARG , [[typename P$(ARG)]]>
435struct BindState<Runnable, RunType, void($for ARG , [[P$(ARG)]])> : public BindStateBase {
436 typedef Runnable RunnableType;
437
438$if ARITY > 0 [[
439 typedef IsWeakMethod<HasIsMethodTag<Runnable>::value, P1> IsWeakCall;
ajwong@chromium.orgc711b822011-05-17 07:35:14 +0900440]] $else [[
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900441 typedef false_type IsWeakCall;
ajwong@chromium.orgc711b822011-05-17 07:35:14 +0900442]]
443
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900444 typedef Invoker<$(ARITY), BindState, RunType> InvokerType;
445 typedef typename InvokerType::UnboundRunType UnboundRunType;
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900446
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900447$if ARITY > 0 [[
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900448
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900449 // Convenience typedefs for bound argument types.
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900450
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900451$for ARG [[
452 typedef UnwrapTraits<P$(ARG)> Bound$(ARG)UnwrapTraits;
453
454]] $$ for ARG
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900455
456
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900457]] $$ if ARITY > 0
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900458
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900459$$ The extra [[ ]] is needed to massage spacing. Silly pump.py.
460[[ ]]$if ARITY == 0 [[explicit ]]BindState(const Runnable& runnable
461$if ARITY > 0 [[, ]] $for ARG , [[const P$(ARG)& p$(ARG)]])
462 : runnable_(runnable)[[]]
463$if ARITY == 0 [[
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900464 {
465
466]] $else [[
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900467, $for ARG , [[
468
469 p$(ARG)_(p$(ARG))
470]] {
471 MaybeRefcount<HasIsMethodTag<Runnable>::value, P1>::AddRef(p1_);
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900472
473]]
474 }
475
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900476 virtual ~BindState() {
477$if ARITY > 0 [[
478 MaybeRefcount<HasIsMethodTag<Runnable>::value, P1>::Release(p1_);
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900479]]
480 }
481
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900482 RunnableType runnable_;
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900483
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900484$for ARG [[
485 P$(ARG) p$(ARG)_;
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900486
487]]
488};
489
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900490]] $$ for ARITY
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900491
492} // namespace internal
493} // namespace base
494
495#endif // BASE_BIND_INTERNAL_H_