lemon/refptr.h
changeset 2152 ba87d27667cd
parent 1977 8ef02f0c4245
child 2391 14a343be7a5a
equal deleted inserted replaced
0:5aa253225491 1:f43d05028566
    43     void lock() {}
    43     void lock() {}
    44     void unlock() {}
    44     void unlock() {}
    45     
    45     
    46     void attach(RefPtr &r) 
    46     void attach(RefPtr &r) 
    47     {
    47     {
    48       prev=&r; next=r.next; ref=r.ref;
    48       if(r.ref) {
    49       r.next=this;
    49 	prev=&r; next=r.next; ref=r.ref;
       
    50 	r.next=this;
       
    51       }
    50     }
    52     }
    51     void attach(const T *p) 
    53     void attach(const T *p) 
    52     {
    54     {
    53       prev=0; next=0; ref=p;
    55       prev=0; next=0; ref=p;
    54     }
    56     }
   137     bool operator!=(const RefPtr &r) const { return this->ref != r.ref; }
   139     bool operator!=(const RefPtr &r) const { return this->ref != r.ref; }
   138     
   140     
   139     ///\e
   141     ///\e
   140     operator bool() const { return ref; }
   142     operator bool() const { return ref; }
   141 
   143 
       
   144     ///\e
       
   145     const RefPtr &borrow(const T* &p) { 
       
   146       lock();
       
   147       if(ref==p) {
       
   148 	if(prev) prev->next=next;
       
   149 	if(next) next->prev=prev;
       
   150       }
       
   151       else release();
       
   152       ref=p;
       
   153       next=prev=this;
       
   154       unlock();
       
   155       return *this;
       
   156     }
       
   157     
       
   158     ///\e
       
   159     const RefPtr &borrow() { 
       
   160       lock();
       
   161       if(prev) prev->next=next;
       
   162       if(next) next->prev=prev;
       
   163       next=prev=this;
       
   164       unlock();
       
   165       return *this;
       
   166     }
       
   167     
   142   };  //END OF CLASS REFPTR
   168   };  //END OF CLASS REFPTR
   143   
   169   
   144 } //END OF NAMESPACE LEMON
   170 } //END OF NAMESPACE LEMON
   145 
   171 
   146 #endif
   172 #endif