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; }
262 template<
class _D,
class _Traits = rw_po
inter::Shared<_D> >
265 typedef typename _Traits::_Ptr
_Ptr;
282 void reset(
typename _Ptr::element_type * dptr )
289 {
_dptr.swap( rhs ); }
298 {
return _dptr.get(); }
300 const _D *
get()
const
301 {
return _dptr.get(); }
307 {
return _dptr.get(); }
310 {
return _dptr.get(); }
314 {
return _Traits().unique(
_dptr ); }
317 {
return _Traits().use_count(
_dptr ); }
335 template<
class _D,
class _Ptr>
336 inline std::ostream &
337 operator<<( std::ostream & str, const RW_pointer<_D, _Ptr> & obj )
340 return str << *obj.get();
341 return str << std::string(
"NULL");
345 template<
class _D,
class _Ptr>
349 return( lhs.
get() == rhs.
get() );
353 template<
class _D,
class _Ptr>
357 return ! ( lhs == rhs );
368 inline _D * rwcowClone(
const _D * rhs )
369 {
return rhs->clone(); }
383 template<
class _D,
class _Traits = rw_po
inter::Shared<_D> >
386 typedef typename _Traits::_Ptr
_Ptr;
403 void reset(
typename _Ptr::element_type * dptr )
410 {
_dptr.swap( rhs ); }
419 {
return _dptr.get(); }
421 const _D *
get()
const
422 {
return _dptr.get(); }
435 {
return _Traits().unique(
_dptr ); }
438 {
return _Traits().use_count(
_dptr ); }
464 template<
class _D,
class _Ptr>
465 inline std::ostream &
466 operator<<( std::ostream & str, const RWCOW_pointer<_D, _Ptr> & obj )
469 return str << *obj.get();
470 return str << std::string(
"NULL");
474 template<
class _D,
class _Ptr>
478 return( lhs.
get() == rhs.
get() );
482 template<
class _D,
class _Ptr>
486 return ! ( lhs == rhs );
497 #define DEFINE_PTR_TYPE(NAME) \
499 extern void intrusive_ptr_add_ref( const NAME * ); \
500 extern void intrusive_ptr_release( const NAME * ); \
501 typedef ca_mgm::intrusive_ptr<NAME> NAME##_Ptr; \
502 typedef ca_mgm::intrusive_ptr<const NAME> NAME##_constPtr;
505 #endif // CA_MGM_BASE_PTRTYPES_H