Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/resources/src/lib/util/loading/resource.h @ 7229

Last change on this file since 7229 was 7229, checked in by bensch, 18 years ago

resources: some minor implementations

File size: 3.4 KB
Line 
1/*!
2 * @file resource.h
3 * @brief Definition of a Resource.
4*/
5
6#ifndef _RESOURCE_H
7#define _RESOURCE_H
8
9#include "base_object.h"
10#include "multi_type.h"
11#include <string>
12#include <map>
13#include <vector>
14
15
16namespace Loading
17{
18  // FORWARD DECLARATION
19
20  //! An enumerator for different (UN)LOAD-types.
21  /**
22   * RP_NO:        will be unloaded on request
23   * RP_LEVEL:     will be unloaded at the end of a Level
24   * RP_CAMPAIGN:  will be unloaded at the end of a Campaign
25   * RP_GAME:      will be unloaded at the end of the whole Game (when closing orxonox)
26   */
27  typedef enum ResourcePriority
28  {
29    RP_NO        =   0,
30    RP_LEVEL     =   1,
31    RP_CAMPAIGN  =   2,
32    RP_GAME      =   3
33  };
34
35
36  //! A Resource is an Object, that can be loaded from Disk
37  /**
38   * A Resource can cahnge the internal type, meaning it is a
39   * SmartPointer, that keeps track of the InternalCount of the
40   * Resource (SharedResource).
41   */
42  class Resource : virtual public BaseObject
43  {
44  protected:
45    /**
46     * This is a Class for the internal handling of the Resource.
47     * Any Resource keeps exactly one of these Classes, so it can
48     * reference and move it around, and keep track of how many
49     * references of it are stored.
50     */
51    class SharedResource
52    {
53    public:
54      SharedResource();
55      std::string       fileName;
56
57      unsigned int      referenceCount;    //!< How many times this Resource has been loaded.
58      ClassID           type;              //!< ResourceType of this Resource.
59      ResourcePriority  prio;              //!< The Priority of this resource. (can only be increased, so noone else will delete this)
60
61      MultiType         param[3];          //!< The Parameters given to this Resource.
62    };
63
64
65  public:
66    Resource(const std::string& fileName = "", ResourcePriority prio = RP_LEVEL);
67    virtual ~Resource();
68
69    // looks if the resource was already loaded and (if not) loads it.
70    virtual bool load(std::string& fileName = "",
71                      ResourcePriority prio = RP_LEVEL,
72                      const MultiType& param0 = MT_NULL,
73                      const MultiType& param1 = MT_NULL,
74                      const MultiType& param2 = MT_NULL);
75    // reloads the resource.
76    virtual bool reload() { };
77    // unloads the sharedResource (from this Resource)
78    virtual bool unload();
79
80    // checks if a resource was already loaded.
81    bool isLoaded(std::string& fileName,
82                  const MultiType& param0 = MT_NULL,
83                  const MultiType& param1 = MT_NULL,
84                  const MultiType& param2 = MT_NULL);
85
86    // raises the priority can only be raised
87    void raisePriority(ResourcePriority prio);
88    /** @returns the referenceCount of the shared resource behind this resource or 0 if no internal Resource is stored */
89  unsigned int referenceCount() const { return (this->resource)? this->resource->referenceCount : 0; };
90
91  protected:
92    const SharedResource* findResource(std::string& fileName,
93                                       const MultiType& param0 = MT_NULL,
94                                       const MultiType& param1 = MT_NULL,
95                                       const MultiType& param2 = MT_NULL);
96
97  protected:
98    SharedResource*     resource;          //!< The internal Resource, this Resource is keeping (at the moment).
99
100    static std::map<ClassID, std::vector<SharedResource> > storedResources;
101  };
102
103}
104#endif /* _RESOURCE_H */
Note: See TracBrowser for help on using the repository browser.