BsResourceManifest.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsIReflectable.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Serializable class that contains UUID <-> file path mapping for resources.
  8. *
  9. * @note This class allows you to reference resources between sessions. At the end of a session
  10. * save the resource manifest, and then restore it at the start of a new session. This way
  11. * ensures that resource UUIDs stay consistent and anything referencing them can find the
  12. * resources.
  13. *
  14. * Thread safe.
  15. */
  16. class BS_CORE_EXPORT ResourceManifest : public IReflectable
  17. {
  18. struct ConstructPrivately {};
  19. public:
  20. explicit ResourceManifest(const ConstructPrivately& dummy);
  21. ResourceManifest(const String& name);
  22. /**
  23. * @brief Returns an unique name of the resource manifest.
  24. */
  25. const String& getName() const { return mName; }
  26. /**
  27. * @brief Registers a new resource in the manifest.
  28. */
  29. void registerResource(const String& uuid, const Path& filePath);
  30. /**
  31. * @brief Removes a resource from the manifest.
  32. */
  33. void unregisterResource(const String& uuid);
  34. /**
  35. * @brief Attempts to find a resource with the provided UUID and outputs the path
  36. * to the resource if found. Returns true if UUID was found, false otherwise.
  37. */
  38. bool uuidToFilePath(const String& uuid, Path& filePath) const;
  39. /**
  40. * @brief Attempts to find a resource with the provided path and outputs the UUID
  41. * to the resource if found. Returns true if path was found, false otherwise.
  42. */
  43. bool filePathToUUID(const Path& filePath, String& outUUID) const;
  44. /**
  45. * @brief Checks if provided UUID exists in the manifest.
  46. */
  47. bool uuidExists(const String& uuid) const;
  48. /**
  49. * @brief Checks if the provided path exists in the manifest.
  50. */
  51. bool filePathExists(const Path& filePath) const;
  52. /**
  53. * @brief Saves the resource manifest to the specified location.
  54. *
  55. * @param manifest Manifest to save.
  56. * @param path Full pathname of the file to save the manifest in.
  57. * @param relativePath If not empty, all pathnames in the manifest will be stored
  58. * as if relative to this path.
  59. */
  60. static void save(const ResourceManifestPtr& manifest, const Path& path, const Path& relativePath);
  61. /**
  62. * @brief Loads the resource manifest from the specified location.
  63. *
  64. * @param path Full pathname of the file to load the manifest from.
  65. * @param relativePath If not empty, all loaded pathnames will have this
  66. * path prepended.
  67. */
  68. static ResourceManifestPtr load(const Path& path, const Path& relativePath);
  69. /**
  70. * @brief Creates a new empty resource manifest. Provided name should be unique
  71. * among manifests.
  72. */
  73. static ResourceManifestPtr create(const String& name);
  74. private:
  75. String mName;
  76. UnorderedMap<String, Path> mUUIDToFilePath;
  77. UnorderedMap<Path, String> mFilePathToUUID;
  78. /************************************************************************/
  79. /* RTTI */
  80. /************************************************************************/
  81. /**
  82. * @brief Creates a new empty resource manifest.
  83. */
  84. static ResourceManifestPtr createEmpty();
  85. public:
  86. friend class ResourceManifestRTTI;
  87. static RTTITypeBase* getRTTIStatic();
  88. virtual RTTITypeBase* getRTTI() const override;
  89. };
  90. }