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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 // provide a unified interface for calling that function. | 117 // provide a unified interface for calling that function. |
118 template <typename> | 118 template <typename> |
119 class FunctionWrapper; | 119 class FunctionWrapper; |
120 | 120 |
121 // Bound static functions: | 121 // Bound static functions: |
122 template <typename R, typename... Parameters> | 122 template <typename R, typename... Parameters> |
123 class FunctionWrapper<R(*)(Parameters...)> { | 123 class FunctionWrapper<R(*)(Parameters...)> { |
124 DISALLOW_NEW(); | 124 DISALLOW_NEW(); |
125 public: | 125 public: |
126 typedef R ResultType; | 126 typedef R ResultType; |
| 127 static const size_t numberOfArguments = sizeof...(Parameters); |
127 | 128 |
128 explicit FunctionWrapper(R(*function)(Parameters...)) | 129 explicit FunctionWrapper(R(*function)(Parameters...)) |
129 : m_function(function) | 130 : m_function(function) |
130 { | 131 { |
131 } | 132 } |
132 | 133 |
133 template <typename... IncomingParameters> | 134 template <typename... IncomingParameters> |
134 R operator()(IncomingParameters&&... parameters) | 135 R operator()(IncomingParameters&&... parameters) |
135 { | 136 { |
136 return m_function(std::forward<IncomingParameters>(parameters)...); | 137 return m_function(std::forward<IncomingParameters>(parameters)...); |
137 } | 138 } |
138 | 139 |
139 private: | 140 private: |
140 R(*m_function)(Parameters...); | 141 R(*m_function)(Parameters...); |
141 }; | 142 }; |
142 | 143 |
143 // Bound member functions: | 144 // Bound member functions: |
144 | 145 |
145 template <typename R, typename C, typename... Parameters> | 146 template <typename R, typename C, typename... Parameters> |
146 class FunctionWrapper<R(C::*)(Parameters...)> { | 147 class FunctionWrapper<R(C::*)(Parameters...)> { |
147 DISALLOW_NEW(); | 148 DISALLOW_NEW(); |
148 public: | 149 public: |
149 typedef R ResultType; | 150 typedef R ResultType; |
| 151 // + 1 is for |this| as an argument. |
| 152 static const size_t numberOfArguments = sizeof...(Parameters) + 1; |
150 | 153 |
151 explicit FunctionWrapper(R(C::*function)(Parameters...)) | 154 explicit FunctionWrapper(R(C::*function)(Parameters...)) |
152 : m_function(function) | 155 : m_function(function) |
153 { | 156 { |
154 } | 157 } |
155 | 158 |
156 template <typename... IncomingParameters> | 159 template <typename... IncomingParameters> |
157 R operator()(C* c, IncomingParameters&&... parameters) | 160 R operator()(C* c, IncomingParameters&&... parameters) |
158 { | 161 { |
159 return (c->*m_function)(std::forward<IncomingParameters>(parameters)...)
; | 162 return (c->*m_function)(std::forward<IncomingParameters>(parameters)...)
; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 340 |
338 } // namespace WTF | 341 } // namespace WTF |
339 | 342 |
340 using WTF::passed; | 343 using WTF::passed; |
341 using WTF::Function; | 344 using WTF::Function; |
342 using WTF::bind; | 345 using WTF::bind; |
343 using WTF::SameThreadClosure; | 346 using WTF::SameThreadClosure; |
344 using WTF::CrossThreadClosure; | 347 using WTF::CrossThreadClosure; |
345 | 348 |
346 #endif // WTF_Functional_h | 349 #endif // WTF_Functional_h |
OLD | NEW |