sftools  2.0 dev
Bunch of tools for SFML application development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
GenericManager.hpp
Go to the documentation of this file.
1 /*
2 
3  sftools - Copyright (c) 2012-2013 Marco Antognini <antognini.marco@gmail.com>
4 
5  This software is provided 'as-is', without any express or implied warranty. In
6  no event will the authors be held liable for any damages arising from the use
7  of this software.
8 
9  Permission is granted to anyone to use this software for any purpose, including
10  commercial applications, and to alter it and redistribute it freely, subject to
11  the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not claim
14  that you wrote the original software. If you use this software in a product,
15  an acknowledgment in the product documentation would be appreciated but is
16  not required.
17 
18  2. Altered source versions must be plainly marked as such, and must not be
19  misrepresented as being the original software.
20 
21  3. This notice may not be removed or altered from any source distribution.
22 
23  */
24 
30 #ifndef __SFTOOLS_GENERICMANAGERS_HPP__
31 #define __SFTOOLS_GENERICMANAGERS_HPP__
32 
33 #include <SFML/System/NonCopyable.hpp>
34 #include <string>
35 #include <map>
36 #include <functional> // std::less
37 
42 namespace sftools
43 {
45 
58  template <typename Resource, typename Id, typename OnLoad>
60  {
61  public:
66 
76  bool load(Id const& id, bool forceReload = false);
77 
83  void unload(Id const& id);
84 
88  void unloadAll();
89 
100  Resource const& operator[](Id const& id) const;
101 
112  Resource& operator[](Id const& id);
113 
114  private:
115  typedef Resource* ResourcePtr;
116 
117  typedef std::map<Id, ResourcePtr> Map;
118 
119  typedef typename Map::iterator MapIterator;
120  typedef typename Map::const_iterator MapConstIterator;
121 
122  Map m_resources;
123 
124  OnLoad m_onLoad;
125  };
126 }
127 
129 
130 #endif // __SFTOOLS_GENERICMANAGERS_HPP__