Changeset 282 in Sophya for trunk/SophyaLib/BaseTools


Ignore:
Timestamp:
Apr 29, 1999, 2:46:32 PM (26 years ago)
Author:
ansari
Message:

comptage de refs simple

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/BaseTools/rcptr.h

    r281 r282  
    66// This implements a very simple "smart pointer" with reference counting.
    77// Many refinements are possible
    8 //  - implement operator =
    98//  - const propagation
    10 //  - invasive, when type T has field refcnt, instead of list
     9// ...
    1110
    1211// Principle :  use RCPtr<T> instead of T*
     
    2221class RCPtr {
    2322public:
    24   RCPtr(T* obj) {
     23  RCPtr(T* obj=0) {
    2524    x = obj;
    2625    cnt = new int;
     
    3231    cnt = other.cnt;
    3332    (*cnt)++;
     33  }
     34
     35  RCPtr<T>& operator = (RCPtr const& other) {
     36    (*cnt)--;
     37    if (!*cnt) {
     38      delete x;
     39      delete cnt;
     40    }
     41    x = other.x;
     42    cnt = other.cnt;
     43    (*cnt)++;
     44    return *this;
    3445  }
    3546 
Note: See TracChangeset for help on using the changeset viewer.