BsResourceManifest.h 3.6 KB

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