#pragma once #include "ReferenceCounter.h" namespace Framework { class Text; class StreamReader { public: //! Reads from the resource //! \param bytes An array to be filled with bytes from the resource //! \param len How many bytes should be read from the resource virtual void read(char* bytes, int len) = 0; //! Reads the next line of the resource //! \return The read line as Text with line break virtual Text* readLine() = 0; //! Checks whether the resource has been fully read //! return 1 if the resource has been fully read. 0 otherwise virtual bool isEnd() const = 0; }; class Reader : public StreamReader { public: //! Sets the position of the byte to be read next //! \param pos The index of the byte //! \param ende 1 if the index counts from the end of the resource. 0 if //! the index counts from the beginning of the resource virtual void setLPosition(__int64 pos, bool ende) = 0; //! Returns the index of the byte from the resource that would be read next //! return -1 if an error occurred. Otherwise the position of the read pointer virtual __int64 getLPosition() const = 0; //! Returns the number of bytes to be read virtual __int64 getSize() const = 0; }; class ByteArrayReader : public Reader, public ReferenceCounter { private: int length; const char* buffer; bool deleteBuffer; int position; public: //! \param buffer The buffer to be read //! \param length The length of the buffer //! \param deleteBuffer true if the buffer should be automatically deleted //! with delete[] DLLEXPORT ByteArrayReader( const char* buffer, int length, bool deleteBuffer); DLLEXPORT ~ByteArrayReader(); //! Reads from the resource //! \param bytes An array to be filled with bytes from the resource //! \param len How many bytes should be read from the resource DLLEXPORT void read(char* bytes, int len) override; //! Reads the next line of the resource //! \return The read line as Text with line break DLLEXPORT Text* readLine() override; //! Checks whether the resource has been fully read //! return 1 if the resource has been fully read. 0 otherwise DLLEXPORT bool isEnd() const override; //! Sets the position of the byte to be read next //! \param pos The index of the byte //! \param ende 1 if the index counts from the end of the resource. 0 if //! the index counts from the beginning of the resource DLLEXPORT void setLPosition(__int64 pos, bool ende) override; //! Returns the index of the byte from the resource that would be read next //! return -1 if an error occurred. Otherwise the position of the read pointer DLLEXPORT __int64 getLPosition() const override; //! Returns the number of bytes to be read DLLEXPORT __int64 getSize() const override; }; } // namespace Framework