1 // This is core/vbl/vbl_ref_count.h 2 #ifndef vbl_ref_count_h 3 #define vbl_ref_count_h 4 //: 5 // \file 6 // 7 // \verbatim 8 // Modifications 9 // 21/03/2001 PDA (Manchester) Tidied up the documentation 10 // 10/09/2004 Peter Vanroose Inlined all 1-line methods in class decl 11 // \endverbatim 12 13 #include <vcl_atomic_count.h> 14 15 class vbl_ref_count 16 { 17 vcl_atomic_count ref_count_; 18 public: vbl_ref_count()19 vbl_ref_count() : ref_count_(0) { } 20 // Copying an object should not copy the ref count. vbl_ref_count(vbl_ref_count const &)21 vbl_ref_count(vbl_ref_count const&) : ref_count_(0) { } 22 23 vbl_ref_count& 24 operator=(vbl_ref_count const& /*rhs*/) 25 { /* should not copy the ref count */ return *this; } 26 27 virtual ~vbl_ref_count() = default; 28 ref()29 void ref() { ++ref_count_; } unref()30 void unref() { /*assert(ref_count_>0);*/ if (--ref_count_ == 0) delete this; } get_references()31 long get_references() const { return ref_count_; } is_referenced()32 bool is_referenced() const { return ref_count_ > 0; } 33 }; 34 35 #endif // vbl_ref_count_h 36