caudio/include/IRefCounted.h

45 lines
932 B
C
Raw Normal View History

2010-02-09 05:18:39 +01:00
// Copyright (c) 2008-2010 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones
// This file is part of the "cAudio Engine"
// For conditions of distribution and use, see copyright notice in cAudio.h
#ifndef IREFCOUNTED_H
#define IREFCOUNTED_H
namespace cAudio
{
2010-02-17 06:57:55 +01:00
//! Applies reference counting to certain cAudio objects.
class IRefCounted
{
public:
IRefCounted() : RefCount(1) { }
virtual ~IRefCounted() { }
2010-02-17 06:57:55 +01:00
//! Increments the reference count by one.
void grab()
{
++RefCount;
}
2010-02-17 06:57:55 +01:00
//! Decrements the reference count by one. If it hits zero, this object is deleted.
bool drop()
{
--RefCount;
if (RefCount < 1)
{
delete this;
return true;
}
return false;
}
2010-02-17 06:57:55 +01:00
//! Returns the current reference count of this object.
int getReferenceCount() const
{
return RefCount;
}
private:
int RefCount;
};
}
#endif //! IREFCOUNTED_H