BsResourceManifest.h 3.3 KB

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