FileReader, cheap to copy, not thread safe. It is assumed that file is not modified during FireReader lifetime, because of caching and assumption that Size() is constant.
| 13 | // It is assumed that file is not modified during FireReader lifetime, |
| 14 | // because of caching and assumption that Size() is constant. |
| 15 | class FileReader : public ModelReader |
| 16 | { |
| 17 | public: |
| 18 | static uint32_t const kDefaultLogPageSize; |
| 19 | static uint32_t const kDefaultLogPageCount; |
| 20 | |
| 21 | explicit FileReader(std::string const & fileName); |
| 22 | FileReader(std::string const & fileName, uint32_t logPageSize, uint32_t logPageCount); |
| 23 | |
| 24 | // Reader overrides: |
| 25 | uint64_t Size() const override { return m_size; } |
| 26 | void Read(uint64_t pos, void * p, size_t size) const override; |
| 27 | std::unique_ptr<Reader> CreateSubReader(uint64_t pos, uint64_t size) const override; |
| 28 | |
| 29 | FileReader SubReader(uint64_t pos, uint64_t size) const; |
| 30 | uint64_t GetOffset() const { return m_offset; } |
| 31 | |
| 32 | protected: |
| 33 | // Used in special derived readers. |
| 34 | void SetOffsetAndSize(uint64_t offset, uint64_t size); |
| 35 | |
| 36 | private: |
| 37 | class FileReaderData; |
| 38 | |
| 39 | FileReader(FileReader const & reader, uint64_t offset, uint64_t size, uint32_t logPageSize, uint32_t logPageCount); |
| 40 | |
| 41 | // Throws an exception if a (pos, size) read would result in an out-of-bounds access. |
| 42 | void CheckPosAndSize(uint64_t pos, uint64_t size) const; |
| 43 | |
| 44 | uint32_t m_logPageSize; |
| 45 | uint32_t m_logPageCount; |
| 46 | std::shared_ptr<FileReaderData> m_fileData; |
| 47 | uint64_t m_offset; |
| 48 | uint64_t m_size; |
| 49 | }; |
no outgoing calls