diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2020-10-27 13:17:26 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2020-10-27 13:18:45 +0300 |
commit | 0c62070b24273e565cce112ab061df6665d3ae8c (patch) | |
tree | a9a36ef593871daef57986fbfbbfb44de8c1116d /include/winapi | |
parent | Boost.Test is broken in 1.62 (diff) | |
download | winapi-common-0c62070b24273e565cce112ab061df6665d3ae8c.tar.gz winapi-common-0c62070b24273e565cce112ab061df6665d3ae8c.zip |
code style
Don't use brace initialization in constructors, VS 2013 doesn't like
that.
Diffstat (limited to 'include/winapi')
-rw-r--r-- | include/winapi/file.hpp | 4 | ||||
-rw-r--r-- | include/winapi/handle.hpp | 4 | ||||
-rw-r--r-- | include/winapi/pipe.hpp | 23 | ||||
-rw-r--r-- | include/winapi/process.hpp | 20 | ||||
-rw-r--r-- | include/winapi/process_io.hpp | 24 | ||||
-rw-r--r-- | include/winapi/resource.hpp | 2 | ||||
-rw-r--r-- | include/winapi/shmem.hpp | 29 |
7 files changed, 66 insertions, 40 deletions
diff --git a/include/winapi/file.hpp b/include/winapi/file.hpp index 3dcd0d1..b9688e9 100644 --- a/include/winapi/file.hpp +++ b/include/winapi/file.hpp @@ -15,8 +15,6 @@ namespace winapi { class File : private Handle { public: - explicit File(Handle&& handle) : Handle{std::move(handle)} {} - static Handle open_r(const std::string&); static Handle open_r(const CanonicalPath&); static Handle open_w(const std::string&); @@ -25,6 +23,8 @@ public: static void remove(const std::string&); static void remove(const CanonicalPath&); + explicit File(Handle&& handle) : Handle(std::move(handle)) {} + using Handle::close; using Handle::read; diff --git a/include/winapi/handle.hpp b/include/winapi/handle.hpp index 7c10735..cd114d5 100644 --- a/include/winapi/handle.hpp +++ b/include/winapi/handle.hpp @@ -25,8 +25,8 @@ public: Handle(Handle&& other) BOOST_NOEXCEPT_OR_NOTHROW; Handle& operator=(Handle other) BOOST_NOEXCEPT_OR_NOTHROW; - void swap(Handle& other) BOOST_NOEXCEPT_OR_NOTHROW; + Handle(const Handle&) = delete; HANDLE get() const { return m_impl.get(); } HANDLE ptr() const { return get(); } @@ -65,8 +65,6 @@ private: }; std::unique_ptr<void, Close> m_impl; - - Handle(const Handle&) = delete; }; inline void swap(Handle& a, Handle& b) BOOST_NOEXCEPT_OR_NOTHROW { diff --git a/include/winapi/pipe.hpp b/include/winapi/pipe.hpp index ebd99e8..9f71858 100644 --- a/include/winapi/pipe.hpp +++ b/include/winapi/pipe.hpp @@ -7,12 +7,22 @@ #include "handle.hpp" +#include <boost/config.hpp> + +#include <utility> + namespace winapi { class Pipe { public: Pipe(); + // VS 2013 won't generate these automatically. + Pipe(Pipe&&) BOOST_NOEXCEPT_OR_NOTHROW; + Pipe& operator=(Pipe) BOOST_NOEXCEPT_OR_NOTHROW; + void swap(Pipe&) BOOST_NOEXCEPT_OR_NOTHROW; + Pipe(const Pipe&) = delete; + Handle& read_end() { return m_read_end; } const Handle& read_end() const { return m_read_end; } Handle& write_end() { return m_write_end; } @@ -23,4 +33,17 @@ private: Handle m_write_end; }; +inline void swap(Pipe& a, Pipe& b) BOOST_NOEXCEPT_OR_NOTHROW { + a.swap(b); +} + } // namespace winapi + +namespace std { + +template <> +inline void swap(winapi::Pipe& a, winapi::Pipe& b) BOOST_NOEXCEPT_OR_NOTHROW { + a.swap(b); +} + +} // namespace std diff --git a/include/winapi/process.hpp b/include/winapi/process.hpp index 3c9a840..db5f5d1 100644 --- a/include/winapi/process.hpp +++ b/include/winapi/process.hpp @@ -27,7 +27,7 @@ struct ProcessParameters { ConsoleNew, }; - explicit ProcessParameters(const CommandLine& cmd_line) : cmd_line{cmd_line} {} + explicit ProcessParameters(const CommandLine& cmd_line) : cmd_line(cmd_line) {} // VS 2013 won't generate these automatically. ProcessParameters(ProcessParameters&&) BOOST_NOEXCEPT_OR_NOTHROW; @@ -40,17 +40,19 @@ struct ProcessParameters { ConsoleCreationMode console_mode = ConsoleNew; }; -void swap(ProcessParameters&, ProcessParameters&) BOOST_NOEXCEPT_OR_NOTHROW; +inline void swap(ProcessParameters& a, ProcessParameters& b) BOOST_NOEXCEPT_OR_NOTHROW { + a.swap(b); +} struct ShellParameters : ProcessParameters { - explicit ShellParameters(const CommandLine& cmd_line) : ProcessParameters{cmd_line} {} - static ShellParameters runas(const CommandLine& cmd_line) { ShellParameters params{cmd_line}; params.verb = "runas"; return params; } + explicit ShellParameters(const CommandLine& cmd_line) : ProcessParameters(cmd_line) {} + // VS 2013 won't generate these automatically. ShellParameters(ShellParameters&&) BOOST_NOEXCEPT_OR_NOTHROW; ShellParameters& operator=(ShellParameters) BOOST_NOEXCEPT_OR_NOTHROW; @@ -60,7 +62,9 @@ struct ShellParameters : ProcessParameters { boost::optional<std::string> verb; }; -void swap(ShellParameters&, ShellParameters&) BOOST_NOEXCEPT_OR_NOTHROW; +inline void swap(ShellParameters& a, ShellParameters& b) BOOST_NOEXCEPT_OR_NOTHROW { + a.swap(b); +} class Process { public: @@ -89,14 +93,16 @@ public: static std::string get_resource_string(unsigned int id); private: - explicit Process(Handle&& handle) : m_handle{std::move(handle)} {} + explicit Process(Handle&& handle) : m_handle(std::move(handle)) {} static HMODULE get_exe_module(); Handle m_handle; }; -void swap(Process& a, Process& b) BOOST_NOEXCEPT_OR_NOTHROW; +inline void swap(Process& a, Process& b) BOOST_NOEXCEPT_OR_NOTHROW { + a.swap(b); +} } // namespace winapi diff --git a/include/winapi/process_io.hpp b/include/winapi/process_io.hpp index 512cb7b..976ad6e 100644 --- a/include/winapi/process_io.hpp +++ b/include/winapi/process_io.hpp @@ -20,16 +20,18 @@ 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; + + Handle handle; }; -void swap(Stream& a, Stream& b) BOOST_NOEXCEPT_OR_NOTHROW; +inline void swap(Stream& a, Stream& b) BOOST_NOEXCEPT_OR_NOTHROW { + a.swap(b); +} struct Stdin : Stream { Stdin(); @@ -70,20 +72,22 @@ struct Stderr : Stream { struct IO { IO() = default; - void close(); - - Stdin std_in; - Stdout std_out; - 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 close(); + + Stdin std_in; + Stdout std_out; + Stderr std_err; }; -void swap(IO& a, IO& b) BOOST_NOEXCEPT_OR_NOTHROW; +inline void swap(IO& a, IO& b) BOOST_NOEXCEPT_OR_NOTHROW { + a.swap(b); +} } // namespace process } // namespace winapi diff --git a/include/winapi/resource.hpp b/include/winapi/resource.hpp index 2f77d3e..3fda73e 100644 --- a/include/winapi/resource.hpp +++ b/include/winapi/resource.hpp @@ -16,7 +16,7 @@ struct Resource { Resource() = default; - Resource(const void* data, std::size_t nb) : data{data}, nb{nb} {} + Resource(const void* data, std::size_t nb) : data(data), nb(nb) {} Buffer copy() const { return {data, nb}; } diff --git a/include/winapi/shmem.hpp b/include/winapi/shmem.hpp index 0fb2b76..f2ce33e 100644 --- a/include/winapi/shmem.hpp +++ b/include/winapi/shmem.hpp @@ -38,7 +38,7 @@ private: SharedMemory() = default; - SharedMemory(Handle&& handle, void* addr) : m_handle{std::move(handle)}, m_addr{addr} {} + SharedMemory(Handle&& handle, void* addr) : m_handle(std::move(handle)), m_addr(addr) {} Handle m_handle; std::unique_ptr<void, Unmap> m_addr; @@ -67,26 +67,28 @@ public: } SharedObject(SharedObject&& other) BOOST_NOEXCEPT_OR_NOTHROW - : m_shmem{std::move(other.m_shmem)}, - m_destruct{other.m_destruct} {} + : m_shmem(std::move(other.m_shmem)), + m_destruct(other.m_destruct) {} SharedObject& operator=(SharedObject other) BOOST_NOEXCEPT_OR_NOTHROW { swap(other); return *this; } - ~SharedObject() { - if (m_destruct && ptr()) { - ptr()->~T(); - } - } - void swap(SharedObject& other) BOOST_NOEXCEPT_OR_NOTHROW { using std::swap; swap(m_shmem, other.m_shmem); swap(m_destruct, other.m_destruct); } + SharedObject(const SharedObject&) = delete; + + ~SharedObject() { + if (m_destruct && ptr()) { + ptr()->~T(); + } + } + T* ptr() const { return reinterpret_cast<T*>(m_shmem.ptr()); } T& get() const { return *ptr(); } @@ -94,13 +96,11 @@ public: T& operator*() const { return get(); } private: - explicit SharedObject(SharedMemory&& shmem) : m_shmem{std::move(shmem)} {} + explicit SharedObject(SharedMemory&& shmem) : m_shmem(std::move(shmem)) {} SharedMemory m_shmem; // Destruct only once, no matter the number of mappings. bool m_destruct = false; - - SharedObject(const SharedObject&) = delete; }; template <typename T> @@ -117,9 +117,4 @@ inline void swap(winapi::SharedMemory& a, winapi::SharedMemory& b) BOOST_NOEXCEP a.swap(b); } -template <typename T> -inline void swap(winapi::SharedObject<T>& a, winapi::SharedObject<T>& b) BOOST_NOEXCEPT_OR_NOTHROW { - a.swap(b); -} - } // namespace std |