Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/new_class_id: resourceManager splitted away

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