BsResourceManifest.h 3.6 KB

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