mini-llvm 0.1.0
Loading...
Searching...
No Matches
FileHandle.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2
3#pragma once
4
5#include <cstdio>
6#include <utility>
7
11
12namespace mini_llvm {
13
15public:
16 FileHandle() = default;
17
18 explicit FileHandle(FILE *handle) : handle_(handle) {}
19
20 FileHandle(const Path &path, const SystemString &mode);
21
23
24 FileHandle(const FileHandle &) = delete;
25
26 FileHandle(FileHandle &&other) noexcept {
27 swap(other);
28 }
29
30 FileHandle &operator=(FileHandle other) noexcept {
31 swap(other);
32 return *this;
33 }
34
35 explicit operator bool() const {
36 return handle_;
37 }
38
39 FILE *get() {
40 return handle_;
41 }
42
43 const FILE *get() const {
44 return handle_;
45 }
46
47 void open(const Path &path, const SystemString &mode);
48
49 void close();
50
51 FILE *release();
52
53 void swap(FileHandle &other) noexcept {
54 std::swap(handle_, other.handle_);
55 }
56
57private:
58 FILE *handle_{};
59};
60
61inline void swap(FileHandle &lhs, FileHandle &rhs) noexcept {
62 lhs.swap(rhs);
63}
64
65} // namespace mini_llvm
#define MINI_LLVM_EXPORT
Definition Compiler.h:17
Definition FileHandle.h:14
FileHandle(FILE *handle)
Definition FileHandle.h:18
FileHandle(FileHandle &&other) noexcept
Definition FileHandle.h:26
FileHandle(const FileHandle &)=delete
FileHandle & operator=(FileHandle other) noexcept
Definition FileHandle.h:30
FileHandle(const Path &path, const SystemString &mode)
void open(const Path &path, const SystemString &mode)
void swap(FileHandle &other) noexcept
Definition FileHandle.h:53
const FILE * get() const
Definition FileHandle.h:43
FILE * get()
Definition FileHandle.h:39
Definition Path.h:18
Definition SystemString.h:19
Definition GraphColoringAllocator.h:13
void swap(FileHandle &lhs, FileHandle &rhs) noexcept
Definition FileHandle.h:61