From f5b479fbabdceda48e3fd20d60bef1af393799cc Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 18 Oct 2020 13:39:44 +0300 Subject: stream.hpp -> process_io.hpp, move IO there --- include/winapi/process.hpp | 45 +---------------- include/winapi/process_io.hpp | 103 +++++++++++++++++++++++++++++++++++++++ include/winapi/stream.hpp | 110 ------------------------------------------ 3 files changed, 105 insertions(+), 153 deletions(-) create mode 100644 include/winapi/process_io.hpp delete mode 100644 include/winapi/stream.hpp (limited to 'include') diff --git a/include/winapi/process.hpp b/include/winapi/process.hpp index 5f841a0..d52ad0a 100644 --- a/include/winapi/process.hpp +++ b/include/winapi/process.hpp @@ -7,8 +7,8 @@ #include "cmd_line.hpp" #include "handle.hpp" +#include "process_io.hpp" #include "resource.hpp" -#include "stream.hpp" #include @@ -21,36 +21,8 @@ namespace winapi { class Process { public: - struct IO { - IO() = default; - - void close(); - - process::Stdin std_in; - process::Stdout std_out; - process::Stderr std_err; - - // VS 2013 won't generate these automatically. - - IO(IO&& other) BOOST_NOEXCEPT_OR_NOTHROW { swap(other); } - - IO& operator=(IO other) BOOST_NOEXCEPT_OR_NOTHROW { - swap(other); - return *this; - } - - void swap(IO& other) BOOST_NOEXCEPT_OR_NOTHROW { - using std::swap; - swap(std_in, other.std_in); - swap(std_out, other.std_out); - swap(std_err, other.std_err); - } - - IO(const IO&) = delete; - }; - static Process create(const CommandLine&); - static Process create(const CommandLine&, IO); + static Process create(const CommandLine&, process::IO); void wait() const; @@ -69,17 +41,4 @@ private: Handle m_handle; }; -inline void swap(Process::IO& a, Process::IO& b) BOOST_NOEXCEPT_OR_NOTHROW { - a.swap(b); -} - } // namespace winapi - -namespace std { - -template <> -inline void swap(winapi::Process::IO& a, winapi::Process::IO& b) BOOST_NOEXCEPT_OR_NOTHROW { - a.swap(b); -} - -} // namespace std diff --git a/include/winapi/process_io.hpp b/include/winapi/process_io.hpp new file mode 100644 index 0000000..597cc08 --- /dev/null +++ b/include/winapi/process_io.hpp @@ -0,0 +1,103 @@ +// Copyright (c) 2020 Egor Tensin +// This file is part of the "winapi-common" project. +// For details, see https://github.com/egor-tensin/winapi-common. +// Distributed under the MIT License. + +#pragma once + +#include "handle.hpp" +#include "path.hpp" +#include "pipe.hpp" + +#include + +#include +#include + +namespace winapi { +namespace process { + +struct Stream { + Stream(Handle&& handle) : handle{std::move(handle)} {} + + Handle handle; + + // VS 2013 won't generate these automatically. + Stream(Stream&& other) BOOST_NOEXCEPT_OR_NOTHROW; + Stream& operator=(Stream other) BOOST_NOEXCEPT_OR_NOTHROW; + void swap(Stream& other) BOOST_NOEXCEPT_OR_NOTHROW; + Stream(const Stream&) = delete; +}; + +void swap(Stream& a, Stream& b) BOOST_NOEXCEPT_OR_NOTHROW; + +struct Stdin : Stream { + Stdin(); + explicit Stdin(const std::string& file); + explicit Stdin(const CanonicalPath& file); + explicit Stdin(Pipe&); + + // VS 2013 won't generate these automatically. + Stdin(Stdin&& other) BOOST_NOEXCEPT_OR_NOTHROW; + Stdin& operator=(Stdin other) BOOST_NOEXCEPT_OR_NOTHROW; + Stdin(const Stdin&) = delete; +}; + +struct Stdout : Stream { + Stdout(); + explicit Stdout(const std::string& file); + explicit Stdout(const CanonicalPath& file); + explicit Stdout(Pipe&); + + // VS 2013 won't generate these automatically. + Stdout(Stdout&& other) BOOST_NOEXCEPT_OR_NOTHROW; + Stdout& operator=(Stdout other) BOOST_NOEXCEPT_OR_NOTHROW; + Stdout(const Stdout&) = delete; +}; + +struct Stderr : Stream { + Stderr(); + explicit Stderr(const std::string& file); + explicit Stderr(const CanonicalPath& file); + explicit Stderr(Pipe&); + + // VS 2013 won't generate these automatically. + Stderr(Stderr&& other) BOOST_NOEXCEPT_OR_NOTHROW; + Stderr& operator=(Stderr other) BOOST_NOEXCEPT_OR_NOTHROW; + Stderr(const Stderr&) = delete; +}; + +struct IO { + IO() = default; + + void close(); + + process::Stdin std_in; + process::Stdout std_out; + process::Stderr std_err; + + // VS 2013 won't generate these automatically. + IO(IO&& other) BOOST_NOEXCEPT_OR_NOTHROW; + IO& operator=(IO other) BOOST_NOEXCEPT_OR_NOTHROW; + void swap(IO& other) BOOST_NOEXCEPT_OR_NOTHROW; + IO(const IO&) = delete; +}; + +void swap(IO& a, IO& b) BOOST_NOEXCEPT_OR_NOTHROW; + +} // namespace process +} // namespace winapi + +namespace std { + +template <> +inline void swap(winapi::process::Stream& a, winapi::process::Stream& b) BOOST_NOEXCEPT_OR_NOTHROW { + a.swap(b); +} + +template <> +inline void swap(winapi::process::IO& a, winapi::process::IO& b) BOOST_NOEXCEPT_OR_NOTHROW { + a.swap(b); +} + +} // namespace std diff --git a/include/winapi/stream.hpp b/include/winapi/stream.hpp deleted file mode 100644 index ed5b40c..0000000 --- a/include/winapi/stream.hpp +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (c) 2020 Egor Tensin -// This file is part of the "winapi-common" project. -// For details, see https://github.com/egor-tensin/winapi-common. -// Distributed under the MIT License. - -#pragma once - -#include "handle.hpp" -#include "path.hpp" -#include "pipe.hpp" - -#include - -#include -#include - -namespace winapi { -namespace process { - -struct Stream { - Stream(Handle&& handle) : handle{std::move(handle)} {} - - Handle handle; - - // VS 2013 won't generate these automatically. - - Stream(Stream&& other) BOOST_NOEXCEPT_OR_NOTHROW { swap(other); } - - Stream& operator=(Stream other) BOOST_NOEXCEPT_OR_NOTHROW { - swap(other); - return *this; - } - - void swap(Stream& other) BOOST_NOEXCEPT_OR_NOTHROW { - using std::swap; - swap(handle, other.handle); - } - - Stream(const Stream&) = delete; -}; - -inline void swap(Stream& a, Stream& b) BOOST_NOEXCEPT_OR_NOTHROW { - a.swap(b); -} - -struct Stdin : Stream { - Stdin(); - explicit Stdin(const std::string& file); - explicit Stdin(const CanonicalPath& file); - explicit Stdin(Pipe&); - - // VS 2013 won't generate these automatically. - - Stdin(Stdin&& other) BOOST_NOEXCEPT_OR_NOTHROW : Stream{std::move(other)} {} - - Stdin& operator=(Stdin other) BOOST_NOEXCEPT_OR_NOTHROW { - Stream::operator=(std::move(other)); - return *this; - } - - Stdin(const Stdin&) = delete; -}; - -struct Stdout : Stream { - Stdout(); - explicit Stdout(const std::string& file); - explicit Stdout(const CanonicalPath& file); - explicit Stdout(Pipe&); - - // VS 2013 won't generate these automatically. - - Stdout(Stdout&& other) BOOST_NOEXCEPT_OR_NOTHROW : Stream{std::move(other)} {} - - Stdout& operator=(Stdout other) BOOST_NOEXCEPT_OR_NOTHROW { - Stream::operator=(std::move(other)); - return *this; - } - - Stdout(const Stdout&) = delete; -}; - -struct Stderr : Stream { - Stderr(); - explicit Stderr(const std::string& file); - explicit Stderr(const CanonicalPath& file); - explicit Stderr(Pipe&); - - // VS 2013 won't generate these automatically. - - Stderr(Stderr&& other) BOOST_NOEXCEPT_OR_NOTHROW : Stream{std::move(other)} {} - - Stderr& operator=(Stderr other) BOOST_NOEXCEPT_OR_NOTHROW { - Stream::operator=(std::move(other)); - return *this; - } - - Stderr(const Stderr&) = delete; -}; - -} // namespace process -} // namespace winapi - -namespace std { - -template <> -inline void swap(winapi::process::Stream& a, winapi::process::Stream& b) BOOST_NOEXCEPT_OR_NOTHROW { - a.swap(b); -} - -} // namespace std -- cgit v1.2.3