Ed Tanous | 7303063 | 2022-01-14 10:09:47 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <filesystem> |
| 4 | #include <ios> |
| 5 | |
| 6 | // An RAII compliant object for holding a posix file descriptor |
| 7 | class FileHandle |
| 8 | { |
| 9 | private: |
| 10 | int fd; |
| 11 | |
| 12 | public: |
| 13 | FileHandle() = delete; |
| 14 | FileHandle(const FileHandle&) = delete; |
| 15 | FileHandle& operator=(const FileHandle&) = delete; |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 16 | FileHandle(FileHandle&& /*in*/) noexcept; |
| 17 | FileHandle& operator=(FileHandle&& /*in*/) noexcept; |
Ed Tanous | 7303063 | 2022-01-14 10:09:47 -0800 | [diff] [blame] | 18 | |
| 19 | explicit FileHandle(const std::filesystem::path& name, |
| 20 | std::ios_base::openmode mode = std::ios_base::in | |
| 21 | std::ios_base::out); |
| 22 | |
| 23 | explicit FileHandle(int fd); |
| 24 | |
| 25 | ~FileHandle(); |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 26 | int handle() const; |
Patrick Williams | 779c96a | 2023-05-10 07:50:42 -0500 | [diff] [blame] | 27 | }; |