2014-05-13 18:00:26 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright 2011 The WebRTC Project Authors. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Originally these classes are from Chromium.
|
|
|
|
|
// http://src.chromium.org/viewvc/chrome/trunk/src/base/memory/ref_counted.h?view=markup
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// A smart pointer class for reference counted objects. Use this class instead
|
|
|
|
|
// of calling AddRef and Release manually on a reference counted object to
|
|
|
|
|
// avoid common memory leaks caused by forgetting to Release an object
|
|
|
|
|
// reference. Sample usage:
|
|
|
|
|
//
|
|
|
|
|
// class MyFoo : public RefCounted<MyFoo> {
|
|
|
|
|
// ...
|
|
|
|
|
// };
|
|
|
|
|
//
|
|
|
|
|
// void some_function() {
|
|
|
|
|
// scoped_refptr<MyFoo> foo = new MyFoo();
|
|
|
|
|
// foo->Method(param);
|
|
|
|
|
// // |foo| is released when this function returns
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// void some_other_function() {
|
|
|
|
|
// scoped_refptr<MyFoo> foo = new MyFoo();
|
|
|
|
|
// ...
|
2017-02-27 14:06:41 -08:00
|
|
|
// foo = nullptr; // explicitly releases |foo|
|
2014-05-13 18:00:26 +00:00
|
|
|
// ...
|
|
|
|
|
// if (foo)
|
|
|
|
|
// foo->Method(param);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// The above examples show how scoped_refptr<T> acts like a pointer to T.
|
|
|
|
|
// Given two scoped_refptr<T> classes, it is also possible to exchange
|
|
|
|
|
// references between the two objects, like so:
|
|
|
|
|
//
|
|
|
|
|
// {
|
|
|
|
|
// scoped_refptr<MyFoo> a = new MyFoo();
|
|
|
|
|
// scoped_refptr<MyFoo> b;
|
|
|
|
|
//
|
|
|
|
|
// b.swap(a);
|
2017-02-27 14:06:41 -08:00
|
|
|
// // now, |b| references the MyFoo object, and |a| references null.
|
2014-05-13 18:00:26 +00:00
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// To make both |a| and |b| in the above example reference the same MyFoo
|
|
|
|
|
// object, simply use the assignment operator:
|
|
|
|
|
//
|
|
|
|
|
// {
|
|
|
|
|
// scoped_refptr<MyFoo> a = new MyFoo();
|
|
|
|
|
// scoped_refptr<MyFoo> b;
|
|
|
|
|
//
|
|
|
|
|
// b = a;
|
|
|
|
|
// // now, |a| and |b| each own a reference to the same MyFoo object.
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#ifndef WEBRTC_BASE_SCOPED_REF_PTR_H_
|
|
|
|
|
#define WEBRTC_BASE_SCOPED_REF_PTR_H_
|
|
|
|
|
|
|
|
|
|
|
2017-06-28 20:58:07 +02:00
|
|
|
// 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/scoped_ref_ptr.h"
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
#endif // WEBRTC_BASE_SCOPED_REF_PTR_H_
|