30#ifndef _RWSTD_SMARTPTR_INCLUDED
31#define _RWSTD_SMARTPTR_INCLUDED
46 : _C_ref (1), _C_weak_ref (0) { }
48 virtual ~__rw_ptr_base () {
51 _C_weak_ref = 0xdeadbeefL;
55 virtual void* _C_get_deleter ()
const {
68 void _C_inc_ref_weak () {
85 void _C_unref_weak () {
96 virtual void _C_delete () = 0;
103template <
class _TypeU>
104struct __rw_ptr_body: __rw_ptr_base
106 __rw_ptr_body (_TypeU *__ptr)
107 : __rw_ptr_base (), _C_ptr (__ptr) { }
111 _TypeU*
const _C_ptr;
115 virtual void _C_delete () {
121template <
class _TypeU,
class _Deleter>
122struct __rw_ptr_deleter: __rw_ptr_body<_TypeU>
124 __rw_ptr_deleter (_TypeU *__ptr,
const _Deleter &__del)
125 : __rw_ptr_body<_TypeU>(__ptr), _C_del (__del) { }
129 virtual void _C_delete () {
130 _C_del (this->_C_ptr);
133 virtual void* _C_get_deleter ()
const {
148struct bad_weak_ptr: _RW::__rw_exception
150 bad_weak_ptr (): _RW::__rw_exception () { }
154template <
class _TypeT>
159template <
class _TypeT>
164 template <
class _TypeU>
167 template <
class _TypeU>
168 friend class weak_ptr;
170 template <
class _TypeU,
class _TypeV>
174 typedef _RW::__rw_ptr_base _C_base;
179 template <
class _TypeU>
182 : _C_pbody (__rhs._C_pbody) {
184 _C_pbody->_C_inc_ref ();
189 typedef _TypeT element_type;
195 template <
class _TypeU>
198 : _C_pbody (__ptr ?
new _RW::__rw_ptr_body<_TypeU>(__ptr) : 0),
201 template <
class _TypeU,
class _Deleter>
203 : _C_pbody (
new _RW::__rw_ptr_deleter<_TypeU, _Deleter>(__ptr, __del)),
207 : _C_pbody (__rhs._C_pbody), _C_ptr (__rhs._C_ptr) {
209 _C_pbody->_C_inc_ref ();
212 template <
class _TypeU>
214 : _C_pbody (__rhs._C_pbody), _C_ptr (__rhs._C_ptr) {
216 _C_pbody->_C_inc_ref ();
219 template <
class _TypeU>
222 : _C_pbody (__rhs._C_pbody), _C_ptr (__rhs._C_ptr) {
224 if (0 >= _C_pbody->_C_get_ref ())
225 throw bad_weak_ptr ();
226 _C_pbody->_C_inc_ref ();
230 template <
class _TypeU>
237 _C_pbody->_C_unref ();
240 _C_pbody = (_C_base*)0xdeadbeefL;
241 _C_ptr = (element_type*)0xdeadbeefL;
249 __rhs._C_pbody->_C_inc_ref ();
251 _C_pbody->_C_unref ();
252 _C_pbody = __rhs._C_pbody;
253 _C_ptr = __rhs._C_ptr;
257 template <
class _TypeU>
259 _C_is_convertible ((_TypeU*)0);
261 __rhs._C_pbody->_C_inc_ref ();
263 _C_pbody->_C_unref ();
264 _C_pbody = __rhs._C_pbody;
265 _C_ptr = __rhs._C_ptr;
269 template <
class _TypeU>
270 shared_ptr& operator= (auto_ptr<_TypeU> &__rhs) {
271 _RW::__rw_ptr_body<_TypeU>*
const __tmp =
272 new _RW::__rw_ptr_body<_TypeU>(__rhs.get ());
274 _C_pbody->_C_unref ();
276 _C_ptr = __rhs.release ();
283 _C_base*
const __body = _C_pbody;
284 element_type*
const __ptr = _C_ptr;
285 _C_pbody = __other._C_pbody;
286 _C_ptr = __other._C_ptr;
287 __other._C_pbody = __body;
288 __other._C_ptr = __ptr;
293 _C_pbody->_C_unref ();
299 template <
class _TypeU>
300 void reset (_TypeU *__ptr) {
304 template <
class _TypeU,
class _Deleter>
305 void reset (_TypeU *__ptr, _Deleter __del) {
311 element_type* get ()
const {
315 typename _RW::__rw_nonvoid_ref<element_type>::_C_ref
321 element_type* operator->()
const {
325 long use_count ()
const {
326 return _C_pbody ? _C_pbody->_C_get_ref () : 0;
329 bool unique ()
const {
330 return 1 == use_count ();
333 operator bool ()
const {
337 template <
class _Deleter>
338 _Deleter* _C_get_deleter ()
const {
340 _C_pbody ? _C_pbody->_C_get_deleter () : 0);
343 template <
class _TypeU>
345 return _C_pbody < __rhs._C_pbody;
352 static void _C_is_convertible (element_type*) { }
357template <
class _TypeT,
class _TypeU>
361 return __lhs.get () == __rhs.get ();
365template <
class _TypeT,
class _TypeU>
369 return __lhs.get () != __rhs.get ();
373template <
class _TypeT,
class _TypeU>
377 return __lhs._C_less (__rhs);
382template <
class _TypeT>
391template <
class _TypeT,
class _TypeU>
403template <
class _TypeT,
class _TypeU>
415template <
class _TypeT,
class _TypeU>
430template <
class _CharT,
class _Traits,
class _TypeT>
431inline basic_ostream<_CharT, _TypeT>&
438template <
class _Deleter,
class _TypeT>
442 return __ptr._C_get_deleter ();
447template <
class _TypeT>
452 template <
class _TypeU>
453 friend class weak_ptr;
455 template <
class _TypeU>
458 typedef _RW::__rw_ptr_base _C_base;
465 typedef _TypeT element_type;
468 weak_ptr (): _C_pbody (0), _C_ptr (0) { }
470 template <
class _TypeU>
472 : _C_pbody (__ptr._C_pbody), _C_ptr (__ptr._C_ptr) {
474 _C_pbody->_C_inc_ref_weak ();
477 weak_ptr (
const weak_ptr &__rhs)
478 : _C_pbody (__rhs._C_pbody), _C_ptr (__rhs._C_ptr) {
480 _C_pbody->_C_inc_ref_weak ();
483 template <
class _TypeU>
484 weak_ptr (
const weak_ptr<_TypeU> &__rhs)
485 : _C_pbody (__rhs._C_pbody), _C_ptr (__rhs._C_ptr) {
487 _C_pbody->_C_inc_ref_weak ();
493 _C_pbody->_C_unref_weak ();
496 _C_pbody = (_C_base*)0xdeadbeefL;
497 _C_ptr = (element_type*)0xdeadbeefL;
502 weak_ptr& operator= (
const weak_ptr &__rhs) {
504 _C_pbody->_C_unref_weak ();
505 if ((_C_pbody = __rhs._C_pbody))
506 _C_pbody->_C_inc_ref_weak ();
507 _C_ptr = __rhs._C_ptr;
511 template <
class _TypeU>
512 weak_ptr& operator= (
const weak_ptr<_TypeU> &__rhs) {
513 _C_is_convertible ((_TypeU*)0);
515 _C_pbody->_C_unref_weak ();
516 if ((_C_pbody = __rhs._C_pbody))
517 _C_pbody->_C_inc_ref_weak ();
518 _C_ptr = __rhs._C_ptr;
522 template<
class _TypeU>
524 _C_is_convertible ((_TypeU*)0);
526 _C_pbody->_C_unref_weak ();
527 if ((_C_pbody = __rhs._C_pbody))
528 _C_pbody->_C_inc_ref_weak ();
529 _C_ptr = __rhs._C_ptr;
535 void swap (weak_ptr &__other) {
536 _C_base*
const __body = _C_pbody;
537 element_type*
const __ptr = _C_ptr;
538 _C_pbody = __other._C_pbody;
539 _C_ptr = __other._C_ptr;
540 __other._C_pbody = __body;
541 __other._C_ptr = __ptr;
546 _C_pbody->_C_unref_weak ();
553 long use_count ()
const {
554 return _C_pbody ? _C_pbody->_C_get_ref () : 0;
557 bool expired ()
const {
558 return 0 == use_count ();
568 template <
class _TypeU>
569 bool operator< (
const weak_ptr<_TypeU> __rhs)
const {
570 return _C_pbody < __rhs._C_pbody;
577 static void _C_is_convertible (element_type*) { }
582template <
class _TypeT,
class _TypeU>
584operator< (
const weak_ptr<_TypeT> &__lhs,
const weak_ptr<_TypeU> &__rhs)
586 return __lhs.operator< (__rhs);
591template <
class _TypeT>
593swap (weak_ptr<_TypeT> &__lhs, weak_ptr<_TypeT> &__rhs)
600template <
class _TypeT>
601class enable_shared_from_this;
const plus_asgn< T > & operator*(const plus_asgn< T > &lhs, const plus_asgn< T > &rhs)
#define _RWSTD_ATOMIC_PREINCREMENT(x, ignore)
#define _RWSTD_DYNAMIC_CAST(T, x)
#define _RWSTD_STATIC_CAST(T, x)
#define _RWSTD_NAMESPACE(name)
#define _RWSTD_ATOMIC_PREDECREMENT(x, ignore)
#define _RWSTD_ASSERT(ignore)
#define _RWSTD_CONST_CAST(T, x)
std::basic_ostream< Char > & operator<<(std::basic_ostream< Char > &lhs, node_type rhs)
Pretty-prints the value of a node_type to a stream.
bool operator==(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
bool operator!=(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
bool operator<(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept