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

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

Issue 6109007: Unified callback system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/base
Patch Set: Fixing up some 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
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 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
8 // Use of this source code is governed by a BSD-style license that can be
9 // found in the LICENSE file.
10
11 #ifndef BASE_PREBIND_H_
12 #define BASE_PREBIND_H_
13
14 #include "base/prebind_helpers.h"
15 #include "base/uber_callback.h"
16
17 namespace base {
18 namespace internal {
19
20 // The method by which a function is invoked is determined by 3 different
21 // dimensions:
22 //
23 // 1) The type of function (normal, method, const-method)
24 // 2) The arity of the function
25 // 3) The number of bound parameters.
26 //
27 // The FunctionTraitsN classes unwrap the function signature type to
28 // specialize based on the first two dimensions. The N in FunctionTraitsN
29 // specifies the 3rd dimension.
30
31 $var MAX_ARITY = 6
32
33 $range PREBOUND 0..MAX_ARITY
34 $for PREBOUND [[
35
36 template <typename StorageType, typename Sig>
37 struct FunctionTraits$(PREBOUND);
38
39 $range ARITY 0..MAX_ARITY
40 $for ARITY [[
41
42 $var UNBOUND = ARITY - PREBOUND
43 $if UNBOUND >= 0 [[
44
45 $$ Variables for function traits generation.
46 $range ARG 1..ARITY
47 $range BOUND_ARG 1..PREBOUND
48 $range UNBOUND_ARG (ARITY - UNBOUND + 1)..ARITY
49
50 $$ Variables for method traits generation. We are always short one arity since
51 $$ the first bound parameter is the object.
52 $var M_ARITY = ARITY - 1
53 $range M_ARG 1..M_ARITY
54 $range M_BOUND_ARG 2..PREBOUND
55 $range M_UNBOUND_ARG (M_ARITY - UNBOUND + 1)..M_ARITY
56
57 // Function: Arity $(ARITY) -> $(UNBOUND).
58 template <typename StorageType, typename R[[]]
59 $if ARITY > 0 [[,]][[]]
60 $for ARG , [[typename X$(ARG)]]>
61 struct FunctionTraits$(PREBOUND)<StorageType, R(*)($for ARG , [[X$(ARG)]])> {
62 static const bool kShouldRef = false;
63 static R DoInvoke(internal::InvokerStorageBase* base[[]]
64 $if UNBOUND != 0 [[, ]][[]]
65 $for UNBOUND_ARG , [[const X$(UNBOUND_ARG)& x$(UNBOUND_ARG)]]) {
66 StorageType* invoker = static_cast<StorageType*>(base);
67 return invoker->f_($for BOUND_ARG , [[Unwrap(invoker->p$(BOUND_ARG)_)]][[]]
68 $$ Add comma if there are both boudn and unbound args.
69 $if UNBOUND > 0 [[$if PREBOUND > 0 [[, ]]]][[]]
70 $for UNBOUND_ARG , [[x$(UNBOUND_ARG)]]);
71 }
72 };
73
74 $if PREBOUND > 0 [[
75
76 // Method: Arity $(M_ARITY) -> $(UNBOUND).
77 template <typename StorageType, typename R, typename T[[]]
78 $if M_ARITY > 0[[, ]] $for M_ARG , [[typename X$(M_ARG)]]>
79 struct FunctionTraits$(PREBOUND)<StorageType, R(T::*)($for M_ARG , [[X$(M_ARG)]] )> {
80 static const bool kShouldRef = true;
81 static R DoInvoke(internal::InvokerStorageBase* base[[]]
82 $if UNBOUND > 0 [[, ]][[]]
83 $for M_UNBOUND_ARG , [[const X$(M_UNBOUND_ARG)& x$(M_UNBOUND_ARG)]]) {
84 StorageType* invoker = static_cast<StorageType*>(base);
85 return (Unwrap(invoker->p1_)->*invoker->f_)([[]]
86 $for M_BOUND_ARG , [[Unwrap(invoker->p$(M_BOUND_ARG)_)]][[]]
87 $if UNBOUND > 0 [[$if PREBOUND > 1 [[, ]]]][[]]
88 $for M_UNBOUND_ARG , [[x$(M_UNBOUND_ARG)]]);
89 }
90 };
91
92 // Const Method: Arity $(M_ARITY) -> $(UNBOUND).
93 template <typename StorageType, typename R, typename T[[]]
94 $if M_ARITY > 0[[, ]] $for M_ARG , [[typename X$(M_ARG)]]>
95 struct FunctionTraits$(PREBOUND)<StorageType, R(T::*)($for M_ARG , [[X$(M_ARG)]] ) const> {
96 static const bool kShouldRef = true;
97 static R DoInvoke(internal::InvokerStorageBase* base[[]]
98 $if UNBOUND > 0 [[, ]]
99 [[]] $for M_UNBOUND_ARG , [[const X$(M_UNBOUND_ARG)& x$(M_UNBOUND_ARG)]]) {
100 StorageType* invoker = static_cast<StorageType*>(base);
101 return (Unwrap(invoker->p1_)->*invoker->f_)([[]]
102 $for M_BOUND_ARG , [[Unwrap(invoker->p$(M_BOUND_ARG)_)]][[]]
103 $if UNBOUND > 0 [[$if PREBOUND > 1 [[, ]]]][[]]
104 $for M_UNBOUND_ARG , [[x$(M_UNBOUND_ARG)]]);
105 }
106 };
107
108 ]] $$ if PREBOUND
109
110 ]] $$ if UNBOUND
111 ]] $$ for ARITY
112 ]] $$ for PREBOUND
113
114
115 // These are the actual storage classes for the invokers.
116
117 $for PREBOUND [[
118 $range BOUND_ARG 1..PREBOUND
119
120 template <typename Sig[[]]
121 $if PREBOUND > 0 [[, ]]
122 $for BOUND_ARG , [[typename P$(BOUND_ARG)]]>
123 class InvokerStorage$(PREBOUND) : public internal::InvokerStorageBase {
124 public:
125 typedef InvokerStorage$(PREBOUND) StorageType;
126 typedef FunctionTraits$(PREBOUND)<StorageType, Sig> FunctionTraits;
127
128 InvokerStorage$(PREBOUND)(Sig f
129 $if PREBOUND > 0 [[, ]]
130 $for BOUND_ARG , [[const P$(BOUND_ARG)& p$(BOUND_ARG)]])
131 : f_(f)[[]]
132 $if PREBOUND == 0 [[
133 {
134
135 ]] $else [[
136 , $for BOUND_ARG , [[p$(BOUND_ARG)_(p$(BOUND_ARG))]] {
137 MaybeRefcount<FunctionTraits::kShouldRef, P1>::AddRef(p1_);
138
139 ]]
140 }
141
142 virtual ~InvokerStorage$(PREBOUND)() {
143 $if PREBOUND > 0 [[
144
145 MaybeRefcount<FunctionTraits::kShouldRef, P1>::Release(p1_);
146
147 ]]
148 }
149
150 Sig f_;
151
152 $for BOUND_ARG [[
153 P$(BOUND_ARG) p$(BOUND_ARG)_;
154
155 ]]
156 };
157
158 ]] $$ for PREBOUND
159
160 } // namespace internal
161
162 $for PREBOUND [[
163 $range BOUND_ARG 1..PREBOUND
164
165 $if PREBOUND == 0 [[
166
167 template <typename Sig>
168 internal::InvokerStorageHolder<internal::InvokerStorage0<Sig> >
169 Prebind(Sig f) {
170 return internal::MakeInvokerStorageHolder(
171 new internal::InvokerStorage0<Sig>(f));
172 }
173
174 ]] $else [[
175
176 template <typename Sig, $for BOUND_ARG , [[typename P$(BOUND_ARG)]]>
177 internal::InvokerStorageHolder<internal::InvokerStorage$(PREBOUND)<Sig,
178 $for BOUND_ARG , [[P$(BOUND_ARG)]]> >
179 Prebind(Sig f, $for BOUND_ARG , [[const P$(BOUND_ARG)& p$(BOUND_ARG)]]) {
180 return internal::MakeInvokerStorageHolder(
181 new internal::InvokerStorage$(PREBOUND)<Sig, [[]]
182 $for BOUND_ARG , [[P$(BOUND_ARG)]]>(
183 f, $for BOUND_ARG , [[p$(BOUND_ARG)]]));
184 }
185
186 ]]
187
188 ]] $$ for PREBOUND
189
190 } // namespace base
191
192 #endif // BASE_PREBIND_H_
OLDNEW
« no previous file with comments | « base/prebind.h ('k') | base/prebind_helpers.h » ('j') | base/uber_callback.h.pump » ('J')

Powered by Google App Engine
This is Rietveld 408576698