Skip to content

Commit

Permalink
enum: avoid using reserved identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Oct 22, 2024
1 parent a578b44 commit 39c142f
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
16 changes: 8 additions & 8 deletions src/uvw/enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
* two values provided.
*/
template<typename Type>
[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::_UVW_ENUM)>
[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::UVW_ENUM)>
operator|(const Type lhs, const Type rhs) noexcept {
return static_cast<Type>(static_cast<std::underlying_type_t<Type>>(lhs) | static_cast<std::underlying_type_t<Type>>(rhs));
}

/*! @copydoc operator| */
template<typename Type>
[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::_UVW_ENUM)>
[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::UVW_ENUM)>
operator&(const Type lhs, const Type rhs) noexcept {
return static_cast<Type>(static_cast<std::underlying_type_t<Type>>(lhs) & static_cast<std::underlying_type_t<Type>>(rhs));
}

/*! @copydoc operator| */
template<typename Type>
[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::_UVW_ENUM)>
[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::UVW_ENUM)>
operator^(const Type lhs, const Type rhs) noexcept {
return static_cast<Type>(static_cast<std::underlying_type_t<Type>>(lhs) ^ static_cast<std::underlying_type_t<Type>>(rhs));
}
Expand All @@ -40,35 +40,35 @@ operator^(const Type lhs, const Type rhs) noexcept {
* value provided.
*/
template<typename Type>
[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::_UVW_ENUM)>
[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::UVW_ENUM)>
operator~(const Type value) noexcept {
return static_cast<Type>(~static_cast<std::underlying_type_t<Type>>(value));
}

/*! @copydoc operator~ */
template<typename Type>
[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::_UVW_ENUM, bool{})>
[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::UVW_ENUM, bool{})>
operator!(const Type value) noexcept {
return !static_cast<std::underlying_type_t<Type>>(value);
}

/*! @copydoc operator| */
template<typename Type>
constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::_UVW_ENUM) &>
constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::UVW_ENUM) &>
operator|=(Type &lhs, const Type rhs) noexcept {
return (lhs = (lhs | rhs));
}

/*! @copydoc operator| */
template<typename Type>
constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::_UVW_ENUM) &>
constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::UVW_ENUM) &>
operator&=(Type &lhs, const Type rhs) noexcept {
return (lhs = (lhs & rhs));
}

/*! @copydoc operator| */
template<typename Type>
constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::_UVW_ENUM) &>
constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::UVW_ENUM) &>
operator^=(Type &lhs, const Type rhs) noexcept {
return (lhs = (lhs ^ rhs));
}
Expand Down
14 changes: 7 additions & 7 deletions src/uvw/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,20 @@ enum class uvw_file_open_flags : int {
TEMPORARY = UV_FS_O_TEMPORARY,
TRUNC = UV_FS_O_TRUNC,
WRONLY = UV_FS_O_WRONLY,
_UVW_ENUM = 0
UVW_ENUM = 0
};

enum class uvw_copy_file_flags : int {
EXCL = UV_FS_COPYFILE_EXCL,
FICLONE = UV_FS_COPYFILE_FICLONE,
FICLONE_FORCE = UV_FS_COPYFILE_FICLONE_FORCE,
_UVW_ENUM = 0
UVW_ENUM = 0
};

enum class uvw_symlink_flags : int {
DIR = UV_FS_SYMLINK_DIR,
JUNCTION = UV_FS_SYMLINK_JUNCTION,
_UVW_ENUM = 0
UVW_ENUM = 0
};

} // namespace details
Expand Down Expand Up @@ -886,7 +886,7 @@ class fs_req final: public fs_request<fs_req> {
* @param path New path, as described in the official documentation.
* @param flags Optional additional flags.
*/
void copyfile(const std::string &old, const std::string &path, copy_file_flags flags = copy_file_flags::_UVW_ENUM);
void copyfile(const std::string &old, const std::string &path, copy_file_flags flags = copy_file_flags::UVW_ENUM);

/**
* @brief Copies a file synchronously from a path to a new one.
Expand All @@ -907,7 +907,7 @@ class fs_req final: public fs_request<fs_req> {
* @param flags Optional additional flags.
* @return True in case of success, false otherwise.
*/
bool copyfile_sync(const std::string &old, const std::string &path, copy_file_flags flags = copy_file_flags::_UVW_ENUM);
bool copyfile_sync(const std::string &old, const std::string &path, copy_file_flags flags = copy_file_flags::UVW_ENUM);

/**
* @brief Async [access](http://linux.die.net/man/2/access).
Expand Down Expand Up @@ -1003,7 +1003,7 @@ class fs_req final: public fs_request<fs_req> {
* @param path New path, as described in the official documentation.
* @param flags Optional additional flags.
*/
void symlink(const std::string &old, const std::string &path, symlink_flags flags = symlink_flags::_UVW_ENUM);
void symlink(const std::string &old, const std::string &path, symlink_flags flags = symlink_flags::UVW_ENUM);

/**
* @brief Sync [symlink](http://linux.die.net/man/2/symlink).
Expand All @@ -1020,7 +1020,7 @@ class fs_req final: public fs_request<fs_req> {
* @param flags Flags, as described in the official documentation.
* @return True in case of success, false otherwise.
*/
bool symlink_sync(const std::string &old, const std::string &path, symlink_flags flags = symlink_flags::_UVW_ENUM);
bool symlink_sync(const std::string &old, const std::string &path, symlink_flags flags = symlink_flags::UVW_ENUM);

/**
* @brief Async [readlink](http://linux.die.net/man/2/readlink).
Expand Down
4 changes: 2 additions & 2 deletions src/uvw/fs_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum class uvw_fs_event_flags : std::underlying_type_t<uv_fs_event_flags> {
WATCH_ENTRY = UV_FS_EVENT_WATCH_ENTRY,
STAT = UV_FS_EVENT_STAT,
RECURSIVE = UV_FS_EVENT_RECURSIVE,
_UVW_ENUM = 0
UVW_ENUM = 0
};

enum class uvw_fs_event : std::underlying_type_t<uv_fs_event> {
Expand Down Expand Up @@ -96,7 +96,7 @@ class fs_event_handle final: public handle<fs_event_handle, uv_fs_event_t, fs_ev
* @param flags Additional flags to control the behavior.
* @return Underlying return value.
*/
int start(const std::string &path, event_flags flags = event_flags::_UVW_ENUM);
int start(const std::string &path, event_flags flags = event_flags::UVW_ENUM);

/**
* @brief Stops polling the file descriptor.
Expand Down
2 changes: 1 addition & 1 deletion src/uvw/pipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace details {
enum class uvw_chmod_flags : std::underlying_type_t<uv_poll_event> {
READABLE = UV_READABLE,
WRITABLE = UV_WRITABLE,
_UVW_ENUM = 0
UVW_ENUM = 0
};

}
Expand Down
2 changes: 1 addition & 1 deletion src/uvw/poll.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum class uvw_poll_event : std::underlying_type_t<uv_poll_event> {
WRITABLE = UV_WRITABLE,
DISCONNECT = UV_DISCONNECT,
PRIORITIZED = UV_PRIORITIZED,
_UVW_ENUM = 0
UVW_ENUM = 0
};

}
Expand Down
4 changes: 2 additions & 2 deletions src/uvw/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ enum class uvw_process_flags : std::underlying_type_t<uv_process_flags> {
WINDOWS_HIDE_CONSOLE = UV_PROCESS_WINDOWS_HIDE_CONSOLE,
WINDOWS_HIDE_GUI = UV_PROCESS_WINDOWS_HIDE_GUI,
WINDOWS_FILE_PATH_EXACT_NAME = UV_PROCESS_WINDOWS_FILE_PATH_EXACT_NAME,
_UVW_ENUM = 0
UVW_ENUM = 0
};

enum class uvw_stdio_flags : std::underlying_type_t<uv_stdio_flags> {
Expand All @@ -37,7 +37,7 @@ enum class uvw_stdio_flags : std::underlying_type_t<uv_stdio_flags> {
READABLE_PIPE = UV_READABLE_PIPE,
WRITABLE_PIPE = UV_WRITABLE_PIPE,
OVERLAPPED_PIPE = UV_OVERLAPPED_PIPE,
_UVW_ENUM = 0
UVW_ENUM = 0
};

} // namespace details
Expand Down
8 changes: 4 additions & 4 deletions src/uvw/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace details {

enum class uvw_tcp_flags : std::underlying_type_t<uv_tcp_flags> {
IPV6ONLY = UV_TCP_IPV6ONLY,
_UVW_ENUM = 0
UVW_ENUM = 0
};

}
Expand Down Expand Up @@ -115,7 +115,7 @@ class tcp_handle final: public stream_handle<tcp_handle, uv_tcp_t> {
* @param opts Optional additional flags.
* @return Underlying return value.
*/
int bind(const sockaddr &addr, tcp_flags opts = tcp_flags::_UVW_ENUM);
int bind(const sockaddr &addr, tcp_flags opts = tcp_flags::UVW_ENUM);

/**
* @brief Binds the handle to an address and port.
Expand All @@ -133,7 +133,7 @@ class tcp_handle final: public stream_handle<tcp_handle, uv_tcp_t> {
* @param opts Optional additional flags.
* @return Underlying return value.
*/
int bind(const std::string &ip, unsigned int port, tcp_flags opts = tcp_flags::_UVW_ENUM);
int bind(const std::string &ip, unsigned int port, tcp_flags opts = tcp_flags::UVW_ENUM);

/**
* @brief Binds the handle to an address and port.
Expand All @@ -150,7 +150,7 @@ class tcp_handle final: public stream_handle<tcp_handle, uv_tcp_t> {
* @param opts Optional additional flags.
* @return Underlying return value.
*/
int bind(socket_address addr, tcp_flags opts = tcp_flags::_UVW_ENUM);
int bind(socket_address addr, tcp_flags opts = tcp_flags::UVW_ENUM);

/**
* @brief Gets the current address to which the handle is bound.
Expand Down
8 changes: 4 additions & 4 deletions src/uvw/udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ enum class uvw_udp_flags : std::underlying_type_t<uv_udp_flags> {
UDP_MMSG_FREE = UV_UDP_MMSG_FREE,
UDP_LINUX_RECVERR = UV_UDP_LINUX_RECVERR,
UDP_RECVMMSG = UV_UDP_RECVMMSG,
_UVW_ENUM = 0
UVW_ENUM = 0
};

enum class uvw_membership : std::underlying_type_t<uv_membership> {
Expand Down Expand Up @@ -193,7 +193,7 @@ class udp_handle final: public handle<udp_handle, uv_udp_t, send_event, udp_data
* @param opts Optional additional flags.
* @return Underlying return value.
*/
int bind(const sockaddr &addr, udp_flags opts = udp_flags::_UVW_ENUM);
int bind(const sockaddr &addr, udp_flags opts = udp_flags::UVW_ENUM);

/**
* @brief Binds the UDP handle to an IP address and port.
Expand All @@ -217,7 +217,7 @@ class udp_handle final: public handle<udp_handle, uv_udp_t, send_event, udp_data
* @param opts Optional additional flags.
* @return Underlying return value.
*/
int bind(const std::string &ip, unsigned int port, udp_flags opts = udp_flags::_UVW_ENUM);
int bind(const std::string &ip, unsigned int port, udp_flags opts = udp_flags::UVW_ENUM);

/**
* @brief Binds the UDP handle to an IP address and port.
Expand All @@ -240,7 +240,7 @@ class udp_handle final: public handle<udp_handle, uv_udp_t, send_event, udp_data
* @param opts Optional additional flags.
* @return Underlying return value.
*/
int bind(socket_address addr, udp_flags opts = udp_flags::_UVW_ENUM);
int bind(socket_address addr, udp_flags opts = udp_flags::UVW_ENUM);

/**
* @brief Get the local IP and port of the UDP handle.
Expand Down

0 comments on commit 39c142f

Please sign in to comment.