ajwong@chromium.org | e2cca63 | 2011-02-15 10:27:38 +0900 | [diff] [blame] | 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. |
| 7 | // Use of this source code is governed by a BSD-style license that can be |
| 8 | // found in the LICENSE file. |
| 9 | |
| 10 | #ifndef BASE_BIND_H_ |
| 11 | #define BASE_BIND_H_ |
ajwong@chromium.org | e2cca63 | 2011-02-15 10:27:38 +0900 | [diff] [blame] | 12 | |
| 13 | #include "base/bind_internal.h" |
ajwong@chromium.org | fa0ff43 | 2011-02-19 08:29:31 +0900 | [diff] [blame] | 14 | #include "base/callback_internal.h" |
ajwong@chromium.org | e2cca63 | 2011-02-15 10:27:38 +0900 | [diff] [blame] | 15 | |
brettw@chromium.org | 11e3bfd | 2012-07-13 05:06:40 +0900 | [diff] [blame] | 16 | // ----------------------------------------------------------------------------- |
| 17 | // Usage documentation |
| 18 | // ----------------------------------------------------------------------------- |
ajwong@chromium.org | e2cca63 | 2011-02-15 10:27:38 +0900 | [diff] [blame] | 19 | // |
brettw@chromium.org | 11e3bfd | 2012-07-13 05:06:40 +0900 | [diff] [blame] | 20 | // See base/callback.h for documentation. |
| 21 | // |
| 22 | // |
| 23 | // ----------------------------------------------------------------------------- |
| 24 | // Implementation notes |
| 25 | // ----------------------------------------------------------------------------- |
| 26 | // |
| 27 | // If you're reading the implementation, before proceeding further, you should |
| 28 | // read the top comment of base/bind_internal.h for a definition of common |
| 29 | // terms and concepts. |
| 30 | // |
| 31 | // RETURN TYPES |
| 32 | // |
ajwong@chromium.org | e2cca63 | 2011-02-15 10:27:38 +0900 | [diff] [blame] | 33 | // Though Bind()'s result is meant to be stored in a Callback<> type, it |
| 34 | // cannot actually return the exact type without requiring a large amount |
| 35 | // of extra template specializations. The problem is that in order to |
| 36 | // discern the correct specialization of Callback<>, Bind would need to |
| 37 | // unwrap the function signature to determine the signature's arity, and |
| 38 | // whether or not it is a method. |
| 39 | // |
| 40 | // Each unique combination of (arity, function_type, num_prebound) where |
| 41 | // function_type is one of {function, method, const_method} would require |
| 42 | // one specialization. We eventually have to do a similar number of |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 43 | // specializations anyways in the implementation (see the Invoker<>, |
ajwong@chromium.org | e2cca63 | 2011-02-15 10:27:38 +0900 | [diff] [blame] | 44 | // classes). However, it is avoidable in Bind if we return the result |
| 45 | // via an indirection like we do below. |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 46 | // |
| 47 | // TODO(ajwong): We might be able to avoid this now, but need to test. |
| 48 | // |
| 49 | // 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 |
| 51 | // need to crack open bind_internal.h. On the other hand, it makes Bind() |
| 52 | // harder to read. |
ajwong@chromium.org | e2cca63 | 2011-02-15 10:27:38 +0900 | [diff] [blame] | 53 | |
| 54 | namespace base { |
| 55 | |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 56 | template <typename Functor> |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 57 | base::Callback< |
| 58 | typename internal::BindState< |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 59 | typename internal::FunctorTraits<Functor>::RunnableType, |
| 60 | typename internal::FunctorTraits<Functor>::RunType, |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 61 | void()> |
| 62 | ::UnboundRunType> |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 63 | Bind(Functor functor) { |
| 64 | // Typedefs for how to store and run the functor. |
| 65 | typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; |
| 66 | typedef typename internal::FunctorTraits<Functor>::RunType RunType; |
| 67 | |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 68 | typedef internal::BindState<RunnableType, RunType, void()> BindState; |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 69 | |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 70 | |
| 71 | return Callback<typename BindState::UnboundRunType>( |
| 72 | new BindState(internal::MakeRunnable(functor))); |
ajwong@chromium.org | e2cca63 | 2011-02-15 10:27:38 +0900 | [diff] [blame] | 73 | } |
| 74 | |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 75 | template <typename Functor, typename P1> |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 76 | base::Callback< |
| 77 | typename internal::BindState< |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 78 | typename internal::FunctorTraits<Functor>::RunnableType, |
| 79 | typename internal::FunctorTraits<Functor>::RunType, |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 80 | void(typename internal::CallbackParamTraits<P1>::StorageType)> |
| 81 | ::UnboundRunType> |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 82 | Bind(Functor functor, const P1& p1) { |
| 83 | // Typedefs for how to store and run the functor. |
| 84 | typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; |
| 85 | 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); |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 113 | typedef internal::BindState<RunnableType, RunType, |
| 114 | void(typename internal::CallbackParamTraits<P1>::StorageType)> BindState; |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 115 | |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 116 | |
| 117 | return Callback<typename BindState::UnboundRunType>( |
| 118 | new BindState(internal::MakeRunnable(functor), p1)); |
ajwong@chromium.org | e2cca63 | 2011-02-15 10:27:38 +0900 | [diff] [blame] | 119 | } |
| 120 | |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 121 | template <typename Functor, typename P1, typename P2> |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 122 | base::Callback< |
| 123 | typename internal::BindState< |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 124 | typename internal::FunctorTraits<Functor>::RunnableType, |
| 125 | typename internal::FunctorTraits<Functor>::RunType, |
| 126 | void(typename internal::CallbackParamTraits<P1>::StorageType, |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 127 | typename internal::CallbackParamTraits<P2>::StorageType)> |
| 128 | ::UnboundRunType> |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 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); |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 163 | typedef internal::BindState<RunnableType, RunType, |
| 164 | void(typename internal::CallbackParamTraits<P1>::StorageType, |
| 165 | typename internal::CallbackParamTraits<P2>::StorageType)> BindState; |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 166 | |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 167 | |
| 168 | return Callback<typename BindState::UnboundRunType>( |
| 169 | new BindState(internal::MakeRunnable(functor), p1, p2)); |
ajwong@chromium.org | e2cca63 | 2011-02-15 10:27:38 +0900 | [diff] [blame] | 170 | } |
| 171 | |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 172 | template <typename Functor, typename P1, typename P2, typename P3> |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 173 | base::Callback< |
| 174 | typename internal::BindState< |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 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, |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 179 | typename internal::CallbackParamTraits<P3>::StorageType)> |
| 180 | ::UnboundRunType> |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 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); |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 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; |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 222 | |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 223 | |
| 224 | return Callback<typename BindState::UnboundRunType>( |
| 225 | new BindState(internal::MakeRunnable(functor), p1, p2, p3)); |
ajwong@chromium.org | e2cca63 | 2011-02-15 10:27:38 +0900 | [diff] [blame] | 226 | } |
| 227 | |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 228 | template <typename Functor, typename P1, typename P2, typename P3, typename P4> |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 229 | base::Callback< |
| 230 | typename internal::BindState< |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 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, |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 236 | typename internal::CallbackParamTraits<P4>::StorageType)> |
| 237 | ::UnboundRunType> |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 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); |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 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; |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 283 | |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 284 | |
| 285 | return Callback<typename BindState::UnboundRunType>( |
| 286 | new BindState(internal::MakeRunnable(functor), p1, p2, p3, p4)); |
ajwong@chromium.org | e2cca63 | 2011-02-15 10:27:38 +0900 | [diff] [blame] | 287 | } |
| 288 | |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 289 | template <typename Functor, typename P1, typename P2, typename P3, typename P4, |
ajwong@chromium.org | e2cca63 | 2011-02-15 10:27:38 +0900 | [diff] [blame] | 290 | typename P5> |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 291 | base::Callback< |
| 292 | typename internal::BindState< |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 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, |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 299 | typename internal::CallbackParamTraits<P5>::StorageType)> |
| 300 | ::UnboundRunType> |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 301 | Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3, const P4& p4, |
ajwong@chromium.org | e2cca63 | 2011-02-15 10:27:38 +0900 | [diff] [blame] | 302 | const P5& p5) { |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 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); |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 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; |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 351 | |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 352 | |
| 353 | return Callback<typename BindState::UnboundRunType>( |
| 354 | new BindState(internal::MakeRunnable(functor), p1, p2, p3, p4, p5)); |
ajwong@chromium.org | e2cca63 | 2011-02-15 10:27:38 +0900 | [diff] [blame] | 355 | } |
| 356 | |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 357 | template <typename Functor, typename P1, typename P2, typename P3, typename P4, |
ajwong@chromium.org | e2cca63 | 2011-02-15 10:27:38 +0900 | [diff] [blame] | 358 | typename P5, typename P6> |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 359 | base::Callback< |
| 360 | typename internal::BindState< |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 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, |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 368 | typename internal::CallbackParamTraits<P6>::StorageType)> |
| 369 | ::UnboundRunType> |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 370 | Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3, const P4& p4, |
ajwong@chromium.org | e2cca63 | 2011-02-15 10:27:38 +0900 | [diff] [blame] | 371 | const P5& p5, const P6& p6) { |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 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; |
ajwong@chromium.org | e2cca63 | 2011-02-15 10:27:38 +0900 | [diff] [blame] | 375 | |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 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; |
ajwong@chromium.org | d483ffe | 2011-09-30 18:09:34 +0900 | [diff] [blame] | 381 | |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 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); |
ajwong@chromium.org | d483ffe | 2011-09-30 18:09:34 +0900 | [diff] [blame] | 395 | |
ajwong@chromium.org | c9c79af | 2011-11-22 04:23:44 +0900 | [diff] [blame] | 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); |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 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; |
ajwong@chromium.org | d483ffe | 2011-09-30 18:09:34 +0900 | [diff] [blame] | 424 | |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 425 | |
| 426 | return Callback<typename BindState::UnboundRunType>( |
| 427 | new BindState(internal::MakeRunnable(functor), p1, p2, p3, p4, p5, p6)); |
ajwong@chromium.org | d483ffe | 2011-09-30 18:09:34 +0900 | [diff] [blame] | 428 | } |
| 429 | |
ajwong@chromium.org | 6f015bd | 2011-11-29 07:13:54 +0900 | [diff] [blame] | 430 | template <typename Functor, typename P1, typename P2, typename P3, typename P4, |
| 431 | typename P5, typename P6, typename P7> |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 432 | base::Callback< |
| 433 | typename internal::BindState< |
ajwong@chromium.org | 6f015bd | 2011-11-29 07:13:54 +0900 | [diff] [blame] | 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, |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 442 | typename internal::CallbackParamTraits<P7>::StorageType)> |
| 443 | ::UnboundRunType> |
ajwong@chromium.org | 6f015bd | 2011-11-29 07:13:54 +0900 | [diff] [blame] | 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 | |
| 450 | // Use RunnableType::RunType instead of RunType above because our |
| 451 | // checks should below for bound references need to know what the actual |
| 452 | // functor is going to interpret the argument as. |
| 453 | typedef internal::FunctionTraits<typename RunnableType::RunType> |
| 454 | BoundFunctorTraits; |
| 455 | |
| 456 | // Do not allow binding a non-const reference parameter. Non-const reference |
| 457 | // parameters are disallowed by the Google style guide. Also, binding a |
| 458 | // non-const reference parameter can make for subtle bugs because the |
| 459 | // invoked function will receive a reference to the stored copy of the |
| 460 | // argument and not the original. |
| 461 | COMPILE_ASSERT( |
| 462 | !(is_non_const_reference<typename BoundFunctorTraits::A1Type>::value || |
| 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 | |
| 471 | // 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 |
| 473 | // methods. We also disallow binding of an array as the method's target |
| 474 | // object. |
| 475 | COMPILE_ASSERT( |
| 476 | internal::HasIsMethodTag<RunnableType>::value || |
| 477 | !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value, |
| 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); |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 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; |
ajwong@chromium.org | 6f015bd | 2011-11-29 07:13:54 +0900 | [diff] [blame] | 502 | |
ajwong@chromium.org | abd7000 | 2011-12-20 09:10:04 +0900 | [diff] [blame] | 503 | |
| 504 | return Callback<typename BindState::UnboundRunType>( |
| 505 | new BindState(internal::MakeRunnable(functor), p1, p2, p3, p4, p5, p6, |
| 506 | p7)); |
ajwong@chromium.org | 6f015bd | 2011-11-29 07:13:54 +0900 | [diff] [blame] | 507 | } |
| 508 | |
ajwong@chromium.org | e2cca63 | 2011-02-15 10:27:38 +0900 | [diff] [blame] | 509 | } // namespace base |
| 510 | |
| 511 | #endif // BASE_BIND_H_ |