| 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 25 matching lines...) Expand all Loading... |
| 36 namespace WTF { | 36 namespace WTF { |
| 37 | 37 |
| 38 // Functional.h provides a very simple way to bind a function pointer and argume
nts together into a function object | 38 // Functional.h provides a very simple way to bind a function pointer and argume
nts together into a function object |
| 39 // that can be stored, copied and invoked, similar to how boost::bind and std::b
ind in C++11. | 39 // that can be stored, copied and invoked, similar to how boost::bind and std::b
ind in C++11. |
| 40 | 40 |
| 41 // Use threadSafeBind() or createCrossThreadTask() if the function/task is | 41 // Use threadSafeBind() or createCrossThreadTask() if the function/task is |
| 42 // called on a (potentially) different thread from the current thread. | 42 // called on a (potentially) different thread from the current thread. |
| 43 | 43 |
| 44 // A FunctionWrapper is a class template that can wrap a function pointer or a m
ember function pointer and | 44 // A FunctionWrapper is a class template that can wrap a function pointer or a m
ember function pointer and |
| 45 // provide a unified interface for calling that function. | 45 // provide a unified interface for calling that function. |
| 46 template<typename> | 46 template <typename> |
| 47 class FunctionWrapper; | 47 class FunctionWrapper; |
| 48 | 48 |
| 49 // Bound static functions: | 49 // Bound static functions: |
| 50 template<typename R, typename... Params> | 50 template <typename R, typename... Params> |
| 51 class FunctionWrapper<R(*)(Params...)> { | 51 class FunctionWrapper<R (*)(Params...)> { |
| 52 public: | 52 public: |
| 53 typedef R ResultType; | 53 typedef R ResultType; |
| 54 | 54 |
| 55 explicit FunctionWrapper(R(*function)(Params...)) | 55 explicit FunctionWrapper(R (*function)(Params...)) |
| 56 : m_function(function) | 56 : m_function(function) { |
| 57 { | 57 } |
| 58 } | 58 |
| 59 | 59 R operator()(Params... params) { |
| 60 R operator()(Params... params) | 60 return m_function(params...); |
| 61 { | 61 } |
| 62 return m_function(params...); | 62 |
| 63 } | 63 private: |
| 64 | 64 R (*m_function) |
| 65 private: | 65 (Params...); |
| 66 R(*m_function)(Params...); | |
| 67 }; | 66 }; |
| 68 | 67 |
| 69 // Bound member functions: | 68 // Bound member functions: |
| 70 | 69 |
| 71 template<typename R, typename C, typename... Params> | 70 template <typename R, typename C, typename... Params> |
| 72 class FunctionWrapper<R(C::*)(Params...)> { | 71 class FunctionWrapper<R (C::*)(Params...)> { |
| 73 public: | 72 public: |
| 74 typedef R ResultType; | 73 typedef R ResultType; |
| 75 | 74 |
| 76 explicit FunctionWrapper(R(C::*function)(Params...)) | 75 explicit FunctionWrapper(R (C::*function)(Params...)) |
| 77 : m_function(function) | 76 : m_function(function) { |
| 78 { | 77 } |
| 79 } | 78 |
| 80 | 79 R operator()(C* c, Params... params) { |
| 81 R operator()(C* c, Params... params) | 80 return (c->*m_function)(params...); |
| 82 { | 81 } |
| 83 return (c->*m_function)(params...); | 82 |
| 84 } | 83 R operator()(PassOwnPtr<C> c, Params... params) { |
| 85 | 84 return (c.get()->*m_function)(params...); |
| 86 R operator()(PassOwnPtr<C> c, Params... params) | 85 } |
| 87 { | 86 |
| 88 return (c.get()->*m_function)(params...); | 87 R operator()(const WeakPtr<C>& c, Params... params) { |
| 89 } | 88 C* obj = c.get(); |
| 90 | 89 if (!obj) |
| 91 R operator()(const WeakPtr<C>& c, Params... params) | 90 return R(); |
| 92 { | 91 return (obj->*m_function)(params...); |
| 93 C* obj = c.get(); | 92 } |
| 94 if (!obj) | 93 |
| 95 return R(); | 94 private: |
| 96 return (obj->*m_function)(params...); | 95 R (C::*m_function) |
| 97 } | 96 (Params...); |
| 98 | 97 }; |
| 99 private: | 98 |
| 100 R(C::*m_function)(Params...); | 99 template <typename T> |
| 101 }; | 100 struct ParamStorageTraits { |
| 102 | 101 typedef T StorageType; |
| 103 template<typename T> struct ParamStorageTraits { | 102 |
| 104 typedef T StorageType; | 103 static StorageType wrap(const T& value) { return value; } |
| 105 | 104 static const T& unwrap(const StorageType& value) { return value; } |
| 106 static StorageType wrap(const T& value) { return value; } | 105 }; |
| 107 static const T& unwrap(const StorageType& value) { return value; } | 106 |
| 108 }; | 107 template <typename T> |
| 109 | 108 struct ParamStorageTraits<PassRefPtr<T>> { |
| 110 template<typename T> struct ParamStorageTraits<PassRefPtr<T>> { | 109 typedef RefPtr<T> StorageType; |
| 111 typedef RefPtr<T> StorageType; | 110 |
| 112 | 111 static StorageType wrap(PassRefPtr<T> value) { return value; } |
| 113 static StorageType wrap(PassRefPtr<T> value) { return value; } | 112 static T* unwrap(const StorageType& value) { return value.get(); } |
| 114 static T* unwrap(const StorageType& value) { return value.get(); } | 113 }; |
| 115 }; | 114 |
| 116 | 115 template <typename T> |
| 117 template<typename T> struct ParamStorageTraits<RefPtr<T>> { | 116 struct ParamStorageTraits<RefPtr<T>> { |
| 118 typedef RefPtr<T> StorageType; | 117 typedef RefPtr<T> StorageType; |
| 119 | 118 |
| 120 static StorageType wrap(RefPtr<T> value) { return value.release(); } | 119 static StorageType wrap(RefPtr<T> value) { return value.release(); } |
| 121 static T* unwrap(const StorageType& value) { return value.get(); } | 120 static T* unwrap(const StorageType& value) { return value.get(); } |
| 122 }; | 121 }; |
| 123 | 122 |
| 124 template<typename> class RetainPtr; | 123 template <typename> |
| 125 | 124 class RetainPtr; |
| 126 template<typename T> struct ParamStorageTraits<RetainPtr<T>> { | 125 |
| 127 typedef RetainPtr<T> StorageType; | 126 template <typename T> |
| 128 | 127 struct ParamStorageTraits<RetainPtr<T>> { |
| 129 static StorageType wrap(const RetainPtr<T>& value) { return value; } | 128 typedef RetainPtr<T> StorageType; |
| 130 static typename RetainPtr<T>::PtrType unwrap(const StorageType& value) { ret
urn value.get(); } | 129 |
| 131 }; | 130 static StorageType wrap(const RetainPtr<T>& value) { return value; } |
| 132 | 131 static typename RetainPtr<T>::PtrType unwrap(const StorageType& value) { retur
n value.get(); } |
| 133 template<typename> | 132 }; |
| 133 |
| 134 template <typename> |
| 134 class Function; | 135 class Function; |
| 135 | 136 |
| 136 template<typename R, typename... Args> | 137 template <typename R, typename... Args> |
| 137 class Function<R(Args...)> { | 138 class Function<R(Args...)> { |
| 138 WTF_MAKE_NONCOPYABLE(Function); | 139 WTF_MAKE_NONCOPYABLE(Function); |
| 139 public: | 140 |
| 140 virtual ~Function() { } | 141 public: |
| 141 virtual R operator()(Args... args) = 0; | 142 virtual ~Function() {} |
| 142 protected: | 143 virtual R operator()(Args... args) = 0; |
| 143 Function() = default; | 144 |
| 144 }; | 145 protected: |
| 145 | 146 Function() = default; |
| 146 template<int boundArgsCount, typename FunctionWrapper, typename FunctionType> | 147 }; |
| 148 |
| 149 template <int boundArgsCount, typename FunctionWrapper, typename FunctionType> |
| 147 class PartBoundFunctionImpl; | 150 class PartBoundFunctionImpl; |
| 148 | 151 |
| 149 // Specialization for unbound functions. | 152 // Specialization for unbound functions. |
| 150 template<typename FunctionWrapper, typename R, typename... UnboundParams> | 153 template <typename FunctionWrapper, typename R, typename... UnboundParams> |
| 151 class PartBoundFunctionImpl<0, FunctionWrapper, R(UnboundParams...)> final : pub
lic Function<typename FunctionWrapper::ResultType(UnboundParams...)> { | 154 class PartBoundFunctionImpl<0, FunctionWrapper, R(UnboundParams...)> final : pub
lic Function<typename FunctionWrapper::ResultType(UnboundParams...)> { |
| 152 public: | 155 public: |
| 153 PartBoundFunctionImpl(FunctionWrapper functionWrapper) | 156 PartBoundFunctionImpl(FunctionWrapper functionWrapper) |
| 154 : m_functionWrapper(functionWrapper) | 157 : m_functionWrapper(functionWrapper) { |
| 155 { | 158 } |
| 156 } | 159 |
| 157 | 160 typename FunctionWrapper::ResultType operator()(UnboundParams... params) overr
ide { |
| 158 typename FunctionWrapper::ResultType operator()(UnboundParams... params) ove
rride | 161 return m_functionWrapper(params...); |
| 159 { | 162 } |
| 160 return m_functionWrapper(params...); | 163 |
| 161 } | 164 private: |
| 162 | 165 FunctionWrapper m_functionWrapper; |
| 163 private: | 166 }; |
| 164 FunctionWrapper m_functionWrapper; | 167 |
| 165 }; | 168 template <typename FunctionWrapper, typename R, typename P1, typename... Unbound
Params> |
| 166 | |
| 167 template<typename FunctionWrapper, typename R, typename P1, typename... UnboundP
arams> | |
| 168 class PartBoundFunctionImpl<1, FunctionWrapper, R(P1, UnboundParams...)> final :
public Function<typename FunctionWrapper::ResultType(UnboundParams...)> { | 169 class PartBoundFunctionImpl<1, FunctionWrapper, R(P1, UnboundParams...)> final :
public Function<typename FunctionWrapper::ResultType(UnboundParams...)> { |
| 169 public: | 170 public: |
| 170 PartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1) | 171 PartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1) |
| 171 : m_functionWrapper(functionWrapper) | 172 : m_functionWrapper(functionWrapper), m_p1(ParamStorageTraits<P1>::wrap(p1
)) { |
| 172 , m_p1(ParamStorageTraits<P1>::wrap(p1)) | 173 } |
| 173 { | 174 |
| 174 } | 175 typename FunctionWrapper::ResultType operator()(UnboundParams... params) overr
ide { |
| 175 | 176 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), params...); |
| 176 typename FunctionWrapper::ResultType operator()(UnboundParams... params) ove
rride | 177 } |
| 177 { | 178 |
| 178 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), params...
); | 179 private: |
| 179 } | 180 FunctionWrapper m_functionWrapper; |
| 180 | 181 typename ParamStorageTraits<P1>::StorageType m_p1; |
| 181 private: | 182 }; |
| 182 FunctionWrapper m_functionWrapper; | 183 |
| 183 typename ParamStorageTraits<P1>::StorageType m_p1; | 184 template <typename FunctionWrapper, typename R, typename P1, typename P2, typena
me... UnboundParams> |
| 184 }; | |
| 185 | |
| 186 template<typename FunctionWrapper, typename R, typename P1, typename P2, typenam
e... UnboundParams> | |
| 187 class PartBoundFunctionImpl<2, FunctionWrapper, R(P1, P2, UnboundParams...)> fin
al : public Function<typename FunctionWrapper::ResultType(UnboundParams...)> { | 185 class PartBoundFunctionImpl<2, FunctionWrapper, R(P1, P2, UnboundParams...)> fin
al : public Function<typename FunctionWrapper::ResultType(UnboundParams...)> { |
| 188 public: | 186 public: |
| 189 PartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P
2& p2) | 187 PartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2&
p2) |
| 190 : m_functionWrapper(functionWrapper) | 188 : m_functionWrapper(functionWrapper), m_p1(ParamStorageTraits<P1>::wrap(p1
)), m_p2(ParamStorageTraits<P2>::wrap(p2)) { |
| 191 , m_p1(ParamStorageTraits<P1>::wrap(p1)) | 189 } |
| 192 , m_p2(ParamStorageTraits<P2>::wrap(p2)) | 190 |
| 193 { | 191 typename FunctionWrapper::ResultType operator()(UnboundParams... params) overr
ide { |
| 194 } | 192 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStorageT
raits<P2>::unwrap(m_p2), params...); |
| 195 | 193 } |
| 196 typename FunctionWrapper::ResultType operator()(UnboundParams... params) ove
rride | 194 |
| 197 { | 195 private: |
| 198 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStor
ageTraits<P2>::unwrap(m_p2), params...); | 196 FunctionWrapper m_functionWrapper; |
| 199 } | 197 typename ParamStorageTraits<P1>::StorageType m_p1; |
| 200 | 198 typename ParamStorageTraits<P2>::StorageType m_p2; |
| 201 private: | 199 }; |
| 202 FunctionWrapper m_functionWrapper; | 200 |
| 203 typename ParamStorageTraits<P1>::StorageType m_p1; | 201 template <typename FunctionWrapper, typename R, typename P1, typename P2, typena
me P3, typename... UnboundParams> |
| 204 typename ParamStorageTraits<P2>::StorageType m_p2; | |
| 205 }; | |
| 206 | |
| 207 template<typename FunctionWrapper, typename R, typename P1, typename P2, typenam
e P3, typename... UnboundParams> | |
| 208 class PartBoundFunctionImpl<3, FunctionWrapper, R(P1, P2, P3, UnboundParams...)>
final : public Function<typename FunctionWrapper::ResultType(UnboundParams...)>
{ | 202 class PartBoundFunctionImpl<3, FunctionWrapper, R(P1, P2, P3, UnboundParams...)>
final : public Function<typename FunctionWrapper::ResultType(UnboundParams...)>
{ |
| 209 public: | 203 public: |
| 210 PartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P
2& p2, const P3& p3) | 204 PartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2&
p2, const P3& p3) |
| 211 : m_functionWrapper(functionWrapper) | 205 : m_functionWrapper(functionWrapper), m_p1(ParamStorageTraits<P1>::wrap(p1
)), m_p2(ParamStorageTraits<P2>::wrap(p2)), m_p3(ParamStorageTraits<P3>::wrap(p3
)) { |
| 212 , m_p1(ParamStorageTraits<P1>::wrap(p1)) | 206 } |
| 213 , m_p2(ParamStorageTraits<P2>::wrap(p2)) | 207 |
| 214 , m_p3(ParamStorageTraits<P3>::wrap(p3)) | 208 typename FunctionWrapper::ResultType operator()(UnboundParams... params) overr
ide { |
| 215 { | 209 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStorageT
raits<P2>::unwrap(m_p2), ParamStorageTraits<P3>::unwrap(m_p3), params...); |
| 216 } | 210 } |
| 217 | 211 |
| 218 typename FunctionWrapper::ResultType operator()(UnboundParams... params) ove
rride | 212 private: |
| 219 { | 213 FunctionWrapper m_functionWrapper; |
| 220 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStor
ageTraits<P2>::unwrap(m_p2), ParamStorageTraits<P3>::unwrap(m_p3), params...); | 214 typename ParamStorageTraits<P1>::StorageType m_p1; |
| 221 } | 215 typename ParamStorageTraits<P2>::StorageType m_p2; |
| 222 | 216 typename ParamStorageTraits<P3>::StorageType m_p3; |
| 223 private: | 217 }; |
| 224 FunctionWrapper m_functionWrapper; | 218 |
| 225 typename ParamStorageTraits<P1>::StorageType m_p1; | 219 template <typename FunctionWrapper, typename R, typename P1, typename P2, typena
me P3, typename P4, typename... UnboundParams> |
| 226 typename ParamStorageTraits<P2>::StorageType m_p2; | |
| 227 typename ParamStorageTraits<P3>::StorageType m_p3; | |
| 228 }; | |
| 229 | |
| 230 template<typename FunctionWrapper, typename R, typename P1, typename P2, typenam
e P3, typename P4, typename... UnboundParams> | |
| 231 class PartBoundFunctionImpl<4, FunctionWrapper, R(P1, P2, P3, P4, UnboundParams.
..)> final : public Function<typename FunctionWrapper::ResultType(UnboundParams.
..)> { | 220 class PartBoundFunctionImpl<4, FunctionWrapper, R(P1, P2, P3, P4, UnboundParams.
..)> final : public Function<typename FunctionWrapper::ResultType(UnboundParams.
..)> { |
| 232 public: | 221 public: |
| 233 PartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P
2& p2, const P3& p3, const P4& p4) | 222 PartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2&
p2, const P3& p3, const P4& p4) |
| 234 : m_functionWrapper(functionWrapper) | 223 : m_functionWrapper(functionWrapper), m_p1(ParamStorageTraits<P1>::wrap(p1
)), m_p2(ParamStorageTraits<P2>::wrap(p2)), m_p3(ParamStorageTraits<P3>::wrap(p3
)), m_p4(ParamStorageTraits<P4>::wrap(p4)) { |
| 235 , m_p1(ParamStorageTraits<P1>::wrap(p1)) | 224 } |
| 236 , m_p2(ParamStorageTraits<P2>::wrap(p2)) | 225 |
| 237 , m_p3(ParamStorageTraits<P3>::wrap(p3)) | 226 typename FunctionWrapper::ResultType operator()(UnboundParams... params) overr
ide { |
| 238 , m_p4(ParamStorageTraits<P4>::wrap(p4)) | 227 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStorageT
raits<P2>::unwrap(m_p2), ParamStorageTraits<P3>::unwrap(m_p3), ParamStorageTrait
s<P4>::unwrap(m_p4), params...); |
| 239 { | 228 } |
| 240 } | 229 |
| 241 | 230 private: |
| 242 typename FunctionWrapper::ResultType operator()(UnboundParams... params) ove
rride | 231 FunctionWrapper m_functionWrapper; |
| 243 { | 232 typename ParamStorageTraits<P1>::StorageType m_p1; |
| 244 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...); | 233 typename ParamStorageTraits<P2>::StorageType m_p2; |
| 245 } | 234 typename ParamStorageTraits<P3>::StorageType m_p3; |
| 246 | 235 typename ParamStorageTraits<P4>::StorageType m_p4; |
| 247 private: | 236 }; |
| 248 FunctionWrapper m_functionWrapper; | 237 |
| 249 typename ParamStorageTraits<P1>::StorageType m_p1; | 238 template <typename FunctionWrapper, typename R, typename P1, typename P2, typena
me P3, typename P4, typename P5, typename... UnboundParams> |
| 250 typename ParamStorageTraits<P2>::StorageType m_p2; | |
| 251 typename ParamStorageTraits<P3>::StorageType m_p3; | |
| 252 typename ParamStorageTraits<P4>::StorageType m_p4; | |
| 253 }; | |
| 254 | |
| 255 template<typename FunctionWrapper, typename R, typename P1, typename P2, typenam
e P3, typename P4, typename P5, typename... UnboundParams> | |
| 256 class PartBoundFunctionImpl<5, FunctionWrapper, R(P1, P2, P3, P4, P5, UnboundPar
ams...)> final : public Function<typename FunctionWrapper::ResultType(UnboundPar
ams...)> { | 239 class PartBoundFunctionImpl<5, FunctionWrapper, R(P1, P2, P3, P4, P5, UnboundPar
ams...)> final : public Function<typename FunctionWrapper::ResultType(UnboundPar
ams...)> { |
| 257 public: | 240 public: |
| 258 PartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P
2& p2, const P3& p3, const P4& p4, const P5& p5) | 241 PartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2&
p2, const P3& p3, const P4& p4, const P5& p5) |
| 259 : m_functionWrapper(functionWrapper) | 242 : m_functionWrapper(functionWrapper), m_p1(ParamStorageTraits<P1>::wrap(p1
)), m_p2(ParamStorageTraits<P2>::wrap(p2)), m_p3(ParamStorageTraits<P3>::wrap(p3
)), m_p4(ParamStorageTraits<P4>::wrap(p4)), m_p5(ParamStorageTraits<P5>::wrap(p5
)) { |
| 260 , m_p1(ParamStorageTraits<P1>::wrap(p1)) | 243 } |
| 261 , m_p2(ParamStorageTraits<P2>::wrap(p2)) | 244 |
| 262 , m_p3(ParamStorageTraits<P3>::wrap(p3)) | 245 typename FunctionWrapper::ResultType operator()(UnboundParams... params) overr
ide { |
| 263 , m_p4(ParamStorageTraits<P4>::wrap(p4)) | 246 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStorageT
raits<P2>::unwrap(m_p2), ParamStorageTraits<P3>::unwrap(m_p3), ParamStorageTrait
s<P4>::unwrap(m_p4), ParamStorageTraits<P5>::unwrap(m_p5), params...); |
| 264 , m_p5(ParamStorageTraits<P5>::wrap(p5)) | 247 } |
| 265 { | 248 |
| 266 } | 249 private: |
| 267 | 250 FunctionWrapper m_functionWrapper; |
| 268 typename FunctionWrapper::ResultType operator()(UnboundParams... params) ove
rride | 251 typename ParamStorageTraits<P1>::StorageType m_p1; |
| 269 { | 252 typename ParamStorageTraits<P2>::StorageType m_p2; |
| 270 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...); | 253 typename ParamStorageTraits<P3>::StorageType m_p3; |
| 271 } | 254 typename ParamStorageTraits<P4>::StorageType m_p4; |
| 272 | 255 typename ParamStorageTraits<P5>::StorageType m_p5; |
| 273 private: | 256 }; |
| 274 FunctionWrapper m_functionWrapper; | 257 |
| 275 typename ParamStorageTraits<P1>::StorageType m_p1; | 258 template <typename FunctionWrapper, typename R, typename P1, typename P2, typena
me P3, typename P4, typename P5, typename P6, typename... UnboundParams> |
| 276 typename ParamStorageTraits<P2>::StorageType m_p2; | |
| 277 typename ParamStorageTraits<P3>::StorageType m_p3; | |
| 278 typename ParamStorageTraits<P4>::StorageType m_p4; | |
| 279 typename ParamStorageTraits<P5>::StorageType m_p5; | |
| 280 }; | |
| 281 | |
| 282 template<typename FunctionWrapper, typename R, typename P1, typename P2, typenam
e P3, typename P4, typename P5, typename P6, typename... UnboundParams> | |
| 283 class PartBoundFunctionImpl<6, FunctionWrapper, R(P1, P2, P3, P4, P5, P6, Unboun
dParams...)> final : public Function<typename FunctionWrapper::ResultType(Unboun
dParams...)> { | 259 class PartBoundFunctionImpl<6, FunctionWrapper, R(P1, P2, P3, P4, P5, P6, Unboun
dParams...)> final : public Function<typename FunctionWrapper::ResultType(Unboun
dParams...)> { |
| 284 public: | 260 public: |
| 285 PartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P
2& p2, const P3& p3, const P4& p4, const P5& p5, const P6& p6) | 261 PartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2&
p2, const P3& p3, const P4& p4, const P5& p5, const P6& p6) |
| 286 : m_functionWrapper(functionWrapper) | 262 : m_functionWrapper(functionWrapper), m_p1(ParamStorageTraits<P1>::wrap(p1
)), m_p2(ParamStorageTraits<P2>::wrap(p2)), m_p3(ParamStorageTraits<P3>::wrap(p3
)), m_p4(ParamStorageTraits<P4>::wrap(p4)), m_p5(ParamStorageTraits<P5>::wrap(p5
)), m_p6(ParamStorageTraits<P6>::wrap(p6)) { |
| 287 , m_p1(ParamStorageTraits<P1>::wrap(p1)) | 263 } |
| 288 , m_p2(ParamStorageTraits<P2>::wrap(p2)) | 264 |
| 289 , m_p3(ParamStorageTraits<P3>::wrap(p3)) | 265 typename FunctionWrapper::ResultType operator()(UnboundParams... params) overr
ide { |
| 290 , m_p4(ParamStorageTraits<P4>::wrap(p4)) | 266 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStorageT
raits<P2>::unwrap(m_p2), ParamStorageTraits<P3>::unwrap(m_p3), ParamStorageTrait
s<P4>::unwrap(m_p4), ParamStorageTraits<P5>::unwrap(m_p5), ParamStorageTraits<P6
>::unwrap(m_p6), params...); |
| 291 , m_p5(ParamStorageTraits<P5>::wrap(p5)) | 267 } |
| 292 , m_p6(ParamStorageTraits<P6>::wrap(p6)) | 268 |
| 293 { | 269 private: |
| 294 } | 270 FunctionWrapper m_functionWrapper; |
| 295 | 271 typename ParamStorageTraits<P1>::StorageType m_p1; |
| 296 typename FunctionWrapper::ResultType operator()(UnboundParams... params) ove
rride | 272 typename ParamStorageTraits<P2>::StorageType m_p2; |
| 297 { | 273 typename ParamStorageTraits<P3>::StorageType m_p3; |
| 298 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...); | 274 typename ParamStorageTraits<P4>::StorageType m_p4; |
| 299 } | 275 typename ParamStorageTraits<P5>::StorageType m_p5; |
| 300 | 276 typename ParamStorageTraits<P6>::StorageType m_p6; |
| 301 private: | 277 }; |
| 302 FunctionWrapper m_functionWrapper; | 278 |
| 303 typename ParamStorageTraits<P1>::StorageType m_p1; | 279 template <typename... UnboundArgs, typename FunctionType, typename... BoundArgs> |
| 304 typename ParamStorageTraits<P2>::StorageType m_p2; | 280 PassOwnPtr<Function<typename FunctionWrapper<FunctionType>::ResultType(UnboundAr
gs...)>> bind(FunctionType function, const BoundArgs&... boundArgs) { |
| 305 typename ParamStorageTraits<P3>::StorageType m_p3; | 281 const int boundArgsCount = sizeof...(BoundArgs); |
| 306 typename ParamStorageTraits<P4>::StorageType m_p4; | 282 using BoundFunctionType = PartBoundFunctionImpl<boundArgsCount, FunctionWrappe
r<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType(BoundArgs...
, UnboundArgs...)>; |
| 307 typename ParamStorageTraits<P5>::StorageType m_p5; | 283 return adoptPtr(new BoundFunctionType(FunctionWrapper<FunctionType>(function),
boundArgs...)); |
| 308 typename ParamStorageTraits<P6>::StorageType m_p6; | |
| 309 }; | |
| 310 | |
| 311 template<typename... UnboundArgs, typename FunctionType, typename... BoundArgs> | |
| 312 PassOwnPtr<Function<typename FunctionWrapper<FunctionType>::ResultType(UnboundAr
gs...)>> bind(FunctionType function, const BoundArgs&... boundArgs) | |
| 313 { | |
| 314 const int boundArgsCount = sizeof...(BoundArgs); | |
| 315 using BoundFunctionType = PartBoundFunctionImpl<boundArgsCount, FunctionWrap
per<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType(BoundArgs.
.., UnboundArgs...)>; | |
| 316 return adoptPtr(new BoundFunctionType(FunctionWrapper<FunctionType>(function
), boundArgs...)); | |
| 317 } | 284 } |
| 318 | 285 |
| 319 typedef Function<void()> Closure; | 286 typedef Function<void()> Closure; |
| 320 | |
| 321 } | 287 } |
| 322 | 288 |
| 323 using WTF::Function; | 289 using WTF::Function; |
| 324 using WTF::bind; | 290 using WTF::bind; |
| 325 using WTF::Closure; | 291 using WTF::Closure; |
| 326 | 292 |
| 327 #endif // WTF_Functional_h | 293 #endif // WTF_Functional_h |
| OLD | NEW |