Files

57 lines
994 B
C++
Raw Permalink Normal View History

2010-06-07 00:09:54 +02:00
/**
2014-08-22 16:58:23 +02:00
\file G3D/ReferenceCount.h
2010-06-07 00:09:54 +02:00
Reference Counting Garbage Collector for C++
2014-08-22 16:58:23 +02:00
\maintainer Morgan McGuire, http://graphics.cs.williams.edu
2010-06-07 00:09:54 +02:00
2014-08-22 16:58:23 +02:00
\created 2001-10-23
\edited 2013-01-05
2010-06-07 00:09:54 +02:00
*/
#ifndef G3D_ReferenceCount_h
#define G3D_ReferenceCount_h
2010-06-07 00:09:54 +02:00
#include "G3D/platform.h"
#include "G3D/debug.h"
#include "G3D/AtomicInt32.h"
2014-08-22 16:58:23 +02:00
#define USE_SHARED_PTR
2010-06-07 00:09:54 +02:00
2014-08-22 16:58:23 +02:00
#define ReferenceCountedPointer shared_ptr
#define WeakReferenceCountedPointer weak_ptr
namespace G3D {
2010-06-07 00:09:54 +02:00
2014-08-22 16:58:23 +02:00
class ReferenceCountedObject : public enable_shared_from_this<ReferenceCountedObject> {
2010-06-07 00:09:54 +02:00
public:
2014-08-22 16:58:23 +02:00
virtual ~ReferenceCountedObject() {};
2010-06-07 00:09:54 +02:00
};
2014-08-22 16:58:23 +02:00
} // namespace
2010-06-07 00:09:54 +02:00
2014-08-22 16:58:23 +02:00
namespace G3D {
2010-06-07 00:09:54 +02:00
2014-08-22 16:58:23 +02:00
template<class T>
bool isNull(const ReferenceCountedPointer<T>& ptr) {
return ! ptr;
2010-06-07 00:09:54 +02:00
}
2014-08-22 16:58:23 +02:00
template<class T>
bool notNull(const ReferenceCountedPointer<T>& ptr) {
return (bool)ptr;
}
2010-06-07 00:09:54 +02:00
2014-08-22 16:58:23 +02:00
template<class T>
bool isNull(const T* ptr) {
return ptr == NULL;
}
2010-06-07 00:09:54 +02:00
2014-08-22 16:58:23 +02:00
template<class T>
bool notNull(const T* ptr) {
return ptr != NULL;
}
2010-06-07 00:09:54 +02:00
} // namespace
#endif