MADARA  3.4.1
ScopedArray.inl
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 #ifndef _SCOPED_ARRAY_CPP_
3 #define _SCOPED_ARRAY_CPP_
4 
6 
8 template<typename T>
10 {
11 }
12 
14 template<typename T>
16  : ptr_(ptr ? new Shim(ptr) : 0)
17 {
18  if (increase_count)
19  increment();
20 }
21 
23 template<typename T>
25  : ptr_(rhs.ptr_)
26 {
27  increment();
28 }
29 
31 template<typename T>
33 {
34  decrement();
35 }
36 
39 template<typename T>
41 {
42  decrement();
43 
44  if (ptr)
45  ptr_ = new Shim(ptr);
46  else
47  ptr_ = 0;
48 }
49 
51 template<typename T>
53 {
54  if (this != &rhs)
55  {
56  decrement();
57  ptr_ = rhs.ptr_;
59  }
60 }
61 
63 template<typename T>
65 {
66  return ptr_ != 0 ? ptr_->t_ : 0;
67 }
68 
70 template<typename T>
72 {
73  return ptr_ != 0 ? ptr_->t_ : 0;
74 }
75 
77 template<typename T>
79 {
80  return ptr_ != 0 ? ptr_->t_ : 0;
81 }
82 
84 template<typename T>
86 {
87  return ptr_ != 0 ? ptr_->t_ : 0;
88 }
89 
91 template<typename T>
93 {
94  if (ptr_)
95  ++ptr_->refcount_;
96 }
97 
99 template<typename T>
101 {
102  if (ptr_)
103  {
104  --ptr_->refcount_;
105  if (ptr_->refcount_ <= 0)
106  {
107  delete ptr_;
108  ptr_ = 0;
109  }
110  }
111 }
112 
113 template<typename T>
115 {
116 }
117 
118 template<typename T>
120 {
121  delete[] t_;
122 }
123 
124 #endif /* _REFCOUNTER_CPP_ */
This template class provides transparent reference counting of its template parameter T.
Definition: ScopedArray.h:23
Shim * ptr_
Pointer to the Shim.
Definition: ScopedArray.h:81
void increment(void)
implementation of the increment operation
Definition: ScopedArray.inl:92
void operator=(T *ptr)
assignment operator for times when you don't want the reference increased for incoming ptr
Definition: ScopedArray.inl:40
T * get_ptr(void)
get the underlying pointer
Definition: ScopedArray.inl:64
T * get(void)
get the underlying pointer
Definition: ScopedArray.inl:78
void decrement(void)
implementation of the decrement operation
ScopedArray(void)
default Ctor
Definition: ScopedArray.inl:9
A shim class that keeps track of the reference count and a pointer to the type T that's reference cou...
Definition: ScopedArray.h:66