2
0

CFileInputStream.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #pragma once
  2. /*
  3. * CFileInputStream.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 "CInputStream.h"
  12. #include "FileStream.h"
  13. class CFileInfo;
  14. /**
  15. * A class which provides method definitions for reading a file from the filesystem.
  16. */
  17. class DLL_LINKAGE CFileInputStream : public CInputStream
  18. {
  19. public:
  20. /**
  21. * C-tor. Opens the specified file.
  22. *
  23. * @see CFileInputStream::open
  24. */
  25. CFileInputStream(const boost::filesystem::path & file, si64 start = 0, si64 size = 0);
  26. /**
  27. * C-tor. Opens the specified file.
  28. *
  29. * @see CFileInputStream::open
  30. */
  31. CFileInputStream(const CFileInfo & file, si64 start=0, si64 size=0);
  32. /**
  33. * D-tor. Calls the close method implicitely, if the file is still opened.
  34. */
  35. ~CFileInputStream();
  36. /**
  37. * Reads n bytes from the stream into the data buffer.
  38. *
  39. * @param data A pointer to the destination data array.
  40. * @param size The number of bytes to read.
  41. * @return the number of bytes read actually.
  42. */
  43. si64 read(ui8 * data, si64 size) override;
  44. /**
  45. * Seeks the internal read pointer to the specified position.
  46. *
  47. * @param position The read position from the beginning.
  48. * @return the position actually moved to, -1 on error.
  49. */
  50. si64 seek(si64 position) override;
  51. /**
  52. * Gets the current read position in the stream.
  53. *
  54. * @return the read position. -1 on failure or if the read pointer isn't in the valid range.
  55. */
  56. si64 tell() override;
  57. /**
  58. * Skips delta numbers of bytes.
  59. *
  60. * @param delta The count of bytes to skip.
  61. * @return the count of bytes skipped actually.
  62. */
  63. si64 skip(si64 delta) override;
  64. /**
  65. * Gets the length in bytes of the stream.
  66. *
  67. * @return the length in bytes of the stream.
  68. */
  69. si64 getSize() override;
  70. private:
  71. /**
  72. * Opens a file. If a file is currently opened, it will be closed.
  73. *
  74. * @param file Path to the file.
  75. * @param start - offset from file start where real data starts (e.g file on archive)
  76. * @param size - size of real data in file (e.g file on archive) or 0 to use whole file
  77. *
  78. * @throws std::runtime_error if file wasn't found
  79. */
  80. void open(const boost::filesystem::path & file, si64 start, si64 size);
  81. si64 dataStart;
  82. si64 dataSize;
  83. /** Native c++ input file stream object. */
  84. FileStream fileStream;
  85. };