blob: 1192974455f4c63b68bc499fb34c8cf13177403e [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.orgc9c79af2011-11-22 04:23:44 +09008// TODO(ajwong): If you create an fully unbound method, is there a way to
9// enforce the first argument must be refcounted? Or do we just say
10// "oh well"?
11//
12// Do we want to allow creating a fully unbound method??
13
jhawkins@chromium.org2720de22011-10-20 06:45:15 +090014$var MAX_ARITY = 6
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +090015$range ARITY 0..MAX_ARITY
ajwong@chromium.orge2cca632011-02-15 10:27:38 +090016
17// Copyright (c) 2011 The Chromium Authors. All rights reserved.
18// Use of this source code is governed by a BSD-style license that can be
19// found in the LICENSE file.
20
21#ifndef BASE_BIND_INTERNAL_H_
22#define BASE_BIND_INTERNAL_H_
23#pragma once
24
25#include "base/bind_helpers.h"
ajwong@chromium.orgfa0ff432011-02-19 08:29:31 +090026#include "base/callback_internal.h"
ajwong@chromium.org27e56852011-10-01 15:31:41 +090027#include "base/memory/raw_scoped_refptr_mismatch_checker.h"
ajwong@chromium.orgc711b822011-05-17 07:35:14 +090028#include "base/memory/weak_ptr.h"
ajwong@chromium.orge2cca632011-02-15 10:27:38 +090029#include "base/template_util.h"
ajwong@chromium.orgcb175342011-02-27 10:25:59 +090030#include "build/build_config.h"
31
32#if defined(OS_WIN)
33#include "base/bind_internal_win.h"
34#endif
ajwong@chromium.orge2cca632011-02-15 10:27:38 +090035
36namespace base {
37namespace internal {
38
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +090039// CONCEPTS:
40// Runnable -- A type (really a type class) that has a single Run() method
41// and a RunType typedef that corresponds to the type of Run().
42// A Runnable can declare that it should treated like a method
43// call by including a typedef named IsMethod. The value of
44// this typedef is NOT inspected, only the existence. When a
45// Runnable declares itself a method, Bind() will enforce special
46// refcounting + WeakPtr handling semantics for the first
47// parameter which is expected to be an object.
48// Functor -- A copyable type representing something that should be called.
49// All function pointers, Callback<>, and Runnables are functors
50// even if the invocation syntax differs.
51// RunType -- A function type (as opposed to function _pointer_ type) for
52// a Run() function. Usually just a convenience typedef.
53// (Bound)ArgsType -- A function type that is being (ab)used to store the
54// types of set of arguments. The "return" type is always
55// void here. We use this hack so that we do not need
56// a new type name for each arity of type. (eg.,
57// BindState1, BindState2). This makes forward
58// declarations and friending much much easier.
ajwong@chromium.orge2cca632011-02-15 10:27:38 +090059//
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +090060// Types:
61// RunnableAdapter<> -- Wraps the various "function" pointer types into an
62// object that adheres to the Runnable interface.
63// There are |3*ARITY| RunnableAdapter types.
64// FunctionTraits<> -- Type traits that unwrap a function signature into a
65// a set of easier to use typedefs. Used mainly for
66// compile time asserts.
67// There are |ARITY| FunctionTraits types.
68// ForceVoidReturn<> -- Helper class for translating function signatures to
69// equivalent forms with a "void" return type.
70// There are |ARITY| ForceVoidReturn types.
71// FunctorTraits<> -- Type traits used determine the correct RunType and
72// RunnableType for a Functor. This is where function
73// signature adapters are applied.
74// There are |ARITY| ForceVoidReturn types.
75// MakeRunnable<> -- Takes a Functor and returns an object in the Runnable
76// type class that represents the underlying Functor.
77// There are |O(1)| MakeRunnable types.
78// InvokeHelper<> -- Take a Runnable + arguments and actully invokes it.
79// Handle the differing syntaxes needed for WeakPtr<> support,
80// and for ignoring return values. This is separate from
81// Invoker to avoid creating multiple version of Invoker<>
82// which grows at O(n^2) with the arity.
83// There are |k*ARITY| InvokeHelper types.
84// Invoker<> -- Unwraps the curried parameters and executes the Runnable.
85// There are |(ARITY^2 + ARITY)/2| Invoketypes.
86// BindState<> -- Stores the curried parameters, and is the main entry point
87// into the Bind() system, doing most of the type resolution.
88// There are ARITY BindState types.
ajwong@chromium.orge0648232011-02-19 09:52:15 +090089
ajwong@chromium.orgc711b822011-05-17 07:35:14 +090090
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +090091// RunnableAdapter<>
ajwong@chromium.orge0648232011-02-19 09:52:15 +090092//
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +090093// The RunnableAdapter<> templates provide a uniform interface for invoking
94// a function pointer, method pointer, or const method pointer. The adapter
95// exposes a Run() method with an appropriate signature. Using this wrapper
96// allows for writing code that supports all three pointer types without
97// undue repetition. Without it, a lot of code would need to be repeated 3
98// times.
ajwong@chromium.orge0648232011-02-19 09:52:15 +090099//
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900100// For method pointers and const method pointers the first argument to Run()
101// is considered to be the received of the method. This is similar to STL's
102// mem_fun().
ajwong@chromium.orge0648232011-02-19 09:52:15 +0900103//
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900104// This class also exposes a RunType typedef that is the function type of the
105// Run() function.
ajwong@chromium.orge0648232011-02-19 09:52:15 +0900106//
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900107// If and only if the wrapper contains a method or const method pointer, an
108// IsMethod typedef is exposed. The existence of this typedef (NOT the value)
109// marks that the wrapper should be considered a method wrapper.
ajwong@chromium.orge0648232011-02-19 09:52:15 +0900110
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900111template <typename Functor>
112class RunnableAdapter;
ajwong@chromium.orge0648232011-02-19 09:52:15 +0900113
ajwong@chromium.orge0648232011-02-19 09:52:15 +0900114$for ARITY [[
115$range ARG 1..ARITY
116
117// Function: Arity $(ARITY).
118template <typename R[[]]
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900119$if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]>
120class RunnableAdapter<R(*)($for ARG , [[A$(ARG)]])> {
121 public:
122 typedef R (RunType)($for ARG , [[A$(ARG)]]);
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900123
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900124 explicit RunnableAdapter(R(*function)($for ARG , [[A$(ARG)]]))
125 : function_(function) {
126 }
ajwong@chromium.orgc711b822011-05-17 07:35:14 +0900127
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900128 R Run($for ARG , [[typename CallbackParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) {
129 return function_($for ARG , [[a$(ARG)]]);
130 }
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900131
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900132 private:
133 R (*function_)($for ARG , [[A$(ARG)]]);
ajwong@chromium.orge0648232011-02-19 09:52:15 +0900134};
135
136// Method: Arity $(ARITY).
137template <typename R, typename T[[]]
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900138$if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]>
139class RunnableAdapter<R(T::*)($for ARG , [[A$(ARG)]])> {
140 public:
141 typedef R (RunType)(T*[[]]
142$if ARITY > 0[[, ]] $for ARG , [[A$(ARG)]]);
ajwong@chromium.orgcb175342011-02-27 10:25:59 +0900143 typedef true_type IsMethod;
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900144
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900145 explicit RunnableAdapter(R(T::*method)($for ARG , [[A$(ARG)]]))
146 : method_(method) {
147 }
ajwong@chromium.orgc711b822011-05-17 07:35:14 +0900148
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900149 R Run(T* object[[]]
150$if ARITY > 0[[, ]] $for ARG, [[typename CallbackParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) {
151 return (object->*method_)($for ARG , [[a$(ARG)]]);
152 }
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900153
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900154 private:
155 R (T::*method_)($for ARG , [[A$(ARG)]]);
ajwong@chromium.orge0648232011-02-19 09:52:15 +0900156};
157
158// Const Method: Arity $(ARITY).
159template <typename R, typename T[[]]
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900160$if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]>
161class RunnableAdapter<R(T::*)($for ARG , [[A$(ARG)]]) const> {
162 public:
163 typedef R (RunType)(const T*[[]]
164$if ARITY > 0[[, ]] $for ARG , [[A$(ARG)]]);
ajwong@chromium.orgcb175342011-02-27 10:25:59 +0900165 typedef true_type IsMethod;
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900166
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900167 explicit RunnableAdapter(R(T::*method)($for ARG , [[A$(ARG)]]) const)
168 : method_(method) {
169 }
ajwong@chromium.orgc711b822011-05-17 07:35:14 +0900170
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900171 R Run(const T* object[[]]
172$if ARITY > 0[[, ]] $for ARG, [[typename CallbackParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) {
173 return (object->*method_)($for ARG , [[a$(ARG)]]);
174 }
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900175
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900176 private:
177 R (T::*method_)($for ARG , [[A$(ARG)]]) const;
178};
179
180]] $$ for ARITY
181
182
183// FunctionTraits<>
184//
185// Breaks a function signature apart into typedefs for easier introspection.
186template <typename Sig>
187struct FunctionTraits;
188
189$for ARITY [[
190$range ARG 1..ARITY
191
192template <typename R[[]]
193$if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]>
194struct FunctionTraits<R($for ARG , [[A$(ARG)]])> {
195 typedef R ReturnType;
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900196$for ARG [[
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900197
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900198 typedef A$(ARG) A$(ARG)Type;
199]]
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900200
ajwong@chromium.orge0648232011-02-19 09:52:15 +0900201};
202
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900203]]
ajwong@chromium.orge0648232011-02-19 09:52:15 +0900204
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900205
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900206// ForceVoidReturn<>
207//
208// Set of templates that support forcing the function return type to void.
209template <typename Sig>
210struct ForceVoidReturn;
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900211
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900212$for ARITY [[
213$range ARG 1..ARITY
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900214
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900215template <typename R[[]]
216$if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]>
217struct ForceVoidReturn<R($for ARG , [[A$(ARG)]])> {
218 typedef void(RunType)($for ARG , [[A$(ARG)]]);
219};
220
221]] $$ for ARITY
222
223
224// FunctorTraits<>
225//
226// See description at top of file.
227template <typename T>
228struct FunctorTraits {
229 typedef RunnableAdapter<T> RunnableType;
230 typedef typename RunnableType::RunType RunType;
231};
232
233template <typename T>
234struct FunctorTraits<IgnoreResultHelper<T> > {
235 typedef typename FunctorTraits<T>::RunnableType RunnableType;
236 typedef typename ForceVoidReturn<
237 typename RunnableType::RunType>::RunType RunType;
238};
239
240template <typename T>
241struct FunctorTraits<Callback<T> > {
242 typedef Callback<T> RunnableType;
243 typedef typename Callback<T>::RunType RunType;
244};
245
246
247// MakeRunnable<>
248//
249// Converts a passed in functor to a RunnableType using type inference.
250
251template <typename T>
252typename FunctorTraits<T>::RunnableType MakeRunnable(const T& t) {
253 return RunnableAdapter<T>(t);
254}
255
256template <typename T>
257typename FunctorTraits<T>::RunnableType
258MakeRunnable(const IgnoreResultHelper<T>& t) {
259 return MakeRunnable(t.functor_);
260}
261
262template <typename T>
263const typename FunctorTraits<Callback<T> >::RunnableType&
264MakeRunnable(const Callback<T>& t) {
265 return t;
266}
267
268
269// InvokeHelper<>
270//
271// There are 3 logical InvokeHelper<> specializations: normal, void-return,
272// WeakCalls.
273//
274// The normal type just calls the underlying runnable.
275//
276// We need a InvokeHelper to handle void return types in order to support
277// IgnoreResult(). Normally, if the Runnable's RunType had a void return,
278// the template system would just accept "return functor.Run()" ignoring
279// the fact that a void function is being used with return. This piece of
280// sugar breaks though when the Runnable's RunType is not void. Thus, we
281// need a partial specialization to change the syntax to drop the "return"
282// from the invocation call.
283//
284// WeakCalls similarly need special syntax that is applied to the first
285// argument to check if they should no-op themselves.
286template <bool IsWeakCall, typename ReturnType, typename Runnable,
287 typename ArgsType>
288struct InvokeHelper;
289
290$for ARITY [[
291$range ARG 1..ARITY
292
293template <typename ReturnType, typename Runnable[[]]
294$if ARITY > 0 [[,]] $for ARG , [[typename A$(ARG)]]>
295struct InvokeHelper<false, ReturnType, Runnable,
296 void($for ARG , [[A$(ARG)]])> {
297 static ReturnType MakeItSo(Runnable runnable[[]]
298$if ARITY > 0[[, ]] $for ARG , [[A$(ARG) a$(ARG)]]) {
299 return runnable.Run($for ARG , [[a$(ARG)]]);
300 }
301};
302
303template <typename Runnable[[]]
304$if ARITY > 0 [[,]] $for ARG , [[typename A$(ARG)]]>
305struct InvokeHelper<false, void, Runnable,
306 void($for ARG , [[A$(ARG)]])> {
307 static void MakeItSo(Runnable runnable[[]]
308$if ARITY > 0[[, ]] $for ARG , [[A$(ARG) a$(ARG)]]) {
309 runnable.Run($for ARG , [[a$(ARG)]]);
310 }
311};
312
313$if ARITY > 0 [[
314
315template <typename Runnable[[]], $for ARG , [[typename A$(ARG)]]>
316struct InvokeHelper<true, void, Runnable,
317 void($for ARG , [[A$(ARG)]])> {
318 static void MakeItSo(Runnable runnable[[]]
319$if ARITY > 0[[, ]] $for ARG , [[A$(ARG) a$(ARG)]]) {
320 if (!a1.get()) {
321 return;
322 }
323
324 runnable.Run($for ARG , [[a$(ARG)]]);
325 }
326};
327
328]]
329
330]] $$ for ARITY
331
332#if !defined(_MSC_VER)
333
334template <typename ReturnType, typename Runnable, typename ArgsType>
335struct InvokeHelper<true, ReturnType, Runnable, ArgsType> {
336 // WeakCalls are only supported for functions with a void return type.
337 // Otherwise, the function result would be undefined if the the WeakPtr<>
338 // is invalidated.
339 COMPILE_ASSERT(is_void<ReturnType>::value,
340 weak_ptrs_can_only_bind_to_methods_without_return_values);
341};
342
343#endif
344
345// Invoker<>
346//
347// See description at the top of the file.
348template <int NumBound, typename Storage, typename RunType>
349struct Invoker;
350
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900351$for ARITY [[
352
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900353$$ Number of bound arguments.
354$range BOUND 0..ARITY
355$for BOUND [[
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900356
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900357$var UNBOUND = ARITY - BOUND
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900358$range ARG 1..ARITY
359$range BOUND_ARG 1..BOUND
360$range UNBOUND_ARG (ARITY - UNBOUND + 1)..ARITY
361
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900362// Arity $(ARITY) -> $(UNBOUND).
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900363template <typename StorageType, typename R[[]]
364$if ARITY > 0 [[,]][[]]
365$for ARG , [[typename X$(ARG)]]>
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900366struct Invoker<$(BOUND), StorageType, R($for ARG , [[X$(ARG)]])> {
367 typedef R(RunType)(BindStateBase*[[]]
ajwong@chromium.orgec1750a2011-06-27 01:22:50 +0900368$if UNBOUND != 0 [[, ]]
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900369$for UNBOUND_ARG , [[typename CallbackParamTraits<X$(UNBOUND_ARG)>::ForwardType]]);
ajwong@chromium.orgec1750a2011-06-27 01:22:50 +0900370
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900371 typedef R(UnboundRunType)($for UNBOUND_ARG , [[X$(UNBOUND_ARG)]]);
372
373 static R Run(BindStateBase* base[[]]
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900374$if UNBOUND != 0 [[, ]][[]]
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900375$for UNBOUND_ARG , [[
376typename CallbackParamTraits<X$(UNBOUND_ARG)>::ForwardType x$(UNBOUND_ARG)
377]][[]]
378) {
379 StorageType* storage = static_cast<StorageType*>(base);
380
381 // Local references to make debugger stepping easier. If in a debugger,
382 // you really want to warp ahead and step through the
383 // InvokeHelper<>::MakeItSo() call below.
384$for BOUND_ARG
385[[
386
387 typedef typename StorageType::Bound$(BOUND_ARG)UnwrapTraits Bound$(BOUND_ARG)UnwrapTraits;
388]]
389
390
391$for BOUND_ARG
392[[
393
394 typename Bound$(BOUND_ARG)UnwrapTraits::ForwardType x$(BOUND_ARG) =
395 Bound$(BOUND_ARG)UnwrapTraits::Unwrap(storage->p$(BOUND_ARG)_);
396]]
397
398 return InvokeHelper<StorageType::IsWeakCall::value, R,
399 typename StorageType::RunnableType,
400 void(
401$for BOUND_ARG , [[
402typename Bound$(BOUND_ARG)UnwrapTraits::ForwardType
403]]
404
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900405$if UNBOUND > 0 [[$if BOUND > 0 [[, ]]]][[]]
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900406
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900407$for UNBOUND_ARG , [[
408typename CallbackParamTraits<X$(UNBOUND_ARG)>::ForwardType x$(UNBOUND_ARG)
ajwong@chromium.orgc711b822011-05-17 07:35:14 +0900409]]
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900410)>
411 ::MakeItSo(storage->runnable_
412$if ARITY > 0[[, ]] $for ARG , [[x$(ARG)]]);
413 }
414};
ajwong@chromium.orgc711b822011-05-17 07:35:14 +0900415
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900416]] $$ for BOUND
417]] $$ for ARITY
418
419
420// BindState<>
421//
422// This stores all the state passed into Bind() and is also where most
423// of the template resolution magic occurs.
424//
425// Runnable is the functor we are binding arguments to.
426// RunType is type of the Run() function that the Invoker<> should use.
427// Normally, this is the same as the RunType of the Runnable, but it can
428// be different if an adapter like IgnoreResult() has been used.
429//
430// BoundArgsType contains the storage type for all the bound arguments by
431// (ab)using a function type.
432template <typename Runnable, typename RunType, typename BoundArgsType>
433struct BindState;
434
435$for ARITY [[
436$range ARG 1..ARITY
437
438template <typename Runnable, typename RunType[[]]
439$if ARITY > 0[[, ]] $for ARG , [[typename P$(ARG)]]>
440struct BindState<Runnable, RunType, void($for ARG , [[P$(ARG)]])> : public BindStateBase {
441 typedef Runnable RunnableType;
442
443$if ARITY > 0 [[
444 typedef IsWeakMethod<HasIsMethodTag<Runnable>::value, P1> IsWeakCall;
ajwong@chromium.orgc711b822011-05-17 07:35:14 +0900445]] $else [[
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900446 typedef false_type IsWeakCall;
ajwong@chromium.orgc711b822011-05-17 07:35:14 +0900447]]
448
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900449 typedef Invoker<$(ARITY), BindState, RunType> InvokerType;
450 typedef typename InvokerType::UnboundRunType UnboundRunType;
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900451
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900452$if ARITY > 0 [[
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900453
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900454 // Convenience typedefs for bound argument types.
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900455
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900456$for ARG [[
457 typedef UnwrapTraits<P$(ARG)> Bound$(ARG)UnwrapTraits;
458
459]] $$ for ARG
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900460
461
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900462]] $$ if ARITY > 0
ajwong@chromium.orga7e74822011-03-24 11:02:17 +0900463
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900464$$ The extra [[ ]] is needed to massage spacing. Silly pump.py.
465[[ ]]$if ARITY == 0 [[explicit ]]BindState(const Runnable& runnable
466$if ARITY > 0 [[, ]] $for ARG , [[const P$(ARG)& p$(ARG)]])
467 : runnable_(runnable)[[]]
468$if ARITY == 0 [[
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900469 {
470
471]] $else [[
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900472, $for ARG , [[
473
474 p$(ARG)_(p$(ARG))
475]] {
476 MaybeRefcount<HasIsMethodTag<Runnable>::value, P1>::AddRef(p1_);
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900477
478]]
479 }
480
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900481 virtual ~BindState() {
482$if ARITY > 0 [[
483 MaybeRefcount<HasIsMethodTag<Runnable>::value, P1>::Release(p1_);
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900484]]
485 }
486
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900487 RunnableType runnable_;
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900488
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900489$for ARG [[
490 P$(ARG) p$(ARG)_;
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900491
492]]
493};
494
ajwong@chromium.orgc9c79af2011-11-22 04:23:44 +0900495]] $$ for ARITY
ajwong@chromium.orge2cca632011-02-15 10:27:38 +0900496
497} // namespace internal
498} // namespace base
499
500#endif // BASE_BIND_INTERNAL_H_