Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: base/bind.h.pump

Issue 6109007: Unified callback system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/base
Patch Set: Address Will's comments. Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/bind.h ('k') | base/bind_helpers.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 = 6
9
10 // Copyright (c) 2011 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 BASE_BIND_H_
15 #define BASE_BIND_H_
16 #pragma once
17
18 #include "base/bind_internal.h"
19 #include "base/callback_helpers.h"
20
21 // See base/callback.h for how to use these functions.
22 //
23 // IMPLEMENTATION NOTE
24 // Though Bind()'s result is meant to be stored in a Callback<> type, it
25 // cannot actually return the exact type without requiring a large amount
26 // of extra template specializations. The problem is that in order to
27 // discern the correct specialization of Callback<>, Bind would need to
28 // unwrap the function signature to determine the signature's arity, and
29 // whether or not it is a method.
30 //
31 // Each unique combination of (arity, function_type, num_prebound) where
32 // function_type is one of {function, method, const_method} would require
33 // one specialization. We eventually have to do a similar number of
34 // specializations anyways in the implementation (see the FunctionTraitsN,
35 // classes). However, it is avoidable in Bind if we return the result
36 // via an indirection like we do below.
37
38 namespace base {
39
40 $range BOUND 0..MAX_ARITY
41 $for BOUND [[
42 $range BOUND_ARG 1..BOUND
43
44 $if BOUND == 0 [[
45
46 template <typename Sig>
47 internal::InvokerStorageHolder<internal::InvokerStorage0<Sig> >
48 Bind(Sig f) {
49 return internal::MakeInvokerStorageHolder(
50 new internal::InvokerStorage0<Sig>(f));
51 }
52
53 ]] $else [[
54
55 template <typename Sig, $for BOUND_ARG , [[typename P$(BOUND_ARG)]]>
56 internal::InvokerStorageHolder<internal::InvokerStorage$(BOUND)<Sig,
57 $for BOUND_ARG , [[P$(BOUND_ARG)]]> >
58 Bind(Sig f, $for BOUND_ARG , [[const P$(BOUND_ARG)& p$(BOUND_ARG)]]) {
59 return internal::MakeInvokerStorageHolder(
60 new internal::InvokerStorage$(BOUND)<Sig, [[]]
61 $for BOUND_ARG , [[P$(BOUND_ARG)]]>(
62 f, $for BOUND_ARG , [[p$(BOUND_ARG)]]));
63 }
64
65 ]]
66
67 ]] $$ for BOUND
68
69 } // namespace base
70
71 #endif // BASE_BIND_H_
OLDNEW
« no previous file with comments | « base/bind.h ('k') | base/bind_helpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698