blob: a2a75d829c4c147f0d92215b110e20f4517173e4 [file] [log] [blame]
Ed Tanous73030632022-01-14 10:09:47 -08001#pragma once
2
3#include <filesystem>
4#include <ios>
5
6// An RAII compliant object for holding a posix file descriptor
7class 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 Tanous2049bd22022-07-09 07:20:26 -070016 FileHandle(FileHandle&& /*in*/) noexcept;
17 FileHandle& operator=(FileHandle&& /*in*/) noexcept;
Ed Tanous73030632022-01-14 10:09:47 -080018
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 Tanous2049bd22022-07-09 07:20:26 -070026 int handle() const;
Ed Tanous73030632022-01-14 10:09:47 -080027};