// Copyright (c) 2016 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 QUICHE_COMMON_PLATFORM_API_QUICHE_REFERENCE_COUNTED_H_ #define QUICHE_COMMON_PLATFORM_API_QUICHE_REFERENCE_COUNTED_H_ #include "quiche_platform_impl/quiche_reference_counted_impl.h" #include "quiche/common/platform/api/quiche_export.h" namespace quiche { // Base class for explicitly reference-counted objects in QUIC. class QUICHE_EXPORT QuicheReferenceCounted : public QuicheReferenceCountedImpl { … }; // A class representing a reference counted pointer in QUIC. // // Construct or initialize QuicheReferenceCountedPointer from raw pointer. Here // raw pointer MUST be a newly created object. Reference count of a newly // created object is undefined, but that will be 1 after being added to // QuicheReferenceCountedPointer. // QuicheReferenceCountedPointer is used as a local variable. // QuicheReferenceCountedPointer<T> r_ptr(new T()); // or, equivalently: // QuicheReferenceCountedPointer<T> r_ptr; // T* p = new T(); // r_ptr = T; // // QuicheReferenceCountedPointer is used as a member variable: // MyClass::MyClass() : r_ptr(new T()) {} // // This is WRONG, since *p is not guaranteed to be newly created: // MyClass::MyClass(T* p) : r_ptr(p) {} // // Given an existing QuicheReferenceCountedPointer, create a duplicate that has // its own reference on the object: // QuicheReferenceCountedPointer<T> r_ptr_b(r_ptr_a); // or, equivalently: // QuicheReferenceCountedPointer<T> r_ptr_b = r_ptr_a; // // Given an existing QuicheReferenceCountedPointer, create a // QuicheReferenceCountedPointer that adopts the reference: // QuicheReferenceCountedPointer<T> r_ptr_b(std::move(r_ptr_a)); // or, equivalently: // QuicheReferenceCountedPointer<T> r_ptr_b = std::move(r_ptr_a); template <class T> class QUICHE_NO_EXPORT QuicheReferenceCountedPointer { … }; } // namespace quiche #endif // QUICHE_COMMON_PLATFORM_API_QUICHE_REFERENCE_COUNTED_H_