CmResourceManifest.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmIReflectable.h"
  4. namespace CamelotFramework
  5. {
  6. /**
  7. * @brief Serializable class that contains UUID <-> file path mapping for resources.
  8. *
  9. * @note This class allows you to reference resources between sessions. At the end of a session
  10. * save the resource manifest, and then restore it at the start of a new session. This way
  11. * ensures that resource UUIDs stay consistent and anything referencing them can find the
  12. * resources.
  13. */
  14. class CM_EXPORT ResourceManifest : public IReflectable
  15. {
  16. struct ConstructPrivately {};
  17. public:
  18. explicit ResourceManifest(const ConstructPrivately& dummy);
  19. ResourceManifest(const String& name);
  20. const String& getName() const { return mName; }
  21. void registerResource(const String& uuid, const WString& filePath);
  22. void unregisterResource(const String& uuid);
  23. bool uuidToFilePath(const String& uuid, WString& filePath) const;
  24. bool filePathToUUID(const WString& filePath, String& outUUID) const;
  25. bool uuidExists(const String& uuid) const;
  26. bool filePathExists(const WString& filePath) const;
  27. /**
  28. * @brief Saves the resource manifest to the specified location.
  29. *
  30. * @param manifest Manifest to save.
  31. * @param path Full pathname of the file.
  32. * @param relativePath If not empty, all pathnames in the manifest will be stored
  33. * as if relative to this path.
  34. */
  35. static void save(const ResourceManifestPtr& manifest, const WString& path, const WString& relativePath);
  36. /**
  37. * @brief Loads the resource manifest from the specified location.
  38. *
  39. * @param path Full pathname of the file.
  40. * @param relativePath If not empty, all loaded pathnames will have this
  41. * path prepended.
  42. */
  43. static ResourceManifestPtr load(const WString& path, const WString& relativePath);
  44. static ResourceManifestPtr create(const String& name);
  45. private:
  46. String mName;
  47. Map<String, WString>::type mUUIDToFilePath;
  48. Map<WString, String>::type mFilePathToUUID;
  49. /************************************************************************/
  50. /* RTTI */
  51. /************************************************************************/
  52. static ResourceManifestPtr createEmpty();
  53. public:
  54. friend class ResourceManifestRTTI;
  55. static RTTITypeBase* getRTTIStatic();
  56. virtual RTTITypeBase* getRTTI() const;
  57. };
  58. }