1 #ifndef s11n_net_refcount_REFCOUNT_HPP_INCLUDED
2 #define s11n_net_refcount_REFCOUNT_HPP_INCLUDED 1
215 template <
typename HandleT,
216 typename FinalizerT = plain_delete_finalizer>
232 typedef int counter_type;
233 typedef std::map<pointer_type,counter_type> map_type;
239 static map_type & map()
259 if( ! ptr )
return false;
260 typename map_type::iterator it = map().find(ptr);
261 if( map().end() == it )
return false;
262 if( 0 == (*it).second )
return 0;
263 counter_type rc = --(*it).second;
280 if( ! ptr )
return -1;
281 return ++(map()[ptr]);
301 this->increment( this->m_ptr );
309 this->increment( this->m_ptr );
321 if( rhs.m_ptr == this->m_ptr )
return *
this;
322 this->decrement( this->m_ptr );
323 this->m_ptr = rhs.m_ptr;
324 this->increment( this->m_ptr );
343 if( this->m_ptr != rhs )
346 this->m_ptr = rhs.m_ptr;
357 this->decrement( this->m_ptr );
363 return this->m_ptr == rhs.m_ptr;
368 return this->m_ptr != rhs.m_ptr;
377 return this->m_ptr < rhs.m_ptr;
396 if( p == this->m_ptr )
return;
397 this->decrement( this->m_ptr );
398 this->increment( this->m_ptr = p );
416 this->map().erase( this->m_ptr );
467 if( ! this->m_ptr )
return 0;
468 typename map_type::iterator it = map().find(this->m_ptr);
469 return ( map().end() == it ) ? 0 : (*it).second;
475 bool empty()
const {
return 0 == this->m_ptr; }
521 #endif // s11n_net_refcount_REFCOUNT_HPP_INCLUDED