ScummVM API documentation
ResourceManager.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * Copyright (C) 2006-2010 - Frictional Games
24  *
25  * This file is part of HPL1 Engine.
26  */
27 
28 #ifndef HPL_RESOURCEMANAGER_H
29 #define HPL_RESOURCEMANAGER_H
30 
31 #include "hpl1/engine/system/SystemTypes.h"
32 #include "common/stablemap.h"
33 
34 namespace hpl {
35 
36 class LowLevelResources;
37 class LowLevelSystem;
38 class cFileSearcher;
39 class iResourceBase;
40 
41 typedef Common::StableMap<unsigned long, iResourceBase *> tResourceHandleMap;
42 typedef tResourceHandleMap::iterator tResourceHandleMapIt;
43 
44 typedef Common::StableMap<tString, iResourceBase *> tResourceNameMap;
45 typedef tResourceNameMap::iterator tResourceNameMapIt;
46 
47 typedef Common::List<iResourceBase *> tResourceBaseList;
48 typedef tResourceBaseList::iterator tResourceBaseListIt;
49 
50 typedef cSTLMapIterator<iResourceBase *, tResourceNameMap, tResourceNameMapIt> cResourceBaseIterator;
51 
53 public:
54  iResourceManager(cFileSearcher *apFileSearcher, LowLevelResources *apLowLevelResources,
55  LowLevelSystem *apLowLevelSystem);
56  virtual ~iResourceManager() {}
57 
58  virtual iResourceBase *Create(const tString &asName) = 0;
59 
60  iResourceBase *GetByName(const tString &asName);
61  iResourceBase *GetByHandle(unsigned long alHandle);
62 
63  cResourceBaseIterator GetResourceBaseIterator();
64 
65  void DestroyUnused(int alMaxToKeep);
66 
67  virtual void Destroy(iResourceBase *apResource) = 0;
68  virtual void DestroyAll();
69 
70  virtual void Unload(iResourceBase *apResource) = 0;
71 
72  virtual void Update(float afTimeStep) {}
73 
74 protected:
75  unsigned long mlHandleCount;
76  tResourceNameMap m_mapNameResources;
77  tResourceHandleMap m_mapHandleResources;
78 
79  cFileSearcher *mpFileSearcher;
80  LowLevelResources *mpLowLevelResources;
81  LowLevelSystem *mpLowLevelSystem;
82 
83  void BeginLoad(const tString &asFile);
84  void EndLoad();
85 
86  unsigned long mlTimeStart;
87 
94  iResourceBase *FindLoadedResource(const tString &asName, tString &asFilePath);
95  void AddResource(iResourceBase *apResource, bool abLog = true);
96  void RemoveResource(iResourceBase *apResource);
97 
98  unsigned long GetHandle();
99 
100  tString GetTabs();
101  static int mlTabCount;
102 };
103 
104 } // namespace hpl
105 
106 #endif // HPL_RESOURCEMANAGER_H
Definition: AI.h:36
Definition: str.h:59
Definition: ResourceBase.h:36
Definition: list.h:44
typename TreeT::BasicIterator iterator
Definition: stablemap.h:48
Definition: FileSearcher.h:43
Definition: low_level_resources.h:40
ListInternal::Iterator< t_T > iterator
Definition: list.h:52
Definition: low_level_system.h:95
Definition: ResourceManager.h:52
iResourceBase * FindLoadedResource(const tString &asName, tString &asFilePath)