MADARA  3.4.1
ScopedArray.h
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 #ifndef _MADARA_UTILITY_SCOPED_ARRAY_H_
3 #define _MADARA_UTILITY_SCOPED_ARRAY_H_
4 
5 namespace madara
6 {
7 namespace utility
8 {
21 template<typename T>
23 {
24 public:
26  ScopedArray(void);
27 
29  ScopedArray(T* ptr, bool increase_count = false);
30 
32  ScopedArray(const ScopedArray& rhs);
33 
35  virtual ~ScopedArray(void);
36 
39  void operator=(T* ptr);
40 
42  void operator=(const ScopedArray& rhs);
43 
45  T* get_ptr(void);
46 
48  const T* get_ptr(void) const;
49 
51  T* get(void);
52 
54  const T* get(void) const;
55 
56 private:
58  inline void increment(void);
59 
61  inline void decrement(void);
62 
65  struct Shim
66  {
68  Shim(T* t);
69 
71  ~Shim(void);
72 
74  T* t_;
75 
77  int refcount_;
78  };
79 
82 };
83 }
84 }
86 
87 #endif /* _MADARA_UTILITY_SCOPED_ARRAY_H_ */
This template class provides transparent reference counting of its template parameter T.
Definition: ScopedArray.h:23
Shim * ptr_
Pointer to the Shim.
Definition: ScopedArray.h:81
void increment(void)
implementation of the increment operation
Definition: ScopedArray.inl:92
void operator=(T *ptr)
assignment operator for times when you don't want the reference increased for incoming ptr
Definition: ScopedArray.inl:40
T * get_ptr(void)
get the underlying pointer
Definition: ScopedArray.inl:64
T * get(void)
get the underlying pointer
Definition: ScopedArray.inl:78
virtual ~ScopedArray(void)
Dtor will delete pointer if refcount becomes 0.
Definition: ScopedArray.inl:32
void decrement(void)
implementation of the decrement operation
ScopedArray(void)
default Ctor
Definition: ScopedArray.inl:9
Provides utility functions and classes for common tasks and needs.
Definition: IteratorImpl.h:15
Copyright(c) 2020 Galois.
A shim class that keeps track of the reference count and a pointer to the type T that's reference cou...
Definition: ScopedArray.h:66
int refcount_
Current value of the reference count.
Definition: ScopedArray.h:77
T * t_
Pointer to the object that's being reference counted.
Definition: ScopedArray.h:74