enum: avoid using reserved identifiers

This commit is contained in:
Michele Caini 2024-10-22 08:00:46 +02:00
parent a578b44788
commit 39c142fa56
8 changed files with 29 additions and 29 deletions

View File

@ -13,21 +13,21 @@
* two values provided. * two values provided.
*/ */
template<typename Type> 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 { 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)); return static_cast<Type>(static_cast<std::underlying_type_t<Type>>(lhs) | static_cast<std::underlying_type_t<Type>>(rhs));
} }
/*! @copydoc operator| */ /*! @copydoc operator| */
template<typename Type> 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 { 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)); return static_cast<Type>(static_cast<std::underlying_type_t<Type>>(lhs) & static_cast<std::underlying_type_t<Type>>(rhs));
} }
/*! @copydoc operator| */ /*! @copydoc operator| */
template<typename Type> 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 { 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)); return static_cast<Type>(static_cast<std::underlying_type_t<Type>>(lhs) ^ static_cast<std::underlying_type_t<Type>>(rhs));
} }
@ -40,35 +40,35 @@ operator^(const Type lhs, const Type rhs) noexcept {
* value provided. * value provided.
*/ */
template<typename Type> 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 { operator~(const Type value) noexcept {
return static_cast<Type>(~static_cast<std::underlying_type_t<Type>>(value)); return static_cast<Type>(~static_cast<std::underlying_type_t<Type>>(value));
} }
/*! @copydoc operator~ */ /*! @copydoc operator~ */
template<typename Type> 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 { operator!(const Type value) noexcept {
return !static_cast<std::underlying_type_t<Type>>(value); return !static_cast<std::underlying_type_t<Type>>(value);
} }
/*! @copydoc operator| */ /*! @copydoc operator| */
template<typename Type> 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 { operator|=(Type &lhs, const Type rhs) noexcept {
return (lhs = (lhs | rhs)); return (lhs = (lhs | rhs));
} }
/*! @copydoc operator| */ /*! @copydoc operator| */
template<typename Type> 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 { operator&=(Type &lhs, const Type rhs) noexcept {
return (lhs = (lhs & rhs)); return (lhs = (lhs & rhs));
} }
/*! @copydoc operator| */ /*! @copydoc operator| */
template<typename Type> 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 { operator^=(Type &lhs, const Type rhs) noexcept {
return (lhs = (lhs ^ rhs)); return (lhs = (lhs ^ rhs));
} }

View File

@ -91,20 +91,20 @@ enum class uvw_file_open_flags : int {
TEMPORARY = UV_FS_O_TEMPORARY, TEMPORARY = UV_FS_O_TEMPORARY,
TRUNC = UV_FS_O_TRUNC, TRUNC = UV_FS_O_TRUNC,
WRONLY = UV_FS_O_WRONLY, WRONLY = UV_FS_O_WRONLY,
_UVW_ENUM = 0 UVW_ENUM = 0
}; };
enum class uvw_copy_file_flags : int { enum class uvw_copy_file_flags : int {
EXCL = UV_FS_COPYFILE_EXCL, EXCL = UV_FS_COPYFILE_EXCL,
FICLONE = UV_FS_COPYFILE_FICLONE, FICLONE = UV_FS_COPYFILE_FICLONE,
FICLONE_FORCE = UV_FS_COPYFILE_FICLONE_FORCE, FICLONE_FORCE = UV_FS_COPYFILE_FICLONE_FORCE,
_UVW_ENUM = 0 UVW_ENUM = 0
}; };
enum class uvw_symlink_flags : int { enum class uvw_symlink_flags : int {
DIR = UV_FS_SYMLINK_DIR, DIR = UV_FS_SYMLINK_DIR,
JUNCTION = UV_FS_SYMLINK_JUNCTION, JUNCTION = UV_FS_SYMLINK_JUNCTION,
_UVW_ENUM = 0 UVW_ENUM = 0
}; };
} // namespace details } // namespace details
@ -886,7 +886,7 @@ public:
* @param path New path, as described in the official documentation. * @param path New path, as described in the official documentation.
* @param flags Optional additional flags. * @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. * @brief Copies a file synchronously from a path to a new one.
@ -907,7 +907,7 @@ public:
* @param flags Optional additional flags. * @param flags Optional additional flags.
* @return True in case of success, false otherwise. * @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). * @brief Async [access](http://linux.die.net/man/2/access).
@ -1003,7 +1003,7 @@ public:
* @param path New path, as described in the official documentation. * @param path New path, as described in the official documentation.
* @param flags Optional additional flags. * @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). * @brief Sync [symlink](http://linux.die.net/man/2/symlink).
@ -1020,7 +1020,7 @@ public:
* @param flags Flags, as described in the official documentation. * @param flags Flags, as described in the official documentation.
* @return True in case of success, false otherwise. * @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). * @brief Async [readlink](http://linux.die.net/man/2/readlink).

View File

@ -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, WATCH_ENTRY = UV_FS_EVENT_WATCH_ENTRY,
STAT = UV_FS_EVENT_STAT, STAT = UV_FS_EVENT_STAT,
RECURSIVE = UV_FS_EVENT_RECURSIVE, RECURSIVE = UV_FS_EVENT_RECURSIVE,
_UVW_ENUM = 0 UVW_ENUM = 0
}; };
enum class uvw_fs_event : std::underlying_type_t<uv_fs_event> { enum class uvw_fs_event : std::underlying_type_t<uv_fs_event> {
@ -96,7 +96,7 @@ public:
* @param flags Additional flags to control the behavior. * @param flags Additional flags to control the behavior.
* @return Underlying return value. * @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. * @brief Stops polling the file descriptor.

View File

@ -19,7 +19,7 @@ namespace details {
enum class uvw_chmod_flags : std::underlying_type_t<uv_poll_event> { enum class uvw_chmod_flags : std::underlying_type_t<uv_poll_event> {
READABLE = UV_READABLE, READABLE = UV_READABLE,
WRITABLE = UV_WRITABLE, WRITABLE = UV_WRITABLE,
_UVW_ENUM = 0 UVW_ENUM = 0
}; };
} }

View File

@ -18,7 +18,7 @@ enum class uvw_poll_event : std::underlying_type_t<uv_poll_event> {
WRITABLE = UV_WRITABLE, WRITABLE = UV_WRITABLE,
DISCONNECT = UV_DISCONNECT, DISCONNECT = UV_DISCONNECT,
PRIORITIZED = UV_PRIORITIZED, PRIORITIZED = UV_PRIORITIZED,
_UVW_ENUM = 0 UVW_ENUM = 0
}; };
} }

View File

@ -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_CONSOLE = UV_PROCESS_WINDOWS_HIDE_CONSOLE,
WINDOWS_HIDE_GUI = UV_PROCESS_WINDOWS_HIDE_GUI, WINDOWS_HIDE_GUI = UV_PROCESS_WINDOWS_HIDE_GUI,
WINDOWS_FILE_PATH_EXACT_NAME = UV_PROCESS_WINDOWS_FILE_PATH_EXACT_NAME, 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> { enum class uvw_stdio_flags : std::underlying_type_t<uv_stdio_flags> {
@ -37,7 +37,7 @@ enum class uvw_stdio_flags : std::underlying_type_t<uv_stdio_flags> {
READABLE_PIPE = UV_READABLE_PIPE, READABLE_PIPE = UV_READABLE_PIPE,
WRITABLE_PIPE = UV_WRITABLE_PIPE, WRITABLE_PIPE = UV_WRITABLE_PIPE,
OVERLAPPED_PIPE = UV_OVERLAPPED_PIPE, OVERLAPPED_PIPE = UV_OVERLAPPED_PIPE,
_UVW_ENUM = 0 UVW_ENUM = 0
}; };
} // namespace details } // namespace details

View File

@ -19,7 +19,7 @@ namespace details {
enum class uvw_tcp_flags : std::underlying_type_t<uv_tcp_flags> { enum class uvw_tcp_flags : std::underlying_type_t<uv_tcp_flags> {
IPV6ONLY = UV_TCP_IPV6ONLY, IPV6ONLY = UV_TCP_IPV6ONLY,
_UVW_ENUM = 0 UVW_ENUM = 0
}; };
} }
@ -115,7 +115,7 @@ public:
* @param opts Optional additional flags. * @param opts Optional additional flags.
* @return Underlying return value. * @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. * @brief Binds the handle to an address and port.
@ -133,7 +133,7 @@ public:
* @param opts Optional additional flags. * @param opts Optional additional flags.
* @return Underlying return value. * @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. * @brief Binds the handle to an address and port.
@ -150,7 +150,7 @@ public:
* @param opts Optional additional flags. * @param opts Optional additional flags.
* @return Underlying return value. * @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. * @brief Gets the current address to which the handle is bound.

View File

@ -38,7 +38,7 @@ enum class uvw_udp_flags : std::underlying_type_t<uv_udp_flags> {
UDP_MMSG_FREE = UV_UDP_MMSG_FREE, UDP_MMSG_FREE = UV_UDP_MMSG_FREE,
UDP_LINUX_RECVERR = UV_UDP_LINUX_RECVERR, UDP_LINUX_RECVERR = UV_UDP_LINUX_RECVERR,
UDP_RECVMMSG = UV_UDP_RECVMMSG, UDP_RECVMMSG = UV_UDP_RECVMMSG,
_UVW_ENUM = 0 UVW_ENUM = 0
}; };
enum class uvw_membership : std::underlying_type_t<uv_membership> { enum class uvw_membership : std::underlying_type_t<uv_membership> {
@ -193,7 +193,7 @@ public:
* @param opts Optional additional flags. * @param opts Optional additional flags.
* @return Underlying return value. * @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. * @brief Binds the UDP handle to an IP address and port.
@ -217,7 +217,7 @@ public:
* @param opts Optional additional flags. * @param opts Optional additional flags.
* @return Underlying return value. * @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. * @brief Binds the UDP handle to an IP address and port.
@ -240,7 +240,7 @@ public:
* @param opts Optional additional flags. * @param opts Optional additional flags.
* @return Underlying return value. * @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. * @brief Get the local IP and port of the UDP handle.