11 #ifndef CA_MGM_BASE_PTRTYPES_H
12 #define CA_MGM_BASE_PTRTYPES_H
16 #include <boost/scoped_ptr.hpp>
17 #include <boost/shared_ptr.hpp>
18 #include <boost/weak_ptr.hpp>
19 #include <boost/intrusive_ptr.hpp>
80 using boost::scoped_ptr;
83 using boost::shared_ptr;
86 using boost::weak_ptr;
89 using boost::intrusive_ptr;
92 using boost::static_pointer_cast;
94 using boost::const_pointer_cast;
96 using boost::dynamic_pointer_cast;
117 inline std::ostream & operator<<( std::ostream & str, const ca_mgm::shared_ptr<_D> & obj )
121 return str << std::string(
"NULL");
125 inline std::ostream & dumpOn( std::ostream & str,
const ca_mgm::shared_ptr<_D> & obj )
128 return dumpOn( str, *obj );
129 return str << std::string(
"NULL");
134 inline std::ostream & operator<<( std::ostream & str, const ca_mgm::intrusive_ptr<_D> & obj )
138 return str << std::string(
"NULL");
142 inline std::ostream & dumpOn( std::ostream & str,
const ca_mgm::intrusive_ptr<_D> & obj )
145 return dumpOn( str, *obj );
146 return str << std::string(
"NULL");
165 namespace rw_pointer {
174 {
return !ptr_r || ptr_r.unique(); }
176 {
return !ptr_r || ptr_r.unique(); }
179 {
return ptr_r.use_count(); }
181 {
return ptr_r.use_count(); }
187 typedef intrusive_ptr<_D>
_Ptr;
191 {
return !ptr_r || (ptr_r->refCount() <= 1); }
193 {
return !ptr_r || (ptr_r->refCount() <= 1); }
196 {
return ptr_r ? ptr_r->refCount() : 0; }
198 {
return ptr_r ? ptr_r->refCount() : 0; }
213 {
return ptr_r ? 1 : 0; }
215 {
return ptr_r ? 1 : 0; }
228 {
return rhs->clone(); }
271 template<
class _D,
class _Traits = rw_po
inter::Shared<_D> >
274 typedef typename _Traits::_Ptr
_Ptr;
276 #if defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS ) || defined( BOOST_NO_CXX11_NULLPTR )
277 typedef typename _Ptr::unspecified_bool_type unspecified_bool_type;
293 void reset(
typename _Ptr::element_type * dptr )
300 {
_dptr.swap( rhs ); }
302 #if defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS ) || defined( BOOST_NO_CXX11_NULLPTR )
303 operator unspecified_bool_type()
const
306 explicit operator bool ()
const {
return _dptr.get() != 0; }
313 {
return _dptr.get(); }
315 const _D *
get()
const
316 {
return _dptr.get(); }
322 {
return _dptr.get(); }
325 {
return _dptr.get(); }
329 {
return _Traits().unique(
_dptr ); }
332 {
return _Traits().use_count(
_dptr ); }
353 template<
class _D,
class _Ptr>
354 inline std::ostream & operator<<( std::ostream & str, const RW_pointer<_D, _Ptr> & obj )
357 return str << *obj.get();
358 return str << std::string(
"NULL");
362 template<
class _D,
class _Ptr>
364 {
return( lhs.
get() == rhs.
get() ); }
366 template<
class _D,
class _Ptr>
368 {
return( lhs.
get() == rhs.get() ); }
370 template<
class _D,
class _Ptr>
372 {
return( lhs.get() == rhs.
get() ); }
374 template<
class _D,
class _Ptr>
376 {
return( lhs.
get() == rhs.get() ); }
378 template<
class _D,
class _Ptr>
380 {
return( lhs.get() == rhs.
get() ); }
384 template<
class _D,
class _Ptr>
386 {
return ! ( lhs == rhs ); }
388 template<
class _D,
class _Ptr>
390 {
return ! ( lhs == rhs ); }
392 template<
class _D,
class _Ptr>
394 {
return ! ( lhs == rhs ); }
396 template<
class _D,
class _Ptr>
398 {
return ! ( lhs == rhs ); }
400 template<
class _D,
class _Ptr>
402 {
return ! ( lhs == rhs ); }
416 template<
class _D,
class _Traits = rw_po
inter::Shared<_D> >
419 typedef typename _Traits::_Ptr
_Ptr;
421 #if defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS ) || defined( BOOST_NO_CXX11_NULLPTR )
422 typedef typename _Ptr::unspecified_bool_type unspecified_bool_type;
437 void reset(
typename _Ptr::element_type * dptr )
444 {
_dptr.swap( rhs ); }
446 #if defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS ) || defined( BOOST_NO_CXX11_NULLPTR )
447 operator unspecified_bool_type()
const
450 explicit operator bool ()
const {
return _dptr.get() != 0; }
457 {
return _dptr.get(); }
459 const _D *
get()
const
460 {
return _dptr.get(); }
473 {
return _Traits().unique(
_dptr ); }
476 {
return _Traits().use_count(
_dptr ); }
505 template<
class _D,
class _Ptr>
506 inline std::ostream & operator<<( std::ostream & str, const RWCOW_pointer<_D, _Ptr> & obj )
509 return str << *obj.get();
510 return str << std::string(
"NULL");
514 template<
class _D,
class _Ptr>
516 {
return( lhs.
get() == rhs.
get() ); }
518 template<
class _D,
class _Ptr>
520 {
return( lhs.
get() == rhs.get() ); }
522 template<
class _D,
class _Ptr>
524 {
return( lhs.get() == rhs.
get() ); }
526 template<
class _D,
class _Ptr>
528 {
return( lhs.
get() == rhs.get() ); }
530 template<
class _D,
class _Ptr>
532 {
return( lhs.get() == rhs.
get() ); }
535 template<
class _D,
class _Ptr>
537 {
return ! ( lhs == rhs ); }
539 template<
class _D,
class _Ptr>
541 {
return ! ( lhs == rhs ); }
543 template<
class _D,
class _Ptr>
545 {
return ! ( lhs == rhs ); }
547 template<
class _D,
class _Ptr>
549 {
return ! ( lhs == rhs ); }
551 template<
class _D,
class _Ptr>
553 {
return ! ( lhs == rhs ); }
563 #define DEFINE_PTR_TYPE(NAME) \
565 extern void intrusive_ptr_add_ref( const NAME * ); \
566 extern void intrusive_ptr_release( const NAME * ); \
567 typedef ca_mgm::intrusive_ptr<NAME> NAME##_Ptr; \
568 typedef ca_mgm::intrusive_ptr<const NAME> NAME##_constPtr;
571 #endif // CA_MGM_BASE_PTRTYPES_H
bool operator!=(const RW_pointer< _D, _Ptr > &lhs, const RW_pointer< _D, _Ptr > &rhs)
Definition: PtrTypes.hpp:385
bool operator!=(const RWCOW_pointer< _D, _Ptr > &lhs, const typename _Ptr::_Ptr &rhs)
Definition: PtrTypes.hpp:540
void reset()
Definition: PtrTypes.hpp:434
bool unique(const _constPtr &ptr_r)
Definition: PtrTypes.hpp:190
long use_count() const
Definition: PtrTypes.hpp:331
shared_ptr< _D > _Ptr
Definition: PtrTypes.hpp:170
Definition: PtrTypes.hpp:202
RW_pointer(typename _Ptr::element_type *dptr=0)
Definition: PtrTypes.hpp:281
Definition: PtrTypes.hpp:185
bool operator!=(const RWCOW_pointer< _D, _Ptr > &lhs, const RWCOW_pointer< _D, _Ptr > &rhs)
Definition: PtrTypes.hpp:536
bool operator==(const RW_pointer< _D, _Ptr > &lhs, const RW_pointer< _D, _Ptr > &rhs)
Definition: PtrTypes.hpp:363
const _D * get() const
Definition: PtrTypes.hpp:315
_Traits::_Ptr _Ptr
Definition: PtrTypes.hpp:274
_Traits::_constPtr _constPtr
Definition: PtrTypes.hpp:275
bool operator==(const RW_pointer< _D, _Ptr > &lhs, const typename _Ptr::_constPtr &rhs)
Definition: PtrTypes.hpp:375
bool operator!=(const typename _Ptr::_constPtr &lhs, const RW_pointer< _D, _Ptr > &rhs)
Definition: PtrTypes.hpp:401
bool unique(const _Ptr &ptr_r)
Definition: PtrTypes.hpp:192
long use_count(const _constPtr &ptr_r) const
Definition: PtrTypes.hpp:195
const _D * operator->() const
Definition: PtrTypes.hpp:456
long use_count(const _Ptr &ptr_r) const
Definition: PtrTypes.hpp:197
bool operator==(const RWCOW_pointer< _D, _Ptr > &lhs, const RWCOW_pointer< _D, _Ptr > &rhs)
Definition: PtrTypes.hpp:515
bool operator==(const typename _Ptr::_constPtr &lhs, const RW_pointer< _D, _Ptr > &rhs)
Definition: PtrTypes.hpp:379
const _D & operator*() const
Definition: PtrTypes.hpp:309
bool operator!=(const typename _Ptr::_Ptr &lhs, const RW_pointer< _D, _Ptr > &rhs)
Definition: PtrTypes.hpp:393
RW_pointer(_Ptr dptr)
Definition: PtrTypes.hpp:286
_constPtr getPtr() const
Definition: PtrTypes.hpp:478
bool operator==(const typename _Ptr::_Ptr &lhs, const RW_pointer< _D, _Ptr > &rhs)
Definition: PtrTypes.hpp:371
bool unique() const
Definition: PtrTypes.hpp:328
intrusive_ptr< _D > _Ptr
Definition: PtrTypes.hpp:187
_constPtr getPtr() const
Definition: PtrTypes.hpp:334
Definition: PtrTypes.hpp:102
Definition: PtrTypes.hpp:417
_constPtr cgetPtr()
Definition: PtrTypes.hpp:484
_D & operator*()
Definition: PtrTypes.hpp:462
_Traits::_constPtr _constPtr
Definition: PtrTypes.hpp:420
shared_ptr< const _D > _constPtr
Definition: PtrTypes.hpp:171
void assertUnshared()
Definition: PtrTypes.hpp:489
long use_count(const _Ptr &ptr_r) const
Definition: PtrTypes.hpp:180
void swap(_Ptr &rhs)
Definition: PtrTypes.hpp:443
const _D & operator*() const
Definition: PtrTypes.hpp:453
_Ptr getPtr()
Definition: PtrTypes.hpp:481
Definition: PtrTypes.hpp:272
long use_count(const _constPtr &ptr_r) const
Definition: PtrTypes.hpp:178
bool operator==(const RWCOW_pointer< _D, _Ptr > &lhs, const typename _Ptr::_constPtr &rhs)
Definition: PtrTypes.hpp:527
_Ptr _dptr
Definition: PtrTypes.hpp:496
void operator()(const void *const ) const
Definition: PtrTypes.hpp:75
void swap(RW_pointer &rhs)
Definition: PtrTypes.hpp:296
_Traits::_Ptr _Ptr
Definition: PtrTypes.hpp:419
RWCOW_pointer(typename _Ptr::element_type *dptr=0)
Definition: PtrTypes.hpp:425
_D * operator->()
Definition: PtrTypes.hpp:321
_constPtr cgetPtr()
Definition: PtrTypes.hpp:340
long use_count() const
Definition: PtrTypes.hpp:475
bool operator!=(const RWCOW_pointer< _D, _Ptr > &lhs, const typename _Ptr::_constPtr &rhs)
Definition: PtrTypes.hpp:548
Definition: PtrTypes.hpp:168
bool operator!=(const RW_pointer< _D, _Ptr > &lhs, const typename _Ptr::_constPtr &rhs)
Definition: PtrTypes.hpp:397
bool operator==(const typename _Ptr::_Ptr &lhs, const RWCOW_pointer< _D, _Ptr > &rhs)
Definition: PtrTypes.hpp:523
void reset(typename _Ptr::element_type *dptr)
Definition: PtrTypes.hpp:437
scoped_ptr< const _D > _constPtr
Definition: PtrTypes.hpp:205
void reset()
Definition: PtrTypes.hpp:290
void reset(typename _Ptr::element_type *dptr)
Definition: PtrTypes.hpp:293
Definition: PtrTypes.hpp:73
bool unique() const
Definition: PtrTypes.hpp:472
bool operator==(const typename _Ptr::_constPtr &lhs, const RWCOW_pointer< _D, _Ptr > &rhs)
Definition: PtrTypes.hpp:531
bool operator!=(const typename _Ptr::_constPtr &lhs, const RWCOW_pointer< _D, _Ptr > &rhs)
Definition: PtrTypes.hpp:552
bool unique(const _constPtr &ptr_r)
Definition: PtrTypes.hpp:207
RWCOW_pointer(_Ptr dptr)
Definition: PtrTypes.hpp:430
bool unique(const _Ptr &ptr_r)
Definition: PtrTypes.hpp:209
intrusive_ptr< const _D > _constPtr
Definition: PtrTypes.hpp:188
bool operator!=(const typename _Ptr::_Ptr &lhs, const RWCOW_pointer< _D, _Ptr > &rhs)
Definition: PtrTypes.hpp:544
void swap(RWCOW_pointer &rhs)
Definition: PtrTypes.hpp:440
void swap(_Ptr &rhs)
Definition: PtrTypes.hpp:299
_D * operator->()
Definition: PtrTypes.hpp:465
long use_count(const _Ptr &ptr_r) const
Definition: PtrTypes.hpp:214
bool operator!=(const RW_pointer< _D, _Ptr > &lhs, const typename _Ptr::_Ptr &rhs)
Definition: PtrTypes.hpp:389
bool operator==(const RW_pointer< _D, _Ptr > &lhs, const typename _Ptr::_Ptr &rhs)
Definition: PtrTypes.hpp:367
bool unique(const _constPtr &ptr_r)
Definition: PtrTypes.hpp:173
bool unique(const _Ptr &ptr_r)
Definition: PtrTypes.hpp:175
_D * rwcowClone(const _D *rhs)
Definition: PtrTypes.hpp:227
_Ptr getPtr()
Definition: PtrTypes.hpp:337
long use_count(const _constPtr &ptr_r) const
Definition: PtrTypes.hpp:212
const _D * get() const
Definition: PtrTypes.hpp:459
bool operator==(const RWCOW_pointer< _D, _Ptr > &lhs, const typename _Ptr::_Ptr &rhs)
Definition: PtrTypes.hpp:519
const _D * operator->() const
Definition: PtrTypes.hpp:312
scoped_ptr< _D > _Ptr
Definition: PtrTypes.hpp:204
_D & operator*()
Definition: PtrTypes.hpp:318
Definition: ByteBuffer.hpp:37
_Ptr _dptr
Definition: PtrTypes.hpp:344