107 inline friend bool operator != (Ptr<T1> const &lhs, T2 const *rhs); |
108 inline friend bool operator != (Ptr<T1> const &lhs, T2 const *rhs); |
108 // allow if (0 != sp) |
109 // allow if (0 != sp) |
109 template <typename T1, typename T2> |
110 template <typename T1, typename T2> |
110 inline friend bool operator != (T1 const *lhs, Ptr<T2> &rhs); |
111 inline friend bool operator != (T1 const *lhs, Ptr<T2> &rhs); |
111 |
112 |
|
113 // allow if (sp0 == sp1) |
|
114 template <typename T1, typename T2> |
|
115 inline friend bool operator == (Ptr<T1> const &lhs, Ptr<T2> const &rhs); |
|
116 // allow if (sp0 != sp1) |
|
117 template <typename T1, typename T2> |
|
118 inline friend bool operator != (Ptr<T1> const &lhs, Ptr<T2> const &rhs); |
|
119 |
112 template <typename T1, typename T2> |
120 template <typename T1, typename T2> |
113 inline friend Ptr<T1> const_pointer_cast (Ptr<T2> const&p); |
121 inline friend Ptr<T1> const_pointer_cast (Ptr<T2> const&p); |
114 |
122 |
115 |
123 |
116 }; |
124 }; |
|
125 |
|
126 template <typename T> |
|
127 void |
|
128 Ptr<T>::Acquire (void) const |
|
129 { |
|
130 if (m_ptr != 0) |
|
131 { |
|
132 m_ptr->Ref (); |
|
133 } |
|
134 } |
117 |
135 |
118 template <typename T> |
136 template <typename T> |
119 Ptr<T>::Ptr () |
137 Ptr<T>::Ptr () |
120 : m_ptr (0) |
138 : m_ptr (0) |
121 {} |
139 {} |
122 |
140 |
123 template <typename T> |
141 template <typename T> |
124 Ptr<T>::Ptr (T *ptr) |
142 Ptr<T>::Ptr (T *ptr) |
125 : m_ptr (ptr) |
143 : m_ptr (ptr) |
126 {} |
144 { |
|
145 Acquire (); |
|
146 } |
127 |
147 |
128 template <typename T> |
148 template <typename T> |
129 Ptr<T>::Ptr (Ptr const&o) |
149 Ptr<T>::Ptr (Ptr const&o) |
130 : m_ptr (o.m_ptr) |
150 : m_ptr (o.Peek ()) |
131 { |
151 { |
132 if (m_ptr != 0) |
152 Acquire (); |
133 { |
|
134 m_ptr->Ref(); |
|
135 } |
|
136 } |
153 } |
137 template <typename T> |
154 template <typename T> |
138 template <typename U> |
155 template <typename U> |
139 Ptr<T>::Ptr (Ptr<U> const &o) |
156 Ptr<T>::Ptr (Ptr<U> const &o) |
140 : m_ptr (o.m_ptr) |
157 : m_ptr (o.Peek ()) |
141 { |
158 { |
142 if (m_ptr != 0) |
159 Acquire (); |
143 { |
|
144 NS_ASSERT (o.m_ptr != 0); |
|
145 m_ptr->Ref(); |
|
146 } |
|
147 } |
160 } |
148 |
161 |
149 template <typename T> |
162 template <typename T> |
150 Ptr<T>::~Ptr () |
163 Ptr<T>::~Ptr () |
151 { |
164 { |
245 { |
257 { |
246 return lhs != rhs.m_ptr; |
258 return lhs != rhs.m_ptr; |
247 } |
259 } |
248 |
260 |
249 template <typename T1, typename T2> |
261 template <typename T1, typename T2> |
|
262 bool |
|
263 operator == (Ptr<T1> const &lhs, Ptr<T2> const &rhs) |
|
264 { |
|
265 return lhs.Get () == rhs.Get (); |
|
266 } |
|
267 template <typename T1, typename T2> |
|
268 bool |
|
269 operator != (Ptr<T1> const &lhs, Ptr<T2> const &rhs) |
|
270 { |
|
271 return lhs.Get () != rhs.Get (); |
|
272 } |
|
273 |
|
274 |
|
275 template <typename T1, typename T2> |
250 Ptr<T1> |
276 Ptr<T1> |
251 const_pointer_cast (Ptr<T2> const&p) |
277 const_pointer_cast (Ptr<T2> const&p) |
252 { |
278 { |
253 return Ptr<T1> (const_cast<T1 *> (p.m_ptr)); |
279 return Ptr<T1> (const_cast<T1 *> (p.m_ptr)); |
254 } |
280 } |