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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 /*
24  * This code is based on Broken Sword 2.5 engine
25  *
26  * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
27  *
28  * Licensed under GNU GPL v2
29  *
30  */
31 
32 #ifndef SWORD25_RESOURCE_H
33 #define SWORD25_RESOURCE_H
34 
35 #include "common/list.h"
36 #include "common/str.h"
37 #include "sword25/kernel/common.h"
38 
39 namespace Sword25 {
40 
41 class Kernel;
42 class ResourceManager;
43 
44 class Resource {
45 	friend class ResourceManager;
46 
47 public:
48 	enum RESOURCE_TYPES {
49 		TYPE_UNKNOWN,
50 		TYPE_BITMAP,
51 		TYPE_ANIMATION,
52 		TYPE_SOUND,
53 		TYPE_FONT
54 	};
55 
56 	Resource(const Common::String &uniqueFileName, RESOURCE_TYPES type);
57 
58 	/**
59 	 * Prevents the resource from being released.
60 	 * @remarks             This method allows a resource to be locked multiple times.
61 	 **/
addReference()62 	void addReference() {
63 		++_refCount;
64 	}
65 
66 	/**
67 	 * Cancels a previous lock
68 	 * @remarks             The resource can still be released more times than it was 'locked', although it is
69 	 * not recommended.
70 	 **/
71 	void release();
72 
73 	/**
74 	 * Returns the current lock count for the resource
75 	 * @return              The current lock count
76 	 **/
getLockCount()77 	int getLockCount() const {
78 		return _refCount;
79 	}
80 
81 	/**
82 	 * Returns the absolute path of the given resource
83 	 */
getFileName()84 	const Common::String &getFileName() const {
85 		return _fileName;
86 	}
87 
88 	/**
89 	 * Returns a resource's type
90 	 */
getType()91 	uint getType() const {
92 		return _type;
93 	}
94 
95 protected:
~Resource()96 	virtual ~Resource() {}
97 
98 private:
99 	Common::String _fileName;          ///< The absolute filename
100 	uint _refCount;          ///< The number of locks
101 	uint _type;              ///< The type of the resource
102 	Common::List<Resource *>::iterator _iterator;        ///< Points to the resource position in the LRU list
103 };
104 
105 } // End of namespace Sword25
106 
107 #endif
108