vbl_ref_count.h
Go to the documentation of this file.
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 
16 {
17  vcl_atomic_count ref_count_;
18  public:
20  // Copying an object should not copy the ref count.
22 
24  operator=(vbl_ref_count const& /*rhs*/)
25  { /* should not copy the ref count */ return *this; }
26 
27  virtual ~vbl_ref_count() = default;
28 
29  void ref() { ++ref_count_; }
30  void unref() { /*assert(ref_count_>0);*/ if (--ref_count_ == 0) delete this; }
31  long get_references() const { return ref_count_; }
32  bool is_referenced() const { return ref_count_ > 0; }
33 };
34 
35 #endif // vbl_ref_count_h
virtual ~vbl_ref_count()=default
vbl_ref_count & operator=(vbl_ref_count const &)
Definition: vbl_ref_count.h:24
long get_references() const
Definition: vbl_ref_count.h:31
vcl_atomic_count ref_count_
Definition: vbl_ref_count.h:17
vbl_ref_count(vbl_ref_count const &)
Definition: vbl_ref_count.h:21
bool is_referenced() const
Definition: vbl_ref_count.h:32