comparison engine/core/util/resource/resource.h @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children 90005975cdbb
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 /***************************************************************************
2 * Copyright (C) 2005-2007 by the FIFE Team *
3 * fife-public@lists.sourceforge.net *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #ifndef FIFE_RESOURE_H
23 #define FIFE_RESOURE_H
24
25 // Standard C++ library includes
26
27 // 3rd party library includes
28
29 // FIFE includes
30 // These includes are split up in two parts, separated by one empty line
31 // First block: files included from the FIFE root src directory
32 // Second block: files included from the same folder
33 #include "resource_location.h"
34
35 namespace FIFE {
36
37 class IReferenceCounted {
38 public:
39 virtual ~IReferenceCounted() { }
40
41 /** Calling this method marks resource be used by some resource client.
42 * It adds one to resource counter that is kept up by the resource itself.
43 * When resource is about to be deleted (e.g. due to pooling algorithms),
44 * reference counter is inspected. In case value is non-zero, resource
45 * shouldn't be deleted.
46 */
47 virtual void addRef() = 0;
48
49 /** Calling this method unmarks resource be used by a resource client.
50 * @see addRef
51 */
52 virtual void decRef() = 0;
53
54 /** Gets the current reference count
55 * @see addRef
56 */
57 virtual unsigned int getRefCount() = 0;
58 };
59
60 /** IResource is the internal representation of a loaded file.
61 * One resource is always associated with one file (resource location).
62 */
63 class IResource: public virtual IReferenceCounted {
64 public:
65 virtual ~IResource() { }
66
67 /** Get the location/file of this resource.
68 */
69 virtual const ResourceLocation& getResourceLocation() = 0;
70 virtual const std::string& getResourceFile() = 0;
71
72 /** Change the location/file of this resource.
73 */
74 virtual void setResourceLocation(const ResourceLocation& location) = 0;
75 virtual void setResourceFile(const std::string& filename) = 0;
76
77 /** returns -1 if not pooled, otherwise its a valid id
78 */
79 virtual int getPoolId() = 0;
80 virtual void setPoolId(int poolid) = 0;
81 };
82
83 /** ResourceLoader defines a class for loading resources. The resource returned is owned by
84 * the caller, and must be deleted when finished.
85 * In case allocation fails, or loader cannot load given location, NULL is returned
86 */
87 class ResourceLoader {
88 public:
89 virtual ~ResourceLoader() { };
90 virtual IResource* loadResource(const ResourceLocation& location) = 0;
91 };
92
93 /** ResourceSaver defines a class for saving Resources.
94 */
95 class ResourceSaver {
96 public:
97 virtual ~ResourceSaver() { };
98
99 virtual void save(const ResourceLocation& location, IResource* resource) = 0;
100 virtual void save(const std::string& filename, IResource* resource) { save(ResourceLocation(filename), resource); }
101 };
102 }
103
104 #endif