| Index: base/prebind.h.pump
|
| diff --git a/base/prebind.h.pump b/base/prebind.h.pump
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ed47fac0b16ab1a3d0e55fff4346ec5f9ca582e0
|
| --- /dev/null
|
| +++ b/base/prebind.h.pump
|
| @@ -0,0 +1,192 @@
|
| +$$ 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
|
| +$$
|
| +// Copyright (c) 2011 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.
|
| +
|
| +#ifndef BASE_PREBIND_H_
|
| +#define BASE_PREBIND_H_
|
| +
|
| +#include "base/prebind_helpers.h"
|
| +#include "base/uber_callback.h"
|
| +
|
| +namespace base {
|
| +namespace internal {
|
| +
|
| +// The method by which a function is invoked is determined by 3 different
|
| +// dimensions:
|
| +//
|
| +// 1) The type of function (normal, method, const-method)
|
| +// 2) The arity of the function
|
| +// 3) The number of bound parameters.
|
| +//
|
| +// The FunctionTraitsN classes unwrap the function signature type to
|
| +// specialize based on the first two dimensions. The N in FunctionTraitsN
|
| +// specifies the 3rd dimension.
|
| +
|
| +$var MAX_ARITY = 6
|
| +
|
| +$range PREBOUND 0..MAX_ARITY
|
| +$for PREBOUND [[
|
| +
|
| +template <typename StorageType, typename Sig>
|
| +struct FunctionTraits$(PREBOUND);
|
| +
|
| +$range ARITY 0..MAX_ARITY
|
| +$for ARITY [[
|
| +
|
| +$var UNBOUND = ARITY - PREBOUND
|
| +$if UNBOUND >= 0 [[
|
| +
|
| +$$ Variables for function traits generation.
|
| +$range ARG 1..ARITY
|
| +$range BOUND_ARG 1..PREBOUND
|
| +$range UNBOUND_ARG (ARITY - UNBOUND + 1)..ARITY
|
| +
|
| +$$ Variables for method traits generation. We are always short one arity since
|
| +$$ the first bound parameter is the object.
|
| +$var M_ARITY = ARITY - 1
|
| +$range M_ARG 1..M_ARITY
|
| +$range M_BOUND_ARG 2..PREBOUND
|
| +$range M_UNBOUND_ARG (M_ARITY - UNBOUND + 1)..M_ARITY
|
| +
|
| +// Function: Arity $(ARITY) -> $(UNBOUND).
|
| +template <typename StorageType, typename R[[]]
|
| +$if ARITY > 0 [[,]][[]]
|
| +$for ARG , [[typename X$(ARG)]]>
|
| +struct FunctionTraits$(PREBOUND)<StorageType, R(*)($for ARG , [[X$(ARG)]])> {
|
| + static const bool kShouldRef = false;
|
| + static R DoInvoke(internal::InvokerStorageBase* base[[]]
|
| +$if UNBOUND != 0 [[, ]][[]]
|
| +$for UNBOUND_ARG , [[const X$(UNBOUND_ARG)& x$(UNBOUND_ARG)]]) {
|
| + StorageType* invoker = static_cast<StorageType*>(base);
|
| + return invoker->f_($for BOUND_ARG , [[Unwrap(invoker->p$(BOUND_ARG)_)]][[]]
|
| +$$ Add comma if there are both boudn and unbound args.
|
| +$if UNBOUND > 0 [[$if PREBOUND > 0 [[, ]]]][[]]
|
| +$for UNBOUND_ARG , [[x$(UNBOUND_ARG)]]);
|
| + }
|
| +};
|
| +
|
| +$if PREBOUND > 0 [[
|
| +
|
| +// Method: Arity $(M_ARITY) -> $(UNBOUND).
|
| +template <typename StorageType, typename R, typename T[[]]
|
| +$if M_ARITY > 0[[, ]] $for M_ARG , [[typename X$(M_ARG)]]>
|
| +struct FunctionTraits$(PREBOUND)<StorageType, R(T::*)($for M_ARG , [[X$(M_ARG)]])> {
|
| + static const bool kShouldRef = true;
|
| + static R DoInvoke(internal::InvokerStorageBase* base[[]]
|
| +$if UNBOUND > 0 [[, ]][[]]
|
| +$for M_UNBOUND_ARG , [[const X$(M_UNBOUND_ARG)& x$(M_UNBOUND_ARG)]]) {
|
| + StorageType* invoker = static_cast<StorageType*>(base);
|
| + return (Unwrap(invoker->p1_)->*invoker->f_)([[]]
|
| +$for M_BOUND_ARG , [[Unwrap(invoker->p$(M_BOUND_ARG)_)]][[]]
|
| +$if UNBOUND > 0 [[$if PREBOUND > 1 [[, ]]]][[]]
|
| +$for M_UNBOUND_ARG , [[x$(M_UNBOUND_ARG)]]);
|
| + }
|
| +};
|
| +
|
| +// Const Method: Arity $(M_ARITY) -> $(UNBOUND).
|
| +template <typename StorageType, typename R, typename T[[]]
|
| +$if M_ARITY > 0[[, ]] $for M_ARG , [[typename X$(M_ARG)]]>
|
| +struct FunctionTraits$(PREBOUND)<StorageType, R(T::*)($for M_ARG , [[X$(M_ARG)]]) const> {
|
| + static const bool kShouldRef = true;
|
| + static R DoInvoke(internal::InvokerStorageBase* base[[]]
|
| +$if UNBOUND > 0 [[, ]]
|
| +[[]] $for M_UNBOUND_ARG , [[const X$(M_UNBOUND_ARG)& x$(M_UNBOUND_ARG)]]) {
|
| + StorageType* invoker = static_cast<StorageType*>(base);
|
| + return (Unwrap(invoker->p1_)->*invoker->f_)([[]]
|
| +$for M_BOUND_ARG , [[Unwrap(invoker->p$(M_BOUND_ARG)_)]][[]]
|
| +$if UNBOUND > 0 [[$if PREBOUND > 1 [[, ]]]][[]]
|
| +$for M_UNBOUND_ARG , [[x$(M_UNBOUND_ARG)]]);
|
| + }
|
| +};
|
| +
|
| +]] $$ if PREBOUND
|
| +
|
| +]] $$ if UNBOUND
|
| +]] $$ for ARITY
|
| +]] $$ for PREBOUND
|
| +
|
| +
|
| +// These are the actual storage classes for the invokers.
|
| +
|
| +$for PREBOUND [[
|
| +$range BOUND_ARG 1..PREBOUND
|
| +
|
| +template <typename Sig[[]]
|
| +$if PREBOUND > 0 [[, ]]
|
| +$for BOUND_ARG , [[typename P$(BOUND_ARG)]]>
|
| +class InvokerStorage$(PREBOUND) : public internal::InvokerStorageBase {
|
| + public:
|
| + typedef InvokerStorage$(PREBOUND) StorageType;
|
| + typedef FunctionTraits$(PREBOUND)<StorageType, Sig> FunctionTraits;
|
| +
|
| + InvokerStorage$(PREBOUND)(Sig f
|
| +$if PREBOUND > 0 [[, ]]
|
| +$for BOUND_ARG , [[const P$(BOUND_ARG)& p$(BOUND_ARG)]])
|
| + : f_(f)[[]]
|
| +$if PREBOUND == 0 [[
|
| + {
|
| +
|
| +]] $else [[
|
| +, $for BOUND_ARG , [[p$(BOUND_ARG)_(p$(BOUND_ARG))]] {
|
| + MaybeRefcount<FunctionTraits::kShouldRef, P1>::AddRef(p1_);
|
| +
|
| +]]
|
| + }
|
| +
|
| + virtual ~InvokerStorage$(PREBOUND)() {
|
| +$if PREBOUND > 0 [[
|
| +
|
| + MaybeRefcount<FunctionTraits::kShouldRef, P1>::Release(p1_);
|
| +
|
| +]]
|
| + }
|
| +
|
| + Sig f_;
|
| +
|
| +$for BOUND_ARG [[
|
| + P$(BOUND_ARG) p$(BOUND_ARG)_;
|
| +
|
| +]]
|
| +};
|
| +
|
| +]] $$ for PREBOUND
|
| +
|
| +} // namespace internal
|
| +
|
| +$for PREBOUND [[
|
| +$range BOUND_ARG 1..PREBOUND
|
| +
|
| +$if PREBOUND == 0 [[
|
| +
|
| +template <typename Sig>
|
| +internal::InvokerStorageHolder<internal::InvokerStorage0<Sig> >
|
| +Prebind(Sig f) {
|
| + return internal::MakeInvokerStorageHolder(
|
| + new internal::InvokerStorage0<Sig>(f));
|
| +}
|
| +
|
| +]] $else [[
|
| +
|
| +template <typename Sig, $for BOUND_ARG , [[typename P$(BOUND_ARG)]]>
|
| +internal::InvokerStorageHolder<internal::InvokerStorage$(PREBOUND)<Sig,
|
| +$for BOUND_ARG , [[P$(BOUND_ARG)]]> >
|
| +Prebind(Sig f, $for BOUND_ARG , [[const P$(BOUND_ARG)& p$(BOUND_ARG)]]) {
|
| + return internal::MakeInvokerStorageHolder(
|
| + new internal::InvokerStorage$(PREBOUND)<Sig, [[]]
|
| +$for BOUND_ARG , [[P$(BOUND_ARG)]]>(
|
| + f, $for BOUND_ARG , [[p$(BOUND_ARG)]]));
|
| +}
|
| +
|
| +]]
|
| +
|
| +]] $$ for PREBOUND
|
| +
|
| +} // namespace base
|
| +
|
| +#endif // BASE_PREBIND_H_
|
|
|