00001 // This is core/vbl/vbl_ref_count.h 00002 #ifndef vbl_ref_count_h 00003 #define vbl_ref_count_h 00004 //: 00005 // \file 00006 // 00007 // \verbatim 00008 // Modifications 00009 // 21/03/2001 PDA (Manchester) Tidied up the documentation 00010 // 10/09/2004 Peter Vanroose Inlined all 1-line methods in class decl 00011 // \endverbatim 00012 00013 #include <vcl_atomic_count.h> 00014 00015 class vbl_ref_count 00016 { 00017 vcl_atomic_count ref_count_; 00018 public: 00019 vbl_ref_count() : ref_count_(0) { } 00020 // Copying an object should not copy the ref count. 00021 vbl_ref_count(vbl_ref_count const&) : ref_count_(0) { } 00022 00023 vbl_ref_count& 00024 operator=(vbl_ref_count const& /*rhs*/) 00025 { /* should not copy the ref count */ return *this; } 00026 00027 virtual ~vbl_ref_count() {} 00028 00029 void ref() { ++ref_count_; } 00030 void unref() { /*assert(ref_count_>0);*/ if (--ref_count_ == 0) delete this; } 00031 int get_references() const { return ref_count_; } 00032 bool is_referenced() const { return ref_count_ > 0; } 00033 }; 00034 00035 #endif // vbl_ref_count_h