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
RevLine 
[4838]1/*!
[7193]2 * @file resource.h
[9788]3 * @brief Definition of a NewResource.
[3245]4*/
[1853]5
[7193]6#ifndef _RESOURCE_H
7#define _RESOURCE_H
[1853]8
[3543]9#include "base_object.h"
[7195]10#include <string>
[9714]11#include <vector>
12#include <set>
[1853]13
[9785]14#include "filesys/directory.h"
15
[9788]16//! A NewResource is an Object, that can be loaded from Disk
[7195]17/**
[9714]18 *
[7195]19 */
[9788]20class NewResource : virtual public BaseObject
[7195]21{
[9788]22  ObjectListDeclaration(NewResource);
[9714]23public:
[9718]24  class KeepLevel
[9714]25  {
26  public:
[9789]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);
[9714]31  private:
[9789]32    unsigned int                        _keepLevel;
33  private:
34    static std::vector<std::string>     _keepLevelNames;
[9714]35  };
[7195]36
[9789]37
[9783]38protected:
[9789]39  class StorePointer
[9786]40  {
41  public:
[9789]42    StorePointer(const std::string& loadString, const NewResource::KeepLevel& keeplevel);
[9786]43    const std::string& loadString() const { return _loadString; };
[9788]44    const NewResource::KeepLevel& keepLevel() const { return _keepLevel; };
[9786]45
46  private:
[9789]47    std::string                 _loadString;             //!< An identifier, to match when loading a File.
[9788]48    NewResource::KeepLevel      _keepLevel;              //!< The Priority of this resource. (can only be increased, so none else will delete this)
[9786]49  };
50
51
[9714]52  class Type
53  {
54  public:
[9790]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; };
[7195]58
[9714]59    void addExtension(const std::string& extension);
[1853]60
[9790]61    bool addResourcePath(const std::string& path);
62    bool addResourceSubPath(const std::string& subPath);
[9784]63
64    /// Retrieve Functions
[9783]65    const ClassID& storedClassID() const { return _classID; };
66    int id() const { return _id; };
[9790]67    const std::vector<Directory>& resourcePaths() const { return _resourcePaths; };
68    const std::vector<Directory>& resourceSubPaths() const { return _resourceSubPaths; };
[9789]69    const std::vector<NewResource::StorePointer*>& storedResources() const { return _storedResources; };
[9783]70
71    void setID(int id);
[9789]72    void addResource(NewResource::StorePointer* resource);
[9783]73
[9714]74  private:
[9786]75    int                             _id;
76    const ClassID&                  _classID;
[9790]77    std::vector<Directory>          _resourcePaths;
78    std::vector<Directory>          _resourceSubPaths;
[9786]79    std::vector<std::string>        _fileExtensions;
[9784]80
[9789]81    std::vector<NewResource::StorePointer*> _storedResources;
[9714]82  };
83
[9758]84
[9714]85public:
[9788]86  NewResource(NewResource::Type* type);
87  virtual ~NewResource();
[1853]88
[9785]89  virtual bool reload() { return false; };
90  virtual bool unload() { return false; };
[3245]91
[9790]92  std::string locateFile(const std::string& fileName) const;
[9785]93
94
[9786]95public:
96  static void setMainGlobalPath(const Directory& directory);
97  static void addGlobalPath(const Directory& directory);
[9785]98
[9790]99  static bool addResourcePath(const std::string& resourceName, const std::string& pathName);
100  static bool addResourceSubPath(const std::string& resourceName, const std::string& pathName);
[9785]101
[9790]102  static void registerType(NewResource::Type* type);
103
104  static void debug();
[9784]105protected:
[9789]106  NewResource::StorePointer* acquireResource(const std::string& loadString);
107  void addResource(NewResource::StorePointer* pointer);
[3245]108
[9714]109private:
[9790]110  std::string locateFileInSubDir(const Directory& directory, const std::string& fileName) const;
111
112private:
[9789]113  NewResource::StorePointer*       _pointer;                         //!< Virtual Pointer to the ResourceData.
[9790]114  NewResource::Type*               _type;                            //!< Type of the NewResource.
[7195]115
[9714]116
[9790]117  static std::vector<NewResource::Type*>  _resourceTypes;
[9714]118
119  //! GLOBALS
[9785]120  static Directory                       _mainGlobalPath;
121  static std::vector<Directory>          _globalPaths;
[1853]122};
123
[7193]124#endif /* _RESOURCE_H */
Note: See TracBrowser for help on using the repository browser.