From 0adeadd2830211f827fd2908e4621f6a4afa810c Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 16 Jan 2019 15:23:44 -0500 Subject: Googletest export Refactor the `Invoke` and `InvokeWithoutArgs` actions: - Replace pump'd classes and functions with templates. - Make the polymorphic actions be polymorphic functors instead. - Fix Invoke(Callback*) to work with subclasses of the callbacks, instead of trying to diagnose that in gmock_doctor. PiperOrigin-RevId: 229604112 --- googlemock/include/gmock/gmock-more-actions.h | 66 +-------------------------- 1 file changed, 1 insertion(+), 65 deletions(-) (limited to 'googlemock/include/gmock/gmock-more-actions.h') diff --git a/googlemock/include/gmock/gmock-more-actions.h b/googlemock/include/gmock/gmock-more-actions.h index 10984081..a052495d 100644 --- a/googlemock/include/gmock/gmock-more-actions.h +++ b/googlemock/include/gmock/gmock-more-actions.h @@ -38,59 +38,13 @@ #define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ #include +#include #include "gmock/gmock-generated-actions.h" namespace testing { namespace internal { -// Implements the Invoke(f) action. The template argument -// FunctionImpl is the implementation type of f, which can be either a -// function pointer or a functor. Invoke(f) can be used as an -// Action as long as f's type is compatible with F (i.e. f can be -// assigned to a tr1::function). -template -class InvokeAction { - public: - // The c'tor makes a copy of function_impl (either a function - // pointer or a functor). - explicit InvokeAction(FunctionImpl function_impl) - : function_impl_(function_impl) {} - - template - Result Perform(const ArgumentTuple& args) { - return InvokeHelper::Invoke(function_impl_, args); - } - - private: - FunctionImpl function_impl_; - - GTEST_DISALLOW_ASSIGN_(InvokeAction); -}; - -// Implements the Invoke(object_ptr, &Class::Method) action. -template -class InvokeMethodAction { - public: - InvokeMethodAction(Class* obj_ptr, MethodPtr method_ptr) - : method_ptr_(method_ptr), obj_ptr_(obj_ptr) {} - - template - Result Perform(const ArgumentTuple& args) const { - return InvokeHelper::InvokeMethod( - obj_ptr_, method_ptr_, args); - } - - private: - // The order of these members matters. Reversing the order can trigger - // warning C4121 in MSVC (see - // http://computer-programming-forum.com/7-vc.net/6fbc30265f860ad1.htm ). - const MethodPtr method_ptr_; - Class* const obj_ptr_; - - GTEST_DISALLOW_ASSIGN_(InvokeMethodAction); -}; - // An internal replacement for std::copy which mimics its behavior. This is // necessary because Visual Studio deprecates ::std::copy, issuing warning 4996. // However Visual Studio 2010 and later do not honor #pragmas which disable that @@ -109,24 +63,6 @@ inline OutputIterator CopyElements(InputIterator first, // Various overloads for Invoke(). -// Creates an action that invokes 'function_impl' with the mock -// function's arguments. -template -PolymorphicAction > Invoke( - FunctionImpl function_impl) { - return MakePolymorphicAction( - internal::InvokeAction(function_impl)); -} - -// Creates an action that invokes the given method on the given object -// with the mock function's arguments. -template -PolymorphicAction > Invoke( - Class* obj_ptr, MethodPtr method_ptr) { - return MakePolymorphicAction( - internal::InvokeMethodAction(obj_ptr, method_ptr)); -} - // The ACTION*() macros trigger warning C4100 (unreferenced formal // parameter) in MSVC with -W4. Unfortunately they cannot be fixed in // the macro definition, as the warnings are generated when the macro -- cgit v1.2.3