Implement "weak pointer" behavior on Topology Path canonicalization hash table.
This commit is contained in:
parent
d1101441b3
commit
4931e44998
3 changed files with 49 additions and 57 deletions
|
@ -119,15 +119,39 @@ public:
|
|||
inline T *ptr() const throw() { return _ptr; }
|
||||
|
||||
/**
|
||||
* Set this pointer to null
|
||||
* Set this pointer to NULL
|
||||
*/
|
||||
inline void zero()
|
||||
{
|
||||
if (_ptr) {
|
||||
if (--_ptr->__refCount <= 0)
|
||||
delete _ptr;
|
||||
_ptr = (T *)0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this pointer to NULL if this is the only pointer holding the object
|
||||
*
|
||||
* @return True if object was deleted and SharedPtr is now NULL (or was already NULL)
|
||||
*/
|
||||
inline bool reclaimIfWeak()
|
||||
{
|
||||
if (_ptr) {
|
||||
if (++_ptr->__refCount <= 2) {
|
||||
if (--_ptr->__refCount <= 1) {
|
||||
delete _ptr;
|
||||
_ptr = (T *)0;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
_ptr = (T *)0;
|
||||
}
|
||||
|
||||
inline bool operator==(const SharedPtr &sp) const throw() { return (_ptr == sp._ptr); }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue