Mobile API Reference  MicroStrategy 2019
ReferenceCountedImpl.h
Go to the documentation of this file.
1 //==============================================================================================
2 // FILENAME : ReferenceCountedImpl.h
3 // AUTHOR : vovechkin
4 // CREATION : Dec 13, 2001
5 // Copyright (C) MicroStrategy Incorporated 2001
6 //==============================================================================================
7 #ifndef MSynch_ReferenceCountedImpl_h
8 #define MSynch_ReferenceCountedImpl_h
9 
10 #include "Base/Defines/Asserte.h"
11 #include "Synch/Synch/AtomicLong.h"
13 
14 #ifdef _MSC_VER
15 #pragma warning(disable:4250) // 'class1' : inherits 'class2::member' via dominance
16 #endif
17 
18 namespace MSynch
19 {
43  template< class T = AtomicLong >
45  virtual public MBase::ReferenceCounted
46  {
47  public:
48  // we have to initialize to 0 because class T may be
49  // a built-in type, without a constructor
51  mnReferenceCounter(0)
52  {
53  }
54 
56  virtual void AddRef() const throw()
57  {
58  ++mnReferenceCounter;
59 
60  _ASSERTE(mnReferenceCounter > 0 && mnReferenceCounter < 100000);
61  }
62 
64  virtual void Release() const throw()
65  {
66  // reference counter is corrupted
67  _ASSERTE(mnReferenceCounter > 0 && mnReferenceCounter < 100000);
68 
69  if (mnReferenceCounter == 1)
70  {
71  // At this time we know that we are about to release
72  // the last strong reference to this object.
73 
74  // But before we do, we notify the object via a virtual
75  // method, so that the object has a chance to drop its
76  // weak references (if any).
78  }
79 
80  if (--mnReferenceCounter == 0)
81  {
82  // that was the last reference
83  delete this;
84  }
85  }
86 
91  virtual void ReferenceCountIsAboutToReachZero() const throw()
92  {
93  }
94 
95  inline const T& GetReferenceCount() const throw()
96  {
97  return mnReferenceCounter;
98  }
99 
100  private:
101  mutable T mnReferenceCounter;
102  };
103 }
104 
105 #endif // MSynch_ReferenceCountedImpl_h
ReferenceCountedImpl()
Definition: ReferenceCountedImpl.h:50
const T & GetReferenceCount() const
Definition: ReferenceCountedImpl.h:95
#define _ASSERTE(x)
Definition: Asserte.h:40
Definition: ReferenceCountedImpl.h:18
virtual void ReferenceCountIsAboutToReachZero() const
Definition: ReferenceCountedImpl.h:91
virtual void AddRef() const
Definition: ReferenceCountedImpl.h:56
Definition: ReferenceCountedImpl.h:44
virtual void Release() const
Definition: ReferenceCountedImpl.h:64
Definition: ReferenceCounted.h:58