CMapService.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * CMapService.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. class CMap;
  12. class CMapHeader;
  13. class CInputStream;
  14. class IMapLoader;
  15. /**
  16. * The map service provides loading of VCMI/H3 map files. It can
  17. * be extended to save maps later as well.
  18. */
  19. class DLL_LINKAGE CMapService
  20. {
  21. public:
  22. /**
  23. * Loads the VCMI/H3 map file specified by the name.
  24. *
  25. * @param name the name of the map
  26. * @return a unique ptr to the loaded map class
  27. */
  28. static std::unique_ptr<CMap> loadMap(const std::string & name);
  29. /**
  30. * Loads the VCMI/H3 map header specified by the name.
  31. *
  32. * @param name the name of the map
  33. * @return a unique ptr to the loaded map header class
  34. */
  35. static std::unique_ptr<CMapHeader> loadMapHeader(const std::string & name);
  36. /**
  37. * Loads the VCMI/H3 map file from a buffer. This method is temporarily
  38. * in use to ease the transition to use the new map service.
  39. *
  40. * TODO Replace method params with a CampaignMapInfo struct which contains
  41. * a campaign loading object + name of map.
  42. *
  43. * @param buffer a pointer to a buffer containing the map data
  44. * @param size the size of the buffer
  45. * @return a unique ptr to the loaded map class
  46. */
  47. static std::unique_ptr<CMap> loadMap(const ui8 * buffer, int size);
  48. /**
  49. * Loads the VCMI/H3 map header from a buffer. This method is temporarily
  50. * in use to ease the transition to use the new map service.
  51. *
  52. * TODO Replace method params with a CampaignMapInfo struct which contains
  53. * a campaign loading object + name of map.
  54. *
  55. * @param buffer a pointer to a buffer containing the map header data
  56. * @param size the size of the buffer
  57. * @return a unique ptr to the loaded map class
  58. */
  59. static std::unique_ptr<CMapHeader> loadMapHeader(const ui8 * buffer, int size);
  60. private:
  61. /**
  62. * Gets a map input stream object specified by a map name.
  63. *
  64. * @param name the name of the map
  65. * @return a unique ptr to the input stream class
  66. */
  67. static std::unique_ptr<CInputStream> getStreamFromFS(const std::string & name);
  68. /**
  69. * Gets a map input stream from a buffer.
  70. *
  71. * @param buffer a pointer to a buffer containing the map data
  72. * @param size the size of the buffer
  73. * @return a unique ptr to the input stream class
  74. */
  75. static std::unique_ptr<CInputStream> getStreamFromMem(const ui8 * buffer, int size);
  76. /**
  77. * Gets a map loader from the given stream. It performs checks to test
  78. * in which map format the map is.
  79. *
  80. * @param stream the input map stream
  81. * @return the constructed map loader
  82. */
  83. static std::unique_ptr<IMapLoader> getMapLoader(std::unique_ptr<CInputStream> & stream);
  84. };
  85. /**
  86. * Interface for loading a map.
  87. */
  88. class DLL_LINKAGE IMapLoader
  89. {
  90. public:
  91. /**
  92. * Loads the VCMI/H3 map file.
  93. *
  94. * @return a unique ptr of the loaded map class
  95. */
  96. virtual std::unique_ptr<CMap> loadMap() = 0;
  97. /**
  98. * Loads the VCMI/H3 map header.
  99. *
  100. * @return a unique ptr of the loaded map header class
  101. */
  102. virtual std::unique_ptr<CMapHeader> loadMapHeader() = 0;
  103. };