| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 namespace WTF { | 37 namespace WTF { |
| 38 | 38 |
| 39 // Functional.h provides a very simple way to bind a function pointer and argume
nts together into a function object | 39 // Functional.h provides a very simple way to bind a function pointer and argume
nts together into a function object |
| 40 // that can be stored, copied and invoked, similar to how boost::bind and std::b
ind in C++11. | 40 // that can be stored, copied and invoked, similar to how boost::bind and std::b
ind in C++11. |
| 41 | 41 |
| 42 // Use threadSafeBind() or createCrossThreadTask() if the function/task is | 42 // Use threadSafeBind() or createCrossThreadTask() if the function/task is |
| 43 // called on a (potentially) different thread from the current thread. | 43 // called on a (potentially) different thread from the current thread. |
| 44 | 44 |
| 45 // A FunctionWrapper is a class template that can wrap a function pointer or a m
ember function pointer and | 45 // A FunctionWrapper is a class template that can wrap a function pointer or a m
ember function pointer and |
| 46 // provide a unified interface for calling that function. | 46 // provide a unified interface for calling that function. |
| 47 template<typename> | 47 template <typename> |
| 48 class FunctionWrapper; | 48 class FunctionWrapper; |
| 49 | 49 |
| 50 // Bound static functions: | 50 // Bound static functions: |
| 51 template<typename R, typename... Params> | 51 template <typename R, typename... Params> |
| 52 class FunctionWrapper<R(*)(Params...)> { | 52 class FunctionWrapper<R (*)(Params...)> { |
| 53 DISALLOW_NEW(); | 53 DISALLOW_NEW(); |
| 54 public: | 54 |
| 55 typedef R ResultType; | 55 public: |
| 56 | 56 typedef R ResultType; |
| 57 explicit FunctionWrapper(R(*function)(Params...)) | 57 |
| 58 : m_function(function) | 58 explicit FunctionWrapper(R (*function)(Params...)) : m_function(function) {} |
| 59 { | 59 |
| 60 } | 60 R operator()(Params... params) { return m_function(params...); } |
| 61 | 61 |
| 62 R operator()(Params... params) | 62 private: |
| 63 { | 63 R (*m_function)(Params...); |
| 64 return m_function(params...); | |
| 65 } | |
| 66 | |
| 67 private: | |
| 68 R(*m_function)(Params...); | |
| 69 }; | 64 }; |
| 70 | 65 |
| 71 // Bound member functions: | 66 // Bound member functions: |
| 72 | 67 |
| 73 template<typename R, typename C, typename... Params> | 68 template <typename R, typename C, typename... Params> |
| 74 class FunctionWrapper<R(C::*)(Params...)> { | 69 class FunctionWrapper<R (C::*)(Params...)> { |
| 75 DISALLOW_NEW(); | 70 DISALLOW_NEW(); |
| 76 public: | 71 |
| 77 typedef R ResultType; | 72 public: |
| 78 | 73 typedef R ResultType; |
| 79 explicit FunctionWrapper(R(C::*function)(Params...)) | 74 |
| 80 : m_function(function) | 75 explicit FunctionWrapper(R (C::*function)(Params...)) |
| 81 { | 76 : m_function(function) {} |
| 82 } | 77 |
| 83 | 78 R operator()(C* c, Params... params) { return (c->*m_function)(params...); } |
| 84 R operator()(C* c, Params... params) | 79 |
| 85 { | 80 R operator()(PassOwnPtr<C> c, Params... params) { |
| 86 return (c->*m_function)(params...); | 81 return (c.get()->*m_function)(params...); |
| 87 } | 82 } |
| 88 | 83 |
| 89 R operator()(PassOwnPtr<C> c, Params... params) | 84 R operator()(const WeakPtr<C>& c, Params... params) { |
| 90 { | 85 C* obj = c.get(); |
| 91 return (c.get()->*m_function)(params...); | 86 if (!obj) |
| 92 } | 87 return R(); |
| 93 | 88 return (obj->*m_function)(params...); |
| 94 R operator()(const WeakPtr<C>& c, Params... params) | 89 } |
| 95 { | 90 |
| 96 C* obj = c.get(); | 91 private: |
| 97 if (!obj) | 92 R (C::*m_function)(Params...); |
| 98 return R(); | 93 }; |
| 99 return (obj->*m_function)(params...); | 94 |
| 100 } | 95 template <typename T> |
| 101 | 96 struct ParamStorageTraits { |
| 102 private: | 97 typedef T StorageType; |
| 103 R(C::*m_function)(Params...); | 98 |
| 104 }; | 99 static StorageType wrap(const T& value) { return value; } |
| 105 | 100 static const T& unwrap(const StorageType& value) { return value; } |
| 106 template<typename T> struct ParamStorageTraits { | 101 }; |
| 107 typedef T StorageType; | 102 |
| 108 | 103 template <typename T> |
| 109 static StorageType wrap(const T& value) { return value; } | 104 struct ParamStorageTraits<PassRefPtr<T>> { |
| 110 static const T& unwrap(const StorageType& value) { return value; } | 105 typedef RefPtr<T> StorageType; |
| 111 }; | 106 |
| 112 | 107 static StorageType wrap(PassRefPtr<T> value) { return value; } |
| 113 template<typename T> struct ParamStorageTraits<PassRefPtr<T>> { | 108 static T* unwrap(const StorageType& value) { return value.get(); } |
| 114 typedef RefPtr<T> StorageType; | 109 }; |
| 115 | 110 |
| 116 static StorageType wrap(PassRefPtr<T> value) { return value; } | 111 template <typename T> |
| 117 static T* unwrap(const StorageType& value) { return value.get(); } | 112 struct ParamStorageTraits<RefPtr<T>> { |
| 118 }; | 113 typedef RefPtr<T> StorageType; |
| 119 | 114 |
| 120 template<typename T> struct ParamStorageTraits<RefPtr<T>> { | 115 static StorageType wrap(RefPtr<T> value) { return value.release(); } |
| 121 typedef RefPtr<T> StorageType; | 116 static T* unwrap(const StorageType& value) { return value.get(); } |
| 122 | 117 }; |
| 123 static StorageType wrap(RefPtr<T> value) { return value.release(); } | 118 |
| 124 static T* unwrap(const StorageType& value) { return value.get(); } | 119 template <typename> |
| 125 }; | 120 class RetainPtr; |
| 126 | 121 |
| 127 template<typename> class RetainPtr; | 122 template <typename T> |
| 128 | 123 struct ParamStorageTraits<RetainPtr<T>> { |
| 129 template<typename T> struct ParamStorageTraits<RetainPtr<T>> { | 124 typedef RetainPtr<T> StorageType; |
| 130 typedef RetainPtr<T> StorageType; | 125 |
| 131 | 126 static StorageType wrap(const RetainPtr<T>& value) { return value; } |
| 132 static StorageType wrap(const RetainPtr<T>& value) { return value; } | 127 static typename RetainPtr<T>::PtrType unwrap(const StorageType& value) { |
| 133 static typename RetainPtr<T>::PtrType unwrap(const StorageType& value) { ret
urn value.get(); } | 128 return value.get(); |
| 134 }; | 129 } |
| 135 | 130 }; |
| 136 template<typename> | 131 |
| 132 template <typename> |
| 137 class Function; | 133 class Function; |
| 138 | 134 |
| 139 template<typename R, typename... Args> | 135 template <typename R, typename... Args> |
| 140 class Function<R(Args...)> { | 136 class Function<R(Args...)> { |
| 141 USING_FAST_MALLOC(Function); | 137 USING_FAST_MALLOC(Function); |
| 142 WTF_MAKE_NONCOPYABLE(Function); | 138 WTF_MAKE_NONCOPYABLE(Function); |
| 143 public: | 139 |
| 144 virtual ~Function() { } | 140 public: |
| 145 virtual R operator()(Args... args) = 0; | 141 virtual ~Function() {} |
| 146 protected: | 142 virtual R operator()(Args... args) = 0; |
| 147 Function() = default; | 143 |
| 148 }; | 144 protected: |
| 149 | 145 Function() = default; |
| 150 template<int boundArgsCount, typename FunctionWrapper, typename FunctionType> | 146 }; |
| 147 |
| 148 template <int boundArgsCount, typename FunctionWrapper, typename FunctionType> |
| 151 class PartBoundFunctionImpl; | 149 class PartBoundFunctionImpl; |
| 152 | 150 |
| 153 // Specialization for unbound functions. | 151 // Specialization for unbound functions. |
| 154 template<typename FunctionWrapper, typename R, typename... UnboundParams> | 152 template <typename FunctionWrapper, typename R, typename... UnboundParams> |
| 155 class PartBoundFunctionImpl<0, FunctionWrapper, R(UnboundParams...)> final : pub
lic Function<typename FunctionWrapper::ResultType(UnboundParams...)> { | 153 class PartBoundFunctionImpl<0, FunctionWrapper, R(UnboundParams...)> final |
| 156 public: | 154 : public Function<typename FunctionWrapper::ResultType(UnboundParams...)> { |
| 157 PartBoundFunctionImpl(FunctionWrapper functionWrapper) | 155 public: |
| 158 : m_functionWrapper(functionWrapper) | 156 PartBoundFunctionImpl(FunctionWrapper functionWrapper) |
| 159 { | 157 : m_functionWrapper(functionWrapper) {} |
| 160 } | 158 |
| 161 | 159 typename FunctionWrapper::ResultType operator()( |
| 162 typename FunctionWrapper::ResultType operator()(UnboundParams... params) ove
rride | 160 UnboundParams... params) override { |
| 163 { | 161 return m_functionWrapper(params...); |
| 164 return m_functionWrapper(params...); | 162 } |
| 165 } | 163 |
| 166 | 164 private: |
| 167 private: | 165 FunctionWrapper m_functionWrapper; |
| 168 FunctionWrapper m_functionWrapper; | 166 }; |
| 169 }; | 167 |
| 170 | 168 template <typename FunctionWrapper, |
| 171 template<typename FunctionWrapper, typename R, typename P1, typename... UnboundP
arams> | 169 typename R, |
| 172 class PartBoundFunctionImpl<1, FunctionWrapper, R(P1, UnboundParams...)> final :
public Function<typename FunctionWrapper::ResultType(UnboundParams...)> { | 170 typename P1, |
| 173 public: | 171 typename... UnboundParams> |
| 174 PartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1) | 172 class PartBoundFunctionImpl<1, FunctionWrapper, R(P1, UnboundParams...)> final |
| 175 : m_functionWrapper(functionWrapper) | 173 : public Function<typename FunctionWrapper::ResultType(UnboundParams...)> { |
| 176 , m_p1(ParamStorageTraits<P1>::wrap(p1)) | 174 public: |
| 177 { | 175 PartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1) |
| 178 } | 176 : m_functionWrapper(functionWrapper), |
| 179 | 177 m_p1(ParamStorageTraits<P1>::wrap(p1)) {} |
| 180 typename FunctionWrapper::ResultType operator()(UnboundParams... params) ove
rride | 178 |
| 181 { | 179 typename FunctionWrapper::ResultType operator()( |
| 182 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), params...
); | 180 UnboundParams... params) override { |
| 183 } | 181 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), params...); |
| 184 | 182 } |
| 185 private: | 183 |
| 186 FunctionWrapper m_functionWrapper; | 184 private: |
| 187 typename ParamStorageTraits<P1>::StorageType m_p1; | 185 FunctionWrapper m_functionWrapper; |
| 188 }; | 186 typename ParamStorageTraits<P1>::StorageType m_p1; |
| 189 | 187 }; |
| 190 template<typename FunctionWrapper, typename R, typename P1, typename P2, typenam
e... UnboundParams> | 188 |
| 191 class PartBoundFunctionImpl<2, FunctionWrapper, R(P1, P2, UnboundParams...)> fin
al : public Function<typename FunctionWrapper::ResultType(UnboundParams...)> { | 189 template <typename FunctionWrapper, |
| 192 public: | 190 typename R, |
| 193 PartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P
2& p2) | 191 typename P1, |
| 194 : m_functionWrapper(functionWrapper) | 192 typename P2, |
| 195 , m_p1(ParamStorageTraits<P1>::wrap(p1)) | 193 typename... UnboundParams> |
| 196 , m_p2(ParamStorageTraits<P2>::wrap(p2)) | 194 class PartBoundFunctionImpl<2, FunctionWrapper, R(P1, P2, UnboundParams...)> |
| 197 { | 195 final |
| 198 } | 196 : public Function<typename FunctionWrapper::ResultType(UnboundParams...)> { |
| 199 | 197 public: |
| 200 typename FunctionWrapper::ResultType operator()(UnboundParams... params) ove
rride | 198 PartBoundFunctionImpl(FunctionWrapper functionWrapper, |
| 201 { | 199 const P1& p1, |
| 202 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStor
ageTraits<P2>::unwrap(m_p2), params...); | 200 const P2& p2) |
| 203 } | 201 : m_functionWrapper(functionWrapper), |
| 204 | 202 m_p1(ParamStorageTraits<P1>::wrap(p1)), |
| 205 private: | 203 m_p2(ParamStorageTraits<P2>::wrap(p2)) {} |
| 206 FunctionWrapper m_functionWrapper; | 204 |
| 207 typename ParamStorageTraits<P1>::StorageType m_p1; | 205 typename FunctionWrapper::ResultType operator()( |
| 208 typename ParamStorageTraits<P2>::StorageType m_p2; | 206 UnboundParams... params) override { |
| 209 }; | 207 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), |
| 210 | 208 ParamStorageTraits<P2>::unwrap(m_p2), params...); |
| 211 template<typename FunctionWrapper, typename R, typename P1, typename P2, typenam
e P3, typename... UnboundParams> | 209 } |
| 212 class PartBoundFunctionImpl<3, FunctionWrapper, R(P1, P2, P3, UnboundParams...)>
final : public Function<typename FunctionWrapper::ResultType(UnboundParams...)>
{ | 210 |
| 213 public: | 211 private: |
| 214 PartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P
2& p2, const P3& p3) | 212 FunctionWrapper m_functionWrapper; |
| 215 : m_functionWrapper(functionWrapper) | 213 typename ParamStorageTraits<P1>::StorageType m_p1; |
| 216 , m_p1(ParamStorageTraits<P1>::wrap(p1)) | 214 typename ParamStorageTraits<P2>::StorageType m_p2; |
| 217 , m_p2(ParamStorageTraits<P2>::wrap(p2)) | 215 }; |
| 218 , m_p3(ParamStorageTraits<P3>::wrap(p3)) | 216 |
| 219 { | 217 template <typename FunctionWrapper, |
| 220 } | 218 typename R, |
| 221 | 219 typename P1, |
| 222 typename FunctionWrapper::ResultType operator()(UnboundParams... params) ove
rride | 220 typename P2, |
| 223 { | 221 typename P3, |
| 224 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStor
ageTraits<P2>::unwrap(m_p2), ParamStorageTraits<P3>::unwrap(m_p3), params...); | 222 typename... UnboundParams> |
| 225 } | 223 class PartBoundFunctionImpl<3, FunctionWrapper, R(P1, P2, P3, UnboundParams...)> |
| 226 | 224 final |
| 227 private: | 225 : public Function<typename FunctionWrapper::ResultType(UnboundParams...)> { |
| 228 FunctionWrapper m_functionWrapper; | 226 public: |
| 229 typename ParamStorageTraits<P1>::StorageType m_p1; | 227 PartBoundFunctionImpl(FunctionWrapper functionWrapper, |
| 230 typename ParamStorageTraits<P2>::StorageType m_p2; | 228 const P1& p1, |
| 231 typename ParamStorageTraits<P3>::StorageType m_p3; | 229 const P2& p2, |
| 232 }; | 230 const P3& p3) |
| 233 | 231 : m_functionWrapper(functionWrapper), |
| 234 template<typename FunctionWrapper, typename R, typename P1, typename P2, typenam
e P3, typename P4, typename... UnboundParams> | 232 m_p1(ParamStorageTraits<P1>::wrap(p1)), |
| 235 class PartBoundFunctionImpl<4, FunctionWrapper, R(P1, P2, P3, P4, UnboundParams.
..)> final : public Function<typename FunctionWrapper::ResultType(UnboundParams.
..)> { | 233 m_p2(ParamStorageTraits<P2>::wrap(p2)), |
| 236 public: | 234 m_p3(ParamStorageTraits<P3>::wrap(p3)) {} |
| 237 PartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P
2& p2, const P3& p3, const P4& p4) | 235 |
| 238 : m_functionWrapper(functionWrapper) | 236 typename FunctionWrapper::ResultType operator()( |
| 239 , m_p1(ParamStorageTraits<P1>::wrap(p1)) | 237 UnboundParams... params) override { |
| 240 , m_p2(ParamStorageTraits<P2>::wrap(p2)) | 238 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), |
| 241 , m_p3(ParamStorageTraits<P3>::wrap(p3)) | 239 ParamStorageTraits<P2>::unwrap(m_p2), |
| 242 , m_p4(ParamStorageTraits<P4>::wrap(p4)) | 240 ParamStorageTraits<P3>::unwrap(m_p3), params...); |
| 243 { | 241 } |
| 244 } | 242 |
| 245 | 243 private: |
| 246 typename FunctionWrapper::ResultType operator()(UnboundParams... params) ove
rride | 244 FunctionWrapper m_functionWrapper; |
| 247 { | 245 typename ParamStorageTraits<P1>::StorageType m_p1; |
| 248 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStor
ageTraits<P2>::unwrap(m_p2), ParamStorageTraits<P3>::unwrap(m_p3), ParamStorageT
raits<P4>::unwrap(m_p4), params...); | 246 typename ParamStorageTraits<P2>::StorageType m_p2; |
| 249 } | 247 typename ParamStorageTraits<P3>::StorageType m_p3; |
| 250 | 248 }; |
| 251 private: | 249 |
| 252 FunctionWrapper m_functionWrapper; | 250 template <typename FunctionWrapper, |
| 253 typename ParamStorageTraits<P1>::StorageType m_p1; | 251 typename R, |
| 254 typename ParamStorageTraits<P2>::StorageType m_p2; | 252 typename P1, |
| 255 typename ParamStorageTraits<P3>::StorageType m_p3; | 253 typename P2, |
| 256 typename ParamStorageTraits<P4>::StorageType m_p4; | 254 typename P3, |
| 257 }; | 255 typename P4, |
| 258 | 256 typename... UnboundParams> |
| 259 template<typename FunctionWrapper, typename R, typename P1, typename P2, typenam
e P3, typename P4, typename P5, typename... UnboundParams> | 257 class PartBoundFunctionImpl<4, |
| 260 class PartBoundFunctionImpl<5, FunctionWrapper, R(P1, P2, P3, P4, P5, UnboundPar
ams...)> final : public Function<typename FunctionWrapper::ResultType(UnboundPar
ams...)> { | 258 FunctionWrapper, |
| 261 public: | 259 R(P1, P2, P3, P4, UnboundParams...)> |
| 262 PartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P
2& p2, const P3& p3, const P4& p4, const P5& p5) | 260 final |
| 263 : m_functionWrapper(functionWrapper) | 261 : public Function<typename FunctionWrapper::ResultType(UnboundParams...)> { |
| 264 , m_p1(ParamStorageTraits<P1>::wrap(p1)) | 262 public: |
| 265 , m_p2(ParamStorageTraits<P2>::wrap(p2)) | 263 PartBoundFunctionImpl(FunctionWrapper functionWrapper, |
| 266 , m_p3(ParamStorageTraits<P3>::wrap(p3)) | 264 const P1& p1, |
| 267 , m_p4(ParamStorageTraits<P4>::wrap(p4)) | 265 const P2& p2, |
| 268 , m_p5(ParamStorageTraits<P5>::wrap(p5)) | 266 const P3& p3, |
| 269 { | 267 const P4& p4) |
| 270 } | 268 : m_functionWrapper(functionWrapper), |
| 271 | 269 m_p1(ParamStorageTraits<P1>::wrap(p1)), |
| 272 typename FunctionWrapper::ResultType operator()(UnboundParams... params) ove
rride | 270 m_p2(ParamStorageTraits<P2>::wrap(p2)), |
| 273 { | 271 m_p3(ParamStorageTraits<P3>::wrap(p3)), |
| 274 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStor
ageTraits<P2>::unwrap(m_p2), ParamStorageTraits<P3>::unwrap(m_p3), ParamStorageT
raits<P4>::unwrap(m_p4), ParamStorageTraits<P5>::unwrap(m_p5), params...); | 272 m_p4(ParamStorageTraits<P4>::wrap(p4)) {} |
| 275 } | 273 |
| 276 | 274 typename FunctionWrapper::ResultType operator()( |
| 277 private: | 275 UnboundParams... params) override { |
| 278 FunctionWrapper m_functionWrapper; | 276 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), |
| 279 typename ParamStorageTraits<P1>::StorageType m_p1; | 277 ParamStorageTraits<P2>::unwrap(m_p2), |
| 280 typename ParamStorageTraits<P2>::StorageType m_p2; | 278 ParamStorageTraits<P3>::unwrap(m_p3), |
| 281 typename ParamStorageTraits<P3>::StorageType m_p3; | 279 ParamStorageTraits<P4>::unwrap(m_p4), params...); |
| 282 typename ParamStorageTraits<P4>::StorageType m_p4; | 280 } |
| 283 typename ParamStorageTraits<P5>::StorageType m_p5; | 281 |
| 284 }; | 282 private: |
| 285 | 283 FunctionWrapper m_functionWrapper; |
| 286 template<typename FunctionWrapper, typename R, typename P1, typename P2, typenam
e P3, typename P4, typename P5, typename P6, typename... UnboundParams> | 284 typename ParamStorageTraits<P1>::StorageType m_p1; |
| 287 class PartBoundFunctionImpl<6, FunctionWrapper, R(P1, P2, P3, P4, P5, P6, Unboun
dParams...)> final : public Function<typename FunctionWrapper::ResultType(Unboun
dParams...)> { | 285 typename ParamStorageTraits<P2>::StorageType m_p2; |
| 288 public: | 286 typename ParamStorageTraits<P3>::StorageType m_p3; |
| 289 PartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P
2& p2, const P3& p3, const P4& p4, const P5& p5, const P6& p6) | 287 typename ParamStorageTraits<P4>::StorageType m_p4; |
| 290 : m_functionWrapper(functionWrapper) | 288 }; |
| 291 , m_p1(ParamStorageTraits<P1>::wrap(p1)) | 289 |
| 292 , m_p2(ParamStorageTraits<P2>::wrap(p2)) | 290 template <typename FunctionWrapper, |
| 293 , m_p3(ParamStorageTraits<P3>::wrap(p3)) | 291 typename R, |
| 294 , m_p4(ParamStorageTraits<P4>::wrap(p4)) | 292 typename P1, |
| 295 , m_p5(ParamStorageTraits<P5>::wrap(p5)) | 293 typename P2, |
| 296 , m_p6(ParamStorageTraits<P6>::wrap(p6)) | 294 typename P3, |
| 297 { | 295 typename P4, |
| 298 } | 296 typename P5, |
| 299 | 297 typename... UnboundParams> |
| 300 typename FunctionWrapper::ResultType operator()(UnboundParams... params) ove
rride | 298 class PartBoundFunctionImpl<5, |
| 301 { | 299 FunctionWrapper, |
| 302 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStor
ageTraits<P2>::unwrap(m_p2), ParamStorageTraits<P3>::unwrap(m_p3), ParamStorageT
raits<P4>::unwrap(m_p4), ParamStorageTraits<P5>::unwrap(m_p5), ParamStorageTrait
s<P6>::unwrap(m_p6), params...); | 300 R(P1, P2, P3, P4, P5, UnboundParams...)> |
| 303 } | 301 final |
| 304 | 302 : public Function<typename FunctionWrapper::ResultType(UnboundParams...)> { |
| 305 private: | 303 public: |
| 306 FunctionWrapper m_functionWrapper; | 304 PartBoundFunctionImpl(FunctionWrapper functionWrapper, |
| 307 typename ParamStorageTraits<P1>::StorageType m_p1; | 305 const P1& p1, |
| 308 typename ParamStorageTraits<P2>::StorageType m_p2; | 306 const P2& p2, |
| 309 typename ParamStorageTraits<P3>::StorageType m_p3; | 307 const P3& p3, |
| 310 typename ParamStorageTraits<P4>::StorageType m_p4; | 308 const P4& p4, |
| 311 typename ParamStorageTraits<P5>::StorageType m_p5; | 309 const P5& p5) |
| 312 typename ParamStorageTraits<P6>::StorageType m_p6; | 310 : m_functionWrapper(functionWrapper), |
| 313 }; | 311 m_p1(ParamStorageTraits<P1>::wrap(p1)), |
| 314 | 312 m_p2(ParamStorageTraits<P2>::wrap(p2)), |
| 315 template<typename FunctionWrapper, typename R, typename P1, typename P2, typenam
e P3, typename P4, typename P5, typename P6, typename P7, typename... UnboundPar
ams> | 313 m_p3(ParamStorageTraits<P3>::wrap(p3)), |
| 316 class PartBoundFunctionImpl<7, FunctionWrapper, R(P1, P2, P3, P4, P5, P6, P7, Un
boundParams...)> final : public Function<typename FunctionWrapper::ResultType(Un
boundParams...)> { | 314 m_p4(ParamStorageTraits<P4>::wrap(p4)), |
| 317 public: | 315 m_p5(ParamStorageTraits<P5>::wrap(p5)) {} |
| 318 PartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P
2& p2, const P3& p3, const P4& p4, const P5& p5, const P6& p6, const P7& p7) | 316 |
| 319 : m_functionWrapper(functionWrapper) | 317 typename FunctionWrapper::ResultType operator()( |
| 320 , m_p1(ParamStorageTraits<P1>::wrap(p1)) | 318 UnboundParams... params) override { |
| 321 , m_p2(ParamStorageTraits<P2>::wrap(p2)) | 319 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), |
| 322 , m_p3(ParamStorageTraits<P3>::wrap(p3)) | 320 ParamStorageTraits<P2>::unwrap(m_p2), |
| 323 , m_p4(ParamStorageTraits<P4>::wrap(p4)) | 321 ParamStorageTraits<P3>::unwrap(m_p3), |
| 324 , m_p5(ParamStorageTraits<P5>::wrap(p5)) | 322 ParamStorageTraits<P4>::unwrap(m_p4), |
| 325 , m_p6(ParamStorageTraits<P6>::wrap(p6)) | 323 ParamStorageTraits<P5>::unwrap(m_p5), params...); |
| 326 , m_p7(ParamStorageTraits<P7>::wrap(p7)) | 324 } |
| 327 { | 325 |
| 328 } | 326 private: |
| 329 | 327 FunctionWrapper m_functionWrapper; |
| 330 typename FunctionWrapper::ResultType operator()(UnboundParams... params) ove
rride | 328 typename ParamStorageTraits<P1>::StorageType m_p1; |
| 331 { | 329 typename ParamStorageTraits<P2>::StorageType m_p2; |
| 332 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStor
ageTraits<P2>::unwrap(m_p2), ParamStorageTraits<P3>::unwrap(m_p3), ParamStorageT
raits<P4>::unwrap(m_p4), ParamStorageTraits<P5>::unwrap(m_p5), ParamStorageTrait
s<P6>::unwrap(m_p6), ParamStorageTraits<P7>::unwrap(m_p7), params...); | 330 typename ParamStorageTraits<P3>::StorageType m_p3; |
| 333 } | 331 typename ParamStorageTraits<P4>::StorageType m_p4; |
| 334 | 332 typename ParamStorageTraits<P5>::StorageType m_p5; |
| 335 private: | 333 }; |
| 336 FunctionWrapper m_functionWrapper; | 334 |
| 337 typename ParamStorageTraits<P1>::StorageType m_p1; | 335 template <typename FunctionWrapper, |
| 338 typename ParamStorageTraits<P2>::StorageType m_p2; | 336 typename R, |
| 339 typename ParamStorageTraits<P3>::StorageType m_p3; | 337 typename P1, |
| 340 typename ParamStorageTraits<P4>::StorageType m_p4; | 338 typename P2, |
| 341 typename ParamStorageTraits<P5>::StorageType m_p5; | 339 typename P3, |
| 342 typename ParamStorageTraits<P6>::StorageType m_p6; | 340 typename P4, |
| 343 typename ParamStorageTraits<P7>::StorageType m_p7; | 341 typename P5, |
| 344 }; | 342 typename P6, |
| 345 | 343 typename... UnboundParams> |
| 346 | 344 class PartBoundFunctionImpl<6, |
| 347 template<typename... UnboundArgs, typename FunctionType, typename... BoundArgs> | 345 FunctionWrapper, |
| 348 PassOwnPtr<Function<typename FunctionWrapper<FunctionType>::ResultType(UnboundAr
gs...)>> bind(FunctionType function, const BoundArgs&... boundArgs) | 346 R(P1, P2, P3, P4, P5, P6, UnboundParams...)> |
| 349 { | 347 final |
| 350 const int boundArgsCount = sizeof...(BoundArgs); | 348 : public Function<typename FunctionWrapper::ResultType(UnboundParams...)> { |
| 351 using BoundFunctionType = PartBoundFunctionImpl<boundArgsCount, FunctionWrap
per<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType(BoundArgs.
.., UnboundArgs...)>; | 349 public: |
| 352 return adoptPtr(new BoundFunctionType(FunctionWrapper<FunctionType>(function
), boundArgs...)); | 350 PartBoundFunctionImpl(FunctionWrapper functionWrapper, |
| 351 const P1& p1, |
| 352 const P2& p2, |
| 353 const P3& p3, |
| 354 const P4& p4, |
| 355 const P5& p5, |
| 356 const P6& p6) |
| 357 : m_functionWrapper(functionWrapper), |
| 358 m_p1(ParamStorageTraits<P1>::wrap(p1)), |
| 359 m_p2(ParamStorageTraits<P2>::wrap(p2)), |
| 360 m_p3(ParamStorageTraits<P3>::wrap(p3)), |
| 361 m_p4(ParamStorageTraits<P4>::wrap(p4)), |
| 362 m_p5(ParamStorageTraits<P5>::wrap(p5)), |
| 363 m_p6(ParamStorageTraits<P6>::wrap(p6)) {} |
| 364 |
| 365 typename FunctionWrapper::ResultType operator()( |
| 366 UnboundParams... params) override { |
| 367 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), |
| 368 ParamStorageTraits<P2>::unwrap(m_p2), |
| 369 ParamStorageTraits<P3>::unwrap(m_p3), |
| 370 ParamStorageTraits<P4>::unwrap(m_p4), |
| 371 ParamStorageTraits<P5>::unwrap(m_p5), |
| 372 ParamStorageTraits<P6>::unwrap(m_p6), params...); |
| 373 } |
| 374 |
| 375 private: |
| 376 FunctionWrapper m_functionWrapper; |
| 377 typename ParamStorageTraits<P1>::StorageType m_p1; |
| 378 typename ParamStorageTraits<P2>::StorageType m_p2; |
| 379 typename ParamStorageTraits<P3>::StorageType m_p3; |
| 380 typename ParamStorageTraits<P4>::StorageType m_p4; |
| 381 typename ParamStorageTraits<P5>::StorageType m_p5; |
| 382 typename ParamStorageTraits<P6>::StorageType m_p6; |
| 383 }; |
| 384 |
| 385 template <typename FunctionWrapper, |
| 386 typename R, |
| 387 typename P1, |
| 388 typename P2, |
| 389 typename P3, |
| 390 typename P4, |
| 391 typename P5, |
| 392 typename P6, |
| 393 typename P7, |
| 394 typename... UnboundParams> |
| 395 class PartBoundFunctionImpl<7, |
| 396 FunctionWrapper, |
| 397 R(P1, P2, P3, P4, P5, P6, P7, UnboundParams...)> |
| 398 final |
| 399 : public Function<typename FunctionWrapper::ResultType(UnboundParams...)> { |
| 400 public: |
| 401 PartBoundFunctionImpl(FunctionWrapper functionWrapper, |
| 402 const P1& p1, |
| 403 const P2& p2, |
| 404 const P3& p3, |
| 405 const P4& p4, |
| 406 const P5& p5, |
| 407 const P6& p6, |
| 408 const P7& p7) |
| 409 : m_functionWrapper(functionWrapper), |
| 410 m_p1(ParamStorageTraits<P1>::wrap(p1)), |
| 411 m_p2(ParamStorageTraits<P2>::wrap(p2)), |
| 412 m_p3(ParamStorageTraits<P3>::wrap(p3)), |
| 413 m_p4(ParamStorageTraits<P4>::wrap(p4)), |
| 414 m_p5(ParamStorageTraits<P5>::wrap(p5)), |
| 415 m_p6(ParamStorageTraits<P6>::wrap(p6)), |
| 416 m_p7(ParamStorageTraits<P7>::wrap(p7)) {} |
| 417 |
| 418 typename FunctionWrapper::ResultType operator()( |
| 419 UnboundParams... params) override { |
| 420 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), |
| 421 ParamStorageTraits<P2>::unwrap(m_p2), |
| 422 ParamStorageTraits<P3>::unwrap(m_p3), |
| 423 ParamStorageTraits<P4>::unwrap(m_p4), |
| 424 ParamStorageTraits<P5>::unwrap(m_p5), |
| 425 ParamStorageTraits<P6>::unwrap(m_p6), |
| 426 ParamStorageTraits<P7>::unwrap(m_p7), params...); |
| 427 } |
| 428 |
| 429 private: |
| 430 FunctionWrapper m_functionWrapper; |
| 431 typename ParamStorageTraits<P1>::StorageType m_p1; |
| 432 typename ParamStorageTraits<P2>::StorageType m_p2; |
| 433 typename ParamStorageTraits<P3>::StorageType m_p3; |
| 434 typename ParamStorageTraits<P4>::StorageType m_p4; |
| 435 typename ParamStorageTraits<P5>::StorageType m_p5; |
| 436 typename ParamStorageTraits<P6>::StorageType m_p6; |
| 437 typename ParamStorageTraits<P7>::StorageType m_p7; |
| 438 }; |
| 439 |
| 440 template <typename... UnboundArgs, typename FunctionType, typename... BoundArgs> |
| 441 PassOwnPtr<Function< |
| 442 typename FunctionWrapper<FunctionType>::ResultType(UnboundArgs...)>> |
| 443 bind(FunctionType function, const BoundArgs&... boundArgs) { |
| 444 const int boundArgsCount = sizeof...(BoundArgs); |
| 445 using BoundFunctionType = |
| 446 PartBoundFunctionImpl<boundArgsCount, FunctionWrapper<FunctionType>, |
| 447 typename FunctionWrapper<FunctionType>::ResultType( |
| 448 BoundArgs..., UnboundArgs...)>; |
| 449 return adoptPtr(new BoundFunctionType(FunctionWrapper<FunctionType>(function), |
| 450 boundArgs...)); |
| 353 } | 451 } |
| 354 | 452 |
| 355 typedef Function<void()> Closure; | 453 typedef Function<void()> Closure; |
| 356 | |
| 357 } | 454 } |
| 358 | 455 |
| 359 using WTF::Function; | 456 using WTF::Function; |
| 360 using WTF::bind; | 457 using WTF::bind; |
| 361 using WTF::Closure; | 458 using WTF::Closure; |
| 362 | 459 |
| 363 #endif // WTF_Functional_h | 460 #endif // WTF_Functional_h |
| OLD | NEW |