/********************************************************************
 * File: RefCountedObject.cpp
 * Author: Keith Schwarz (htiek@cs.stanford.edu)
 *
 * Implementation of the RefCountedObject interface.
 */
#include "RefCountedObject.h"

/* Ctor sets reference count to zero. */
Copper3D::RefCountedObject::RefCountedObject() {
	refCount = 0;
}

/* Dtor does nothing; it's there so that:
 * 1. The class can't be destroyed from the outside.
 * 2. The class has a virtual destructor.
 */
Copper3D::RefCountedObject::~RefCountedObject() {
}

/* Bump the reference count. */
void Copper3D::RefCountedObject::addRef() const {
	++refCount;
}

void Copper3D::RefCountedObject::deleteRef() const {
	/* Drop the reference count and commit suicide if it hits zero. */
	if (--refCount == 0)
		delete this;
}

/* Return the reference count. */
size_t Copper3D::RefCountedObject::referenceCount() const {
	return refCount;
}
