3 // $Id: Refcounted_Auto_Ptr.inl 81179 2008-03-31 19:00:29Z iliyan $
5 #include "ace/Guard_T.h"
6 #include "ace/Log_Msg.h"
8 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
10 template <class X, class ACE_LOCK> inline long
11 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::count (void) const
13 return this->ref_count_.value();
16 template <class X, class ACE_LOCK> inline long
17 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::count (void) const
19 return this->rep_->count ();
22 template <class X, class ACE_LOCK> inline bool
23 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::null (void) const
25 return (this->rep_ == 0 || this->rep_->get () == 0);
28 template <class X, class ACE_LOCK> inline ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *
29 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::internal_create (X *p)
31 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *temp = 0;
33 (ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>) (p),
38 template <class X, class ACE_LOCK> inline ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *
39 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::create (X *p)
41 // Yes set ref count to zero.
42 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *temp = internal_create (p);
43 #if defined (ACE_NEW_THROWS_EXCEPTIONS)
47 ACE_ASSERT (temp != 0);
48 #endif /* ACE_NEW_THROWS_EXCEPTIONS */
52 template <class X, class ACE_LOCK> inline ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *
53 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::attach (ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>*& rep)
63 template <class X, class ACE_LOCK> inline void
64 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::detach (ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>*& rep)
69 if (rep->ref_count_-- == 0)
73 template <class X, class ACE_LOCK> inline
74 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::ACE_Refcounted_Auto_Ptr_Rep (X *p)
80 template <class X, class ACE_LOCK> inline
81 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::~ACE_Refcounted_Auto_Ptr_Rep (void)
85 template <class X, class ACE_LOCK> inline X *
86 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::get (void) const
88 return this->ptr_.get ();
91 template <class X, class ACE_LOCK> inline
92 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::ACE_Refcounted_Auto_Ptr (X *p)
93 : rep_ (AUTO_REFCOUNTED_PTR_REP::create (p))
97 template <class X, class ACE_LOCK> inline
98 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::ACE_Refcounted_Auto_Ptr (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r)
99 : rep_ (AUTO_REFCOUNTED_PTR_REP::attach (((ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &) r).rep_))
103 template <class X, class ACE_LOCK> inline bool
104 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator== (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r) const
106 return r.rep_ == this->rep_;
109 template <class X, class ACE_LOCK> inline bool
110 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator!= (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r) const
112 return r.rep_ != this->rep_;
115 template <class X, class ACE_LOCK> inline X *
116 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator-> (void) const
118 return this->rep_->get();
121 template<class X, class ACE_LOCK> inline X &
122 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator *() const
124 return *this->rep_->get ();
127 template<class X, class ACE_LOCK> inline bool
128 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator !() const
130 return this->rep_->get () == 0;
133 template<class X, class ACE_LOCK> inline
134 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator bool () const
136 return this->rep_->get () != 0;
139 template <class X, class ACE_LOCK> inline X*
140 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::get (void) const
142 // We return the ACE_Future_rep.
143 return this->rep_->get ();
146 template<class X, class ACE_LOCK> inline X *
147 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::release (void)
150 AUTO_REFCOUNTED_PTR_REP::detach (this->rep_);
155 template<class X, class ACE_LOCK> inline void
156 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::reset (X *p)
158 // Avoid deleting the underlying auto_ptr if assigning the same actual
160 if (this->get () == p)
163 AUTO_REFCOUNTED_PTR_REP *old_rep = this->rep_;
164 if ((this->rep_ = AUTO_REFCOUNTED_PTR_REP::create (p)) != 0)
165 AUTO_REFCOUNTED_PTR_REP::detach (old_rep);
167 this->rep_ = old_rep;
171 template <class X, class ACE_LOCK> inline void
172 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator = (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &rhs)
174 // bind <this> to the same <ACE_Refcounted_Auto_Ptr_Rep> as <r>.
175 AUTO_REFCOUNTED_PTR_REP *old_rep = this->rep_;
178 this->rep_ = AUTO_REFCOUNTED_PTR_REP::attach
179 (const_cast<ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>& > (rhs).rep_);
181 AUTO_REFCOUNTED_PTR_REP::detach (old_rep);
183 else // Assign a 0 rep to this
185 AUTO_REFCOUNTED_PTR_REP::detach (old_rep);
190 ACE_END_VERSIONED_NAMESPACE_DECL