Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Unified Diff: webrtc/base/bind.h

Issue 2877023002: Move webrtc/{base => rtc_base} (Closed)
Patch Set: update presubmit.py and DEPS include rules Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/base/basictypes_unittest.cc ('k') | webrtc/base/bind_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/bind.h
diff --git a/webrtc/base/bind.h b/webrtc/base/bind.h
index 94eb164986f9b717766a68f6c85d4c10b2e1501a..39d441f00861643e498e2476dd2aeae99b05b823 100644
--- a/webrtc/base/bind.h
+++ b/webrtc/base/bind.h
@@ -61,224 +61,9 @@
#ifndef WEBRTC_BASE_BIND_H_
#define WEBRTC_BASE_BIND_H_
-#include <tuple>
-#include <type_traits>
-#include "webrtc/base/scoped_ref_ptr.h"
-#include "webrtc/base/template_util.h"
-
-#define NONAME
-
-namespace rtc {
-namespace detail {
-// This is needed because the template parameters in Bind can't be resolved
-// if they're used both as parameters of the function pointer type and as
-// parameters to Bind itself: the function pointer parameters are exact
-// matches to the function prototype, but the parameters to bind have
-// references stripped. This trick allows the compiler to dictate the Bind
-// parameter types rather than deduce them.
-template <class T> struct identity { typedef T type; };
-
-// IsRefCounted<T>::value will be true for types that can be used in
-// rtc::scoped_refptr<T>, i.e. types that implements nullary functions AddRef()
-// and Release(), regardless of their return types. AddRef() and Release() can
-// be defined in T or any superclass of T.
-template <typename T>
-class IsRefCounted {
- // This is a complex implementation detail done with SFINAE.
-
- // Define types such that sizeof(Yes) != sizeof(No).
- struct Yes { char dummy[1]; };
- struct No { char dummy[2]; };
- // Define two overloaded template functions with return types of different
- // size. This way, we can use sizeof() on the return type to determine which
- // function the compiler would have chosen. One function will be preferred
- // over the other if it is possible to create it without compiler errors,
- // otherwise the compiler will simply remove it, and default to the less
- // preferred function.
- template <typename R>
- static Yes test(R* r, decltype(r->AddRef(), r->Release(), 42));
- template <typename C> static No test(...);
-
-public:
- // Trick the compiler to tell if it's possible to call AddRef() and Release().
- static const bool value = sizeof(test<T>((T*)nullptr, 42)) == sizeof(Yes);
-};
-
-// TernaryTypeOperator is a helper class to select a type based on a static bool
-// value.
-template <bool condition, typename IfTrueT, typename IfFalseT>
-struct TernaryTypeOperator {};
-
-template <typename IfTrueT, typename IfFalseT>
-struct TernaryTypeOperator<true, IfTrueT, IfFalseT> {
- typedef IfTrueT type;
-};
-
-template <typename IfTrueT, typename IfFalseT>
-struct TernaryTypeOperator<false, IfTrueT, IfFalseT> {
- typedef IfFalseT type;
-};
-
-// PointerType<T>::type will be scoped_refptr<T> for ref counted types, and T*
-// otherwise.
-template <class T>
-struct PointerType {
- typedef typename TernaryTypeOperator<IsRefCounted<T>::value,
- scoped_refptr<T>,
- T*>::type type;
-};
-
-template <typename T>
-class UnretainedWrapper {
- public:
- explicit UnretainedWrapper(T* o) : ptr_(o) {}
- T* get() const { return ptr_; }
-
- private:
- T* ptr_;
-};
-
-} // namespace detail
-
-template <typename T>
-static inline detail::UnretainedWrapper<T> Unretained(T* o) {
- return detail::UnretainedWrapper<T>(o);
-}
-
-template <class ObjectT, class MethodT, class R, typename... Args>
-class MethodFunctor {
- public:
- MethodFunctor(MethodT method, ObjectT* object, Args... args)
- : method_(method), object_(object), args_(args...) {}
- R operator()() const {
- return CallMethod(typename sequence_generator<sizeof...(Args)>::type());
- }
-
- private:
- // Use sequence_generator (see template_util.h) to expand a MethodFunctor
- // with 2 arguments to (std::get<0>(args_), std::get<1>(args_)), for
- // instance.
- template <int... S>
- R CallMethod(sequence<S...>) const {
- return (object_->*method_)(std::get<S>(args_)...);
- }
-
- MethodT method_;
- typename detail::PointerType<ObjectT>::type object_;
- typename std::tuple<typename std::remove_reference<Args>::type...> args_;
-};
-
-template <class ObjectT, class MethodT, class R, typename... Args>
-class UnretainedMethodFunctor {
- public:
- UnretainedMethodFunctor(MethodT method,
- detail::UnretainedWrapper<ObjectT> object,
- Args... args)
- : method_(method), object_(object.get()), args_(args...) {}
- R operator()() const {
- return CallMethod(typename sequence_generator<sizeof...(Args)>::type());
- }
-
- private:
- // Use sequence_generator (see template_util.h) to expand an
- // UnretainedMethodFunctor with 2 arguments to (std::get<0>(args_),
- // std::get<1>(args_)), for instance.
- template <int... S>
- R CallMethod(sequence<S...>) const {
- return (object_->*method_)(std::get<S>(args_)...);
- }
-
- MethodT method_;
- ObjectT* object_;
- typename std::tuple<typename std::remove_reference<Args>::type...> args_;
-};
-
-template <class FunctorT, class R, typename... Args>
-class Functor {
- public:
- Functor(const FunctorT& functor, Args... args)
- : functor_(functor), args_(args...) {}
- R operator()() const {
- return CallFunction(typename sequence_generator<sizeof...(Args)>::type());
- }
-
- private:
- // Use sequence_generator (see template_util.h) to expand a Functor
- // with 2 arguments to (std::get<0>(args_), std::get<1>(args_)), for
- // instance.
- template <int... S>
- R CallFunction(sequence<S...>) const {
- return functor_(std::get<S>(args_)...);
- }
-
- FunctorT functor_;
- typename std::tuple<typename std::remove_reference<Args>::type...> args_;
-};
-
-#define FP_T(x) R (ObjectT::*x)(Args...)
-
-template <class ObjectT, class R, typename... Args>
-MethodFunctor<ObjectT, FP_T(NONAME), R, Args...> Bind(
- FP_T(method),
- ObjectT* object,
- typename detail::identity<Args>::type... args) {
- return MethodFunctor<ObjectT, FP_T(NONAME), R, Args...>(method, object,
- args...);
-}
-
-template <class ObjectT, class R, typename... Args>
-MethodFunctor<ObjectT, FP_T(NONAME), R, Args...> Bind(
- FP_T(method),
- const scoped_refptr<ObjectT>& object,
- typename detail::identity<Args>::type... args) {
- return MethodFunctor<ObjectT, FP_T(NONAME), R, Args...>(method, object.get(),
- args...);
-}
-
-template <class ObjectT, class R, typename... Args>
-UnretainedMethodFunctor<ObjectT, FP_T(NONAME), R, Args...> Bind(
- FP_T(method),
- detail::UnretainedWrapper<ObjectT> object,
- typename detail::identity<Args>::type... args) {
- return UnretainedMethodFunctor<ObjectT, FP_T(NONAME), R, Args...>(
- method, object, args...);
-}
-
-#undef FP_T
-#define FP_T(x) R (ObjectT::*x)(Args...) const
-
-template <class ObjectT, class R, typename... Args>
-MethodFunctor<const ObjectT, FP_T(NONAME), R, Args...> Bind(
- FP_T(method),
- const ObjectT* object,
- typename detail::identity<Args>::type... args) {
- return MethodFunctor<const ObjectT, FP_T(NONAME), R, Args...>(method, object,
- args...);
-}
-template <class ObjectT, class R, typename... Args>
-UnretainedMethodFunctor<const ObjectT, FP_T(NONAME), R, Args...> Bind(
- FP_T(method),
- detail::UnretainedWrapper<const ObjectT> object,
- typename detail::identity<Args>::type... args) {
- return UnretainedMethodFunctor<const ObjectT, FP_T(NONAME), R, Args...>(
- method, object, args...);
-}
-
-#undef FP_T
-#define FP_T(x) R (*x)(Args...)
-
-template <class R, typename... Args>
-Functor<FP_T(NONAME), R, Args...> Bind(
- FP_T(function),
- typename detail::identity<Args>::type... args) {
- return Functor<FP_T(NONAME), R, Args...>(function, args...);
-}
-
-#undef FP_T
-
-} // namespace rtc
-
-#undef NONAME
+// This header is deprecated and is just left here temporarily during
+// refactoring. See https://bugs.webrtc.org/7634 for more details.
+#include "webrtc/rtc_base/bind.h"
#endif // WEBRTC_BASE_BIND_H_
« no previous file with comments | « webrtc/base/basictypes_unittest.cc ('k') | webrtc/base/bind_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698