[6916] Fixed typos in spell checking code.
[getmangos.git] / dep / ACE_wrappers / ace / Refcounted_Auto_Ptr.inl
blobd9aacfacc749c28ff262a45074a7e13f2ec49b12
1 // -*- C++ -*-
2 //
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;
32   ACE_NEW_RETURN (temp,
33                   (ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>) (p),
34                   0);
35   return temp;
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)
44   if (temp == 0)
45     ACE_throw_bad_alloc;
46 #else
47   ACE_ASSERT (temp != 0);
48 #endif /* ACE_NEW_THROWS_EXCEPTIONS */
49    return temp;
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)
55   if (rep == 0)
56     return 0;
58   ++rep->ref_count_;
60   return 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)
66   if (rep == 0)
67     return;
69   if (rep->ref_count_-- == 0)
70     delete rep;
73 template <class X, class ACE_LOCK> inline
74 ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::ACE_Refcounted_Auto_Ptr_Rep (X *p)
75   : ptr_ (p),
76     ref_count_ (0)
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)
149   X *p = this->get ();
150   AUTO_REFCOUNTED_PTR_REP::detach (this->rep_);
151   this->rep_ = 0;
152   return p;
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
159   // pointer value.
160   if (this->get () == p)
161     return;
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);
166   else
167     this->rep_ = old_rep;
168   return;
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_;
176   if (rhs.rep_ != 0)
177     {
178       this->rep_ = AUTO_REFCOUNTED_PTR_REP::attach
179         (const_cast<ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>& > (rhs).rep_);
180       if (this->rep_ != 0)
181         AUTO_REFCOUNTED_PTR_REP::detach (old_rep);
182     }
183   else    // Assign a 0 rep to this
184     {
185       AUTO_REFCOUNTED_PTR_REP::detach (old_rep);
186       this->rep_ = 0;
187     }
190 ACE_END_VERSIONED_NAMESPACE_DECL