UGDK  0.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
resourcemanager.h
Go to the documentation of this file.
1 #ifndef UGDK_BASE_RESOURCEMANAGER_H_
2 #define UGDK_BASE_RESOURCEMANAGER_H_
3 
4 #include <typeinfo>
5 #include <map>
6 #include <ugdk/action.h>
8 #include <ugdk/graphic.h>
9 #include <ugdk/util.h>
10 
11 #define RESOURCE_MANAGER() (ugdk::Engine::reference()->resource_manager())
12 
13 namespace ugdk {
14 namespace base {
15 
17  public:
20 
21  static graphic::Texture* GetTextureFromTag (const std::string& tag);
22  static graphic::Texture* GetTextureFromFile (const std::string& file);
23  static graphic::Spritesheet* GetSpritesheetFromTag (const std::string& tag);
24  static action::AnimationSet* GetAnimationSetFromFile (const std::string& file);
25  static graphic::Text* CreateTextFromLanguageTag(const std::string& tag);
26 
27  // Generic Methods
28  template <class T>
30  containers_[&typeid(T)] = container;
31  }
32 
33  template <class T>
35  ResourceContainerBase* base = containers_[&typeid(T)];
36  ResourceContainer<T>* container = static_cast<ResourceContainer<T>*>(base);
37  return *container;
38  }
39 
40  // Retro-compatibility
41  ResourceContainer<graphic::Texture*>& texture_container() { return get_container<graphic::Texture*>(); }
42  ResourceContainer<graphic::Spritesheet*>& spritesheet_container() { return get_container<graphic::Spritesheet*>(); }
43  ResourceContainer<action::AnimationSet*>& animation_loader() { return get_container<action::AnimationSet*>(); }
44  ResourceContainer<LanguageWord*>& word_container() { return get_container<LanguageWord*>(); }
45 
46  private:
47  typedef std::map<const std::type_info*, ResourceContainerBase*,
48  bool (*)(const std::type_info*, const std::type_info*) > ResourceMap;
49  ResourceMap containers_;
50 };
51 
52 } // namespace base
53 } // namespace ugdk
54 
55 #endif // UGDK_BASE_RESOURCEMANAGER_H_
56