Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/util/loading/resource.h @ 9785

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

some implementations of the new self sustained Resources. It works, but does not yet load the correct stuff

File size: 2.9 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 <vector>
13#include <set>
14
15#include "filesys/directory.h"
16
17//! A Resource is an Object, that can be loaded from Disk
18/**
19 *
20 */
21class Resource : virtual public BaseObject
22{
23  ObjectListDeclaration(Resource);
24public:
25  class KeepLevel
26  {
27  public:
28    void setKeepLevelName(unsigned int level, const std::string& name);
29  private:
30    std::vector<std::string>     _keepLevelName;
31  };
32
33protected:
34  class Type
35  {
36  public:
37    Type(const ClassID& classID) : _id(-1), _classID(classID) { };
38
39    void addExtension(const std::string& extension);
40
41    void addResourcePath(const std::string& path);
42    void addResourceSubPath(const std::string& subPath);
43
44    /// Retrieve Functions
45    const ClassID& storedClassID() const { return _classID; };
46    int id() const { return _id; };
47    const std::vector<std::string>& resourcePaths() const { return _resourcePaths; };
48    const std::vector<std::string>& resourceSubPaths() const { return _resourceSubPaths; };
49    const std::vector<Resource*>& storedResources() const { return _storedResources; };
50
51    void setID(int id);
52    void addResource(Resource* resource);
53
54  private:
55    int                           _id;
56    const ClassID&                _classID;
57    std::vector<std::string>      _resourcePaths;
58    std::vector<std::string>      _resourceSubPaths;
59    std::vector<std::string>      _fileExtensions;
60
61    std::vector<Resource*>        _storedResources;
62  };
63
64  class Pointer
65  {
66  public:
67    Pointer(const std::string& loadString, const Resource::KeepLevel& keeplevel);
68    const std::string& loadString() const { return _loadString; };
69    const Resource::KeepLevel& keepLevel() const { return _keepLevel; };
70
71  private:
72    std::string              _loadString;             //!< An identifier, to match when loading a File.
73    Resource::KeepLevel      _keepLevel;              //!< The Priority of this resource. (can only be increased, so none else will delete this)
74  };
75
76
77public:
78  Resource(Resource::Type* type);
79  virtual ~Resource();
80
81  virtual bool reload() { return false; };
82  virtual bool unload() { return false; };
83
84  std::string locateFile(const std::string& fileName);
85
86
87  public:
88    static void setMainGlobalPath(const Directory& directory);
89    static void addGlobalPath(const Directory& directory);
90
91
92protected:
93  Resource::Pointer* acquireResource(const std::string& loadString);
94  void addResource(Resource::Pointer* pointer);
95
96private:
97  Resource::Pointer*       _pointer;                //!< Virtual Pointer to the ResourceData.
98  Resource::Type*          _type;                   //!< Type of the Resource.
99
100
101  static std::vector<Resource::Type*>    _resourceTypes;
102
103  //! GLOBALS
104  static Directory                       _mainGlobalPath;
105  static std::vector<Directory>          _globalPaths;
106};
107
108#endif /* _RESOURCE_H */
Note: See TracBrowser for help on using the repository browser.