CFileInputStream.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. class CFileInfo;
  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. * Standard c-tor.
  21. */
  22. CFileInputStream();
  23. /**
  24. * C-tor. Opens the specified file.
  25. *
  26. * @param file Path to the file.
  27. *
  28. * @throws std::runtime_error if file wasn't found
  29. */
  30. CFileInputStream(const std::string & file);
  31. /**
  32. * C-tor. Opens the specified file.
  33. *
  34. * @param file A file info object, pointing to a location in the file system
  35. *
  36. * @throws std::runtime_error if file wasn't found
  37. */
  38. CFileInputStream(const CFileInfo & file);
  39. /**
  40. * D-tor. Calls the close method implicitely, if the file is still opened.
  41. */
  42. ~CFileInputStream();
  43. /**
  44. * Opens a file. If a file is currently opened, it will be closed.
  45. *
  46. * @param file Path to the file.
  47. *
  48. * @throws std::runtime_error if file wasn't found
  49. */
  50. void open(const std::string & file);
  51. /**
  52. * Opens a file.
  53. *
  54. * @param file A file info object, pointing to a location in the file system
  55. *
  56. * @throws std::runtime_error if file wasn't found
  57. */
  58. void open(const CFileInfo & file);
  59. /**
  60. * Reads n bytes from the stream into the data buffer.
  61. *
  62. * @param data A pointer to the destination data array.
  63. * @param size The number of bytes to read.
  64. * @return the number of bytes read actually.
  65. */
  66. si64 read(ui8 * data, si64 size);
  67. /**
  68. * Seeks the internal read pointer to the specified position.
  69. *
  70. * @param position The read position from the beginning.
  71. * @return the position actually moved to, -1 on error.
  72. */
  73. si64 seek(si64 position);
  74. /**
  75. * Gets the current read position in the stream.
  76. *
  77. * @return the read position. -1 on failure or if the read pointer isn't in the valid range.
  78. */
  79. si64 tell();
  80. /**
  81. * Skips delta numbers of bytes.
  82. *
  83. * @param delta The count of bytes to skip.
  84. * @return the count of bytes skipped actually.
  85. */
  86. si64 skip(si64 delta);
  87. /**
  88. * Gets the length in bytes of the stream.
  89. *
  90. * @return the length in bytes of the stream.
  91. */
  92. si64 getSize();
  93. /**
  94. * Closes the stream and releases any system resources associated with the stream explicitely.
  95. */
  96. void close();
  97. private:
  98. /** Native c++ input file stream object. */
  99. std::ifstream fileStream;
  100. };