class File;
A type to help manage reading from and writing to text files.
EVO_NODISCARD File() noexcept;
EVO_NODISCARD auto open(const std::string& path, Flags<FileMode> mode) noexcept -> bool;
Opens a file.
auto close() noexcept -> void;
Closes the file.
EVO_NODISCARD constexpr auto getHandle() const noexcept -> ::FILE*;
Gets the underlying file handle.
EVO_NODISCARD constexpr auto isValid() const noexcept -> bool;
Gets if the file is handle is valid (essentially if the file is open).
EVO_NODISCARD auto read() const noexcept -> std::optional<std::string>; // 1
EVO_NODISCARD auto read(size_t data_size) const noexcept -> std::optional<std::string>; // 2
Reads the file. Returns std::nullopt
if an error occured.
- Function 1 will read the entire file
- Function 2 will read up
data_size
EVO_NODISCARD auto readLine() const noexcept -> std::optional<std::string>;
Reads a line from the file (calls ::fgets()
). Can call this function multiple times to get next lines. Returns std::nullopt
if an error occured.
EVO_NODISCARD auto write(const std::string& data) noexcept -> bool;
Writes data to the file. Returns if the write was successful.
EVO_NODISCARD auto writeLine(const std::string& text) noexcept -> bool;
Appends a line to the file. Returns if the write was successful.
EVO_NODISCARD auto size() const noexcept -> size_t;
Gets the size of the file