aboutsummaryrefslogtreecommitdiff
path: root/butl/fdstream.ixx
diff options
context:
space:
mode:
Diffstat (limited to 'butl/fdstream.ixx')
-rw-r--r--butl/fdstream.ixx266
1 files changed, 0 insertions, 266 deletions
diff --git a/butl/fdstream.ixx b/butl/fdstream.ixx
deleted file mode 100644
index 884d190..0000000
--- a/butl/fdstream.ixx
+++ /dev/null
@@ -1,266 +0,0 @@
-// file : butl/fdstream.ixx -*- C++ -*-
-// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
-// license : MIT; see accompanying LICENSE file
-
-#include <cassert>
-
-namespace butl
-{
- // auto_fd
- //
- inline void auto_fd::
- reset (int fd) noexcept
- {
- if (fd_ >= 0)
- fdclose (fd_); // Don't check for an error as not much we can do here.
-
- fd_ = fd;
- }
-
- inline auto_fd& auto_fd::
- operator= (auto_fd&& fd) noexcept
- {
- reset (fd.release ());
- return *this;
- }
-
- inline auto_fd::
- ~auto_fd () noexcept
- {
- reset ();
- }
-
- // fdbuf
- //
- inline auto_fd fdbuf::
- release ()
- {
- return std::move (fd_);
- }
-
- // ifdstream
- //
- inline ifdstream::
- ifdstream (auto_fd&& fd, iostate e)
- : fdstream_base (std::move (fd)), std::istream (&buf_)
- {
- assert (e & badbit);
- exceptions (e);
- }
-
- inline ifdstream::
- ifdstream (iostate e)
- : ifdstream (auto_fd (), e) // Delegate.
- {
- }
-
- inline ifdstream::
- ifdstream (auto_fd&& fd, fdstream_mode m, iostate e)
- : fdstream_base (std::move (fd), m),
- std::istream (&buf_),
- skip_ ((m & fdstream_mode::skip) == fdstream_mode::skip)
- {
- assert (e & badbit);
- exceptions (e);
- }
-
- inline ifdstream::
- ifdstream (const std::string& f, openmode m, iostate e)
- : ifdstream (f.c_str (), m, e) // Delegate.
- {
- }
-
- inline ifdstream::
- ifdstream (const path& f, openmode m, iostate e)
- : ifdstream (f.string (), m, e) // Delegate.
- {
- }
-
- inline ifdstream::
- ifdstream (const std::string& f, fdopen_mode m, iostate e)
- : ifdstream (f.c_str (), m, e) // Delegate.
- {
- }
-
- inline ifdstream::
- ifdstream (const path& f, fdopen_mode m, iostate e)
- : ifdstream (f.string (), m, e) // Delegate.
- {
- }
-
- inline void ifdstream::
- open (const std::string& f, openmode m)
- {
- open (f.c_str (), m);
- }
-
- inline void ifdstream::
- open (const path& f, openmode m)
- {
- open (f.string (), m);
- }
-
- inline void ifdstream::
- open (const std::string& f, fdopen_mode m)
- {
- open (f.c_str (), m);
- }
-
- inline void ifdstream::
- open (const path& f, fdopen_mode m)
- {
- open (f.string (), m);
- }
-
- inline auto_fd ifdstream::
- release ()
- {
- return buf_.release ();
- }
-
- // ofdstream
- //
- inline ofdstream::
- ofdstream (auto_fd&& fd, iostate e)
- : fdstream_base (std::move (fd)), std::ostream (&buf_)
- {
- assert (e & badbit);
- exceptions (e);
- }
-
- inline ofdstream::
- ofdstream (iostate e)
- : ofdstream (auto_fd (), e) // Delegate.
- {
- }
-
- inline ofdstream::
- ofdstream (auto_fd&& fd, fdstream_mode m, iostate e)
- : fdstream_base (std::move (fd), m), std::ostream (&buf_)
- {
- assert (e & badbit);
- exceptions (e);
- }
-
- inline ofdstream::
- ofdstream (const std::string& f, openmode m, iostate e)
- : ofdstream (f.c_str (), m, e) // Delegate.
- {
- }
-
- inline ofdstream::
- ofdstream (const path& f, openmode m, iostate e)
- : ofdstream (f.string (), m, e) // Delegate.
- {
- }
-
- inline ofdstream::
- ofdstream (const std::string& f, fdopen_mode m, iostate e)
- : ofdstream (f.c_str (), m, e) // Delegate.
- {
- }
-
- inline ofdstream::
- ofdstream (const path& f, fdopen_mode m, iostate e)
- : ofdstream (f.string (), m, e) // Delegate.
- {
- }
-
- inline void ofdstream::
- open (const std::string& f, openmode m)
- {
- open (f.c_str (), m);
- }
-
- inline void ofdstream::
- open (const path& f, openmode m)
- {
- open (f.string (), m);
- }
-
- inline void ofdstream::
- open (const std::string& f, fdopen_mode m)
- {
- open (f.c_str (), m);
- }
-
- inline void ofdstream::
- open (const path& f, fdopen_mode m)
- {
- open (f.string (), m);
- }
-
- inline auto_fd ofdstream::
- release ()
- {
- if (is_open ())
- flush ();
-
- return buf_.release ();
- }
-
- // fdopen()
- //
- inline auto_fd
- fdopen (const std::string& f, fdopen_mode m, permissions p)
- {
- return fdopen (f.c_str (), m, p);
- }
-
- inline auto_fd
- fdopen (const path& f, fdopen_mode m, permissions p)
- {
- return fdopen (f.string (), m, p);
- }
-
- // fdstream_mode
- //
- inline fdstream_mode
- operator& (fdstream_mode x, fdstream_mode y)
- {
- return x &= y;
- }
-
- inline fdstream_mode
- operator| (fdstream_mode x, fdstream_mode y)
- {
- return x |= y;
- }
-
- inline fdstream_mode
- operator&= (fdstream_mode& x, fdstream_mode y)
- {
- return x = static_cast<fdstream_mode> (
- static_cast<std::uint16_t> (x) &
- static_cast<std::uint16_t> (y));
- }
-
- inline fdstream_mode
- operator|= (fdstream_mode& x, fdstream_mode y)
- {
- return x = static_cast<fdstream_mode> (
- static_cast<std::uint16_t> (x) |
- static_cast<std::uint16_t> (y));
- }
-
- // fdopen_mode
- //
- inline fdopen_mode operator& (fdopen_mode x, fdopen_mode y) {return x &= y;}
- inline fdopen_mode operator| (fdopen_mode x, fdopen_mode y) {return x |= y;}
-
- inline fdopen_mode
- operator&= (fdopen_mode& x, fdopen_mode y)
- {
- return x = static_cast<fdopen_mode> (
- static_cast<std::uint16_t> (x) &
- static_cast<std::uint16_t> (y));
- }
-
- inline fdopen_mode
- operator|= (fdopen_mode& x, fdopen_mode y)
- {
- return x = static_cast<fdopen_mode> (
- static_cast<std::uint16_t> (x) |
- static_cast<std::uint16_t> (y));
- }
-}