2011-06-02 21:59:20 +02:00
|
|
|
// Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
|
2011-05-19 06:36:14 +02:00
|
|
|
// This file is part of the "cAudio Engine"
|
|
|
|
// For conditions of distribution and use, see copyright notice in cAudio.h
|
|
|
|
|
2011-05-29 20:33:24 +02:00
|
|
|
#pragma once
|
2011-05-19 06:36:14 +02:00
|
|
|
|
|
|
|
#include "cAudioMemory.h"
|
|
|
|
|
|
|
|
namespace cAudio
|
|
|
|
{
|
|
|
|
//! Applies reference counting to certain cAudio objects.
|
|
|
|
class IRefCounted
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
IRefCounted() : RefCount(1) { }
|
|
|
|
virtual ~IRefCounted() { }
|
|
|
|
|
|
|
|
//! Increments the reference count by one.
|
|
|
|
void grab()
|
|
|
|
{
|
|
|
|
++RefCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Decrements the reference count by one. If it hits zero, this object is deleted.
|
|
|
|
bool drop()
|
|
|
|
{
|
|
|
|
--RefCount;
|
|
|
|
if (RefCount < 1)
|
|
|
|
{
|
|
|
|
CAUDIO_DELETE this;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Returns the current reference count of this object.
|
|
|
|
int getReferenceCount() const
|
|
|
|
{
|
|
|
|
return RefCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int RefCount;
|
|
|
|
};
|
|
|
|
}
|