10 #ifndef __AGORA_REF_COUNTED_OBJECT_H__
11 #define __AGORA_REF_COUNTED_OBJECT_H__
14 #if defined(__AGORA_REF_COUNTED_OBJECT_INTERNAL_H__)
15 #error AgoraRefCountedObject is deprected now, its only purpose is for API compatiable.
18 #include "AgoraRefPtr.h"
19 #include "AgoraAtomicOps.h"
21 #ifndef OPTIONAL_REFCOUNTRELEASESTATUS_SPECIFIER
22 #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)
23 #define OPTIONAL_REFCOUNTRELEASESTATUS_SPECIFIER agora::RefCountReleaseStatus::
25 #define OPTIONAL_REFCOUNTRELEASESTATUS_SPECIFIER
32 explicit RefCounter(
int ref_count) : ref_count_(ref_count) {}
34 void IncRef() { AtomicOps::Increment(&ref_count_); }
40 agora::RefCountReleaseStatus
DecRef() {
41 return (AtomicOps::Decrement(&ref_count_) == 0
42 ? OPTIONAL_REFCOUNTRELEASESTATUS_SPECIFIER kDroppedLastRef
43 : OPTIONAL_REFCOUNTRELEASESTATUS_SPECIFIER kOtherRefsRemained);
54 bool HasOneRef()
const {
return (AtomicOps::AcquireLoad(&ref_count_) == 1); }
60 volatile int ref_count_;
76 #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)
77 explicit RefCountedObject(P0&& p0) : T(std::forward<P0>(p0)), ref_count_(0) {}
82 #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)
83 template <
class P0,
class P1,
class... Args>
85 : T(std::forward<P0>(p0),
87 std::forward<Args>(args)...),
91 virtual void AddRef()
const { ref_count_.IncRef(); }
93 virtual agora::RefCountReleaseStatus Release()
const {
94 const agora::RefCountReleaseStatus status = ref_count_.
DecRef();
95 if (status == OPTIONAL_REFCOUNTRELEASESTATUS_SPECIFIER kDroppedLastRef) {
115 RefCountedObject(
const RefCountedObject&);
116 RefCountedObject& operator=(
const RefCountedObject&);
122 #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)
123 template <
typename T,
typename... types>
124 inline agora_refptr<T> make_refptr(types&&... args) {
125 return agora_refptr<T>(
new RefCountedObject<T>(std::forward<types>(args)...));
128 template <
typename T>
129 inline agora_refptr<T> make_refptr() {
130 return agora_refptr<T>(
new RefCountedObject<T>());
132 template <
typename T,
typename P0>
133 inline agora_refptr<T> make_refptr(
const P0& p0) {
134 return agora_refptr<T>(
new RefCountedObject<T>(p0));