Make use of the new EnumMap class

This commit is contained in:
SirLynix
2023-05-30 12:32:37 +02:00
parent d914f41404
commit dfe6b2ddcf
46 changed files with 354 additions and 379 deletions

View File

@@ -9,6 +9,7 @@
#include <Nazara/Network/Algorithm.hpp>
#include <Nazara/Network/NetBuffer.hpp>
#include <Nazara/Network/Posix/IpAddressImpl.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <NazaraUtils/StackArray.hpp>
#include <cstring>
#include <poll.h>
@@ -1016,31 +1017,29 @@ namespace Nz
int SocketImpl::TranslateNetProtocolToAF(NetProtocol protocol)
{
NazaraAssert(protocol <= NetProtocol::Max, "Protocol has value out of enum");
static int addressFamily[] = {
constexpr EnumMap<NetProtocol, int> addressFamily {
AF_UNSPEC, //< NetProtocol::Any
AF_INET, //< NetProtocol::IPv4
AF_INET6, //< NetProtocol::IPv6
-1 //< NetProtocol::Unknown
};
static_assert(sizeof(addressFamily) / sizeof(int) == NetProtocolCount, "Address family array is incomplete");
return addressFamily[UnderlyingCast(protocol)];
return addressFamily[protocol];
}
int SocketImpl::TranslateSocketTypeToSock(SocketType type)
{
NazaraAssert(type <= SocketType::Max, "Socket type has value out of enum");
static int socketType[] = {
constexpr EnumMap<SocketType, int> socketType {
SOCK_RAW, //< SocketType::Raw
SOCK_STREAM, //< SocketType::TCP
SOCK_DGRAM, //< SocketType::UDP
-1 //< SocketType::Unknown
};
static_assert(sizeof(socketType) / sizeof(int) == SocketTypeCount, "Socket type array is incomplete");
return socketType[UnderlyingCast(type)];
return socketType[type];
}
void SocketImpl::Uninitialize()

View File

@@ -8,6 +8,7 @@
#include <Nazara/Core/Log.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <Nazara/Network/Win32/IpAddressImpl.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <NazaraUtils/StackArray.hpp>
// Some compilers (older versions of MinGW) lack Mstcpip.h which defines some structs/defines
@@ -999,30 +1000,28 @@ namespace Nz
{
NazaraAssert(protocol <= NetProtocol::Max, "Protocol has value out of enum");
static int addressFamily[] = {
constexpr EnumMap<NetProtocol, int> addressFamily {
AF_UNSPEC, //< NetProtocol::Any
AF_INET, //< NetProtocol::IPv4
AF_INET6, //< NetProtocol::IPv6
-1 //< NetProtocol::Unknown
};
static_assert(sizeof(addressFamily) / sizeof(int) == NetProtocolCount, "Address family array is incomplete");
return addressFamily[UnderlyingCast(protocol)];
return addressFamily[protocol];
}
int SocketImpl::TranslateSocketTypeToSock(SocketType type)
{
NazaraAssert(type <= SocketType::Max, "Socket type has value out of enum");
static int socketType[] = {
constexpr EnumMap<SocketType, int> socketType {
SOCK_RAW, //< SocketType::Raw
SOCK_STREAM, //< SocketType::TCP
SOCK_DGRAM, //< SocketType::UDP
-1 //< SocketType::Unknown
};
static_assert(sizeof(socketType) / sizeof(int) == SocketTypeCount, "Socket type array is incomplete");
return socketType[UnderlyingCast(type)];
return socketType[type];
}
void SocketImpl::Uninitialize()