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

Side by Side Diff: base/bind_internal.h

Issue 1507143003: Clean up base::Callback stuff (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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/bind.h ('k') | base/bind_unittest.nc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // 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
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_BIND_INTERNAL_H_ 5 #ifndef BASE_BIND_INTERNAL_H_
6 #define BASE_BIND_INTERNAL_H_ 6 #define BASE_BIND_INTERNAL_H_
7 7
8 #include <type_traits> 8 #include <type_traits>
9 9
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 21 matching lines...) Expand all
32 // call by including a typedef named IsMethod. The value of 32 // call by including a typedef named IsMethod. The value of
33 // this typedef is NOT inspected, only the existence. When a 33 // this typedef is NOT inspected, only the existence. When a
34 // Runnable declares itself a method, Bind() will enforce special 34 // Runnable declares itself a method, Bind() will enforce special
35 // refcounting + WeakPtr handling semantics for the first 35 // refcounting + WeakPtr handling semantics for the first
36 // parameter which is expected to be an object. 36 // parameter which is expected to be an object.
37 // Functor -- A copyable type representing something that should be called. 37 // Functor -- A copyable type representing something that should be called.
38 // All function pointers, Callback<>, and Runnables are functors 38 // All function pointers, Callback<>, and Runnables are functors
39 // even if the invocation syntax differs. 39 // even if the invocation syntax differs.
40 // RunType -- A function type (as opposed to function _pointer_ type) for 40 // RunType -- A function type (as opposed to function _pointer_ type) for
41 // a Run() function. Usually just a convenience typedef. 41 // a Run() function. Usually just a convenience typedef.
42 // (Bound)ArgsType -- A function type that is being (ab)used to store the 42 // (Bound)Args -- A set of types that stores the arguments.
43 // types of set of arguments. The "return" type is always
44 // void here. We use this hack so that we do not need
45 // a new type name for each arity of type. (eg.,
46 // BindState1, BindState2). This makes forward
47 // declarations and friending much much easier.
48 // 43 //
49 // Types: 44 // Types:
50 // RunnableAdapter<> -- Wraps the various "function" pointer types into an 45 // RunnableAdapter<> -- Wraps the various "function" pointer types into an
51 // object that adheres to the Runnable interface. 46 // object that adheres to the Runnable interface.
52 // ForceVoidReturn<> -- Helper class for translating function signatures to 47 // ForceVoidReturn<> -- Helper class for translating function signatures to
53 // equivalent forms with a "void" return type. 48 // equivalent forms with a "void" return type.
54 // FunctorTraits<> -- Type traits used determine the correct RunType and 49 // FunctorTraits<> -- Type traits used determine the correct RunType and
55 // RunnableType for a Functor. This is where function 50 // RunnableType for a Functor. This is where function
56 // signature adapters are applied. 51 // signature adapters are applied.
57 // MakeRunnable<> -- Takes a Functor and returns an object in the Runnable 52 // MakeRunnable<> -- Takes a Functor and returns an object in the Runnable
58 // type class that represents the underlying Functor. 53 // type class that represents the underlying Functor.
59 // There are |O(1)| MakeRunnable types.
60 // InvokeHelper<> -- Take a Runnable + arguments and actully invokes it. 54 // InvokeHelper<> -- Take a Runnable + arguments and actully invokes it.
61 // Handle the differing syntaxes needed for WeakPtr<> 55 // Handle the differing syntaxes needed for WeakPtr<>
62 // support, and for ignoring return values. This is separate 56 // support, and for ignoring return values. This is separate
63 // from Invoker to avoid creating multiple version of 57 // from Invoker to avoid creating multiple version of
64 // Invoker<>. 58 // Invoker<>.
65 // Invoker<> -- Unwraps the curried parameters and executes the Runnable. 59 // Invoker<> -- Unwraps the curried parameters and executes the Runnable.
66 // BindState<> -- Stores the curried parameters, and is the main entry point 60 // BindState<> -- Stores the curried parameters, and is the main entry point
67 // into the Bind() system, doing most of the type resolution. 61 // into the Bind() system, doing most of the type resolution.
68 // There are ARITY BindState types. 62 // There are ARITY BindState types.
69 63
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 // BindState<> 347 // BindState<>
354 // 348 //
355 // This stores all the state passed into Bind() and is also where most 349 // This stores all the state passed into Bind() and is also where most
356 // of the template resolution magic occurs. 350 // of the template resolution magic occurs.
357 // 351 //
358 // Runnable is the functor we are binding arguments to. 352 // Runnable is the functor we are binding arguments to.
359 // RunType is type of the Run() function that the Invoker<> should use. 353 // RunType is type of the Run() function that the Invoker<> should use.
360 // Normally, this is the same as the RunType of the Runnable, but it can 354 // Normally, this is the same as the RunType of the Runnable, but it can
361 // be different if an adapter like IgnoreResult() has been used. 355 // be different if an adapter like IgnoreResult() has been used.
362 // 356 //
363 // BoundArgsType contains the storage type for all the bound arguments by 357 // BoundArgs contains the storage type for all the bound arguments.
364 // (ab)using a function type. 358 template <typename Runnable, typename RunType, typename... BoundArgs>
365 template <typename Runnable, typename RunType, typename BoundArgList>
366 struct BindState; 359 struct BindState;
367 360
368 template <typename Runnable, 361 template <typename Runnable,
369 typename R, 362 typename R,
370 typename... Args, 363 typename... Args,
371 typename... BoundArgs> 364 typename... BoundArgs>
372 struct BindState<Runnable, R(Args...), TypeList<BoundArgs...>> final 365 struct BindState<Runnable, R(Args...), BoundArgs...> final
373 : public BindStateBase { 366 : public BindStateBase {
374 private: 367 private:
375 using StorageType = BindState<Runnable, R(Args...), TypeList<BoundArgs...>>; 368 using StorageType = BindState<Runnable, R(Args...), BoundArgs...>;
376 using RunnableType = Runnable; 369 using RunnableType = Runnable;
377 370
378 // true_type if Runnable is a method invocation and the first bound argument 371 // true_type if Runnable is a method invocation and the first bound argument
379 // is a WeakPtr. 372 // is a WeakPtr.
380 using IsWeakCall = 373 using IsWeakCall =
381 IsWeakMethod<HasIsMethodTag<Runnable>::value, BoundArgs...>; 374 IsWeakMethod<HasIsMethodTag<Runnable>::value, BoundArgs...>;
382 375
383 using BoundIndices = MakeIndexSequence<sizeof...(BoundArgs)>; 376 using BoundIndices = MakeIndexSequence<sizeof...(BoundArgs)>;
384 using Unwrappers = TypeList<UnwrapTraits<BoundArgs>...>; 377 using Unwrappers = TypeList<UnwrapTraits<BoundArgs>...>;
385 using UnboundForwardArgs = DropTypeListItem< 378 using UnboundForwardArgs = DropTypeListItem<
(...skipping 29 matching lines...) Expand all
415 408
416 static void Destroy(BindStateBase* self) { 409 static void Destroy(BindStateBase* self) {
417 delete static_cast<BindState*>(self); 410 delete static_cast<BindState*>(self);
418 } 411 }
419 }; 412 };
420 413
421 } // namespace internal 414 } // namespace internal
422 } // namespace base 415 } // namespace base
423 416
424 #endif // BASE_BIND_INTERNAL_H_ 417 #endif // BASE_BIND_INTERNAL_H_
OLDNEW
« no previous file with comments | « base/bind.h ('k') | base/bind_unittest.nc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698