lemon/refptr.h
changeset 2151 38ec4a930c05
parent 1977 8ef02f0c4245
child 2391 14a343be7a5a
     1.1 --- a/lemon/refptr.h	Tue Jul 18 12:10:52 2006 +0000
     1.2 +++ b/lemon/refptr.h	Tue Jul 18 13:29:59 2006 +0000
     1.3 @@ -45,8 +45,10 @@
     1.4      
     1.5      void attach(RefPtr &r) 
     1.6      {
     1.7 -      prev=&r; next=r.next; ref=r.ref;
     1.8 -      r.next=this;
     1.9 +      if(r.ref) {
    1.10 +	prev=&r; next=r.next; ref=r.ref;
    1.11 +	r.next=this;
    1.12 +      }
    1.13      }
    1.14      void attach(const T *p) 
    1.15      {
    1.16 @@ -139,6 +141,30 @@
    1.17      ///\e
    1.18      operator bool() const { return ref; }
    1.19  
    1.20 +    ///\e
    1.21 +    const RefPtr &borrow(const T* &p) { 
    1.22 +      lock();
    1.23 +      if(ref==p) {
    1.24 +	if(prev) prev->next=next;
    1.25 +	if(next) next->prev=prev;
    1.26 +      }
    1.27 +      else release();
    1.28 +      ref=p;
    1.29 +      next=prev=this;
    1.30 +      unlock();
    1.31 +      return *this;
    1.32 +    }
    1.33 +    
    1.34 +    ///\e
    1.35 +    const RefPtr &borrow() { 
    1.36 +      lock();
    1.37 +      if(prev) prev->next=next;
    1.38 +      if(next) next->prev=prev;
    1.39 +      next=prev=this;
    1.40 +      unlock();
    1.41 +      return *this;
    1.42 +    }
    1.43 +    
    1.44    };  //END OF CLASS REFPTR
    1.45    
    1.46  } //END OF NAMESPACE LEMON