2 #include "ace/Guard_T.h"
3 #include "ace/Log_Category.h"
5 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
7 template <class X, class ACE_LOCK> inline long
8 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::count (void) const
10 return this->ref_count_.value();
13 template <class X, class ACE_LOCK> inline long
14 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::count (void) const
16 return this->rep_->count ();
19 template <class X, class ACE_LOCK> inline bool
20 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::null (void) const
22 return (this->rep_ == 0 || this->rep_->get () == 0);
25 template <class X, class ACE_LOCK> inline ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *
26 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::internal_create (X *p)
28 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *temp = 0;
30 (ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>) (p),
35 template <class X, class ACE_LOCK> inline ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *
36 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::create (X *p)
38 // Yes set ref count to zero.
39 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *temp = internal_create (p);
40 #if defined (ACE_NEW_THROWS_EXCEPTIONS)
44 ACE_ASSERT (temp != 0);
45 #endif /* ACE_NEW_THROWS_EXCEPTIONS */
49 template <class X, class ACE_LOCK> inline ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *
50 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::attach (ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>*& rep)
60 template <class X, class ACE_LOCK> inline void
61 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::detach (ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>*& rep)
66 if (rep->ref_count_-- == 0)
70 template <class X, class ACE_LOCK> inline
71 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::ACE_Refcounted_Auto_Ptr_Rep (X *p)
77 template <class X, class ACE_LOCK> inline
78 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::~ACE_Refcounted_Auto_Ptr_Rep (void)
82 template <class X, class ACE_LOCK> inline X *
83 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::get (void) const
85 return this->ptr_.get ();
88 template <class X, class ACE_LOCK> inline
89 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::ACE_Refcounted_Auto_Ptr (X *p)
90 : rep_ (AUTO_REFCOUNTED_PTR_REP::create (p))
94 template <class X, class ACE_LOCK> inline
95 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::ACE_Refcounted_Auto_Ptr (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r)
96 : rep_ (AUTO_REFCOUNTED_PTR_REP::attach (((ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &) r).rep_))
100 template <class X, class ACE_LOCK> inline bool
101 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator== (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r) const
103 return r.rep_ == this->rep_;
106 template <class X, class ACE_LOCK> inline bool
107 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator!= (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r) const
109 return r.rep_ != this->rep_;
112 template <class X, class ACE_LOCK> inline X *
113 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator-> (void) const
115 return this->rep_->get();
118 template<class X, class ACE_LOCK> inline X &
119 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator *() const
121 return *this->rep_->get ();
124 template<class X, class ACE_LOCK> inline bool
125 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator !() const
127 return this->rep_->get () == 0;
130 template<class X, class ACE_LOCK> inline
131 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator bool () const
133 return this->rep_->get () != 0;
136 template <class X, class ACE_LOCK> inline X*
137 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::get (void) const
139 // We return the ACE_Future_rep.
140 return this->rep_->get ();
143 template<class X, class ACE_LOCK> inline X *
144 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::release (void)
147 AUTO_REFCOUNTED_PTR_REP::detach (this->rep_);
152 template<class X, class ACE_LOCK> inline void
153 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::reset (X *p)
155 // Avoid deleting the underlying auto_ptr if assigning the same actual
157 if (this->get () == p)
160 AUTO_REFCOUNTED_PTR_REP *old_rep = this->rep_;
161 if ((this->rep_ = AUTO_REFCOUNTED_PTR_REP::create (p)) != 0)
162 AUTO_REFCOUNTED_PTR_REP::detach (old_rep);
164 this->rep_ = old_rep;
168 template <class X, class ACE_LOCK> inline void
169 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator = (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &rhs)
171 // bind <this> to the same <ACE_Refcounted_Auto_Ptr_Rep> as <r>.
172 AUTO_REFCOUNTED_PTR_REP *old_rep = this->rep_;
175 this->rep_ = AUTO_REFCOUNTED_PTR_REP::attach
176 (const_cast<ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>& > (rhs).rep_);
178 AUTO_REFCOUNTED_PTR_REP::detach (old_rep);
180 else // Assign a 0 rep to this
182 AUTO_REFCOUNTED_PTR_REP::detach (old_rep);
187 ACE_END_VERSIONED_NAMESPACE_DECL