ResourcePtr.inl
00001 00002 // 00003 // SFML - Simple and Fast Multimedia Library 00004 // Copyright (C) 2007 Laurent Gomila ([email protected]) 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 ResourcePtr<T>::ResourcePtr() : 00031 myResource(NULL) 00032 { 00033 00034 } 00035 00036 00040 template <typename T> 00041 ResourcePtr<T>::ResourcePtr(const T* Resource) : 00042 myResource(Resource) 00043 { 00044 if (myResource) 00045 myResource->Connect(*this); 00046 } 00047 00048 00052 template <typename T> 00053 ResourcePtr<T>::ResourcePtr(const ResourcePtr<T>& Copy) : 00054 myResource(Copy.myResource) 00055 { 00056 if (myResource) 00057 myResource->Connect(*this); 00058 } 00059 00060 00064 template <typename T> 00065 ResourcePtr<T>::~ResourcePtr() 00066 { 00067 if (myResource) 00068 myResource->Disconnect(*this); 00069 } 00070 00071 00075 template <typename T> 00076 ResourcePtr<T>& ResourcePtr<T>::operator =(const ResourcePtr<T>& Other) 00077 { 00078 if (myResource) 00079 myResource->Disconnect(*this); 00080 00081 myResource = Other.myResource; 00082 00083 if (myResource) 00084 myResource->Connect(*this); 00085 00086 return *this; 00087 } 00088 00089 00093 template <typename T> 00094 ResourcePtr<T>& ResourcePtr<T>::operator =(const T* Resource) 00095 { 00096 if (myResource) 00097 myResource->Disconnect(*this); 00098 00099 myResource = Resource; 00100 00101 if (myResource) 00102 myResource->Connect(*this); 00103 00104 return *this; 00105 } 00106 00107 00114 template <typename T> 00115 ResourcePtr<T>::operator const T*() const 00116 { 00117 return myResource; 00118 } 00119 00120 00124 template <typename T> 00125 const T& ResourcePtr<T>::operator *() const 00126 { 00127 return *myResource; 00128 } 00129 00130 00134 template <typename T> 00135 const T* ResourcePtr<T>::operator ->() const 00136 { 00137 return myResource; 00138 } 00139 00140 00145 template <typename T> 00146 void ResourcePtr<T>::OnResourceDestroyed() 00147 { 00148 myResource = NULL; 00149 }
:: Copyright © 2007-2008 Laurent Gomila, all rights reserved :: Documentation generated by doxygen 1.5.2 ::