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 () 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 () const
16 return this->rep_->count ();
19 template <class X, class ACE_LOCK> inline bool
20 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::null () 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);
41 throw std::bad_alloc ();
45 template <class X, class ACE_LOCK> inline ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *
46 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::attach (ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>*& rep)
56 template <class X, class ACE_LOCK> inline void
57 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::detach (ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>*& rep)
62 if (rep->ref_count_-- == 0)
66 template <class X, class ACE_LOCK> inline
67 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::ACE_Refcounted_Auto_Ptr_Rep (X *p)
73 template <class X, class ACE_LOCK> inline
74 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::~ACE_Refcounted_Auto_Ptr_Rep ()
78 template <class X, class ACE_LOCK> inline X *
79 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::get () const
81 return this->ptr_.get ();
84 template <class X, class ACE_LOCK> inline
85 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::ACE_Refcounted_Auto_Ptr (X *p)
86 : rep_ (AUTO_REFCOUNTED_PTR_REP::create (p))
90 template <class X, class ACE_LOCK> inline
91 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::ACE_Refcounted_Auto_Ptr (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r)
92 : rep_ (AUTO_REFCOUNTED_PTR_REP::attach (((ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &) r).rep_))
96 template <class X, class ACE_LOCK> inline bool
97 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator== (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r) const
99 return r.rep_ == this->rep_;
102 template <class X, class ACE_LOCK> inline bool
103 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator!= (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r) const
105 return r.rep_ != this->rep_;
108 template <class X, class ACE_LOCK> inline X *
109 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator-> () const
111 return this->rep_->get();
114 template<class X, class ACE_LOCK> inline X &
115 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator *() const
117 return *this->rep_->get ();
120 template<class X, class ACE_LOCK> inline bool
121 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator !() const
123 return this->rep_->get () == 0;
126 template<class X, class ACE_LOCK> inline
127 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator unspecified_bool_type () const
129 return this->rep_->get () != 0 ? unspecified_bool : 0;
132 template <class X, class ACE_LOCK> inline X*
133 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::get () const
135 // We return the ACE_Future_rep.
136 return this->rep_->get ();
139 template<class X, class ACE_LOCK> inline X *
140 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::release ()
143 AUTO_REFCOUNTED_PTR_REP::detach (this->rep_);
148 template<class X, class ACE_LOCK> inline void
149 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::reset (X *p)
151 // Avoid deleting the underlying auto_ptr if assigning the same actual
153 if (this->get () == p)
156 AUTO_REFCOUNTED_PTR_REP *old_rep = this->rep_;
157 if ((this->rep_ = AUTO_REFCOUNTED_PTR_REP::create (p)) != 0)
158 AUTO_REFCOUNTED_PTR_REP::detach (old_rep);
160 this->rep_ = old_rep;
164 template <class X, class ACE_LOCK> inline void
165 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator = (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &rhs)
167 // bind <this> to the same <ACE_Refcounted_Auto_Ptr_Rep> as <r>.
168 AUTO_REFCOUNTED_PTR_REP *old_rep = this->rep_;
171 this->rep_ = AUTO_REFCOUNTED_PTR_REP::attach
172 (const_cast<ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>& > (rhs).rep_);
174 AUTO_REFCOUNTED_PTR_REP::detach (old_rep);
176 else // Assign a 0 rep to this
178 AUTO_REFCOUNTED_PTR_REP::detach (old_rep);
183 ACE_END_VERSIONED_NAMESPACE_DECL