AdapterLoaders.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #pragma once
  2. /*
  3. * AdapterLoaders.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. #include "ISimpleResourceLoader.h"
  12. #include "ResourceID.h"
  13. class CFileInfo;
  14. class CInputStream;
  15. class JsonNode;
  16. /**
  17. * Class that implements file mapping (aka *nix symbolic links)
  18. * Uses json file as input, content is map:
  19. * "fileA.txt" : "fileB.txt"
  20. * Note that extension is necessary, but used only to determine type
  21. *
  22. * fileA - file which will be replaced
  23. * fileB - file which will be used as replacement
  24. */
  25. class DLL_LINKAGE CMappedFileLoader : public ISimpleResourceLoader
  26. {
  27. public:
  28. /**
  29. * Ctor.
  30. *
  31. * @param config Specifies filesystem configuration
  32. */
  33. explicit CMappedFileLoader(const std::string &mountPoint, const JsonNode & config);
  34. /// Interface implementation
  35. /// @see ISimpleResourceLoader
  36. std::unique_ptr<CInputStream> load(const ResourceID & resourceName) const override;
  37. bool existsResource(const ResourceID & resourceName) const override;
  38. std::string getMountPoint() const override;
  39. boost::optional<std::string> getResourceName(const ResourceID & resourceName) const override;
  40. std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override;
  41. private:
  42. /** A list of files in this map
  43. * key = ResourceID for resource loader
  44. * value = ResourceID to which file this request will be redirected
  45. */
  46. std::unordered_map<ResourceID, ResourceID> fileList;
  47. };
  48. class DLL_LINKAGE CFilesystemList : public ISimpleResourceLoader
  49. {
  50. std::vector<std::unique_ptr<ISimpleResourceLoader> > loaders;
  51. std::set<ISimpleResourceLoader *> writeableLoaders;
  52. //FIXME: this is only compile fix, should be removed in the end
  53. CFilesystemList(CFilesystemList &)
  54. {
  55. //class is not copyable
  56. }
  57. CFilesystemList &operator=(CFilesystemList &)
  58. {
  59. //class is not copyable
  60. return *this;
  61. }
  62. public:
  63. CFilesystemList();
  64. ~CFilesystemList();
  65. /// Interface implementation
  66. /// @see ISimpleResourceLoader
  67. std::unique_ptr<CInputStream> load(const ResourceID & resourceName) const override;
  68. bool existsResource(const ResourceID & resourceName) const override;
  69. std::string getMountPoint() const override;
  70. boost::optional<std::string> getResourceName(const ResourceID & resourceName) const override;
  71. std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override;
  72. bool createResource(std::string filename, bool update = false) override;
  73. std::vector<const ISimpleResourceLoader *> getResourcesWithName(const ResourceID & resourceName) const override;
  74. /**
  75. * Adds a resource loader to the loaders list
  76. * Passes loader ownership to this object
  77. *
  78. * @param loader The simple resource loader object to add
  79. * @param writeable - resource shall be treated as writeable
  80. */
  81. void addLoader(ISimpleResourceLoader * loader, bool writeable);
  82. };