CmResourceManifest.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmIReflectable.h"
  4. #include "CmPath.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Serializable class that contains UUID <-> file path mapping for resources.
  9. *
  10. * @note This class allows you to reference resources between sessions. At the end of a session
  11. * save the resource manifest, and then restore it at the start of a new session. This way
  12. * ensures that resource UUIDs stay consistent and anything referencing them can find the
  13. * resources.
  14. */
  15. class CM_EXPORT ResourceManifest : public IReflectable
  16. {
  17. struct ConstructPrivately {};
  18. public:
  19. explicit ResourceManifest(const ConstructPrivately& dummy);
  20. ResourceManifest(const String& name);
  21. const String& getName() const { return mName; }
  22. void registerResource(const String& uuid, const Path& filePath);
  23. void unregisterResource(const String& uuid);
  24. bool uuidToFilePath(const String& uuid, Path& filePath) const;
  25. bool filePathToUUID(const Path& filePath, String& outUUID) const;
  26. bool uuidExists(const String& uuid) const;
  27. bool filePathExists(const Path& filePath) const;
  28. /**
  29. * @brief Saves the resource manifest to the specified location.
  30. *
  31. * @param manifest Manifest to save.
  32. * @param path Full pathname of the file.
  33. * @param relativePath If not empty, all pathnames in the manifest will be stored
  34. * as if relative to this path.
  35. */
  36. static void save(const ResourceManifestPtr& manifest, const Path& path, const Path& relativePath);
  37. /**
  38. * @brief Loads the resource manifest from the specified location.
  39. *
  40. * @param path Full pathname of the file.
  41. * @param relativePath If not empty, all loaded pathnames will have this
  42. * path prepended.
  43. */
  44. static ResourceManifestPtr load(const Path& path, const Path& relativePath);
  45. static ResourceManifestPtr create(const String& name);
  46. private:
  47. String mName;
  48. UnorderedMap<String, Path> mUUIDToFilePath;
  49. UnorderedMap<Path, String> mFilePathToUUID;
  50. /************************************************************************/
  51. /* RTTI */
  52. /************************************************************************/
  53. static ResourceManifestPtr createEmpty();
  54. public:
  55. friend class ResourceManifestRTTI;
  56. static RTTITypeBase* getRTTIStatic();
  57. virtual RTTITypeBase* getRTTI() const;
  58. };
  59. }