Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

73 lines (60 sloc) 1.332 kB
#pragma once
namespace clay {
template<class T>
class Pointer {
T *p;
public :
Pointer()
: p(0) {}
Pointer(T *p)
: p(p) {
if (p)
p->incRef();
}
Pointer(const Pointer<T> &other)
: p(other.p) {
if (p)
p->incRef();
}
~Pointer() {
if (p)
p->decRef();
}
Pointer<T> &operator=(const Pointer<T> &other) {
T *q = other.p;
if (q) q->incRef();
if (p) p->decRef();
p = q;
return *this;
}
T &operator*() const { return *p; }
T *operator->() const { return p; }
T *ptr() const { return p; }
bool operator!() const { return p == 0; }
bool operator==(const Pointer<T> &other) const {
return p == other.p;
}
bool operator!=(const Pointer<T> &other) const {
return p != other.p;
}
bool operator<(const Pointer<T> &other) const {
return p < other.p;
}
};
struct RefCounted {
private:
int refCount;
public:
RefCounted()
: refCount(0) {}
RefCounted(const RefCounted& that): refCount(0) {}
void incRef() { ++refCount; }
void decRef() {
if (--refCount == 0) {
delete this;
}
}
int getRefCount() { return refCount; }
virtual ~RefCounted() {}
};
}
Jump to Line
Something went wrong with that request. Please try again.