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