OpenCurves  0.9
refcountobject.h
1 //
2 // author Kazys Stepanas
3 //
4 // Copyright (c) CSIRO 2015
5 //
6 #ifndef REFCOUNTOBJECT_H_
7 #define REFCOUNTOBJECT_H_
8 
9 namespace plotutil
10 {
29  template <class T>
31  {
32  public:
34  inline RefCountObject() : _referenceCount(0) {}
35 
38  inline RefCountObject(int initialCount) : _referenceCount(initialCount) {}
39 
42  inline int referenceCount() const { return _referenceCount; }
43 
46  inline int addReference() { return ++_referenceCount; }
47 
51  int decReference();
52 
53  private:
54  int _referenceCount;
55  };
56 
57 
58  template <class T>
60  {
61  int postDecCount = --_referenceCount;
62  if (postDecCount <= 0)
63  {
64  delete static_cast<T *>(this);
65  }
66  return postDecCount;
67  }
68 }
69 
70 #endif // REFCOUNTOBJECT_H_
RefCountObject()
Constructor, setting a zero reference count.
Definition: refcountobject.h:34
int decReference()
Decrement the reference count.
Definition: refcountobject.h:59
int referenceCount() const
Access the current reference count.
Definition: refcountobject.h:42
A base class for adding reference counting to a class.
Definition: refcountobject.h:30
RefCountObject(int initialCount)
Constructor, setting the given initial reference count.
Definition: refcountobject.h:38
int addReference()
Increment and return the reference count.
Definition: refcountobject.h:46
Utility functions for sampling and filtering plots and expression evaluation.
Definition: plotutil.h:13