1 //===-- jitcs_adt_refcounter.h - pointer helper type ------------*- C++ -*-===//
4 //===----------------------------------------------------------------------===//
6 #ifndef _JITCS_ADT_REFCOUNTER_H_
7 #define _JITCS_ADT_REFCOUNTER_H_
12 // Ref represents a nonnull pointer to some object.
13 template <typename T
> struct RefCounter
{
16 RefCounter() = delete;
17 RefCounter
& operator =(const RefCounter
&) = delete;
18 RefCounter(const RefCounter
& r
) { _ptr
= r
._ptr
; _ptr
->_incRef(); }
19 RefCounter(T
* d
) { assert(d
!= nullptr); _ptr
= d
; _ptr
->_incRef(); }
20 ~RefCounter() { _ptr
->_decRef(); }
22 T
* operator ->() { return _ptr
; }
23 T
& operator *() { return *_ptr
; }
28 // _JITCS_ADT_REFCOUNTER_H_