21 #ifndef FIFE_SHARED_PTR_H_
22 #define FIFE_SHARED_PTR_H_
34 #include "fife_stdint.h"
50 : m_ptr(0), m_refCount(0) {
61 : m_ptr(ptr), m_refCount(ptr ? new uint32_t(1) : 0) {
69 : m_ptr(rhs.m_ptr), m_refCount(rhs.m_refCount) {
95 if (m_refCount && *m_refCount == 0) {
108 if (rhs.
get() == m_ptr) {
123 template <
typename U>
126 if (rhs.
get() == m_ptr) {
155 inline T*
get()
const {
165 assert(ptr == 0 || ptr != m_ptr);
199 return (*m_refCount == 1);
207 operator bool()
const {
223 std::swap(m_ptr, rhs.m_ptr);
224 std::swap(m_refCount, rhs.m_refCount);
230 inline void incRefCount() {
239 inline void decRefCount() {
247 uint32_t* m_refCount;
252 template <
typename T,
typename U>
254 return (lhs.
get() == rhs.
get());
259 template <
typename T,
typename U>
261 return (lhs.
get() != rhs.
get());
266 template<
class T,
class U>
267 inline bool operator<(SharedPtr<T>
const& lhs,
SharedPtr<U> const& rhs) {
268 return std::less<const void*>()(lhs.get(), rhs.get());
274 template <
typename T>
280 #endif //FIFE_SHARED_PTR_H_
SharedPtr< T > make_shared(T *ptr)
SharedPtr(const SharedPtr< U > &rhs)
bool operator!=(const SharedPtr< T > &lhs, const SharedPtr< U > &rhs)
bool operator==(const SharedPtr< T > &lhs, const SharedPtr< U > &rhs)
uint32_t * useCountPtr() const
SharedPtr & operator=(const SharedPtr &rhs)
SharedPtr(const SharedPtr &rhs)
SharedPtr & operator=(const SharedPtr< U > &rhs)
uint32_t useCount() const