OLD | NEW |
| 1 $$ This is a pump file for generating file templates. Pump is a python |
| 2 $$ script that is part of the Google Test suite of utilities. Description |
| 3 $$ can be found here: |
| 4 $$ |
| 5 $$ http://code.google.com/p/googletest/wiki/PumpManual |
| 6 $$ |
| 7 |
| 8 $$ See comment for MAX_ARITY in base/bind.h.pump. |
| 9 $var MAX_ARITY = 7 |
| 10 |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 11 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 12 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 13 // found in the LICENSE file. |
4 | 14 |
5 #ifndef BASE_CALLBACK_REGISTRY_H_ | 15 #ifndef BASE_CALLBACK_REGISTRY_H_ |
6 #define BASE_CALLBACK_REGISTRY_H_ | 16 #define BASE_CALLBACK_REGISTRY_H_ |
7 | 17 |
8 #include <list> | 18 #include <list> |
9 | 19 |
10 #include "base/basictypes.h" | 20 #include "base/basictypes.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 176 |
167 private: | 177 private: |
168 std::list<CallbackType> callbacks_; | 178 std::list<CallbackType> callbacks_; |
169 int active_iterator_count_; | 179 int active_iterator_count_; |
170 | 180 |
171 DISALLOW_COPY_AND_ASSIGN(CallbackRegistryBase); | 181 DISALLOW_COPY_AND_ASSIGN(CallbackRegistryBase); |
172 }; | 182 }; |
173 | 183 |
174 } // namespace internal | 184 } // namespace internal |
175 | 185 |
176 template <typename Details> | 186 template <typename Sig> class CallbackRegistry; |
177 class CallbackRegistry | 187 |
178 : public internal::CallbackRegistryBase<Callback<void(const Details&)> > { | 188 $range ARITY 0..MAX_ARITY |
| 189 $for ARITY [[ |
| 190 $range ARG 1..ARITY |
| 191 |
| 192 $if ARITY == 0 [[ |
| 193 template <> |
| 194 class CallbackRegistry<void(void)> |
| 195 : public internal::CallbackRegistryBase<Callback<void(void)> > { |
| 196 ]] $else [[ |
| 197 template <$for ARG , [[typename A$(ARG)]]> |
| 198 class CallbackRegistry<void($for ARG , [[const A$(ARG)&]])> |
| 199 : public internal::CallbackRegistryBase< |
| 200 Callback<void($for ARG , [[const A$(ARG)&]])> > { |
| 201 ]] |
| 202 |
179 public: | 203 public: |
| 204 $if ARITY == 0 [[ |
| 205 |
| 206 typedef Callback<void(void)> CallbackType; |
| 207 ]] $else [[ |
| 208 |
| 209 typedef Callback<void($for ARG , [[const A$(ARG)&]])> CallbackType; |
| 210 ]] |
| 211 |
| 212 |
180 CallbackRegistry() {} | 213 CallbackRegistry() {} |
181 | 214 |
182 // Execute all active callbacks with |details| parameter. | 215 void Notify($for ARG , [[const A$(ARG)& a$(ARG)]]) { |
183 void Notify(const Details& details) { | 216 typename internal::CallbackRegistryBase<CallbackType>::Iterator it = |
184 typename internal::CallbackRegistryBase< | 217 this->GetIterator(); |
185 Callback<void(const Details&)> >::Iterator it = this->GetIterator(); | 218 CallbackType* cb; |
186 Callback<void(const Details&)>* cb; | |
187 while((cb = it.GetNext()) != NULL) { | 219 while((cb = it.GetNext()) != NULL) { |
188 cb->Run(details); | 220 cb->Run($for ARG , [[a$(ARG)]]); |
189 } | |
190 } | |
191 | |
192 private: | |
193 DISALLOW_COPY_AND_ASSIGN(CallbackRegistry); | |
194 }; | |
195 | |
196 template <> class CallbackRegistry<void> | |
197 : public internal::CallbackRegistryBase<Closure> { | |
198 public: | |
199 CallbackRegistry() {} | |
200 | |
201 // Execute all active callbacks. | |
202 void Notify() { | |
203 Iterator it = this->GetIterator(); | |
204 Closure* cb; | |
205 while((cb = it.GetNext()) != NULL) { | |
206 cb->Run(); | |
207 } | 221 } |
208 } | 222 } |
209 | 223 |
210 private: | 224 private: |
211 DISALLOW_COPY_AND_ASSIGN(CallbackRegistry); | 225 DISALLOW_COPY_AND_ASSIGN(CallbackRegistry); |
| 226 |
| 227 |
212 }; | 228 }; |
213 | 229 |
| 230 |
| 231 ]] $$ for ARITY |
214 } // namespace base | 232 } // namespace base |
215 | 233 |
216 #endif // BASE_CALLBACK_REGISTRY_H_ | 234 #endif // BASE_CALLBACK_REGISTRY_H |
OLD | NEW |