| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 // bar = nullptr; | 54 // bar = nullptr; |
| 55 // // The functor stores an internal scoped_refptr<Bar>, so this is safe. | 55 // // The functor stores an internal scoped_refptr<Bar>, so this is safe. |
| 56 // functor(); | 56 // functor(); |
| 57 // } | 57 // } |
| 58 // | 58 // |
| 59 | 59 |
| 60 #ifndef WEBRTC_BASE_BIND_H_ | 60 #ifndef WEBRTC_BASE_BIND_H_ |
| 61 #define WEBRTC_BASE_BIND_H_ | 61 #define WEBRTC_BASE_BIND_H_ |
| 62 | 62 |
| 63 #include "webrtc/base/scoped_ref_ptr.h" | 63 #include "webrtc/base/scoped_ref_ptr.h" |
| 64 #include "webrtc/base/template_util.h" |
| 64 | 65 |
| 65 #define NONAME | 66 #define NONAME |
| 66 | 67 |
| 67 namespace rtc { | 68 namespace rtc { |
| 68 namespace detail { | 69 namespace detail { |
| 69 // This is needed because the template parameters in Bind can't be resolved | 70 // This is needed because the template parameters in Bind can't be resolved |
| 70 // if they're used both as parameters of the function pointer type and as | 71 // if they're used both as parameters of the function pointer type and as |
| 71 // parameters to Bind itself: the function pointer parameters are exact | 72 // parameters to Bind itself: the function pointer parameters are exact |
| 72 // matches to the function prototype, but the parameters to bind have | 73 // matches to the function prototype, but the parameters to bind have |
| 73 // references stripped. This trick allows the compiler to dictate the Bind | 74 // references stripped. This trick allows the compiler to dictate the Bind |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 118 |
| 118 // PointerType<T>::type will be scoped_refptr<T> for ref counted types, and T* | 119 // PointerType<T>::type will be scoped_refptr<T> for ref counted types, and T* |
| 119 // otherwise. | 120 // otherwise. |
| 120 template <class T> | 121 template <class T> |
| 121 struct PointerType { | 122 struct PointerType { |
| 122 typedef typename TernaryTypeOperator<IsRefCounted<T>::value, | 123 typedef typename TernaryTypeOperator<IsRefCounted<T>::value, |
| 123 scoped_refptr<T>, | 124 scoped_refptr<T>, |
| 124 T*>::type type; | 125 T*>::type type; |
| 125 }; | 126 }; |
| 126 | 127 |
| 127 // RemoveScopedPtrRef will capture scoped_refptr by-value instead of | |
| 128 // by-reference. | |
| 129 template <class T> struct RemoveScopedPtrRef { typedef T type; }; | |
| 130 template <class T> | |
| 131 struct RemoveScopedPtrRef<const scoped_refptr<T>&> { | |
| 132 typedef scoped_refptr<T> type; | |
| 133 }; | |
| 134 template <class T> | |
| 135 struct RemoveScopedPtrRef<scoped_refptr<T>&> { | |
| 136 typedef scoped_refptr<T> type; | |
| 137 }; | |
| 138 | |
| 139 } // namespace detail | 128 } // namespace detail |
| 140 | 129 |
| 141 $var n = 6 | 130 $var n = 9 |
| 142 $range i 0..n | 131 $range i 0..n |
| 143 $for i [[ | 132 $for i [[ |
| 144 $range j 1..i | 133 $range j 1..i |
| 145 | 134 |
| 146 template <class ObjectT, class MethodT, class R$for j [[, | 135 template <class ObjectT, class MethodT, class R$for j [[, |
| 147 class P$j]]> | 136 class P$j]]> |
| 148 class MethodFunctor$i { | 137 class MethodFunctor$i { |
| 149 public: | 138 public: |
| 150 MethodFunctor$i(MethodT method, ObjectT* object$for j [[, | 139 MethodFunctor$i(MethodT method, ObjectT* object$for j [[, |
| 151 P$j p$j]]) | 140 P$j p$j]]) |
| 152 : method_(method), object_(object)$for j [[, | 141 : method_(method), object_(object)$for j [[, |
| 153 p$(j)_(p$j)]] {} | 142 p$(j)_(p$j)]] {} |
| 154 R operator()() const { | 143 R operator()() const { |
| 155 return (object_->*method_)($for j , [[p$(j)_]]); } | 144 return (object_->*method_)($for j , [[p$(j)_]]); } |
| 156 private: | 145 private: |
| 157 MethodT method_; | 146 MethodT method_; |
| 158 typename detail::PointerType<ObjectT>::type object_;$for j [[ | 147 typename detail::PointerType<ObjectT>::type object_;$for j [[ |
| 159 | 148 |
| 160 typename detail::RemoveScopedPtrRef<P$j>::type p$(j)_;]] | 149 typename rtc::remove_reference<P$j>::type p$(j)_;]] |
| 161 | 150 |
| 162 }; | 151 }; |
| 163 | 152 |
| 164 template <class FunctorT, class R$for j [[, | 153 template <class FunctorT, class R$for j [[, |
| 165 class P$j]]> | 154 class P$j]]> |
| 166 class Functor$i { | 155 class Functor$i { |
| 167 public: | 156 public: |
| 168 $if i == 0 [[explicit ]] | 157 $if i == 0 [[explicit ]] |
| 169 Functor$i(const FunctorT& functor$for j [[, P$j p$j]]) | 158 Functor$i(const FunctorT& functor$for j [[, P$j p$j]]) |
| 170 : functor_(functor)$for j [[, | 159 : functor_(functor)$for j [[, |
| 171 p$(j)_(p$j)]] {} | 160 p$(j)_(p$j)]] {} |
| 172 R operator()() const { | 161 R operator()() const { |
| 173 return functor_($for j , [[p$(j)_]]); } | 162 return functor_($for j , [[p$(j)_]]); } |
| 174 private: | 163 private: |
| 175 FunctorT functor_;$for j [[ | 164 FunctorT functor_;$for j [[ |
| 176 | 165 |
| 177 typename detail::RemoveScopedPtrRef<P$j>::type p$(j)_;]] | 166 typename rtc::remove_reference<P$j>::type p$(j)_;]] |
| 178 | 167 |
| 179 }; | 168 }; |
| 180 | 169 |
| 181 | 170 |
| 182 #define FP_T(x) R (ObjectT::*x)($for j , [[P$j]]) | 171 #define FP_T(x) R (ObjectT::*x)($for j , [[P$j]]) |
| 183 | 172 |
| 184 template <class ObjectT, class R$for j [[, | 173 template <class ObjectT, class R$for j [[, |
| 185 class P$j]]> | 174 class P$j]]> |
| 186 MethodFunctor$i<ObjectT, FP_T(NONAME), R$for j [[, P$j]]> | 175 MethodFunctor$i<ObjectT, FP_T(NONAME), R$for j [[, P$j]]> |
| 187 Bind(FP_T(method), ObjectT* object$for j [[, | 176 Bind(FP_T(method), ObjectT* object$for j [[, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 217 |
| 229 #undef FP_T | 218 #undef FP_T |
| 230 | 219 |
| 231 ]] | 220 ]] |
| 232 | 221 |
| 233 } // namespace rtc | 222 } // namespace rtc |
| 234 | 223 |
| 235 #undef NONAME | 224 #undef NONAME |
| 236 | 225 |
| 237 #endif // WEBRTC_BASE_BIND_H_ | 226 #endif // WEBRTC_BASE_BIND_H_ |
| OLD | NEW |