Logo Search packages:      
Sourcecode: djvulibre version File versions  Download package

GPBase & GPBase::assign ( GPEnabled nptr  )  [inherited]

Assignment from pointer. Checks that the object is not being destroyed. Increments the counter of the new value of the pointer. Decrements the counter of the previous value of the pointer.

Definition at line 143 of file GSmartPointer.cpp.

References GPEnabled::count, GPEnabled::destroy(), and GPBase::ptr.

{
  gcsCounter.lock();
  if (nptr)
    {
      if (nptr->count >= 0)  
        nptr->count++;
      else
        nptr = 0;
    }
  if (ptr)
    {
      GPEnabled *old = ptr;
      ptr = nptr;
      int cnt = old->count;
      if (! --cnt) 
        cnt = -1;
      old->count = cnt;
      gcsCounter.unlock();      
      if (cnt < 0)
        old->destroy();
    }
  else
    {
      ptr = nptr;
      gcsCounter.unlock();
    }
  return *this;
}


Generated by  Doxygen 1.6.0   Back to index