BsResourceManifest.h 3.5 KB

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