21 #ifndef FIFE_SHARED_PTR_H_ 22 #define FIFE_SHARED_PTR_H_ 123 template <
typename U>
155 inline T*
get()
const {
165 assert(ptr == 0 || ptr !=
m_ptr);
207 operator bool()
const {
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)
convenience function for making a shared pointer can be used anytime a shared pointer should be creat...
T * operator->() const
allows dereferencing of shared pointer to act identical to dereferencing the underlying pointer ...
uint32_t useCount() const
returns the current reference count this should only be called on a non-null shared pointer ...
SharedPtr(U *ptr)
Constructor takes over ownership of the provided pointer and will delete it automatically when last r...
void reset(T *ptr=0)
reset this pointer to a null shared pointer this can be used to lower the reference count of the shar...
void decRefCount()
decreases the reference count for this shared resource, used internally
SharedPtr(const SharedPtr< U > &rhs)
Constructor shares ownership with the value passed into rhs the pointer type passed in must be conver...
T & operator*() const
allows dereferencing of shared pointer to act identical to dereferencing the underlying pointer ...
void incRefCount()
increases the reference count for this shared resource, used internally
SharedPtr()
Constructor default constructor creates a null shared pointer.
void swap(SharedPtr< T > &rhs)
provides swapping function between two shared pointers, used internally
bool operator!=(const SharedPtr< T > &lhs, const SharedPtr< U > &rhs)
provides inequality operator for shared pointers
uint32_t * useCountPtr() const
returns the current reference count provides direct access to the user count pointer this should real...
~SharedPtr()
Destructor handles deletion of underlying pointer if the reference count reaches 0.
shared pointer implementation to provide automatic reference counting and deletion when last referenc...
bool operator!() const
negation operator overload
bool operator==(const SharedPtr< T > &lhs, const SharedPtr< U > &rhs)
provides equality operator for shared pointers
SharedPtr & operator=(const SharedPtr &rhs)
provides functionality for the equality operator
SharedPtr(const SharedPtr &rhs)
Copy Constructor provides ability to properly copy a shared resource.
bool unique() const
provides the ability to see if a shared resource is currently only held by a single shared pointer th...
T * get() const
allows direct access to underlying pointer
SharedPtr & operator=(const SharedPtr< U > &rhs)
provides functionality for the equality operator the passed in pointer type must be convertible to th...