Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

renaming for namespace-purposes

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