Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

nicer definition of the StorePointer

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
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) : _id(-1), _classID(classID) { };
56
57    void addExtension(const std::string& extension);
58
59    void addResourcePath(const std::string& path);
60    void addResourceSubPath(const std::string& subPath);
61
62    /// Retrieve Functions
63    const ClassID& storedClassID() const { return _classID; };
64    int id() const { return _id; };
65    const std::vector<std::string>& resourcePaths() const { return _resourcePaths; };
66    const std::vector<std::string>& resourceSubPaths() const { return _resourceSubPaths; };
67    const std::vector<NewResource::StorePointer*>& storedResources() const { return _storedResources; };
68
69    void setID(int id);
70    void addResource(NewResource::StorePointer* resource);
71
72  private:
73    int                             _id;
74    const ClassID&                  _classID;
75    std::vector<std::string>        _resourcePaths;
76    std::vector<std::string>        _resourceSubPaths;
77    std::vector<std::string>        _fileExtensions;
78
79    std::vector<NewResource::StorePointer*> _storedResources;
80  };
81
82
83public:
84  NewResource(NewResource::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);
91
92
93public:
94  static void setMainGlobalPath(const Directory& directory);
95  static void addGlobalPath(const Directory& directory);
96
97
98protected:
99  NewResource::StorePointer* acquireResource(const std::string& loadString);
100  void addResource(NewResource::StorePointer* pointer);
101
102private:
103  NewResource::StorePointer*       _pointer;                         //!< Virtual Pointer to the ResourceData.
104  NewResource::Type*          _type;                            //!< Type of the NewResource.
105
106
107  static std::vector<NewResource::Type*>    _resourceTypes;
108
109  //! GLOBALS
110  static Directory                       _mainGlobalPath;
111  static std::vector<Directory>          _globalPaths;
112};
113
114#endif /* _RESOURCE_H */
Note: See TracBrowser for help on using the repository browser.