Another massive overhaul to make calling conventions work. Solved several
[jitcs.git] / include / jitcs_adt_refcounter.h
blob4396d636e4b348612df67395a79c5e30486f3e0e
1 //===-- jitcs_adt_refcounter.h - pointer helper type ------------*- C++ -*-===//
2 //
3 //
4 //===----------------------------------------------------------------------===//
6 #ifndef _JITCS_ADT_REFCOUNTER_H_
7 #define _JITCS_ADT_REFCOUNTER_H_
9 #include <assert.h>
11 namespace jitcs {
12 // Ref represents a nonnull pointer to some object.
13 template <typename T> struct RefCounter {
14 T* _ptr;
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; }
26 #endif
27 // _JITCS_ADT_REFCOUNTER_H_