2
0

CFileInputStream.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * CFileInputStream.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. #include "CInputStream.h"
  12. #include "FileStream.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  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. * @param file Path to the file.
  24. * @param start - offset from file start where real data starts (e.g file on archive)
  25. * @param size - size of real data in file (e.g file on archive) or 0 to use whole file
  26. *
  27. * @throws std::runtime_error if file wasn't found
  28. */
  29. CFileInputStream(const boost::filesystem::path & file, si64 start = 0, si64 size = 0);
  30. /**
  31. * Reads n bytes from the stream into the data buffer.
  32. *
  33. * @param data A pointer to the destination data array.
  34. * @param size The number of bytes to read.
  35. * @return the number of bytes read actually.
  36. */
  37. si64 read(ui8 * data, si64 size) override;
  38. /**
  39. * Seeks the internal read pointer to the specified position.
  40. *
  41. * @param position The read position from the beginning.
  42. * @return the position actually moved to, -1 on error.
  43. */
  44. si64 seek(si64 position) override;
  45. /**
  46. * Gets the current read position in the stream.
  47. *
  48. * @return the read position. -1 on failure or if the read pointer isn't in the valid range.
  49. */
  50. si64 tell() override;
  51. /**
  52. * Skips delta numbers of bytes.
  53. *
  54. * @param delta The count of bytes to skip.
  55. * @return the count of bytes skipped actually.
  56. */
  57. si64 skip(si64 delta) override;
  58. /**
  59. * Gets the length in bytes of the stream.
  60. *
  61. * @return the length in bytes of the stream.
  62. */
  63. si64 getSize() override;
  64. private:
  65. si64 dataStart;
  66. si64 dataSize;
  67. /** Native c++ input file stream object. */
  68. FileStream fileStream;
  69. };
  70. VCMI_LIB_NAMESPACE_END