/
resourceclass.h
163 lines (141 loc) · 4.38 KB
/
resourceclass.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* @file resourceclass.h
*
* Resource Class. @ingroup resource
*
* @author Copyright © 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
* @author Copyright © 2006-2012 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#ifndef LIBDENG_RESOURCECLASS_H
#define LIBDENG_RESOURCECLASS_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* Resource Class Identifier.
*
* @ingroup base
*
* @todo Refactor away. These identifiers are no longer needed.
*/
typedef enum resourceclassid_e {
RC_NULL = -2, ///< Not a real class.
RC_UNKNOWN = -1, ///< Attempt to guess the class through evaluation of the path.
RESOURCECLASS_FIRST = 0,
RC_PACKAGE = RESOURCECLASS_FIRST,
RC_DEFINITION,
RC_GRAPHIC,
RC_MODEL,
RC_SOUND,
RC_MUSIC,
RC_FONT,
RESOURCECLASS_COUNT
} resourceclassid_t;
#define VALID_RESOURCECLASSID(n) ((n) >= RESOURCECLASS_FIRST && (n) < RESOURCECLASS_COUNT)
#ifdef __cplusplus
} // extern "C"
#endif
#ifdef __cplusplus
#ifndef DENG2_C_API_ONLY
#include <QList>
#include <de/String>
#include "filetype.h"
namespace de
{
/**
* ResourceClass encapsulates the properties and logics belonging to a logical
* class of resource (e.g., Graphic, Model, Sound, etc...)
*
* @ingroup base
*/
struct ResourceClass
{
public:
typedef QList<FileType*> FileTypes;
public:
ResourceClass(String _name, String _defaultScheme)
: name_(_name), defaultScheme_(_defaultScheme)
{}
virtual ~ResourceClass() {
DENG2_FOR_EACH(FileTypes, i, fileTypes_)
{
delete *i;
}
}
/// Return the symbolic name of this resource class.
String const& name() const
{
return name_;
}
/// Return the symbolic name of the default filesystem subspace scheme
/// for this class of resource.
String const& defaultScheme() const
{
return defaultScheme_;
}
/// Return the number of file types for this class of resource.
int fileTypeCount() const
{
return fileTypes_.count();
}
/**
* Add a new file type to the resource class. ResourceClass takes ownership.
* Earlier types have priority.
*
* @param ftype File type to add.
* @return This instance.
*/
ResourceClass& addFileType(FileType& ftype)
{
fileTypes_.push_back(&ftype);
return *this;
}
/**
* Provides access to the file type list for efficient iteration.
*
* @return List of file types for this class of resource.
*/
FileTypes const& fileTypes() const
{
return fileTypes_;
}
private:
/// Symbolic name for this class.
String name_;
/// Symbolic name of the default filesystem subspace scheme.
String defaultScheme_;
/// Recognized file types (in order of importance, left to right).
FileTypes fileTypes_;
};
/**
* The special "null" ResourceClass object.
*
* @ingroup core
*/
struct NullResourceClass : public ResourceClass
{
NullResourceClass() : ResourceClass("FC_NONE", "")
{}
};
/// @return @c true= @a rclass is a "null-resourceclass" object (not a real class).
inline bool isNullResourceClass(ResourceClass const& rclass) {
return !!dynamic_cast<NullResourceClass const*>(&rclass);
}
} // namespace de
#endif // DENG2_C_API_ONLY
#endif // __cplusplus
#endif /* LIBDENG_RESOURCECLASS_H */