Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added new_resource_manager

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