BmnRoot 26.10.0-233-gb9bbe585
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnFileReaderRaw.h
Go to the documentation of this file.
1#pragma once
2#ifndef BmnFileReaderRaw_h
3#define BmnFileReaderRaw_h
4
5// headers from this target
6#include "BmnIFileReader.h"
7// std:: headers
8#include <fstream>
9
10/*
11 * A class that allows one to read raw binary files. This class is very similar to `std::ifstream`
12 * and only implements its methods. Still, APi of `BmnIFileReader` is used so one can use this class
13 * along with other children classes based on needs
14 */
16{
17 public:
18 /*
19 * A standard constructor that sets a path to the input raw binary file
20 * @param aFilePath A path to the input raw binary file. If provided, the file will be opened in the constructor
21 * @warning If using relative paths, be very careful about currently-working directory as it might
22 * be something unexpected based on the directory that initialized an application
23 */
24 explicit BmnFileReaderRaw(const std::filesystem::path& aFilePath);
25
26 virtual ~BmnFileReaderRaw() = default;
29 BmnFileReaderRaw(BmnFileReaderRaw&&) noexcept = delete;
30 BmnFileReaderRaw& operator=(BmnFileReaderRaw&&) noexcept = delete;
31
32 // ========== BmnIFileReaderInterface ==========
33
34 /*
35 * A method that opens a raw-binary file for reading
36 * @param aFilePath A path to the file that should be opened
37 * @warning Be very carful with "the currently-working directory" as it may not be the same as the executable path!
38 */
39 virtual void Open(const std::filesystem::path& aFilePath) override;
40
41 /*
42 * Closes the input stream. After calling `Close`, it's safe to reopen using the same instance of this class
43 */
44 virtual void Close() noexcept override;
45
46 /*
47 * Reads the binary-file data and writes them into the provided buffer.
48 * @param dataToFill A buffer that will be filled with uncompressed data
49 * @param sizeToFill A number of bytes that will be filled in `dataToFill`
50 * @return A number of bytes that were filled in `dataToFill`. This value should almost always be the same as
51 * `sizeToFill` except when the end of the stream is reached (only if the user asked for more data than
52 * possible)
53 */
54 virtual int64_t Read(void* dataToFill, const int64_t sizeToFill) override;
55
56 /*
57 * A method that tells us what's next to read
58 * @return A position of the next byte that should be read
59 */
60 [[nodiscard]] virtual int64_t Tell() const noexcept override;
61
62 /*
63 * A method that sets a position for a next-byte read
64 * @param value A position in the raw-data file to which one wants to move before the next read
65 */
66 virtual void Seek(int64_t value) override;
67
68 /*
69 * Checks whether the reading stream is good
70 * @return 'true' if the underlying stream is good, or 'false' otherwise
71 */
72 [[nodiscard]] virtual bool IsGood() const noexcept override;
73
74 /*
75 * Check if we have reached the file.
76 * @note This method will return 'true' ONLY IF one tries to a byte after the last one
77 * @return 'true' if eof flag of the internal stream is set, 'false' otherwise
78 */
79 [[nodiscard]] virtual bool IsEOF() const noexcept override;
80
81 /*
82 * A method that clears bad flags after an error has occurred. Just calling this error will most likely
83 * not solve the problem, and you will get an error again in the next read. That is, before calling `Read`,
84 * remove the previous error source
85 */
86 virtual void ClearStateFlags() override;
87
88 /*
89 * @return 'true' if the input stream is open, or 'false' if not
90 */
91 [[nodiscard]] virtual bool IsOpen() const noexcept override;
92
93 /*
94 * @return BmnFileType::Raw
95 */
96 [[nodiscard]] virtual BmnFileType GetFileType() const noexcept override;
97
98 private:
99 std::ifstream fInputStream;
101};
102
103#endif // BmnFileReaderRaw_h
BmnFileReaderRaw(BmnFileReaderRaw &&) noexcept=delete
virtual bool IsOpen() const noexcept override
virtual BmnFileType GetFileType() const noexcept override
std::ifstream fInputStream
virtual void ClearStateFlags() override
virtual void Close() noexcept override
virtual int64_t Tell() const noexcept override
virtual void Open(const std::filesystem::path &aFilePath) override
virtual void Seek(int64_t value) override
BmnFileReaderRaw & operator=(const BmnFileReaderRaw &)=delete
BmnFileReaderRaw(const std::filesystem::path &aFilePath)
BmnFileReaderRaw(const BmnFileReaderRaw &)=delete
virtual bool IsEOF() const noexcept override
virtual bool IsGood() const noexcept override
virtual ~BmnFileReaderRaw()=default
virtual int64_t Read(void *dataToFill, const int64_t sizeToFill) override
BmnIFileReader()=default