| OLD | NEW |
| 1 $$ This is a pump file for generating file templates. Pump is a python | 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 | 2 $$ script that is part of the Google Test suite of utilities. Description |
| 3 $$ can be found here: | 3 $$ can be found here: |
| 4 $$ | 4 $$ |
| 5 $$ http://code.google.com/p/googletest/wiki/PumpManual | 5 $$ http://code.google.com/p/googletest/wiki/PumpManual |
| 6 $$ | 6 $$ |
| 7 | 7 |
| 8 $var MAX_ARITY = 6 | 8 $var MAX_ARITY = 7 |
| 9 | 9 |
| 10 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 11 // Use of this source code is governed by a BSD-style license that can be |
| 12 // found in the LICENSE file. | 12 // found in the LICENSE file. |
| 13 | 13 |
| 14 #ifndef BASE_BIND_INTERNAL_H_ | 14 #ifndef BASE_BIND_INTERNAL_H_ |
| 15 #define BASE_BIND_INTERNAL_H_ | 15 #define BASE_BIND_INTERNAL_H_ |
| 16 #pragma once | 16 #pragma once |
| 17 | 17 |
| 18 #include "base/bind_helpers.h" | 18 #include "base/bind_helpers.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 32 // The method by which a function is invoked is determined by 3 different | 32 // The method by which a function is invoked is determined by 3 different |
| 33 // dimensions: | 33 // dimensions: |
| 34 // | 34 // |
| 35 // 1) The type of function (normal or method). | 35 // 1) The type of function (normal or method). |
| 36 // 2) The arity of the function. | 36 // 2) The arity of the function. |
| 37 // 3) The number of bound parameters. | 37 // 3) The number of bound parameters. |
| 38 // | 38 // |
| 39 // The templates below handle the determination of each of these dimensions. | 39 // The templates below handle the determination of each of these dimensions. |
| 40 // In brief: | 40 // In brief: |
| 41 // | 41 // |
| 42 // FunctionTraits<> -- Provides a normalied signature, and other traits. | 42 // FunctionTraits<> -- Provides a normalized signature, and other traits. |
| 43 // InvokerN<> -- Provides a DoInvoke() function that actually executes | 43 // InvokerN<> -- Provides a DoInvoke() function that actually executes |
| 44 // a calback. | 44 // a callback. |
| 45 // InvokerStorageN<> -- Provides storage for the bound parameters, and | 45 // InvokerStorageN<> -- Provides storage for the bound parameters, and |
| 46 // typedefs to the above. | 46 // typedefs to the above. |
| 47 // IsWeakMethod<> -- Determines if we are binding a method to a WeakPtr<>. | 47 // IsWeakMethod<> -- Determines if we are binding a method to a WeakPtr<>. |
| 48 // | 48 // |
| 49 // More details about the design of each class is included in a comment closer | 49 // More details about the design of each class is included in a comment closer |
| 50 // to their defition. | 50 // to their definition. |
| 51 | 51 |
| 52 | 52 |
| 53 // IsWeakMethod determines if we are binding a method to a WeakPtr<> for an | 53 // IsWeakMethod determines if we are binding a method to a WeakPtr<> for an |
| 54 // object. It is used to select an InvokerN that will no-op itself in the | 54 // object. It is used to select an InvokerN that will no-op itself in the |
| 55 // event the WeakPtr<> for the target object is invalidated. | 55 // event the WeakPtr<> for the target object is invalidated. |
| 56 template <bool IsMethod, typename T> | 56 template <bool IsMethod, typename T> |
| 57 struct IsWeakMethod : public false_type {}; | 57 struct IsWeakMethod : public false_type {}; |
| 58 | 58 |
| 59 template <typename T> | 59 template <typename T> |
| 60 struct IsWeakMethod<true, WeakPtr<T> > : public true_type {}; | 60 struct IsWeakMethod<true, WeakPtr<T> > : public true_type {}; |
| 61 | 61 |
| 62 // FunctionTraits<> | 62 // FunctionTraits<> |
| 63 // | 63 // |
| 64 // The FunctionTraits<> template determines the type of function, and also | 64 // The FunctionTraits<> template determines the type of function, and also |
| 65 // creates a NormalizedType used to select the InvokerN classes. It turns out | 65 // creates a NormalizedType used to select the InvokerN classes. It turns out |
| 66 // that syntactically, you only really have 2 variations when invoking a | 66 // that syntactically, you only really have 2 variations when invoking a |
| 67 // funciton pointer: normal, and method. One is invoked func_ptr(arg1). The | 67 // function pointer: normal, and method. One is invoked func_ptr(arg1). The |
| 68 // other is invoked (*obj_->method_ptr(arg1)). | 68 // other is invoked (*obj_->method_ptr(arg1)). |
| 69 // | 69 // |
| 70 // However, in the type system, there are many more distinctions. In standard | 70 // However, in the type system, there are many more distinctions. In standard |
| 71 // C++, there's all variations of const, and volatile on the function pointer. | 71 // C++, there's all variations of const, and volatile on the function pointer. |
| 72 // In Windows, there are additional calling conventions (eg., __stdcall, | 72 // In Windows, there are additional calling conventions (eg., __stdcall, |
| 73 // __fastcall, etc.). FunctionTraits<> handles categorizing each of these into | 73 // __fastcall, etc.). FunctionTraits<> handles categorizing each of these into |
| 74 // a normalized signature. | 74 // a normalized signature. |
| 75 // | 75 // |
| 76 // Having a NormalizedSignature signature, reduces the combinatoric | 76 // Having a NormalizedSignature signature, reduces the combinatoric |
| 77 // complexity of defintions for the InvokerN<> later. Even though there are | 77 // complexity of definitions for the InvokerN<> later. Even though there are |
| 78 // only 2 syntactic variations on invoking a function, without normalizing the | 78 // only 2 syntactic variations on invoking a function, without normalizing the |
| 79 // signature, there would need to be one specialization of InvokerN for each | 79 // signature, there would need to be one specialization of InvokerN for each |
| 80 // unique (function_type, bound_arg, unbound_args) tuple in order to match all | 80 // unique (function_type, bound_arg, unbound_args) tuple in order to match all |
| 81 // function signatures. | 81 // function signatures. |
| 82 // | 82 // |
| 83 // By normalizing the function signature, we reduce function_type to exactly 2. | 83 // By normalizing the function signature, we reduce function_type to exactly 2. |
| 84 | 84 |
| 85 template <typename Sig> | 85 template <typename Sig> |
| 86 struct FunctionTraits; | 86 struct FunctionTraits; |
| 87 | 87 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 150 |
| 151 ]] $$for ARITY | 151 ]] $$for ARITY |
| 152 | 152 |
| 153 // InvokerN<> | 153 // InvokerN<> |
| 154 // | 154 // |
| 155 // The InvokerN templates contain a static DoInvoke() function that is the key | 155 // The InvokerN templates contain a static DoInvoke() function that is the key |
| 156 // to implementing type erasure in the Callback() classes. | 156 // to implementing type erasure in the Callback() classes. |
| 157 // | 157 // |
| 158 // DoInvoke() is a static function with a fixed signature that is independent | 158 // DoInvoke() is a static function with a fixed signature that is independent |
| 159 // of StorageType; its first argument is a pointer to the non-templated common | 159 // of StorageType; its first argument is a pointer to the non-templated common |
| 160 // baseclass of StorageType. This lets us store pointer to DoInvoke() in a | 160 // base class of StorageType. This lets us store pointer to DoInvoke() in a |
| 161 // function pointer that has knowledge of the specific StorageType, and thus | 161 // function pointer that has knowledge of the specific StorageType, and thus |
| 162 // no knowledge of the bound function and bound parameter types. | 162 // no knowledge of the bound function and bound parameter types. |
| 163 // | 163 // |
| 164 // As long as we ensure that DoInvoke() is only used with pointers there were | 164 // As long as we ensure that DoInvoke() is only used with pointers there were |
| 165 // upcasted from the correct StorageType, we can be sure that execution is | 165 // up-casted from the correct StorageType, we can be sure that execution is |
| 166 // safe. | 166 // safe. |
| 167 // | 167 // |
| 168 // The InvokerN templates are the only point that knows the number of bound | 168 // The InvokerN templates are the only point that knows the number of bound |
| 169 // and unbound arguments. This is intentional because it allows the other | 169 // and unbound arguments. This is intentional because it allows the other |
| 170 // templates classes in the system to only have as many specializations as | 170 // templates classes in the system to only have as many specializations as |
| 171 // the max arity of function we wish to support. | 171 // the max arity of function we wish to support. |
| 172 | 172 |
| 173 $range BOUND 0..MAX_ARITY | 173 $range BOUND 0..MAX_ARITY |
| 174 $for BOUND [[ | 174 $for BOUND [[ |
| 175 | 175 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 | 392 |
| 393 ]] | 393 ]] |
| 394 }; | 394 }; |
| 395 | 395 |
| 396 ]] $$ for BOUND | 396 ]] $$ for BOUND |
| 397 | 397 |
| 398 } // namespace internal | 398 } // namespace internal |
| 399 } // namespace base | 399 } // namespace base |
| 400 | 400 |
| 401 #endif // BASE_BIND_INTERNAL_H_ | 401 #endif // BASE_BIND_INTERNAL_H_ |
| OLD | NEW |