00001
00002
00003
00004
00005 #include "ace/Guard_T.h"
00006 #include "ace/Log_Msg.h"
00007
00008 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00009
00010 template <class X, class ACE_LOCK> inline long
00011 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::count (void) const
00012 {
00013 return this->ref_count_.value();
00014 }
00015
00016 template <class X, class ACE_LOCK> inline long
00017 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::count (void) const
00018 {
00019 return this->rep_->count ();
00020 }
00021
00022 template <class X, class ACE_LOCK> inline bool
00023 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::null (void) const
00024 {
00025 return (this->rep_ == 0 || this->rep_->get () == 0);
00026 }
00027
00028 template <class X, class ACE_LOCK> inline ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *
00029 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::internal_create (X *p)
00030 {
00031 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *temp = 0;
00032 ACE_NEW_RETURN (temp,
00033 (ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>) (p),
00034 0);
00035 return temp;
00036 }
00037
00038 template <class X, class ACE_LOCK> inline ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *
00039 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::create (X *p)
00040 {
00041
00042 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *temp = internal_create (p);
00043 #if defined (ACE_NEW_THROWS_EXCEPTIONS)
00044 if (temp == 0)
00045 ACE_throw_bad_alloc;
00046 #else
00047 ACE_ASSERT (temp != 0);
00048 #endif
00049 return temp;
00050 }
00051
00052 template <class X, class ACE_LOCK> inline ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *
00053 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::attach (ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>*& rep)
00054 {
00055 if (rep == 0)
00056 return 0;
00057
00058 ++rep->ref_count_;
00059
00060 return rep;
00061 }
00062
00063 template <class X, class ACE_LOCK> inline void
00064 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::detach (ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>*& rep)
00065 {
00066 if (rep == 0)
00067 return;
00068
00069 if (rep->ref_count_-- == 0)
00070 delete rep;
00071 }
00072
00073 template <class X, class ACE_LOCK> inline
00074 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::ACE_Refcounted_Auto_Ptr_Rep (X *p)
00075 : ptr_ (p),
00076 ref_count_ (0)
00077 {
00078 }
00079
00080 template <class X, class ACE_LOCK> inline
00081 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::~ACE_Refcounted_Auto_Ptr_Rep (void)
00082 {
00083 }
00084
00085 template <class X, class ACE_LOCK> inline X *
00086 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::get (void) const
00087 {
00088 return this->ptr_.get ();
00089 }
00090
00091 template <class X, class ACE_LOCK> inline
00092 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::ACE_Refcounted_Auto_Ptr (X *p)
00093 : rep_ (AUTO_REFCOUNTED_PTR_REP::create (p))
00094 {
00095 }
00096
00097 template <class X, class ACE_LOCK> inline
00098 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::ACE_Refcounted_Auto_Ptr (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r)
00099 : rep_ (AUTO_REFCOUNTED_PTR_REP::attach (((ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &) r).rep_))
00100 {
00101 }
00102
00103 template <class X, class ACE_LOCK> inline bool
00104 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator== (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r) const
00105 {
00106 return r.rep_ == this->rep_;
00107 }
00108
00109 template <class X, class ACE_LOCK> inline bool
00110 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator!= (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r) const
00111 {
00112 return r.rep_ != this->rep_;
00113 }
00114
00115 template <class X, class ACE_LOCK> inline X *
00116 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator-> (void) const
00117 {
00118 return this->rep_->get();
00119 }
00120
00121 template<class X, class ACE_LOCK> inline X &
00122 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator *() const
00123 {
00124 return *this->rep_->get ();
00125 }
00126
00127 template <class X, class ACE_LOCK> inline X*
00128 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::get (void) const
00129 {
00130
00131 return this->rep_->get ();
00132 }
00133
00134 template<class X, class ACE_LOCK> inline X *
00135 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::release (void)
00136 {
00137 X *p = this->get ();
00138 AUTO_REFCOUNTED_PTR_REP::detach (this->rep_);
00139 this->rep_ = 0;
00140 return p;
00141 }
00142
00143 template<class X, class ACE_LOCK> inline void
00144 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::reset (X *p)
00145 {
00146
00147
00148 if (this->get () == p)
00149 return;
00150
00151 AUTO_REFCOUNTED_PTR_REP *old_rep = this->rep_;
00152 if ((this->rep_ = AUTO_REFCOUNTED_PTR_REP::create (p)) != 0)
00153 AUTO_REFCOUNTED_PTR_REP::detach (old_rep);
00154 else
00155 this->rep_ = old_rep;
00156 return;
00157 }
00158
00159 template <class X, class ACE_LOCK> inline void
00160 ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator = (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &rhs)
00161 {
00162
00163 AUTO_REFCOUNTED_PTR_REP *old_rep = this->rep_;
00164 if (rhs.rep_ != 0)
00165 {
00166 this->rep_ = AUTO_REFCOUNTED_PTR_REP::attach
00167 (const_cast<ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>& > (rhs).rep_);
00168 if (this->rep_ != 0)
00169 AUTO_REFCOUNTED_PTR_REP::detach (old_rep);
00170 }
00171 else
00172 {
00173 AUTO_REFCOUNTED_PTR_REP::detach (old_rep);
00174 this->rep_ = 0;
00175 }
00176 }
00177
00178 ACE_END_VERSIONED_NAMESPACE_DECL