00001 00002 // 00003 // SFML - Simple and Fast Multimedia Library 00004 // Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com) 00005 // 00006 // This software is provided 'as-is', without any express or implied warranty. 00007 // In no event will the authors be held liable for any damages arising from the use of this software. 00008 // 00009 // Permission is granted to anyone to use this software for any purpose, 00010 // including commercial applications, and to alter it and redistribute it freely, 00011 // subject to the following restrictions: 00012 // 00013 // 1. The origin of this software must not be misrepresented; 00014 // you must not claim that you wrote the original software. 00015 // If you use this software in a product, an acknowledgment 00016 // in the product documentation would be appreciated but is not required. 00017 // 00018 // 2. Altered source versions must be plainly marked as such, 00019 // and must not be misrepresented as being the original software. 00020 // 00021 // 3. This notice may not be removed or altered from any source distribution. 00022 // 00024 00025 00029 template <typename T> 00030 sfSharedPtr<T>::sfSharedPtr() : 00031 myPointee(0), 00032 myCount (new unsigned int(1)) 00033 { 00034 00035 } 00036 00037 00041 template <typename T> 00042 sfSharedPtr<T>::sfSharedPtr(T* Pointee) : 00043 myPointee(Pointee), 00044 myCount (new unsigned int(1)) 00045 { 00046 00047 } 00048 00049 00053 template <typename T> 00054 sfSharedPtr<T>::sfSharedPtr(const sfSharedPtr<T>& Copy) : 00055 myPointee(Copy.myPointee), 00056 myCount (Copy.myCount) 00057 { 00058 (*myCount)++; 00059 } 00060 00061 00065 template <typename T> 00066 sfSharedPtr<T>::~sfSharedPtr() 00067 { 00068 (*myCount)--; 00069 00070 if (*myCount == 0) 00071 { 00072 delete myPointee; 00073 delete myCount; 00074 } 00075 } 00076 00077 00081 template <typename T> 00082 sfSharedPtr<T>& sfSharedPtr<T>::operator =(const sfSharedPtr<T>& Other) 00083 { 00084 sfSharedPtr<T> Temp(Other); 00085 std::swap(myPointee, Temp.myPointee); 00086 std::swap(myCount, Temp.myCount); 00087 00088 return *this; 00089 } 00090 00091 00095 template <typename T> 00096 sfSharedPtr<T>& sfSharedPtr<T>::operator =(T* Pointee) 00097 { 00098 sfSharedPtr<T> Temp(Pointee); 00099 std::swap(myPointee, Temp.myPointee); 00100 std::swap(myCount, Temp.myCount); 00101 00102 return *this; 00103 } 00104 00105 00109 template <typename T> 00110 T* sfSharedPtr<T>::operator ->() const 00111 { 00112 return myPointee; 00113 } 00114 00115 00119 template <typename T> 00120 T& sfSharedPtr<T>::operator *() const 00121 { 00122 return *myPointee; 00123 } 00124 00125 00129 template <typename T> 00130 sfSharedPtr<T>::operator BoolType() const 00131 { 00132 return myPointee ? &sfSharedPtr<T>::myPointee : 0; 00133 } 00134 00135 00139 template <typename T> 00140 unsigned int sfSharedPtr<T>::GetRefCount() const 00141 { 00142 return *myCount; 00143 }