ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
te_resource_manager.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 #ifndef TETRAEDGE_TE_TE_RESOURCE_MANAGER_H
23 #define TETRAEDGE_TE_TE_RESOURCE_MANAGER_H
24 
25 #include "common/array.h"
26 #include "common/path.h"
27 #include "common/ptr.h"
28 #include "common/file.h"
29 #include "common/textconsole.h"
30 
31 #include "tetraedge/tetraedge.h"
32 #include "tetraedge/te/te_resource.h"
33 #include "tetraedge/te/te_core.h"
34 #include "tetraedge/te/te_intrusive_ptr.h"
35 
36 namespace Tetraedge {
37 
38 class TeResource;
39 
41 public:
43 
45 
46  void addResource(const TeIntrusivePtr<TeResource> &resource);
47  void addResource(TeResource *resource);
48  bool exists(const Common::Path &path);
49  void removeResource(const TeIntrusivePtr<TeResource> &resource);
50  void removeResource(const TeResource *resource);
51 
52  template<class T> TeIntrusivePtr<T> getResourceByName(const Common::Path &path) {
53  for (TeIntrusivePtr<TeResource> &resource : this->_resources) {
54  if (resource->getAccessName() == path) {
55  return TeIntrusivePtr<T>(dynamic_cast<T *>(resource.get()));
56  }
57  }
58  debug("getResourceByName: didn't find resource %s", path.toString(Common::Path::kNativeSeparator).c_str());
59  return TeIntrusivePtr<T>();
60  }
61 
62  template<class T>
63  TeIntrusivePtr<T> getResource(const TetraedgeFSNode &node) {
64  Common::Path path = node.getPath();
65  for (TeIntrusivePtr<TeResource> &resource : this->_resources) {
66  if (resource->getAccessName() == path) {
67  return TeIntrusivePtr<T>(dynamic_cast<T *>(resource.get()));
68  }
69  }
70 
71  TeIntrusivePtr<T> retval = new T();
72 
73  if (retval.get()) {
74  if (!node.isReadable())
75  warning("getResource: asked to fetch unreadable resource %s", node.toString().c_str());
76  retval->load(node);
77  addResource(retval.get());
78  }
79  return retval;
80  }
81 
82 private:
84 
85 };
86 
87 } // end namespace Tetraedge
88 
89 #endif // TETRAEDGE_TE_TE_RESOURCE_MANAGER_H
Definition: detection.h:27
void warning(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: array.h:52
Definition: te_resource.h:31
Definition: tetraedge.h:58
Definition: path.h:52
static const char kNativeSeparator
Definition: path.h:195
Definition: te_resource_manager.h:40
void debug(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
String toString(char separator='/') const
Definition: te_intrusive_ptr.h:31