2
0

ISimpleResourceLoader.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma once
  2. /*
  3. * ISimpleResourceLoader.h, part of VCMI engine
  4. *
  5. * Authors: listed in file AUTHORS in main folder
  6. *
  7. * License: GNU General Public License v2.0 or later
  8. * Full text of license available in license.txt file, in main folder
  9. *
  10. */
  11. class CInputStream;
  12. class ResourceID;
  13. /**
  14. * A class which knows the files containing in the archive or system and how to load them.
  15. */
  16. class DLL_LINKAGE ISimpleResourceLoader
  17. {
  18. public:
  19. virtual ~ISimpleResourceLoader() { };
  20. /**
  21. * Loads a resource with the given resource name.
  22. *
  23. * @param resourceName The unqiue resource name in space of the archive.
  24. * @return a input stream object
  25. */
  26. virtual std::unique_ptr<CInputStream> load(const ResourceID & resourceName) const = 0;
  27. /**
  28. * Checks if the entry exists.
  29. *
  30. * @return Returns true if the entry exists, false if not.
  31. */
  32. virtual bool existsResource(const ResourceID & resourceName) const = 0;
  33. /**
  34. * Gets mount point to which this loader was attached
  35. *
  36. * @return mount point URI
  37. */
  38. virtual std::string getMountPoint() const = 0;
  39. /**
  40. * Gets full name of resource, e.g. name of file in filesystem.
  41. *
  42. * @return path or empty optional if file can't be accessed independently (e.g. file in archive)
  43. */
  44. virtual boost::optional<std::string> getResourceName(const ResourceID & resourceName) const
  45. {
  46. return boost::optional<std::string>();
  47. }
  48. /**
  49. * Get list of files that matches filter function
  50. *
  51. * @param filter Filter that returns true if specified ID matches filter
  52. * @return Returns list of flies
  53. */
  54. virtual std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const = 0;
  55. /**
  56. * Creates new resource with specified filename.
  57. *
  58. * @return true if new file was created, false on error or if file already exists
  59. */
  60. virtual bool createResource(std::string filename, bool update = false)
  61. {
  62. return false;
  63. }
  64. /**
  65. * @brief Returns all loaders that have resource with such name
  66. *
  67. * @return vector with all loaders
  68. */
  69. virtual std::vector<const ISimpleResourceLoader *> getResourcesWithName(const ResourceID & resourceName) const
  70. {
  71. if (existsResource(resourceName))
  72. return std::vector<const ISimpleResourceLoader *>(1, this);
  73. return std::vector<const ISimpleResourceLoader *>();
  74. }
  75. };