| 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 $$ See comment for MAX_ARITY in base/bind.h.pump. | 8 $$ See comment for MAX_ARITY in base/bind.h.pump. |
| 9 $var MAX_ARITY = 7 | 9 $var MAX_ARITY = 7 |
| 10 $range ARITY 0..MAX_ARITY | 10 $range ARITY 0..MAX_ARITY |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 // and for ignoring return values. This is separate from | 75 // and for ignoring return values. This is separate from |
| 76 // Invoker to avoid creating multiple version of Invoker<> | 76 // Invoker to avoid creating multiple version of Invoker<> |
| 77 // which grows at O(n^2) with the arity. | 77 // which grows at O(n^2) with the arity. |
| 78 // There are |k*ARITY| InvokeHelper types. | 78 // There are |k*ARITY| InvokeHelper types. |
| 79 // Invoker<> -- Unwraps the curried parameters and executes the Runnable. | 79 // Invoker<> -- Unwraps the curried parameters and executes the Runnable. |
| 80 // There are |(ARITY^2 + ARITY)/2| Invoketypes. | 80 // There are |(ARITY^2 + ARITY)/2| Invoketypes. |
| 81 // BindState<> -- Stores the curried parameters, and is the main entry point | 81 // BindState<> -- Stores the curried parameters, and is the main entry point |
| 82 // into the Bind() system, doing most of the type resolution. | 82 // into the Bind() system, doing most of the type resolution. |
| 83 // There are ARITY BindState types. | 83 // There are ARITY BindState types. |
| 84 | 84 |
| 85 | |
| 86 // RunnableAdapter<> | 85 // RunnableAdapter<> |
| 87 // | 86 // |
| 88 // The RunnableAdapter<> templates provide a uniform interface for invoking | 87 // The RunnableAdapter<> templates provide a uniform interface for invoking |
| 89 // a function pointer, method pointer, or const method pointer. The adapter | 88 // a function pointer, method pointer, or const method pointer. The adapter |
| 90 // exposes a Run() method with an appropriate signature. Using this wrapper | 89 // exposes a Run() method with an appropriate signature. Using this wrapper |
| 91 // allows for writing code that supports all three pointer types without | 90 // allows for writing code that supports all three pointer types without |
| 92 // undue repetition. Without it, a lot of code would need to be repeated 3 | 91 // undue repetition. Without it, a lot of code would need to be repeated 3 |
| 93 // times. | 92 // times. |
| 94 // | 93 // |
| 95 // For method pointers and const method pointers the first argument to Run() | 94 // For method pointers and const method pointers the first argument to Run() |
| (...skipping 18 matching lines...) Expand all Loading... |
| 114 $if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]> | 113 $if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]> |
| 115 class RunnableAdapter<R(*)($for ARG , [[A$(ARG)]])> { | 114 class RunnableAdapter<R(*)($for ARG , [[A$(ARG)]])> { |
| 116 public: | 115 public: |
| 117 typedef R (RunType)($for ARG , [[A$(ARG)]]); | 116 typedef R (RunType)($for ARG , [[A$(ARG)]]); |
| 118 | 117 |
| 119 explicit RunnableAdapter(R(*function)($for ARG , [[A$(ARG)]])) | 118 explicit RunnableAdapter(R(*function)($for ARG , [[A$(ARG)]])) |
| 120 : function_(function) { | 119 : function_(function) { |
| 121 } | 120 } |
| 122 | 121 |
| 123 R Run($for ARG , [[typename CallbackParamTraits<A$(ARG)>::ForwardType a$(ARG)]
]) { | 122 R Run($for ARG , [[typename CallbackParamTraits<A$(ARG)>::ForwardType a$(ARG)]
]) { |
| 124 return function_($for ARG , [[a$(ARG)]]); | 123 return function_($for ARG , [[CallbackForward(a$(ARG))]]); |
| 125 } | 124 } |
| 126 | 125 |
| 127 private: | 126 private: |
| 128 R (*function_)($for ARG , [[A$(ARG)]]); | 127 R (*function_)($for ARG , [[A$(ARG)]]); |
| 129 }; | 128 }; |
| 130 | 129 |
| 131 // Method: Arity $(ARITY). | 130 // Method: Arity $(ARITY). |
| 132 template <typename R, typename T[[]] | 131 template <typename R, typename T[[]] |
| 133 $if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]> | 132 $if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]> |
| 134 class RunnableAdapter<R(T::*)($for ARG , [[A$(ARG)]])> { | 133 class RunnableAdapter<R(T::*)($for ARG , [[A$(ARG)]])> { |
| 135 public: | 134 public: |
| 136 typedef R (RunType)(T*[[]] | 135 typedef R (RunType)(T*[[]] |
| 137 $if ARITY > 0[[, ]] $for ARG , [[A$(ARG)]]); | 136 $if ARITY > 0[[, ]] $for ARG , [[A$(ARG)]]); |
| 138 typedef true_type IsMethod; | 137 typedef true_type IsMethod; |
| 139 | 138 |
| 140 explicit RunnableAdapter(R(T::*method)($for ARG , [[A$(ARG)]])) | 139 explicit RunnableAdapter(R(T::*method)($for ARG , [[A$(ARG)]])) |
| 141 : method_(method) { | 140 : method_(method) { |
| 142 } | 141 } |
| 143 | 142 |
| 144 R Run(T* object[[]] | 143 R Run(T* object[[]] |
| 145 $if ARITY > 0[[, ]] $for ARG, [[typename CallbackParamTraits<A$(ARG)>::ForwardT
ype a$(ARG)]]) { | 144 $if ARITY > 0[[, ]] $for ARG, [[typename CallbackParamTraits<A$(ARG)>::ForwardT
ype a$(ARG)]]) { |
| 146 return (object->*method_)($for ARG , [[a$(ARG)]]); | 145 return (object->*method_)($for ARG , [[CallbackForward(a$(ARG))]]); |
| 147 } | 146 } |
| 148 | 147 |
| 149 private: | 148 private: |
| 150 R (T::*method_)($for ARG , [[A$(ARG)]]); | 149 R (T::*method_)($for ARG , [[A$(ARG)]]); |
| 151 }; | 150 }; |
| 152 | 151 |
| 153 // Const Method: Arity $(ARITY). | 152 // Const Method: Arity $(ARITY). |
| 154 template <typename R, typename T[[]] | 153 template <typename R, typename T[[]] |
| 155 $if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]> | 154 $if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]> |
| 156 class RunnableAdapter<R(T::*)($for ARG , [[A$(ARG)]]) const> { | 155 class RunnableAdapter<R(T::*)($for ARG , [[A$(ARG)]]) const> { |
| 157 public: | 156 public: |
| 158 typedef R (RunType)(const T*[[]] | 157 typedef R (RunType)(const T*[[]] |
| 159 $if ARITY > 0[[, ]] $for ARG , [[A$(ARG)]]); | 158 $if ARITY > 0[[, ]] $for ARG , [[A$(ARG)]]); |
| 160 typedef true_type IsMethod; | 159 typedef true_type IsMethod; |
| 161 | 160 |
| 162 explicit RunnableAdapter(R(T::*method)($for ARG , [[A$(ARG)]]) const) | 161 explicit RunnableAdapter(R(T::*method)($for ARG , [[A$(ARG)]]) const) |
| 163 : method_(method) { | 162 : method_(method) { |
| 164 } | 163 } |
| 165 | 164 |
| 166 R Run(const T* object[[]] | 165 R Run(const T* object[[]] |
| 167 $if ARITY > 0[[, ]] $for ARG, [[typename CallbackParamTraits<A$(ARG)>::ForwardT
ype a$(ARG)]]) { | 166 $if ARITY > 0[[, ]] $for ARG, [[typename CallbackParamTraits<A$(ARG)>::ForwardT
ype a$(ARG)]]) { |
| 168 return (object->*method_)($for ARG , [[a$(ARG)]]); | 167 return (object->*method_)($for ARG , [[CallbackForward(a$(ARG))]]); |
| 169 } | 168 } |
| 170 | 169 |
| 171 private: | 170 private: |
| 172 R (T::*method_)($for ARG , [[A$(ARG)]]) const; | 171 R (T::*method_)($for ARG , [[A$(ARG)]]) const; |
| 173 }; | 172 }; |
| 174 | 173 |
| 175 ]] $$ for ARITY | 174 ]] $$ for ARITY |
| 176 | 175 |
| 177 | 176 |
| 178 // FunctionTraits<> | 177 // FunctionTraits<> |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 | 283 |
| 285 $for ARITY [[ | 284 $for ARITY [[ |
| 286 $range ARG 1..ARITY | 285 $range ARG 1..ARITY |
| 287 | 286 |
| 288 template <typename ReturnType, typename Runnable[[]] | 287 template <typename ReturnType, typename Runnable[[]] |
| 289 $if ARITY > 0 [[,]] $for ARG , [[typename A$(ARG)]]> | 288 $if ARITY > 0 [[,]] $for ARG , [[typename A$(ARG)]]> |
| 290 struct InvokeHelper<false, ReturnType, Runnable, | 289 struct InvokeHelper<false, ReturnType, Runnable, |
| 291 void($for ARG , [[A$(ARG)]])> { | 290 void($for ARG , [[A$(ARG)]])> { |
| 292 static ReturnType MakeItSo(Runnable runnable[[]] | 291 static ReturnType MakeItSo(Runnable runnable[[]] |
| 293 $if ARITY > 0[[, ]] $for ARG , [[A$(ARG) a$(ARG)]]) { | 292 $if ARITY > 0[[, ]] $for ARG , [[A$(ARG) a$(ARG)]]) { |
| 294 return runnable.Run($for ARG , [[a$(ARG)]]); | 293 return runnable.Run($for ARG , [[CallbackForward(a$(ARG))]]); |
| 295 } | 294 } |
| 296 }; | 295 }; |
| 297 | 296 |
| 298 template <typename Runnable[[]] | 297 template <typename Runnable[[]] |
| 299 $if ARITY > 0 [[,]] $for ARG , [[typename A$(ARG)]]> | 298 $if ARITY > 0 [[,]] $for ARG , [[typename A$(ARG)]]> |
| 300 struct InvokeHelper<false, void, Runnable, | 299 struct InvokeHelper<false, void, Runnable, |
| 301 void($for ARG , [[A$(ARG)]])> { | 300 void($for ARG , [[A$(ARG)]])> { |
| 302 static void MakeItSo(Runnable runnable[[]] | 301 static void MakeItSo(Runnable runnable[[]] |
| 303 $if ARITY > 0[[, ]] $for ARG , [[A$(ARG) a$(ARG)]]) { | 302 $if ARITY > 0[[, ]] $for ARG , [[A$(ARG) a$(ARG)]]) { |
| 304 runnable.Run($for ARG , [[a$(ARG)]]); | 303 runnable.Run($for ARG , [[CallbackForward(a$(ARG))]]); |
| 305 } | 304 } |
| 306 }; | 305 }; |
| 307 | 306 |
| 308 $if ARITY > 0 [[ | 307 $if ARITY > 0 [[ |
| 309 | 308 |
| 310 template <typename Runnable[[]], $for ARG , [[typename A$(ARG)]]> | 309 template <typename Runnable[[]], $for ARG , [[typename A$(ARG)]]> |
| 311 struct InvokeHelper<true, void, Runnable, | 310 struct InvokeHelper<true, void, Runnable, |
| 312 void($for ARG , [[A$(ARG)]])> { | 311 void($for ARG , [[A$(ARG)]])> { |
| 313 static void MakeItSo(Runnable runnable[[]] | 312 static void MakeItSo(Runnable runnable[[]] |
| 314 $if ARITY > 0[[, ]] $for ARG , [[A$(ARG) a$(ARG)]]) { | 313 $if ARITY > 0[[, ]] $for ARG , [[A$(ARG) a$(ARG)]]) { |
| 315 if (!a1.get()) { | 314 if (!a1.get()) { |
| 316 return; | 315 return; |
| 317 } | 316 } |
| 318 | 317 |
| 319 runnable.Run($for ARG , [[a$(ARG)]]); | 318 runnable.Run($for ARG , [[CallbackForward(a$(ARG))]]); |
| 320 } | 319 } |
| 321 }; | 320 }; |
| 322 | 321 |
| 323 ]] | 322 ]] |
| 324 | 323 |
| 325 ]] $$ for ARITY | 324 ]] $$ for ARITY |
| 326 | 325 |
| 327 #if !defined(_MSC_VER) | 326 #if !defined(_MSC_VER) |
| 328 | 327 |
| 329 template <typename ReturnType, typename Runnable, typename ArgsType> | 328 template <typename ReturnType, typename Runnable, typename ArgsType> |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 typename Bound$(BOUND_ARG)UnwrapTraits::ForwardType | 396 typename Bound$(BOUND_ARG)UnwrapTraits::ForwardType |
| 398 ]] | 397 ]] |
| 399 | 398 |
| 400 $if UNBOUND > 0 [[$if BOUND > 0 [[, ]]]][[]] | 399 $if UNBOUND > 0 [[$if BOUND > 0 [[, ]]]][[]] |
| 401 | 400 |
| 402 $for UNBOUND_ARG , [[ | 401 $for UNBOUND_ARG , [[ |
| 403 typename CallbackParamTraits<X$(UNBOUND_ARG)>::ForwardType x$(UNBOUND_ARG) | 402 typename CallbackParamTraits<X$(UNBOUND_ARG)>::ForwardType x$(UNBOUND_ARG) |
| 404 ]] | 403 ]] |
| 405 )> | 404 )> |
| 406 ::MakeItSo(storage->runnable_ | 405 ::MakeItSo(storage->runnable_ |
| 407 $if ARITY > 0[[, ]] $for ARG , [[x$(ARG)]]); | 406 $if ARITY > 0[[, ]] $for ARG , [[CallbackForward(x$(ARG))]]); |
| 408 } | 407 } |
| 409 }; | 408 }; |
| 410 | 409 |
| 411 ]] $$ for BOUND | 410 ]] $$ for BOUND |
| 412 ]] $$ for ARITY | 411 ]] $$ for ARITY |
| 413 | 412 |
| 414 | 413 |
| 415 // BindState<> | 414 // BindState<> |
| 416 // | 415 // |
| 417 // This stores all the state passed into Bind() and is also where most | 416 // This stores all the state passed into Bind() and is also where most |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 | 485 |
| 487 ]] | 486 ]] |
| 488 }; | 487 }; |
| 489 | 488 |
| 490 ]] $$ for ARITY | 489 ]] $$ for ARITY |
| 491 | 490 |
| 492 } // namespace internal | 491 } // namespace internal |
| 493 } // namespace base | 492 } // namespace base |
| 494 | 493 |
| 495 #endif // BASE_BIND_INTERNAL_H_ | 494 #endif // BASE_BIND_INTERNAL_H_ |
| OLD | NEW |