SFML logo
  • Main Page
  • Namespaces
  • Classes
  • Files
  • File List

Resource.hpp

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 #ifndef SFML_RESOURCE_HPP
00026 #define SFML_RESOURCE_HPP
00027 
00029 // Headers
00031 #include <SFML/System/Lock.hpp>
00032 #include <SFML/System/Mutex.hpp>
00033 #include <set>
00034 
00035 
00036 namespace sf
00037 {
00039 // These two classes are defined in the same header because
00040 // they depend on each other. And as they're template classes,
00041 // they must be entirely defined in header files, which
00042 // prevents from proper separate compiling
00044 
00045 template <typename> class ResourcePtr;
00046 
00052 template <typename T>
00053 class Resource
00054 {
00055 protected :
00056 
00061     Resource();
00062 
00069     Resource(const Resource<T>& copy);
00070 
00075     ~Resource();
00076 
00085     Resource<T>& operator =(const Resource<T>& other);
00086 
00087 private :
00088 
00089     friend class ResourcePtr<T>;
00090 
00100     void Connect(ResourcePtr<T>& observer) const;
00101 
00111     void Disconnect(ResourcePtr<T>& observer) const;
00112 
00114     // Member data
00116     mutable std::set<ResourcePtr<T>*> myObservers; 
00117     mutable Mutex                     myMutex;     
00118 };
00119 
00120 
00125 template <typename T>
00126 class ResourcePtr
00127 {
00128 public :
00129 
00136     ResourcePtr();
00137 
00144     ResourcePtr(const T* resource);
00145 
00154     ResourcePtr(const ResourcePtr<T>& copy);
00155 
00160     ~ResourcePtr();
00161 
00170     ResourcePtr<T>& operator =(const ResourcePtr<T>& other);
00171 
00180     ResourcePtr<T>& operator =(const T* resource);
00181 
00192     operator const T*() const;
00193 
00203     const T& operator *() const;
00204 
00214     const T* operator ->() const;
00215 
00225     void OnResourceDestroyed();
00226 
00227 private :
00228 
00230     // Member data
00232     const T* myResource; 
00233 };
00234 
00235 #include <SFML/System/Resource.inl>
00236 #include <SFML/System/ResourcePtr.inl>
00237 
00238 } // namespace sf
00239 
00240 
00241 #endif // SFML_RESOURCE_HPP
00242 
00243 
00255 
00256 

 ::  Copyright © 2007-2008 Laurent Gomila, all rights reserved  ::  Documentation generated by doxygen 1.5.2  ::