| Index: base/callback_registry.h.pump
|
| diff --git a/base/callback_registry.h b/base/callback_registry.h.pump
|
| similarity index 74%
|
| copy from base/callback_registry.h
|
| copy to base/callback_registry.h.pump
|
| index fcacbf549f2a79412130e0b1d902715a9663cca0..fff1dc89e7bf8aad4a820d99d83813b7a78ff2ee 100644
|
| --- a/base/callback_registry.h
|
| +++ b/base/callback_registry.h.pump
|
| @@ -1,3 +1,13 @@
|
| +$$ This is a pump file for generating file templates. Pump is a python
|
| +$$ script that is part of the Google Test suite of utilities. Description
|
| +$$ can be found here:
|
| +$$
|
| +$$ http://code.google.com/p/googletest/wiki/PumpManual
|
| +$$
|
| +
|
| +$$ See comment for MAX_ARITY in base/bind.h.pump.
|
| +$var MAX_ARITY = 7
|
| +
|
| // Copyright 2013 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
| @@ -9,6 +19,7 @@
|
|
|
| #include "base/basictypes.h"
|
| #include "base/callback.h"
|
| +#include "base/callback_internal.h"
|
| #include "base/compiler_specific.h"
|
| #include "base/logging.h"
|
| #include "base/memory/scoped_ptr.h"
|
| @@ -28,8 +39,8 @@
|
| //
|
| // typedef base::Callback<void(const Foo&)> OnFooCallback;
|
| //
|
| -// scoped_ptr<base::CallbackRegistry<Foo>::Subscription> RegisterCallback(
|
| -// const OnFooCallback& cb) {
|
| +// scoped_ptr<base::CallbackRegistry<void(const Foo&)>::Subscription>
|
| +// RegisterCallback(const OnFooCallback& cb) {
|
| // return callback_registry_.Add(cb);
|
| // }
|
| //
|
| @@ -38,7 +49,7 @@
|
| // callback_registry_.Notify(foo);
|
| // }
|
| //
|
| -// base::CallbackRegistry<Foo> callback_registry_;
|
| +// base::CallbackRegistry<void(const Foo&)> callback_registry_;
|
| // };
|
| //
|
| //
|
| @@ -173,37 +184,51 @@ class CallbackRegistryBase {
|
|
|
| } // namespace internal
|
|
|
| -template <typename Details>
|
| -class CallbackRegistry
|
| - : public internal::CallbackRegistryBase<Callback<void(const Details&)> > {
|
| - public:
|
| - CallbackRegistry() {}
|
| +template <typename Sig> class CallbackRegistry;
|
|
|
| - // Execute all active callbacks with |details| parameter.
|
| - void Notify(const Details& details) {
|
| - typename internal::CallbackRegistryBase<
|
| - Callback<void(const Details&)> >::Iterator it = this->GetIterator();
|
| - Callback<void(const Details&)>* cb;
|
| - while((cb = it.GetNext()) != NULL) {
|
| - cb->Run(details);
|
| - }
|
| - }
|
|
|
| -private:
|
| - DISALLOW_COPY_AND_ASSIGN(CallbackRegistry);
|
| -};
|
| +$range ARITY 0..MAX_ARITY
|
| +$for ARITY [[
|
| +$range ARG 1..ARITY
|
| +
|
| +$if ARITY == 0 [[
|
| +template <>
|
| +class CallbackRegistry<void(void)>
|
| + : public internal::CallbackRegistryBase<Callback<void(void)> > {
|
| +]] $else [[
|
| +template <$for ARG , [[typename A$(ARG)]]>
|
| +class CallbackRegistry<void($for ARG , [[A$(ARG)]])>
|
| + : public internal::CallbackRegistryBase<
|
| + Callback<void($for ARG , [[A$(ARG)]])> > {
|
| +]]
|
|
|
| -template <> class CallbackRegistry<void>
|
| - : public internal::CallbackRegistryBase<Closure> {
|
| public:
|
| +$if ARITY == 0 [[
|
| +
|
| + typedef Callback<void(void)> CallbackType;
|
| +]] $else [[
|
| +
|
| + typedef Callback<void($for ARG , [[A$(ARG)]])> CallbackType;
|
| +]]
|
| +
|
| +
|
| CallbackRegistry() {}
|
|
|
| - // Execute all active callbacks.
|
| - void Notify() {
|
| - Iterator it = this->GetIterator();
|
| - Closure* cb;
|
| + void Notify($for ARG ,
|
| + [[typename internal::CallbackParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) {
|
| +$if ARITY == 0 [[
|
| +
|
| + internal::CallbackRegistryBase<CallbackType>::Iterator it =
|
| + this->GetIterator();
|
| +]] $else [[
|
| +
|
| + typename internal::CallbackRegistryBase<CallbackType>::Iterator it =
|
| + this->GetIterator();
|
| +]]
|
| +
|
| + CallbackType* cb;
|
| while((cb = it.GetNext()) != NULL) {
|
| - cb->Run();
|
| + cb->Run($for ARG , [[a$(ARG)]]);
|
| }
|
| }
|
|
|
| @@ -211,6 +236,8 @@ template <> class CallbackRegistry<void>
|
| DISALLOW_COPY_AND_ASSIGN(CallbackRegistry);
|
| };
|
|
|
| +
|
| +]] $$ for ARITY
|
| } // namespace base
|
|
|
| -#endif // BASE_CALLBACK_REGISTRY_H_
|
| +#endif // BASE_CALLBACK_REGISTRY_H
|
|
|