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

Side by Side Diff: base/bind.h

Issue 610313003: [WIP][Base] Use variadic template for Callback and Bind (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wrap tuple Created 6 years, 2 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
« no previous file with comments | « base/base.gypi ('k') | base/bind.h.pump » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // This file was GENERATED by command:
2 // pump.py bind.h.pump
3 // DO NOT EDIT BY HAND!!!
4
5
6 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file. 3 // found in the LICENSE file.
9 4
10 #ifndef BASE_BIND_H_ 5 #ifndef BASE_BIND_H_
11 #define BASE_BIND_H_ 6 #define BASE_BIND_H_
12 7
13 #include "base/bind_internal.h" 8 #include "base/bind_internal.h"
14 #include "base/callback_internal.h" 9 #include "base/callback_internal.h"
10 #include "base/memory/raw_scoped_refptr_mismatch_checker.h"
15 11
16 // ----------------------------------------------------------------------------- 12 // -----------------------------------------------------------------------------
17 // Usage documentation 13 // Usage documentation
18 // ----------------------------------------------------------------------------- 14 // -----------------------------------------------------------------------------
19 // 15 //
20 // See base/callback.h for documentation. 16 // See base/callback.h for documentation.
21 // 17 //
22 // 18 //
23 // ----------------------------------------------------------------------------- 19 // -----------------------------------------------------------------------------
24 // Implementation notes 20 // Implementation notes
(...skipping 21 matching lines...) Expand all
46 // 42 //
47 // TODO(ajwong): We might be able to avoid this now, but need to test. 43 // TODO(ajwong): We might be able to avoid this now, but need to test.
48 // 44 //
49 // It is possible to move most of the COMPILE_ASSERT asserts into BindState<>, 45 // It is possible to move most of the COMPILE_ASSERT asserts into BindState<>,
50 // but it feels a little nicer to have the asserts here so people do not 46 // but it feels a little nicer to have the asserts here so people do not
51 // need to crack open bind_internal.h. On the other hand, it makes Bind() 47 // need to crack open bind_internal.h. On the other hand, it makes Bind()
52 // harder to read. 48 // harder to read.
53 49
54 namespace base { 50 namespace base {
55 51
52 namespace internal {
53
54 // HasNonConstReferenceParam takes a function signature and returns true as
55 // HasNonConstReferenceParam::value if any of its parameters is non-const
56 // reference type.
57 template <typename Sig>
58 struct HasNonConstReferenceParam : false_type {};
59
60 // Check if the first parameter is a non-const reference.
61 // If not, skip the first parameter and check rest of parameters recursively.
62 template <typename R, typename T, typename... Args>
63 struct HasNonConstReferenceParam<R(T, Args...)>
64 : SelectType<is_non_const_reference<T>::value,
65 true_type,
66 HasNonConstReferenceParam<R(Args...)> >::Type {};
67
68 // HasRefCountedParamAsRawPtr takes a function signature and return true as
69 // HasRefCountedParamAsRawPtr::value if any of its parameter is a raw pointer to
70 // a RefCounted type.
71 template <typename Sig>
72 struct HasRefCountedParamAsRawPtr : false_type {};
73
74 // Check if the first parameter is a raw pointer to a RefCounted type.
75 // If not, skip the first parameter and check rest of parameters recursively.
76 template <typename R, typename T, typename... Args>
77 struct HasRefCountedParamAsRawPtr<R(T, Args...)>
78 : SelectType<NeedsScopedRefptrButGetsRawPtr<T>::value,
79 true_type,
80 HasRefCountedParamAsRawPtr<R(Args...)> >::Type {};
81
82 // UsesBannedBindingType takes a boolean to specify
83 // a functor signature and a function signature and
84 // returns true as UsesBannedBinding::value if any of the forbidden cases below
85 // hits:
86 // - Any of non-this pointer parameters is a raw pointer to a RefCounted type.
87 // - The parameter for this pointer is an array.
88 template <bool is_method, typename Signature>
89 struct UsesBannedBindingType : HasRefCountedParamAsRawPtr<Signature> {};
90
91 // Check if the first parameter of a method binding is an array.
92 // If not, skip the first parameter and check if any of rest of parameters
93 // is a raw pointer to a RefCounted type.
94 template <typename R, typename T, typename... Args>
95 struct UsesBannedBindingType<true, R(T, Args...)>
96 : SelectType<is_array<T>::value,
97 true_type,
98 HasRefCountedParamAsRawPtr<R(Args...)> >::Type {};
99
100 } // namespace internal
101
56 template <typename Functor> 102 template <typename Functor>
57 base::Callback< 103 base::Callback<
58 typename internal::BindState< 104 typename internal::BindState<
59 typename internal::FunctorTraits<Functor>::RunnableType, 105 typename internal::FunctorTraits<Functor>::RunnableType,
60 typename internal::FunctorTraits<Functor>::RunType, 106 typename internal::FunctorTraits<Functor>::RunType,
61 void()> 107 internal::TypeList<> >::UnboundRunType>
62 ::UnboundRunType>
63 Bind(Functor functor) { 108 Bind(Functor functor) {
64 // Typedefs for how to store and run the functor. 109 // Typedefs for how to store and run the functor.
65 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; 110 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
66 typedef typename internal::FunctorTraits<Functor>::RunType RunType; 111 typedef typename internal::FunctorTraits<Functor>::RunType RunType;
67 112
68 typedef internal::BindState<RunnableType, RunType, void()> BindState; 113 typedef internal::BindState<RunnableType, RunType,
69 114 internal::TypeList<>> BindState;
70 115
71 return Callback<typename BindState::UnboundRunType>( 116 return Callback<typename BindState::UnboundRunType>(
72 new BindState(internal::MakeRunnable(functor))); 117 new BindState(internal::MakeRunnable(functor)));
73 } 118 }
74 119
75 template <typename Functor, typename P1> 120 template <typename Functor, typename... Args>
76 base::Callback< 121 base::Callback<
77 typename internal::BindState< 122 typename internal::BindState<
78 typename internal::FunctorTraits<Functor>::RunnableType, 123 typename internal::FunctorTraits<Functor>::RunnableType,
79 typename internal::FunctorTraits<Functor>::RunType, 124 typename internal::FunctorTraits<Functor>::RunType,
80 void(typename internal::CallbackParamTraits<P1>::StorageType)> 125 internal::TypeList<
126 typename internal::CallbackParamTraits<Args>::StorageType...>>
81 ::UnboundRunType> 127 ::UnboundRunType>
82 Bind(Functor functor, const P1& p1) { 128 Bind(Functor functor, const Args&... args) {
83 // Typedefs for how to store and run the functor. 129 // Typedefs for how to store and run the functor.
84 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; 130 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
85 typedef typename internal::FunctorTraits<Functor>::RunType RunType; 131 typedef typename internal::FunctorTraits<Functor>::RunType RunType;
86
87 // Use RunnableType::RunType instead of RunType above because our
88 // checks should below for bound references need to know what the actual
89 // functor is going to interpret the argument as.
90 typedef internal::FunctionTraits<typename RunnableType::RunType>
91 BoundFunctorTraits;
92
93 // Do not allow binding a non-const reference parameter. Non-const reference
94 // parameters are disallowed by the Google style guide. Also, binding a
95 // non-const reference parameter can make for subtle bugs because the
96 // invoked function will receive a reference to the stored copy of the
97 // argument and not the original.
98 COMPILE_ASSERT(
99 !(is_non_const_reference<typename BoundFunctorTraits::A1Type>::value ),
100 do_not_bind_functions_with_nonconst_ref);
101
102 // For methods, we need to be careful for parameter 1. We do not require
103 // a scoped_refptr because BindState<> itself takes care of AddRef() for
104 // methods. We also disallow binding of an array as the method's target
105 // object.
106 COMPILE_ASSERT(
107 internal::HasIsMethodTag<RunnableType>::value ||
108 !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value,
109 p1_is_refcounted_type_and_needs_scoped_refptr);
110 COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value ||
111 !is_array<P1>::value,
112 first_bound_argument_to_method_cannot_be_array);
113 typedef internal::BindState<RunnableType, RunType,
114 void(typename internal::CallbackParamTraits<P1>::StorageType)> BindState;
115
116
117 return Callback<typename BindState::UnboundRunType>(
118 new BindState(internal::MakeRunnable(functor), p1));
119 }
120
121 template <typename Functor, typename P1, typename P2>
122 base::Callback<
123 typename internal::BindState<
124 typename internal::FunctorTraits<Functor>::RunnableType,
125 typename internal::FunctorTraits<Functor>::RunType,
126 void(typename internal::CallbackParamTraits<P1>::StorageType,
127 typename internal::CallbackParamTraits<P2>::StorageType)>
128 ::UnboundRunType>
129 Bind(Functor functor, const P1& p1, const P2& p2) {
130 // Typedefs for how to store and run the functor.
131 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
132 typedef typename internal::FunctorTraits<Functor>::RunType RunType;
133
134 // Use RunnableType::RunType instead of RunType above because our
135 // checks should below for bound references need to know what the actual
136 // functor is going to interpret the argument as.
137 typedef internal::FunctionTraits<typename RunnableType::RunType>
138 BoundFunctorTraits;
139
140 // Do not allow binding a non-const reference parameter. Non-const reference
141 // parameters are disallowed by the Google style guide. Also, binding a
142 // non-const reference parameter can make for subtle bugs because the
143 // invoked function will receive a reference to the stored copy of the
144 // argument and not the original.
145 COMPILE_ASSERT(
146 !(is_non_const_reference<typename BoundFunctorTraits::A1Type>::value ||
147 is_non_const_reference<typename BoundFunctorTraits::A2Type>::value ),
148 do_not_bind_functions_with_nonconst_ref);
149
150 // For methods, we need to be careful for parameter 1. We do not require
151 // a scoped_refptr because BindState<> itself takes care of AddRef() for
152 // methods. We also disallow binding of an array as the method's target
153 // object.
154 COMPILE_ASSERT(
155 internal::HasIsMethodTag<RunnableType>::value ||
156 !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value,
157 p1_is_refcounted_type_and_needs_scoped_refptr);
158 COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value ||
159 !is_array<P1>::value,
160 first_bound_argument_to_method_cannot_be_array);
161 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value,
162 p2_is_refcounted_type_and_needs_scoped_refptr);
163 typedef internal::BindState<RunnableType, RunType,
164 void(typename internal::CallbackParamTraits<P1>::StorageType,
165 typename internal::CallbackParamTraits<P2>::StorageType)> BindState;
166
167
168 return Callback<typename BindState::UnboundRunType>(
169 new BindState(internal::MakeRunnable(functor), p1, p2));
170 }
171
172 template <typename Functor, typename P1, typename P2, typename P3>
173 base::Callback<
174 typename internal::BindState<
175 typename internal::FunctorTraits<Functor>::RunnableType,
176 typename internal::FunctorTraits<Functor>::RunType,
177 void(typename internal::CallbackParamTraits<P1>::StorageType,
178 typename internal::CallbackParamTraits<P2>::StorageType,
179 typename internal::CallbackParamTraits<P3>::StorageType)>
180 ::UnboundRunType>
181 Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3) {
182 // Typedefs for how to store and run the functor.
183 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
184 typedef typename internal::FunctorTraits<Functor>::RunType RunType;
185
186 // Use RunnableType::RunType instead of RunType above because our
187 // checks should below for bound references need to know what the actual
188 // functor is going to interpret the argument as.
189 typedef internal::FunctionTraits<typename RunnableType::RunType>
190 BoundFunctorTraits;
191
192 // Do not allow binding a non-const reference parameter. Non-const reference
193 // parameters are disallowed by the Google style guide. Also, binding a
194 // non-const reference parameter can make for subtle bugs because the
195 // invoked function will receive a reference to the stored copy of the
196 // argument and not the original.
197 COMPILE_ASSERT(
198 !(is_non_const_reference<typename BoundFunctorTraits::A1Type>::value ||
199 is_non_const_reference<typename BoundFunctorTraits::A2Type>::value ||
200 is_non_const_reference<typename BoundFunctorTraits::A3Type>::value ),
201 do_not_bind_functions_with_nonconst_ref);
202
203 // For methods, we need to be careful for parameter 1. We do not require
204 // a scoped_refptr because BindState<> itself takes care of AddRef() for
205 // methods. We also disallow binding of an array as the method's target
206 // object.
207 COMPILE_ASSERT(
208 internal::HasIsMethodTag<RunnableType>::value ||
209 !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value,
210 p1_is_refcounted_type_and_needs_scoped_refptr);
211 COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value ||
212 !is_array<P1>::value,
213 first_bound_argument_to_method_cannot_be_array);
214 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value,
215 p2_is_refcounted_type_and_needs_scoped_refptr);
216 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P3>::value,
217 p3_is_refcounted_type_and_needs_scoped_refptr);
218 typedef internal::BindState<RunnableType, RunType,
219 void(typename internal::CallbackParamTraits<P1>::StorageType,
220 typename internal::CallbackParamTraits<P2>::StorageType,
221 typename internal::CallbackParamTraits<P3>::StorageType)> BindState;
222
223
224 return Callback<typename BindState::UnboundRunType>(
225 new BindState(internal::MakeRunnable(functor), p1, p2, p3));
226 }
227
228 template <typename Functor, typename P1, typename P2, typename P3, typename P4>
229 base::Callback<
230 typename internal::BindState<
231 typename internal::FunctorTraits<Functor>::RunnableType,
232 typename internal::FunctorTraits<Functor>::RunType,
233 void(typename internal::CallbackParamTraits<P1>::StorageType,
234 typename internal::CallbackParamTraits<P2>::StorageType,
235 typename internal::CallbackParamTraits<P3>::StorageType,
236 typename internal::CallbackParamTraits<P4>::StorageType)>
237 ::UnboundRunType>
238 Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3, const P4& p4) {
239 // Typedefs for how to store and run the functor.
240 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
241 typedef typename internal::FunctorTraits<Functor>::RunType RunType;
242
243 // Use RunnableType::RunType instead of RunType above because our
244 // checks should below for bound references need to know what the actual
245 // functor is going to interpret the argument as.
246 typedef internal::FunctionTraits<typename RunnableType::RunType>
247 BoundFunctorTraits;
248
249 // Do not allow binding a non-const reference parameter. Non-const reference
250 // parameters are disallowed by the Google style guide. Also, binding a
251 // non-const reference parameter can make for subtle bugs because the
252 // invoked function will receive a reference to the stored copy of the
253 // argument and not the original.
254 COMPILE_ASSERT(
255 !(is_non_const_reference<typename BoundFunctorTraits::A1Type>::value ||
256 is_non_const_reference<typename BoundFunctorTraits::A2Type>::value ||
257 is_non_const_reference<typename BoundFunctorTraits::A3Type>::value ||
258 is_non_const_reference<typename BoundFunctorTraits::A4Type>::value ),
259 do_not_bind_functions_with_nonconst_ref);
260
261 // For methods, we need to be careful for parameter 1. We do not require
262 // a scoped_refptr because BindState<> itself takes care of AddRef() for
263 // methods. We also disallow binding of an array as the method's target
264 // object.
265 COMPILE_ASSERT(
266 internal::HasIsMethodTag<RunnableType>::value ||
267 !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value,
268 p1_is_refcounted_type_and_needs_scoped_refptr);
269 COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value ||
270 !is_array<P1>::value,
271 first_bound_argument_to_method_cannot_be_array);
272 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value,
273 p2_is_refcounted_type_and_needs_scoped_refptr);
274 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P3>::value,
275 p3_is_refcounted_type_and_needs_scoped_refptr);
276 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P4>::value,
277 p4_is_refcounted_type_and_needs_scoped_refptr);
278 typedef internal::BindState<RunnableType, RunType,
279 void(typename internal::CallbackParamTraits<P1>::StorageType,
280 typename internal::CallbackParamTraits<P2>::StorageType,
281 typename internal::CallbackParamTraits<P3>::StorageType,
282 typename internal::CallbackParamTraits<P4>::StorageType)> BindState;
283
284
285 return Callback<typename BindState::UnboundRunType>(
286 new BindState(internal::MakeRunnable(functor), p1, p2, p3, p4));
287 }
288
289 template <typename Functor, typename P1, typename P2, typename P3, typename P4,
290 typename P5>
291 base::Callback<
292 typename internal::BindState<
293 typename internal::FunctorTraits<Functor>::RunnableType,
294 typename internal::FunctorTraits<Functor>::RunType,
295 void(typename internal::CallbackParamTraits<P1>::StorageType,
296 typename internal::CallbackParamTraits<P2>::StorageType,
297 typename internal::CallbackParamTraits<P3>::StorageType,
298 typename internal::CallbackParamTraits<P4>::StorageType,
299 typename internal::CallbackParamTraits<P5>::StorageType)>
300 ::UnboundRunType>
301 Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3, const P4& p4,
302 const P5& p5) {
303 // Typedefs for how to store and run the functor.
304 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
305 typedef typename internal::FunctorTraits<Functor>::RunType RunType;
306
307 // Use RunnableType::RunType instead of RunType above because our
308 // checks should below for bound references need to know what the actual
309 // functor is going to interpret the argument as.
310 typedef internal::FunctionTraits<typename RunnableType::RunType>
311 BoundFunctorTraits;
312
313 // Do not allow binding a non-const reference parameter. Non-const reference
314 // parameters are disallowed by the Google style guide. Also, binding a
315 // non-const reference parameter can make for subtle bugs because the
316 // invoked function will receive a reference to the stored copy of the
317 // argument and not the original.
318 COMPILE_ASSERT(
319 !(is_non_const_reference<typename BoundFunctorTraits::A1Type>::value ||
320 is_non_const_reference<typename BoundFunctorTraits::A2Type>::value ||
321 is_non_const_reference<typename BoundFunctorTraits::A3Type>::value ||
322 is_non_const_reference<typename BoundFunctorTraits::A4Type>::value ||
323 is_non_const_reference<typename BoundFunctorTraits::A5Type>::value ),
324 do_not_bind_functions_with_nonconst_ref);
325
326 // For methods, we need to be careful for parameter 1. We do not require
327 // a scoped_refptr because BindState<> itself takes care of AddRef() for
328 // methods. We also disallow binding of an array as the method's target
329 // object.
330 COMPILE_ASSERT(
331 internal::HasIsMethodTag<RunnableType>::value ||
332 !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value,
333 p1_is_refcounted_type_and_needs_scoped_refptr);
334 COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value ||
335 !is_array<P1>::value,
336 first_bound_argument_to_method_cannot_be_array);
337 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value,
338 p2_is_refcounted_type_and_needs_scoped_refptr);
339 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P3>::value,
340 p3_is_refcounted_type_and_needs_scoped_refptr);
341 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P4>::value,
342 p4_is_refcounted_type_and_needs_scoped_refptr);
343 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P5>::value,
344 p5_is_refcounted_type_and_needs_scoped_refptr);
345 typedef internal::BindState<RunnableType, RunType,
346 void(typename internal::CallbackParamTraits<P1>::StorageType,
347 typename internal::CallbackParamTraits<P2>::StorageType,
348 typename internal::CallbackParamTraits<P3>::StorageType,
349 typename internal::CallbackParamTraits<P4>::StorageType,
350 typename internal::CallbackParamTraits<P5>::StorageType)> BindState;
351
352
353 return Callback<typename BindState::UnboundRunType>(
354 new BindState(internal::MakeRunnable(functor), p1, p2, p3, p4, p5));
355 }
356
357 template <typename Functor, typename P1, typename P2, typename P3, typename P4,
358 typename P5, typename P6>
359 base::Callback<
360 typename internal::BindState<
361 typename internal::FunctorTraits<Functor>::RunnableType,
362 typename internal::FunctorTraits<Functor>::RunType,
363 void(typename internal::CallbackParamTraits<P1>::StorageType,
364 typename internal::CallbackParamTraits<P2>::StorageType,
365 typename internal::CallbackParamTraits<P3>::StorageType,
366 typename internal::CallbackParamTraits<P4>::StorageType,
367 typename internal::CallbackParamTraits<P5>::StorageType,
368 typename internal::CallbackParamTraits<P6>::StorageType)>
369 ::UnboundRunType>
370 Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3, const P4& p4,
371 const P5& p5, const P6& p6) {
372 // Typedefs for how to store and run the functor.
373 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
374 typedef typename internal::FunctorTraits<Functor>::RunType RunType;
375
376 // Use RunnableType::RunType instead of RunType above because our
377 // checks should below for bound references need to know what the actual
378 // functor is going to interpret the argument as.
379 typedef internal::FunctionTraits<typename RunnableType::RunType>
380 BoundFunctorTraits;
381
382 // Do not allow binding a non-const reference parameter. Non-const reference
383 // parameters are disallowed by the Google style guide. Also, binding a
384 // non-const reference parameter can make for subtle bugs because the
385 // invoked function will receive a reference to the stored copy of the
386 // argument and not the original.
387 COMPILE_ASSERT(
388 !(is_non_const_reference<typename BoundFunctorTraits::A1Type>::value ||
389 is_non_const_reference<typename BoundFunctorTraits::A2Type>::value ||
390 is_non_const_reference<typename BoundFunctorTraits::A3Type>::value ||
391 is_non_const_reference<typename BoundFunctorTraits::A4Type>::value ||
392 is_non_const_reference<typename BoundFunctorTraits::A5Type>::value ||
393 is_non_const_reference<typename BoundFunctorTraits::A6Type>::value ),
394 do_not_bind_functions_with_nonconst_ref);
395
396 // For methods, we need to be careful for parameter 1. We do not require
397 // a scoped_refptr because BindState<> itself takes care of AddRef() for
398 // methods. We also disallow binding of an array as the method's target
399 // object.
400 COMPILE_ASSERT(
401 internal::HasIsMethodTag<RunnableType>::value ||
402 !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value,
403 p1_is_refcounted_type_and_needs_scoped_refptr);
404 COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value ||
405 !is_array<P1>::value,
406 first_bound_argument_to_method_cannot_be_array);
407 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value,
408 p2_is_refcounted_type_and_needs_scoped_refptr);
409 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P3>::value,
410 p3_is_refcounted_type_and_needs_scoped_refptr);
411 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P4>::value,
412 p4_is_refcounted_type_and_needs_scoped_refptr);
413 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P5>::value,
414 p5_is_refcounted_type_and_needs_scoped_refptr);
415 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P6>::value,
416 p6_is_refcounted_type_and_needs_scoped_refptr);
417 typedef internal::BindState<RunnableType, RunType,
418 void(typename internal::CallbackParamTraits<P1>::StorageType,
419 typename internal::CallbackParamTraits<P2>::StorageType,
420 typename internal::CallbackParamTraits<P3>::StorageType,
421 typename internal::CallbackParamTraits<P4>::StorageType,
422 typename internal::CallbackParamTraits<P5>::StorageType,
423 typename internal::CallbackParamTraits<P6>::StorageType)> BindState;
424
425
426 return Callback<typename BindState::UnboundRunType>(
427 new BindState(internal::MakeRunnable(functor), p1, p2, p3, p4, p5, p6));
428 }
429
430 template <typename Functor, typename P1, typename P2, typename P3, typename P4,
431 typename P5, typename P6, typename P7>
432 base::Callback<
433 typename internal::BindState<
434 typename internal::FunctorTraits<Functor>::RunnableType,
435 typename internal::FunctorTraits<Functor>::RunType,
436 void(typename internal::CallbackParamTraits<P1>::StorageType,
437 typename internal::CallbackParamTraits<P2>::StorageType,
438 typename internal::CallbackParamTraits<P3>::StorageType,
439 typename internal::CallbackParamTraits<P4>::StorageType,
440 typename internal::CallbackParamTraits<P5>::StorageType,
441 typename internal::CallbackParamTraits<P6>::StorageType,
442 typename internal::CallbackParamTraits<P7>::StorageType)>
443 ::UnboundRunType>
444 Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3, const P4& p4,
445 const P5& p5, const P6& p6, const P7& p7) {
446 // Typedefs for how to store and run the functor.
447 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
448 typedef typename internal::FunctorTraits<Functor>::RunType RunType;
449 132
450 // Use RunnableType::RunType instead of RunType above because our 133 // Use RunnableType::RunType instead of RunType above because our
451 // checks should below for bound references need to know what the actual 134 // checks should below for bound references need to know what the actual
452 // functor is going to interpret the argument as. 135 // functor is going to interpret the argument as.
453 typedef internal::FunctionTraits<typename RunnableType::RunType> 136 typedef typename RunnableType::RunType BoundRunType;
454 BoundFunctorTraits;
455 137
456 // Do not allow binding a non-const reference parameter. Non-const reference 138 // Do not allow binding a non-const reference parameter. Non-const reference
457 // parameters are disallowed by the Google style guide. Also, binding a 139 // parameters are disallowed by the Google style guide. Also, binding a
458 // non-const reference parameter can make for subtle bugs because the 140 // non-const reference parameter can make for subtle bugs because the
459 // invoked function will receive a reference to the stored copy of the 141 // invoked function will receive a reference to the stored copy of the
460 // argument and not the original. 142 // argument and not the original.
461 COMPILE_ASSERT( 143 COMPILE_ASSERT(!internal::HasNonConstReferenceParam<BoundRunType>::value,
462 !(is_non_const_reference<typename BoundFunctorTraits::A1Type>::value || 144 do_not_bind_functions_with_nonconst_ref);
463 is_non_const_reference<typename BoundFunctorTraits::A2Type>::value ||
464 is_non_const_reference<typename BoundFunctorTraits::A3Type>::value ||
465 is_non_const_reference<typename BoundFunctorTraits::A4Type>::value ||
466 is_non_const_reference<typename BoundFunctorTraits::A5Type>::value ||
467 is_non_const_reference<typename BoundFunctorTraits::A6Type>::value ||
468 is_non_const_reference<typename BoundFunctorTraits::A7Type>::value ),
469 do_not_bind_functions_with_nonconst_ref);
470 145
471 // For methods, we need to be careful for parameter 1. We do not require 146 // For methods, we need to be careful for parameter 1. We do not require
472 // a scoped_refptr because BindState<> itself takes care of AddRef() for 147 // a scoped_refptr because BindState<> itself takes care of AddRef() for
473 // methods. We also disallow binding of an array as the method's target 148 // methods. We also disallow binding of an array as the method's target
474 // object. 149 // object.
475 COMPILE_ASSERT( 150 COMPILE_ASSERT((!internal::UsesBannedBindingType<
476 internal::HasIsMethodTag<RunnableType>::value || 151 internal::HasIsMethodTag<RunnableType>::value, void(Args...)>::value),
477 !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value, 152 this_param_is_a_array_or_a_param_is_raw_pointer_to_refcounted_type);
478 p1_is_refcounted_type_and_needs_scoped_refptr);
479 COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value ||
480 !is_array<P1>::value,
481 first_bound_argument_to_method_cannot_be_array);
482 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value,
483 p2_is_refcounted_type_and_needs_scoped_refptr);
484 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P3>::value,
485 p3_is_refcounted_type_and_needs_scoped_refptr);
486 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P4>::value,
487 p4_is_refcounted_type_and_needs_scoped_refptr);
488 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P5>::value,
489 p5_is_refcounted_type_and_needs_scoped_refptr);
490 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P6>::value,
491 p6_is_refcounted_type_and_needs_scoped_refptr);
492 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P7>::value,
493 p7_is_refcounted_type_and_needs_scoped_refptr);
494 typedef internal::BindState<RunnableType, RunType,
495 void(typename internal::CallbackParamTraits<P1>::StorageType,
496 typename internal::CallbackParamTraits<P2>::StorageType,
497 typename internal::CallbackParamTraits<P3>::StorageType,
498 typename internal::CallbackParamTraits<P4>::StorageType,
499 typename internal::CallbackParamTraits<P5>::StorageType,
500 typename internal::CallbackParamTraits<P6>::StorageType,
501 typename internal::CallbackParamTraits<P7>::StorageType)> BindState;
502 153
154 typedef internal::BindState<
155 RunnableType, RunType,
156 internal::TypeList<
157 typename internal::CallbackParamTraits<Args>::StorageType...>>
158 BindState;
503 159
504 return Callback<typename BindState::UnboundRunType>( 160 return Callback<typename BindState::UnboundRunType>(
505 new BindState(internal::MakeRunnable(functor), p1, p2, p3, p4, p5, p6, 161 new BindState(internal::MakeRunnable(functor), args...));
506 p7));
507 } 162 }
508 163
509 } // namespace base 164 } // namespace base
510 165
511 #endif // BASE_BIND_H_ 166 #endif // BASE_BIND_H_
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/bind.h.pump » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698