BsResourceManifest.h 3.3 KB

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