/*! * @file resource.h * @brief Definition of a NewResource. */ #ifndef _RESOURCE_H #define _RESOURCE_H #include "base_object.h" #include #include #include #include "filesys/directory.h" //! A NewResource is an Object, that can be loaded from Disk /** * */ class NewResource : virtual public BaseObject { ObjectListDeclaration(NewResource); public: class KeepLevel { public: KeepLevel(unsigned int keepLevel) { _keepLevel = keepLevel; }; KeepLevel(const std::string& keepLevelName); static void defineKeepLevelName(unsigned int level, const std::string& name); private: unsigned int _keepLevel; private: static std::vector _keepLevelNames; }; protected: class StorePointer { public: StorePointer(const std::string& loadString, const NewResource::KeepLevel& keeplevel); const std::string& loadString() const { return _loadString; }; const NewResource::KeepLevel& keepLevel() const { return _keepLevel; }; private: std::string _loadString; //!< An identifier, to match when loading a File. NewResource::KeepLevel _keepLevel; //!< The Priority of this resource. (can only be increased, so none else will delete this) }; class Type { public: Type(const ClassID& classID); bool operator==(const ClassID& classID) const { return this->_classID == classID; }; bool operator==(const std::string& resourceName) const { return this->_classID.name() == resourceName; }; void addExtension(const std::string& extension); bool addResourcePath(const std::string& path); bool addResourceSubPath(const std::string& subPath); /// Retrieve Functions const ClassID& storedClassID() const { return _classID; }; int id() const { return _id; }; const std::vector& resourcePaths() const { return _resourcePaths; }; const std::vector& resourceSubPaths() const { return _resourceSubPaths; }; const std::vector& storedResources() const { return _storedResources; }; void setID(int id); void addResource(NewResource::StorePointer* resource); private: int _id; const ClassID& _classID; std::vector _resourcePaths; std::vector _resourceSubPaths; std::vector _fileExtensions; std::vector _storedResources; }; public: NewResource(NewResource::Type* type); virtual ~NewResource(); virtual bool reload() { return false; }; virtual bool unload() { return false; }; std::string locateFile(const std::string& fileName) const; public: static void setMainGlobalPath(const Directory& directory); static void addGlobalPath(const Directory& directory); static bool addResourcePath(const std::string& resourceName, const std::string& pathName); static bool addResourceSubPath(const std::string& resourceName, const std::string& pathName); static void registerType(NewResource::Type* type); static void debug(); protected: NewResource::StorePointer* acquireResource(const std::string& loadString); void addResource(NewResource::StorePointer* pointer); private: std::string locateFileInSubDir(const Directory& directory, const std::string& fileName) const; private: NewResource::StorePointer* _pointer; //!< Virtual Pointer to the ResourceData. NewResource::Type* _type; //!< Type of the NewResource. static std::vector _resourceTypes; //! GLOBALS static Directory _mainGlobalPath; static std::vector _globalPaths; }; #endif /* _RESOURCE_H */