MADARA  3.2.3
Refcounter.h
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 #ifndef _MADARA_UTILITY_REFCOUNTER_H_
3 #define _MADARA_UTILITY_REFCOUNTER_H_
4 
5 namespace madara
6 {
7  namespace utility
8  {
20  template <typename T>
21  class Refcounter
22  {
23  public:
25  Refcounter (void);
26 
28  Refcounter (T * ptr, bool increase_count = false);
29 
31  Refcounter (const Refcounter & rhs);
32 
34  virtual ~Refcounter (void);
35 
38  void operator= (T * ptr);
39 
41  void operator= (const Refcounter & rhs);
42 
44  inline T & operator* (void);
45 
47  inline const T & operator* (void) const;
48 
50  inline T * operator-> (void);
51 
53  inline const T * operator-> (void) const;
54 
56  T * get_ptr (void);
57 
59  const T * get_ptr (void) const;
60 
62  T * get (void);
63 
65  const T * get (void) const;
66 
67  private:
69  inline void increment (void);
70 
72  inline void decrement (void);
73 
76  struct Shim
77  {
79  Shim (T * t);
80 
82  ~Shim (void);
83 
85  T * t_;
86 
88  int refcount_;
89  };
90 
93  };
94  }
95 }
97 
98 #endif /* _MADARA_UTILITY_REFCOUNTER_H_ */
T & operator*(void)
dereference operator
Definition: Refcounter.cpp:97
T * operator->(void)
mimic pointer dereferencing
Definition: Refcounter.cpp:114
A shim class that keeps track of the reference count and a pointer to the type T that&#39;s reference cou...
Definition: Refcounter.h:76
Shim * ptr_
Pointer to the Shim.
Definition: Refcounter.h:92
T * t_
Pointer to the object that&#39;s being reference counted.
Definition: Refcounter.h:85
T * get_ptr(void)
get the underlying pointer
Definition: Refcounter.cpp:64
virtual ~Refcounter(void)
Dtor will delete pointer if refcount becomes 0.
Definition: Refcounter.cpp:33
void decrement(void)
implementation of the decrement operation
Definition: Refcounter.cpp:139
Provides utility functions and classes for common tasks and needs.
Definition: IteratorImpl.h:14
void increment(void)
implementation of the increment operation
Definition: Refcounter.cpp:130
Copyright (c) 2015 Carnegie Mellon University.
Refcounter(void)
default Ctor
Definition: Refcounter.cpp:9
int refcount_
Current value of the reference count.
Definition: Refcounter.h:88
void operator=(T *ptr)
assignment operator for times when you don&#39;t want the reference increased for incoming ptr ...
Definition: Refcounter.cpp:42