ScummVM API documentation
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
40
class
TeResourceManager
{
41
public
:
42
TeResourceManager
();
43
44
~
TeResourceManager
();
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
Common::Path
&path) {
64
for
(
TeIntrusivePtr<TeResource>
&resource : this->_resources) {
65
if
(resource->getAccessName() == path) {
66
return
TeIntrusivePtr<T>
(
dynamic_cast<
T *
>
(resource.get()));
67
}
68
}
69
70
TeIntrusivePtr<T>
retval =
new
T();
71
72
if
(retval.get()) {
73
if
(!
Common::File::exists
(path))
74
warning
(
"getResource: asked to fetch unreadable resource %s"
, path.
toString
(
Common::Path::kNativeSeparator
).c_str());
75
retval->load(path);
76
addResource(retval.get());
77
}
78
return
retval;
79
}
80
81
private
:
82
Common::Array<TeIntrusivePtr<TeResource>
> _resources;
83
84
};
85
86
}
// end namespace Tetraedge
87
88
#endif // TETRAEDGE_TE_TE_RESOURCE_MANAGER_H
Tetraedge
Definition:
detection.h:27
warning
void warning(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Common::Array
Definition:
array.h:52
Tetraedge::TeResource
Definition:
te_resource.h:31
Common::Path
Definition:
path.h:52
Common::Path::kNativeSeparator
static const char kNativeSeparator
Definition:
path.h:195
Tetraedge::TeResourceManager
Definition:
te_resource_manager.h:40
debug
void debug(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Common::Path::toString
String toString(char separator='/') const
Tetraedge::TeIntrusivePtr
Definition:
te_intrusive_ptr.h:31
Common::File::exists
static bool exists(const Path &filename)
engines
tetraedge
te
te_resource_manager.h
Generated on Thu Nov 21 2024 09:19:38 for ScummVM API documentation by
1.8.13