Reader.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #include "ReferenceCounter.h"
  3. namespace Framework
  4. {
  5. class Text;
  6. class StreamReader
  7. {
  8. public:
  9. //! Reads from the resource
  10. //! \param bytes An array to be filled with bytes from the resource
  11. //! \param len How many bytes should be read from the resource
  12. virtual void read(char* bytes, int len) = 0;
  13. //! Reads the next line of the resource
  14. //! \return The read line as Text with line break
  15. virtual Text* readLine() = 0;
  16. //! Checks whether the resource has been fully read
  17. //! return 1 if the resource has been fully read. 0 otherwise
  18. virtual bool isEnd() const = 0;
  19. };
  20. class Reader : public StreamReader
  21. {
  22. public:
  23. //! Sets the position of the byte to be read next
  24. //! \param pos The index of the byte
  25. //! \param ende 1 if the index counts from the end of the resource. 0 if
  26. //! the index counts from the beginning of the resource
  27. virtual void setLPosition(__int64 pos, bool ende) = 0;
  28. //! Returns the index of the byte from the resource that would be read next
  29. //! return -1 if an error occurred. Otherwise the position of the read pointer
  30. virtual __int64 getLPosition() const = 0;
  31. //! Returns the number of bytes to be read
  32. virtual __int64 getSize() const = 0;
  33. };
  34. class ByteArrayReader : public Reader,
  35. public ReferenceCounter
  36. {
  37. private:
  38. int length;
  39. const char* buffer;
  40. bool deleteBuffer;
  41. int position;
  42. public:
  43. //! \param buffer The buffer to be read
  44. //! \param length The length of the buffer
  45. //! \param deleteBuffer true if the buffer should be automatically deleted
  46. //! with delete[]
  47. DLLEXPORT ByteArrayReader(
  48. const char* buffer, int length, bool deleteBuffer);
  49. DLLEXPORT ~ByteArrayReader();
  50. //! Reads from the resource
  51. //! \param bytes An array to be filled with bytes from the resource
  52. //! \param len How many bytes should be read from the resource
  53. DLLEXPORT void read(char* bytes, int len) override;
  54. //! Reads the next line of the resource
  55. //! \return The read line as Text with line break
  56. DLLEXPORT Text* readLine() override;
  57. //! Checks whether the resource has been fully read
  58. //! return 1 if the resource has been fully read. 0 otherwise
  59. DLLEXPORT bool isEnd() const override;
  60. //! Sets the position of the byte to be read next
  61. //! \param pos The index of the byte
  62. //! \param ende 1 if the index counts from the end of the resource. 0 if
  63. //! the index counts from the beginning of the resource
  64. DLLEXPORT void setLPosition(__int64 pos, bool ende) override;
  65. //! Returns the index of the byte from the resource that would be read next
  66. //! return -1 if an error occurred. Otherwise the position of the read pointer
  67. DLLEXPORT __int64 getLPosition() const override;
  68. //! Returns the number of bytes to be read
  69. DLLEXPORT __int64 getSize() const override;
  70. };
  71. } // namespace Framework