Intrusive_Auto_Ptr.inl

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // $Id: Intrusive_Auto_Ptr.inl 81219 2008-04-02 20:23:32Z iliyan $
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> ACE_INLINE
00011 ACE_Intrusive_Auto_Ptr<X>::ACE_Intrusive_Auto_Ptr (X *p, bool addref)
00012   : rep_ (p)
00013 {
00014   if (rep_ != 0  && addref)
00015     X::intrusive_add_ref (rep_);
00016 }
00017 
00018 template <class X> ACE_INLINE
00019 ACE_Intrusive_Auto_Ptr<X>::ACE_Intrusive_Auto_Ptr (const ACE_Intrusive_Auto_Ptr<X> &r)
00020   : rep_ (r.rep_)
00021 {
00022   if (rep_ != 0)
00023     X::intrusive_add_ref (rep_);
00024 }
00025 
00026 template <class X> ACE_INLINE X *
00027 ACE_Intrusive_Auto_Ptr<X>::operator-> (void) const
00028 {
00029     return this->rep_;
00030 }
00031 
00032 template<class X> ACE_INLINE X &
00033 ACE_Intrusive_Auto_Ptr<X>::operator *() const
00034 {
00035   return *this->rep_;
00036 }
00037 
00038 template <class X> ACE_INLINE X*
00039 ACE_Intrusive_Auto_Ptr<X>::get (void) const
00040 {
00041   // We return the ACE_Future_rep.
00042   return this->rep_;
00043 }
00044 
00045 template<class X> ACE_INLINE X *
00046 ACE_Intrusive_Auto_Ptr<X>::release (void)
00047 {
00048   X *p = this->rep_;
00049   if (this->rep_ != 0)
00050     X::intrusive_remove_ref (this->rep_);
00051 
00052   this->rep_ = 0;
00053   return p;
00054 }
00055 
00056 template<class X> ACE_INLINE void
00057 ACE_Intrusive_Auto_Ptr<X>::reset (X *p)
00058 {
00059   // Avoid deleting the underlying auto_ptr if assigning the same actual
00060   // pointer value.
00061   if (this->rep_ == p)
00062     return;
00063 
00064   X *old_rep = this->rep_;
00065   this->rep_ = p;
00066 
00067   if (this->rep_ != 0)
00068     X::intrusive_add_ref (this->rep_);
00069 
00070   if (old_rep != 0)
00071     X::intrusive_remove_ref (old_rep);
00072 
00073   return;
00074 }
00075 
00076 template <class X> ACE_INLINE void
00077 ACE_Intrusive_Auto_Ptr<X>::operator = (const ACE_Intrusive_Auto_Ptr<X> &rhs)
00078 {
00079   // do nothing when aliasing
00080   if (this->rep_ == rhs.rep_)
00081     return;
00082 
00083   // assign a zero
00084   if (rhs.rep_  == 0)
00085     {
00086       X::intrusive_remove_ref (rhs.rep_);
00087       this->rep_ = 0;
00088       return;
00089     }
00090 
00091   //  bind <this> to the same <ACE_Intrusive_Auto_Ptr_Rep> as <rhs>.
00092   X *old_rep = this->rep_;
00093   this->rep_ = rhs.rep_;
00094   X::intrusive_add_ref (this->rep_);
00095   X::intrusive_remove_ref (old_rep);
00096 }
00097 
00098 // Copy derived class constructor
00099 template<class X> template <class U> ACE_INLINE
00100 ACE_Intrusive_Auto_Ptr<X>::ACE_Intrusive_Auto_Ptr (const ACE_Intrusive_Auto_Ptr<U> & rhs)
00101 {
00102   // note implicit cast from U* to T* so illegal copy will generate a
00103   // compiler warning here
00104   this->rep_ = rhs.operator-> ();
00105   X::intrusive_add_ref(this->rep_);
00106 }
00107 
00108   /// Equality operator that returns @c true if both
00109   /// ACE_Intrusive_Auto_Ptr objects point to the same underlying
00110   /// representation. It does not compare the actual pointers.
00111   /**
00112    * @note It also returns @c true if both objects have just been
00113    *       instantiated and not used yet.
00114    */
00115 template<class T, class U> ACE_INLINE bool operator==(ACE_Intrusive_Auto_Ptr<T> const & a, ACE_Intrusive_Auto_Ptr<U> const & b)
00116 {
00117     return a.get() == b.get();
00118 }
00119 
00120   /// Inequality operator, which is the opposite of equality.
00121   template<class T, class U> ACE_INLINE bool operator!=(ACE_Intrusive_Auto_Ptr<T> const & a, ACE_Intrusive_Auto_Ptr<U> const & b)
00122 {
00123     return a.get() != b.get();
00124 }
00125 
00126     template<class T, class U> ACE_INLINE bool operator==(ACE_Intrusive_Auto_Ptr<T> const & a, U * b)
00127 {
00128     return a.get() == b;
00129 }
00130 
00131       template<class T, class U> ACE_INLINE bool operator!=(ACE_Intrusive_Auto_Ptr<T> & a, U * b)
00132 {
00133     return a.get() != b;
00134 }
00135 
00136         template<class T, class U> ACE_INLINE bool operator==(T * a, ACE_Intrusive_Auto_Ptr<U> const & b)
00137 {
00138     return a == b.get();
00139 }
00140 
00141           template<class T, class U> ACE_INLINE bool operator!=(T * a, ACE_Intrusive_Auto_Ptr<U> const & b)
00142 {
00143     return a != b.get();
00144 }
00145 
00146 
00147 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:18:40 2010 for ACE by  doxygen 1.4.7