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