From 6232d13f5321b87ddf12a1aa36b4545da45f173d Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Wed, 17 Nov 2021 22:34:57 +0100 Subject: Travel3: Simple image and video display site Reads the images and videos from filesystem and builds a site in memroy. --- src/unique_pipe.hh | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/unique_pipe.hh (limited to 'src/unique_pipe.hh') diff --git a/src/unique_pipe.hh b/src/unique_pipe.hh new file mode 100644 index 0000000..7020cdf --- /dev/null +++ b/src/unique_pipe.hh @@ -0,0 +1,51 @@ +#ifndef UNIQUE_PIPE_HH +#define UNIQUE_PIPE_HH + +#include + +#include "unique_fd.hh" + +class unique_pipe { +public: + explicit unique_pipe(bool non_blocking = false) + : unique_pipe(non_blocking, non_blocking) {} + unique_pipe(bool non_blocking_reader, + bool non_blocking_writer); + unique_pipe(unique_pipe&& fd) noexcept; + unique_pipe(std::nullptr_t) noexcept + : fd_{nullptr, nullptr} {} + + ~unique_pipe() = default; + + unique_pipe& operator=(unique_pipe&& fd) noexcept { + fd_[0].reset(fd.fd_[0].release()); + fd_[1].reset(fd.fd_[1].release()); + return *this; + } + + unique_pipe& operator=(std::nullptr_t) noexcept { + reset(); + return *this; + } + + int reader() const noexcept { return fd_[0].get(); } + int writer() const noexcept { return fd_[1].get(); } + + explicit operator bool() const noexcept { + return fd_[0] || fd_[1]; + } + + void reset(); + + unique_fd release_reader(); + unique_fd release_writer(); + +private: + unique_pipe(unique_pipe const&) = delete; + unique_pipe& operator=(unique_pipe const&) = delete; + + unique_fd fd_[2]; +}; + + +#endif // UNIQUE_PIPE_HH -- cgit v1.2.3-70-g09d2