summaryrefslogtreecommitdiff
path: root/src/unique_fd.hh
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2025-09-10 22:12:22 +0200
committerJoel Klinghed <the_jk@spawned.biz>2025-09-10 22:12:22 +0200
commit32e14551a90e85000e41b3f0445d34d58a1431e4 (patch)
tree912c1e50b93b501446b1b179ee2a3e93586fb854 /src/unique_fd.hh
parentcf99d0c865474105c14b2348fdbd1c83d87d5a29 (diff)
Add unicode general category lookup
Generate the lookup tables from UnicodeData.txt, do to that, add gen_ugc, which uses csv, buffers, line, io and other modules to do the job.
Diffstat (limited to 'src/unique_fd.hh')
-rw-r--r--src/unique_fd.hh45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/unique_fd.hh b/src/unique_fd.hh
new file mode 100644
index 0000000..189d513
--- /dev/null
+++ b/src/unique_fd.hh
@@ -0,0 +1,45 @@
+#ifndef UNIQUE_FD_HH
+#define UNIQUE_FD_HH
+
+class unique_fd {
+ public:
+ constexpr unique_fd()
+ : fd_(-1) {}
+ explicit constexpr unique_fd(int fd)
+ : fd_(fd) {}
+ unique_fd(unique_fd& fd) = delete;
+ unique_fd& operator=(unique_fd& fd) = delete;
+ unique_fd(unique_fd&& fd)
+ : fd_(fd.release()) {}
+ unique_fd& operator=(unique_fd&& fd) {
+ reset(fd.release());
+ return *this;
+ }
+ ~unique_fd() {
+ reset();
+ }
+
+ bool operator==(unique_fd const& fd) const {
+ return get() == fd.get();
+ }
+ bool operator!=(unique_fd const& fd) const {
+ return get() != fd.get();
+ }
+
+ int get() const { return fd_; }
+ explicit operator bool() const { return fd_ != -1; }
+ int operator*() const { return fd_; }
+
+ int release() {
+ int ret = fd_;
+ fd_ = -1;
+ return ret;
+ }
+
+ void reset(int fd = -1);
+
+ private:
+ int fd_;
+};
+
+#endif // UNIQUE_FD_HH