Skip to content

Commit

Permalink
switch to "auto method() -> return_type" convention in device object
Browse files Browse the repository at this point in the history
  • Loading branch information
wbenny committed Aug 1, 2019
1 parent d8eb913 commit 8014193
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
36 changes: 16 additions & 20 deletions src/hvpp/hvpp/lib/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,40 @@
class device
{
public:
device() noexcept = default;
virtual ~device() noexcept { destroy(); }

virtual const char* name() const noexcept = 0;
device() noexcept = default;
device(const device& other) noexcept = delete;
device(device&& other) noexcept = delete;
device& operator=(const device& other) noexcept = delete;
device& operator=(device&& other) noexcept = delete;
virtual ~device() noexcept
{ destroy(); }

auto create() noexcept -> error_code_t;
void destroy() noexcept;

//
// Dispatch methods.
//
virtual auto name() const noexcept -> const char * = 0;

//
// A function declared with a return type that uses a placeholder
// type shall not be virtual ([class.virtual]).
// (ref: C++ standard, [dcl.spec.auto])
//
// TL;DR:
// We can't use "virtual auto on_create() -> error_code_t" :(
// Dispatch methods.
//

virtual error_code_t on_create() noexcept
virtual auto on_create() noexcept -> error_code_t
{ return {}; }

virtual error_code_t on_close() noexcept
virtual auto on_close() noexcept -> error_code_t
{ return {}; }

virtual error_code_t on_read(void* buffer, size_t buffer_size, size_t& bytes_read) noexcept
virtual auto on_read(void* buffer, size_t buffer_size, size_t& bytes_read) noexcept -> error_code_t
{ (void)(buffer); (void)(buffer_size); (void)(bytes_read); return {}; }

virtual error_code_t on_write(void* buffer, size_t buffer_size, size_t& bytes_written) noexcept
virtual auto on_write(void* buffer, size_t buffer_size, size_t& bytes_written) noexcept -> error_code_t
{ (void)(buffer); (void)(buffer_size); (void)(bytes_written); return {}; }

virtual error_code_t on_ioctl(void* buffer, size_t buffer_size, uint32_t code) noexcept
virtual auto on_ioctl(void* buffer, size_t buffer_size, uint32_t code) noexcept -> error_code_t
{ (void)(buffer); (void)(buffer_size); (void)(code); return {}; }

static error_code_t copy_from_user(void* buffer_to, const void* buffer_from, size_t length) noexcept;
static error_code_t copy_to_user(void* buffer_to, const void* buffer_from, size_t length) noexcept;
static auto copy_from_user(void* buffer_to, const void* buffer_from, size_t length) noexcept -> error_code_t;
static auto copy_to_user(void* buffer_to, const void* buffer_from, size_t length) noexcept -> error_code_t;

private:
void* impl_;
Expand Down
4 changes: 2 additions & 2 deletions src/hvpp/hvpp/lib/win32/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void device::destroy() noexcept
impl_ = nullptr;
}

error_code_t device::copy_from_user(void* buffer_to, const void* buffer_from, size_t length) noexcept
auto device::copy_from_user(void* buffer_to, const void* buffer_from, size_t length) noexcept -> error_code_t
{
if (!length)
{
Expand Down Expand Up @@ -200,7 +200,7 @@ error_code_t device::copy_from_user(void* buffer_to, const void* buffer_from, si
return {};
}

error_code_t device::copy_to_user(void* buffer_to, const void* buffer_from, size_t length) noexcept
auto device::copy_to_user(void* buffer_to, const void* buffer_from, size_t length) noexcept -> error_code_t
{
if (!length)
{
Expand Down

0 comments on commit 8014193

Please sign in to comment.