diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/handle.cpp | 2 | ||||
-rw-r--r-- | src/pipe.cpp | 16 | ||||
-rw-r--r-- | src/process.cpp | 50 | ||||
-rw-r--r-- | src/process_io.cpp | 46 |
4 files changed, 55 insertions, 59 deletions
diff --git a/src/handle.cpp b/src/handle.cpp index fa3d8c0..4678519 100644 --- a/src/handle.cpp +++ b/src/handle.cpp @@ -35,7 +35,7 @@ bool is_std_handle(HANDLE handle) { } // namespace -Handle::Handle(HANDLE impl) : m_impl{impl} {} +Handle::Handle(HANDLE impl) : m_impl(impl) {} Handle::Handle(Handle&& other) BOOST_NOEXCEPT_OR_NOTHROW { swap(other); diff --git a/src/pipe.cpp b/src/pipe.cpp index f809995..299ab0f 100644 --- a/src/pipe.cpp +++ b/src/pipe.cpp @@ -12,6 +12,7 @@ #include <windows.h> #include <cstring> +#include <utility> namespace winapi { namespace { @@ -43,4 +44,19 @@ Pipe::Pipe() { create_pipe(m_read_end, m_write_end); } +Pipe::Pipe(Pipe&& other) BOOST_NOEXCEPT_OR_NOTHROW { + swap(other); +} + +Pipe& Pipe::operator=(Pipe other) BOOST_NOEXCEPT_OR_NOTHROW { + swap(other); + return *this; +} + +void Pipe::swap(Pipe& other) BOOST_NOEXCEPT_OR_NOTHROW { + using std::swap; + swap(m_read_end, other.m_read_end); + swap(m_write_end, other.m_write_end); +} + } // namespace winapi diff --git a/src/process.cpp b/src/process.cpp index 2fe6f4b..bac8bb8 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -161,9 +161,9 @@ Handle shell_execute(const ShellParameters& params) { } // namespace ProcessParameters::ProcessParameters(ProcessParameters&& other) BOOST_NOEXCEPT_OR_NOTHROW - : cmd_line{std::move(other.cmd_line)}, - io{std::move(other.io)}, - console_mode{std::move(other.console_mode)} {} + : cmd_line(std::move(other.cmd_line)), + io(std::move(other.io)), + console_mode(std::move(other.console_mode)) {} ProcessParameters& ProcessParameters::operator=(ProcessParameters other) BOOST_NOEXCEPT_OR_NOTHROW { swap(other); @@ -177,13 +177,9 @@ void ProcessParameters::swap(ProcessParameters& other) BOOST_NOEXCEPT_OR_NOTHROW swap(console_mode, other.console_mode); } -void swap(ProcessParameters& a, ProcessParameters& b) BOOST_NOEXCEPT_OR_NOTHROW { - a.swap(b); -} - ShellParameters::ShellParameters(ShellParameters&& other) BOOST_NOEXCEPT_OR_NOTHROW - : ProcessParameters{std::move(other)}, - verb{std::move(verb)} {} + : ProcessParameters(std::move(other)), + verb(std::move(verb)) {} ShellParameters& ShellParameters::operator=(ShellParameters other) BOOST_NOEXCEPT_OR_NOTHROW { swap(other); @@ -196,28 +192,6 @@ void ShellParameters::swap(ShellParameters& other) BOOST_NOEXCEPT_OR_NOTHROW { swap(verb, other.verb); } -void swap(ShellParameters& a, ShellParameters& b) BOOST_NOEXCEPT_OR_NOTHROW { - a.swap(b); -} - -Process::Process(Process&& other) BOOST_NOEXCEPT_OR_NOTHROW { - swap(other); -} - -Process& Process::operator=(Process other) BOOST_NOEXCEPT_OR_NOTHROW { - swap(other); - return *this; -} - -void Process::swap(Process& other) BOOST_NOEXCEPT_OR_NOTHROW { - using std::swap; - swap(m_handle, other.m_handle); -} - -void swap(Process& a, Process& b) BOOST_NOEXCEPT_OR_NOTHROW { - a.swap(b); -} - Process Process::create(ProcessParameters params) { return Process{create_process(params)}; } @@ -242,6 +216,20 @@ Process Process::shell(const CommandLine& cmd_line) { return shell(params); } +Process::Process(Process&& other) BOOST_NOEXCEPT_OR_NOTHROW { + swap(other); +} + +Process& Process::operator=(Process other) BOOST_NOEXCEPT_OR_NOTHROW { + swap(other); + return *this; +} + +void Process::swap(Process& other) BOOST_NOEXCEPT_OR_NOTHROW { + using std::swap; + swap(m_handle, other.m_handle); +} + bool Process::is_running() const { const auto ret = ::WaitForSingleObject(static_cast<HANDLE>(m_handle), 0); diff --git a/src/process_io.cpp b/src/process_io.cpp index ec7dbc9..e18558c 100644 --- a/src/process_io.cpp +++ b/src/process_io.cpp @@ -16,33 +16,33 @@ namespace winapi { namespace process { -Stdin::Stdin() : Stream{Handle::std_in()} {} +Stdin::Stdin() : Stream(Handle::std_in()) {} -Stdout::Stdout() : Stream{Handle::std_out()} {} +Stdout::Stdout() : Stream(Handle::std_out()) {} -Stderr::Stderr() : Stream{Handle::std_err()} {} +Stderr::Stderr() : Stream(Handle::std_err()) {} -Stdin::Stdin(const std::string& path) : Stream{File::open_r(path)} {} +Stdin::Stdin(const std::string& path) : Stream(File::open_r(path)) {} -Stdin::Stdin(const CanonicalPath& path) : Stream{File::open_r(path)} {} +Stdin::Stdin(const CanonicalPath& path) : Stream(File::open_r(path)) {} -Stdout::Stdout(const std::string& path) : Stream{File::open_w(path)} {} +Stdout::Stdout(const std::string& path) : Stream(File::open_w(path)) {} -Stdout::Stdout(const CanonicalPath& path) : Stream{File::open_w(path)} {} +Stdout::Stdout(const CanonicalPath& path) : Stream(File::open_w(path)) {} -Stderr::Stderr(const std::string& path) : Stream{File::open_w(path)} {} +Stderr::Stderr(const std::string& path) : Stream(File::open_w(path)) {} -Stderr::Stderr(const CanonicalPath& path) : Stream{File::open_w(path)} {} +Stderr::Stderr(const CanonicalPath& path) : Stream(File::open_w(path)) {} -Stdin::Stdin(Pipe& pipe) : Stream{std::move(pipe.read_end())} { +Stdin::Stdin(Pipe& pipe) : Stream(std::move(pipe.read_end())) { pipe.write_end().dont_inherit(); } -Stdout::Stdout(Pipe& pipe) : Stream{std::move(pipe.write_end())} { +Stdout::Stdout(Pipe& pipe) : Stream(std::move(pipe.write_end())) { pipe.read_end().dont_inherit(); } -Stderr::Stderr(Pipe& pipe) : Stream{std::move(pipe.write_end())} { +Stderr::Stderr(Pipe& pipe) : Stream(std::move(pipe.write_end())) { pipe.read_end().dont_inherit(); } @@ -60,37 +60,27 @@ void Stream::swap(Stream& other) BOOST_NOEXCEPT_OR_NOTHROW { swap(handle, other.handle); } -void swap(Stream& a, Stream& b) BOOST_NOEXCEPT_OR_NOTHROW { - a.swap(b); -} - -Stdin::Stdin(Stdin&& other) BOOST_NOEXCEPT_OR_NOTHROW : Stream{std::move(other)} {} +Stdin::Stdin(Stdin&& other) BOOST_NOEXCEPT_OR_NOTHROW : Stream(std::move(other)) {} Stdin& Stdin::operator=(Stdin other) BOOST_NOEXCEPT_OR_NOTHROW { Stream::operator=(std::move(other)); return *this; } -Stdout::Stdout(Stdout&& other) BOOST_NOEXCEPT_OR_NOTHROW : Stream{std::move(other)} {} +Stdout::Stdout(Stdout&& other) BOOST_NOEXCEPT_OR_NOTHROW : Stream(std::move(other)) {} Stdout& Stdout::operator=(Stdout other) BOOST_NOEXCEPT_OR_NOTHROW { Stream::operator=(std::move(other)); return *this; } -Stderr::Stderr(Stderr&& other) BOOST_NOEXCEPT_OR_NOTHROW : Stream{std::move(other)} {} +Stderr::Stderr(Stderr&& other) BOOST_NOEXCEPT_OR_NOTHROW : Stream(std::move(other)) {} Stderr& Stderr::operator=(Stderr other) BOOST_NOEXCEPT_OR_NOTHROW { Stream::operator=(std::move(other)); return *this; } -void IO::close() { - std_in.handle.close(); - std_out.handle.close(); - std_err.handle.close(); -} - IO::IO(IO&& other) BOOST_NOEXCEPT_OR_NOTHROW { swap(other); } @@ -107,8 +97,10 @@ void IO::swap(IO& other) BOOST_NOEXCEPT_OR_NOTHROW { swap(std_err, other.std_err); } -void swap(IO& a, IO& b) BOOST_NOEXCEPT_OR_NOTHROW { - a.swap(b); +void IO::close() { + std_in.handle.close(); + std_out.handle.close(); + std_err.handle.close(); } } // namespace process |