Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

modular KeepLevel implementation

File size: 3.1 KB
Line 
1/*!
2 * @file resource.h
3 * @brief Definition of a NewResource.
4*/
5
6#ifndef _RESOURCE_H
7#define _RESOURCE_H
8
9#include "base_object.h"
10#include <string>
11#include <vector>
12#include <set>
13
14#include "filesys/directory.h"
15
16namespace Resources
17{
18  class KeepLevel
19  {
20  public:
21    KeepLevel(unsigned int keepLevel) { _keepLevel = keepLevel; };
22    KeepLevel(const std::string& keepLevelName);
23
24    unsigned int keepLevel() const { return _keepLevel; };
25  private:
26    unsigned int                        _keepLevel;
27  };
28
29  class StorePointer
30  {
31    public:
32      StorePointer(const std::string& loadString, const Resources::KeepLevel& keeplevel);
33      const std::string& loadString() const { return _loadString; };
34      const Resources::KeepLevel& keepLevel() const { return _keepLevel; };
35
36    private:
37      std::string                 _loadString;             //!< An identifier, to match when loading a File.
38      Resources::KeepLevel        _keepLevel;              //!< The Priority of this resource. (can only be increased, so none else will delete this)
39  };
40
41  class Type
42  {
43  public:
44    Type(const std::string& typeName);
45    bool operator==(const std::string& resourceName) const { return this->_typeName == resourceName; };
46
47    void addExtension(const std::string& extension);
48
49    bool addResourcePath(const std::string& path);
50    bool addResourceSubPath(const std::string& subPath);
51
52    /// Retrieve Functions
53    const std::string& storedClassName() const { return _typeName; };
54    int id() const { return _id; };
55    const std::vector<Directory>& resourcePaths() const { return _resourcePaths; };
56    const std::vector<Directory>& resourceSubPaths() const { return _resourceSubPaths; };
57    const std::vector<Resources::StorePointer*>& storedResources() const { return _storedResources; };
58
59    void setID(int id);
60    void addResource(Resources::StorePointer* resource);
61
62    void debug() const;
63
64  private:
65    int                             _id;
66    const std::string               _typeName;
67    std::vector<Directory>          _resourcePaths;
68    std::vector<Directory>          _resourceSubPaths;
69    std::vector<std::string>        _fileExtensions;
70
71    std::vector<Resources::StorePointer*> _storedResources;
72  };
73}
74
75//! A NewResource is an Object, that can be loaded from Disk
76/**
77 *
78 */
79class NewResource : virtual public BaseObject
80{
81  ObjectListDeclaration(NewResource);
82
83public:
84  NewResource(Resources::Type* type);
85  virtual ~NewResource();
86
87  virtual bool reload() { return false; };
88  virtual bool unload() { return false; };
89
90  std::string locateFile(const std::string& fileName) const;
91
92
93public:
94protected:
95  Resources::StorePointer* acquireResource(const std::string& loadString);
96  void addResource(Resources::StorePointer* pointer);
97
98private:
99  std::string locateFileInSubDir(const Directory& directory, const std::string& fileName) const;
100
101private:
102  Resources::StorePointer*       _pointer;                         //!< Virtual Pointer to the ResourceData.
103  Resources::Type*               _type;                            //!< Type of the NewResource.
104};
105
106#endif /* _RESOURCE_H */
Note: See TracBrowser for help on using the repository browser.