Googletest export
Remove linked_ptr and use std::shared_ptr instead PiperOrigin-RevId: 218618184
This commit is contained in:
		
				
					committed by
					
						
						Gennadiy Civil
					
				
			
			
				
	
			
			
			
						parent
						
							a50e4f05b3
						
					
				
				
					commit
					b57c703963
				
			@@ -42,7 +42,6 @@
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <utility>
 | 
			
		||||
 | 
			
		||||
@@ -347,7 +346,9 @@ class ActionInterface {
 | 
			
		||||
// An Action<F> is a copyable and IMMUTABLE (except by assignment)
 | 
			
		||||
// object that represents an action to be taken when a mock function
 | 
			
		||||
// of type F is called.  The implementation of Action<T> is just a
 | 
			
		||||
// std::shared_ptr to const ActionInterface<T>. Don't inherit from Action!
 | 
			
		||||
// linked_ptr to const ActionInterface<T>, so copying is fairly cheap.
 | 
			
		||||
// Don't inherit from Action!
 | 
			
		||||
//
 | 
			
		||||
// You can view an object implementing ActionInterface<F> as a
 | 
			
		||||
// concrete action (including its current state), and an Action<F>
 | 
			
		||||
// object as a handle to it.
 | 
			
		||||
@@ -424,7 +425,7 @@ class Action {
 | 
			
		||||
#if GTEST_LANG_CXX11
 | 
			
		||||
  ::std::function<F> fun_;
 | 
			
		||||
#endif
 | 
			
		||||
  std::shared_ptr<ActionInterface<F>> impl_;
 | 
			
		||||
  internal::linked_ptr<ActionInterface<F> > impl_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// The PolymorphicAction class template makes it easy to implement a
 | 
			
		||||
@@ -518,7 +519,7 @@ class ActionAdaptor : public ActionInterface<F1> {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  const std::shared_ptr<ActionInterface<F2>> impl_;
 | 
			
		||||
  const internal::linked_ptr<ActionInterface<F2> > impl_;
 | 
			
		||||
 | 
			
		||||
  GTEST_DISALLOW_ASSIGN_(ActionAdaptor);
 | 
			
		||||
};
 | 
			
		||||
@@ -600,7 +601,7 @@ class ReturnAction {
 | 
			
		||||
    // Result to call.  ImplicitCast_ forces the compiler to convert R to
 | 
			
		||||
    // Result without considering explicit constructors, thus resolving the
 | 
			
		||||
    // ambiguity. value_ is then initialized using its copy constructor.
 | 
			
		||||
    explicit Impl(const std::shared_ptr<R>& value)
 | 
			
		||||
    explicit Impl(const linked_ptr<R>& value)
 | 
			
		||||
        : value_before_cast_(*value),
 | 
			
		||||
          value_(ImplicitCast_<Result>(value_before_cast_)) {}
 | 
			
		||||
 | 
			
		||||
@@ -625,7 +626,7 @@ class ReturnAction {
 | 
			
		||||
    typedef typename Function<F>::Result Result;
 | 
			
		||||
    typedef typename Function<F>::ArgumentTuple ArgumentTuple;
 | 
			
		||||
 | 
			
		||||
    explicit Impl(const std::shared_ptr<R>& wrapper)
 | 
			
		||||
    explicit Impl(const linked_ptr<R>& wrapper)
 | 
			
		||||
        : performed_(false), wrapper_(wrapper) {}
 | 
			
		||||
 | 
			
		||||
    virtual Result Perform(const ArgumentTuple&) {
 | 
			
		||||
@@ -637,12 +638,12 @@ class ReturnAction {
 | 
			
		||||
 | 
			
		||||
   private:
 | 
			
		||||
    bool performed_;
 | 
			
		||||
    const std::shared_ptr<R> wrapper_;
 | 
			
		||||
    const linked_ptr<R> wrapper_;
 | 
			
		||||
 | 
			
		||||
    GTEST_DISALLOW_ASSIGN_(Impl);
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  const std::shared_ptr<R> value_;
 | 
			
		||||
  const linked_ptr<R> value_;
 | 
			
		||||
 | 
			
		||||
  GTEST_DISALLOW_ASSIGN_(ReturnAction);
 | 
			
		||||
};
 | 
			
		||||
@@ -865,7 +866,7 @@ class SetArgumentPointeeAction<N, Proto, true> {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  const std::shared_ptr<Proto> proto_;
 | 
			
		||||
  const internal::linked_ptr<Proto> proto_;
 | 
			
		||||
 | 
			
		||||
  GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
 | 
			
		||||
};
 | 
			
		||||
@@ -930,7 +931,7 @@ class InvokeCallbackWithoutArgsAction {
 | 
			
		||||
  Result Perform(const ArgumentTuple&) const { return callback_->Run(); }
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  const std::shared_ptr<CallbackType> callback_;
 | 
			
		||||
  const internal::linked_ptr<CallbackType> callback_;
 | 
			
		||||
 | 
			
		||||
  GTEST_DISALLOW_ASSIGN_(InvokeCallbackWithoutArgsAction);
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -40,7 +40,6 @@
 | 
			
		||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
 | 
			
		||||
 | 
			
		||||
#include <limits.h>
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <ostream>  // NOLINT
 | 
			
		||||
#include "gmock/internal/gmock-port.h"
 | 
			
		||||
#include "gtest/gtest.h"
 | 
			
		||||
@@ -82,8 +81,9 @@ class CardinalityInterface {
 | 
			
		||||
 | 
			
		||||
// A Cardinality is a copyable and IMMUTABLE (except by assignment)
 | 
			
		||||
// object that specifies how many times a mock function is expected to
 | 
			
		||||
// be called.  The implementation of Cardinality is just a std::shared_ptr
 | 
			
		||||
// to const CardinalityInterface. Don't inherit from Cardinality!
 | 
			
		||||
// be called.  The implementation of Cardinality is just a linked_ptr
 | 
			
		||||
// to const CardinalityInterface, so copying is fairly cheap.
 | 
			
		||||
// Don't inherit from Cardinality!
 | 
			
		||||
class GTEST_API_ Cardinality {
 | 
			
		||||
 public:
 | 
			
		||||
  // Constructs a null cardinality.  Needed for storing Cardinality
 | 
			
		||||
@@ -123,7 +123,7 @@ class GTEST_API_ Cardinality {
 | 
			
		||||
                                        ::std::ostream* os);
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  std::shared_ptr<const CardinalityInterface> impl_;
 | 
			
		||||
  internal::linked_ptr<const CardinalityInterface> impl_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Creates a cardinality that allows at least n calls.
 | 
			
		||||
 
 | 
			
		||||
@@ -41,7 +41,6 @@
 | 
			
		||||
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
 | 
			
		||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
 | 
			
		||||
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <utility>
 | 
			
		||||
 | 
			
		||||
#include "gmock/gmock-actions.h"
 | 
			
		||||
@@ -349,7 +348,7 @@ class InvokeCallbackAction {
 | 
			
		||||
        callback_.get(), args);
 | 
			
		||||
  }
 | 
			
		||||
 private:
 | 
			
		||||
  const std::shared_ptr<CallbackType> callback_;
 | 
			
		||||
  const linked_ptr<CallbackType> callback_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// An INTERNAL macro for extracting the type of a tuple field.  It's
 | 
			
		||||
 
 | 
			
		||||
@@ -43,7 +43,6 @@ $$}} This meta comment fixes auto-indentation in editors.
 | 
			
		||||
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
 | 
			
		||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
 | 
			
		||||
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <utility>
 | 
			
		||||
 | 
			
		||||
#include "gmock/gmock-actions.h"
 | 
			
		||||
@@ -119,7 +118,7 @@ class InvokeCallbackAction {
 | 
			
		||||
        callback_.get(), args);
 | 
			
		||||
  }
 | 
			
		||||
 private:
 | 
			
		||||
  const std::shared_ptr<CallbackType> callback_;
 | 
			
		||||
  const linked_ptr<CallbackType> callback_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// An INTERNAL macro for extracting the type of a tuple field.  It's
 | 
			
		||||
 
 | 
			
		||||
@@ -43,15 +43,14 @@
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
#include <iterator>
 | 
			
		||||
#include <limits>
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <ostream>  // NOLINT
 | 
			
		||||
#include <sstream>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <utility>
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include "gtest/gtest.h"
 | 
			
		||||
#include "gmock/internal/gmock-internal-utils.h"
 | 
			
		||||
#include "gmock/internal/gmock-port.h"
 | 
			
		||||
#include "gtest/gtest.h"
 | 
			
		||||
 | 
			
		||||
#if GTEST_HAS_STD_INITIALIZER_LIST_
 | 
			
		||||
# include <initializer_list>  // NOLINT -- must be after gtest.h
 | 
			
		||||
@@ -339,15 +338,29 @@ class MatcherBase {
 | 
			
		||||
  virtual ~MatcherBase() {}
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  std::shared_ptr<const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)>> impl_;
 | 
			
		||||
  // shared_ptr (util/gtl/shared_ptr.h) and linked_ptr have similar
 | 
			
		||||
  // interfaces.  The former dynamically allocates a chunk of memory
 | 
			
		||||
  // to hold the reference count, while the latter tracks all
 | 
			
		||||
  // references using a circular linked list without allocating
 | 
			
		||||
  // memory.  It has been observed that linked_ptr performs better in
 | 
			
		||||
  // typical scenarios.  However, shared_ptr can out-perform
 | 
			
		||||
  // linked_ptr when there are many more uses of the copy constructor
 | 
			
		||||
  // than the default constructor.
 | 
			
		||||
  //
 | 
			
		||||
  // If performance becomes a problem, we should see if using
 | 
			
		||||
  // shared_ptr helps.
 | 
			
		||||
  ::testing::internal::linked_ptr<
 | 
			
		||||
      const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> >
 | 
			
		||||
      impl_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
}  // namespace internal
 | 
			
		||||
 | 
			
		||||
// A Matcher<T> is a copyable and IMMUTABLE (except by assignment)
 | 
			
		||||
// object that can check whether a value of type T matches.  The
 | 
			
		||||
// implementation of Matcher<T> is just a std::shared_ptr to const
 | 
			
		||||
// MatcherInterface<T>.  Don't inherit from Matcher!
 | 
			
		||||
// implementation of Matcher<T> is just a linked_ptr to const
 | 
			
		||||
// MatcherInterface<T>, so copying is fairly cheap.  Don't inherit
 | 
			
		||||
// from Matcher!
 | 
			
		||||
template <typename T>
 | 
			
		||||
class Matcher : public internal::MatcherBase<T> {
 | 
			
		||||
 public:
 | 
			
		||||
@@ -1573,7 +1586,7 @@ class MatchesRegexMatcher {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  const std::shared_ptr<const RE> regex_;
 | 
			
		||||
  const internal::linked_ptr<const RE> regex_;
 | 
			
		||||
  const bool full_match_;
 | 
			
		||||
 | 
			
		||||
  GTEST_DISALLOW_ASSIGN_(MatchesRegexMatcher);
 | 
			
		||||
 
 | 
			
		||||
@@ -62,7 +62,6 @@
 | 
			
		||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
 | 
			
		||||
 | 
			
		||||
#include <map>
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <set>
 | 
			
		||||
#include <sstream>
 | 
			
		||||
#include <string>
 | 
			
		||||
@@ -220,7 +219,8 @@ class GTEST_API_ UntypedFunctionMockerBase {
 | 
			
		||||
 protected:
 | 
			
		||||
  typedef std::vector<const void*> UntypedOnCallSpecs;
 | 
			
		||||
 | 
			
		||||
  using UntypedExpectations = std::vector<std::shared_ptr<ExpectationBase>>;
 | 
			
		||||
  typedef std::vector<internal::linked_ptr<ExpectationBase> >
 | 
			
		||||
  UntypedExpectations;
 | 
			
		||||
 | 
			
		||||
  // Returns an Expectation object that references and co-owns exp,
 | 
			
		||||
  // which must be an expectation on this mock function.
 | 
			
		||||
@@ -498,7 +498,12 @@ class GTEST_API_ Mock {
 | 
			
		||||
//   - Constness is shallow: a const Expectation object itself cannot
 | 
			
		||||
//     be modified, but the mutable methods of the ExpectationBase
 | 
			
		||||
//     object it references can be called via expectation_base().
 | 
			
		||||
 | 
			
		||||
//   - The constructors and destructor are defined out-of-line because
 | 
			
		||||
//     the Symbian WINSCW compiler wants to otherwise instantiate them
 | 
			
		||||
//     when it sees this class definition, at which point it doesn't have
 | 
			
		||||
//     ExpectationBase available yet, leading to incorrect destruction
 | 
			
		||||
//     in the linked_ptr (or compilation errors if using a checking
 | 
			
		||||
//     linked_ptr).
 | 
			
		||||
class GTEST_API_ Expectation {
 | 
			
		||||
 public:
 | 
			
		||||
  // Constructs a null object that doesn't reference any expectation.
 | 
			
		||||
@@ -550,15 +555,16 @@ class GTEST_API_ Expectation {
 | 
			
		||||
  typedef ::std::set<Expectation, Less> Set;
 | 
			
		||||
 | 
			
		||||
  Expectation(
 | 
			
		||||
      const std::shared_ptr<internal::ExpectationBase>& expectation_base);
 | 
			
		||||
      const internal::linked_ptr<internal::ExpectationBase>& expectation_base);
 | 
			
		||||
 | 
			
		||||
  // Returns the expectation this object references.
 | 
			
		||||
  const std::shared_ptr<internal::ExpectationBase>& expectation_base() const {
 | 
			
		||||
  const internal::linked_ptr<internal::ExpectationBase>&
 | 
			
		||||
  expectation_base() const {
 | 
			
		||||
    return expectation_base_;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // A shared_ptr that co-owns the expectation this handle references.
 | 
			
		||||
  std::shared_ptr<internal::ExpectationBase> expectation_base_;
 | 
			
		||||
  // A linked_ptr that co-owns the expectation this handle references.
 | 
			
		||||
  internal::linked_ptr<internal::ExpectationBase> expectation_base_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// A set of expectation handles.  Useful in the .After() clause of
 | 
			
		||||
@@ -640,8 +646,11 @@ class GTEST_API_ Sequence {
 | 
			
		||||
  void AddExpectation(const Expectation& expectation) const;
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  // The last expectation in this sequence.
 | 
			
		||||
  std::shared_ptr<Expectation> last_expectation_;
 | 
			
		||||
  // The last expectation in this sequence.  We use a linked_ptr here
 | 
			
		||||
  // because Sequence objects are copyable and we want the copies to
 | 
			
		||||
  // be aliases.  The linked_ptr allows the copies to co-own and share
 | 
			
		||||
  // the same Expectation object.
 | 
			
		||||
  internal::linked_ptr<Expectation> last_expectation_;
 | 
			
		||||
};  // class Sequence
 | 
			
		||||
 | 
			
		||||
// An object of this type causes all EXPECT_CALL() statements
 | 
			
		||||
@@ -864,7 +873,7 @@ class GTEST_API_ ExpectationBase {
 | 
			
		||||
  Cardinality cardinality_;            // The cardinality of the expectation.
 | 
			
		||||
  // The immediate pre-requisites (i.e. expectations that must be
 | 
			
		||||
  // satisfied before this expectation can be matched) of this
 | 
			
		||||
  // expectation.  We use std::shared_ptr in the set because we want an
 | 
			
		||||
  // expectation.  We use linked_ptr in the set because we want an
 | 
			
		||||
  // Expectation object to be co-owned by its FunctionMocker and its
 | 
			
		||||
  // successors.  This allows multiple mock objects to be deleted at
 | 
			
		||||
  // different times.
 | 
			
		||||
@@ -1622,7 +1631,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
 | 
			
		||||
    Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
 | 
			
		||||
    TypedExpectation<F>* const expectation =
 | 
			
		||||
        new TypedExpectation<F>(this, file, line, source_text, m);
 | 
			
		||||
    const std::shared_ptr<ExpectationBase> untyped_expectation(expectation);
 | 
			
		||||
    const linked_ptr<ExpectationBase> untyped_expectation(expectation);
 | 
			
		||||
    // See the definition of untyped_expectations_ for why access to
 | 
			
		||||
    // it is unprotected here.
 | 
			
		||||
    untyped_expectations_.push_back(untyped_expectation);
 | 
			
		||||
 
 | 
			
		||||
@@ -92,6 +92,15 @@ inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) {
 | 
			
		||||
template <typename Element>
 | 
			
		||||
inline Element* GetRawPointer(Element* p) { return p; }
 | 
			
		||||
 | 
			
		||||
// This comparator allows linked_ptr to be stored in sets.
 | 
			
		||||
template <typename T>
 | 
			
		||||
struct LinkedPtrLessThan {
 | 
			
		||||
  bool operator()(const ::testing::internal::linked_ptr<T>& lhs,
 | 
			
		||||
                  const ::testing::internal::linked_ptr<T>& rhs) const {
 | 
			
		||||
    return lhs.get() < rhs.get();
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Symbian compilation can be done with wchar_t being either a native
 | 
			
		||||
// type or a typedef.  Using Google Mock with OpenC without wchar_t
 | 
			
		||||
// should require the definition of _STLP_NO_WCHAR_T.
 | 
			
		||||
 
 | 
			
		||||
@@ -52,6 +52,7 @@
 | 
			
		||||
// here, as Google Mock depends on Google Test.  Only add a utility
 | 
			
		||||
// here if it's truly specific to Google Mock.
 | 
			
		||||
 | 
			
		||||
#include "gtest/internal/gtest-linked_ptr.h"
 | 
			
		||||
#include "gtest/internal/gtest-port.h"
 | 
			
		||||
#include "gmock/internal/custom/gmock-port.h"
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user