CFileInputStream.h 1.9 KB

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