OLD | NEW |
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 <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <type_traits> | 10 #include <type_traits> |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 174 |
175 explicit RunnableAdapter(R(T::*method)(Args...)) | 175 explicit RunnableAdapter(R(T::*method)(Args...)) |
176 : method_(method) { | 176 : method_(method) { |
177 } | 177 } |
178 | 178 |
179 template <typename... RunArgs> | 179 template <typename... RunArgs> |
180 R Run(T* object, RunArgs&&... args) { | 180 R Run(T* object, RunArgs&&... args) { |
181 return (object->*method_)(std::forward<RunArgs>(args)...); | 181 return (object->*method_)(std::forward<RunArgs>(args)...); |
182 } | 182 } |
183 | 183 |
| 184 template <typename RefType, typename... RunArgs> |
| 185 R Run(const scoped_refptr<RefType>& object, RunArgs&&... args) { |
| 186 return (object.get()->*method_)(std::forward<RunArgs>(args)...); |
| 187 } |
| 188 |
184 private: | 189 private: |
185 R (T::*method_)(Args...); | 190 R (T::*method_)(Args...); |
186 }; | 191 }; |
187 | 192 |
188 // Const Method. | 193 // Const Method. |
189 template <typename R, typename T, typename... Args> | 194 template <typename R, typename T, typename... Args> |
190 class RunnableAdapter<R(T::*)(Args...) const> { | 195 class RunnableAdapter<R(T::*)(Args...) const> { |
191 public: | 196 public: |
192 using RunType = R(const T*, Args...); | 197 using RunType = R(const T*, Args...); |
193 using IsMethod = std::true_type; | 198 using IsMethod = std::true_type; |
194 | 199 |
195 explicit RunnableAdapter(R(T::*method)(Args...) const) | 200 explicit RunnableAdapter(R(T::*method)(Args...) const) |
196 : method_(method) { | 201 : method_(method) { |
197 } | 202 } |
198 | 203 |
199 template <typename... RunArgs> | 204 template <typename... RunArgs> |
200 R Run(const T* object, RunArgs&&... args) { | 205 R Run(const T* object, RunArgs&&... args) { |
201 return (object->*method_)(std::forward<RunArgs>(args)...); | 206 return (object->*method_)(std::forward<RunArgs>(args)...); |
202 } | 207 } |
203 | 208 |
| 209 template <typename RefType, typename... RunArgs> |
| 210 R Run(const scoped_refptr<RefType>& object, RunArgs&&... args) { |
| 211 return (object.get()->*method_)(std::forward<RunArgs>(args)...); |
| 212 } |
| 213 |
204 private: | 214 private: |
205 R (T::*method_)(Args...) const; | 215 R (T::*method_)(Args...) const; |
206 }; | 216 }; |
207 | 217 |
208 | 218 |
209 // ForceVoidReturn<> | 219 // ForceVoidReturn<> |
210 // | 220 // |
211 // Set of templates that support forcing the function return type to void. | 221 // Set of templates that support forcing the function return type to void. |
212 template <typename Sig> | 222 template <typename Sig> |
213 struct ForceVoidReturn; | 223 struct ForceVoidReturn; |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 | 439 |
430 static void Destroy(BindStateBase* self) { | 440 static void Destroy(BindStateBase* self) { |
431 delete static_cast<BindState*>(self); | 441 delete static_cast<BindState*>(self); |
432 } | 442 } |
433 }; | 443 }; |
434 | 444 |
435 } // namespace internal | 445 } // namespace internal |
436 } // namespace base | 446 } // namespace base |
437 | 447 |
438 #endif // BASE_BIND_INTERNAL_H_ | 448 #endif // BASE_BIND_INTERNAL_H_ |
OLD | NEW |