Convert all remaining enums to enum classes (!)

This commit is contained in:
Jérôme Leclercq
2021-05-25 00:08:50 +02:00
parent 8cdd0b51cb
commit 874fb3542e
122 changed files with 1082 additions and 2169 deletions

View File

@@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/AbstractHash.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Hash/CRC32.hpp>
#include <Nazara/Core/Hash/CRC64.hpp>
@@ -40,42 +41,42 @@ namespace Nz
std::unique_ptr<AbstractHash> AbstractHash::Get(HashType type)
{
NazaraAssert(type <= HashType_Max, "Hash type value out of enum");
NazaraAssert(type <= HashType::Max, "Hash type value out of enum");
switch (type)
{
case HashType_Fletcher16:
case HashType::Fletcher16:
return std::make_unique<HashFletcher16>();
case HashType_CRC32:
case HashType::CRC32:
return std::make_unique<HashCRC32>();
case HashType_CRC64:
case HashType::CRC64:
return std::make_unique<HashCRC64>();
case HashType_MD5:
case HashType::MD5:
return std::make_unique<HashMD5>();
case HashType_SHA1:
case HashType::SHA1:
return std::make_unique<HashSHA1>();
case HashType_SHA224:
case HashType::SHA224:
return std::make_unique<HashSHA224>();
case HashType_SHA256:
case HashType::SHA256:
return std::make_unique<HashSHA256>();
case HashType_SHA384:
case HashType::SHA384:
return std::make_unique<HashSHA384>();
case HashType_SHA512:
case HashType::SHA512:
return std::make_unique<HashSHA512>();
case HashType_Whirlpool:
case HashType::Whirlpool:
return std::make_unique<HashWhirlpool>();
}
NazaraInternalError("Hash type not handled (0x" + NumberToString(type, 16) + ')');
NazaraInternalError("Hash type not handled (0x" + NumberToString(UnderlyingCast(type), 16) + ')');
return nullptr;
}
}

View File

@@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/AbstractLogger.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <sstream>
#include <Nazara/Core/Debug.hpp>
@@ -11,13 +12,13 @@ namespace Nz
namespace
{
const char* errorType[] = {
"Assert failed: ", // ErrorType_AssertFailed
"Internal error: ", // ErrorType_Internal
"Error: ", // ErrorType_Normal
"Warning: " // ErrorType_Warning
"Assert failed: ", // ErrorType::AssertFailed
"Internal error: ", // ErrorType::Internal
"Error: ", // ErrorType::Normal
"Warning: " // ErrorType::Warning
};
static_assert(sizeof(errorType) / sizeof(const char*) == ErrorType_Max + 1, "Error type array is incomplete");
static_assert(sizeof(errorType) / sizeof(const char*) == ErrorTypeCount, "Error type array is incomplete");
}
/*!
@@ -27,7 +28,6 @@ namespace Nz
*
* \remark This class is abstract
*/
AbstractLogger::~AbstractLogger() = default;
/*!
@@ -39,11 +39,10 @@ namespace Nz
* \param file Filename
* \param function Name of the function throwing the error
*/
void AbstractLogger::WriteError(ErrorType type, const std::string_view& error, unsigned int line, const char* file, const char* function)
{
std::ostringstream ss;
ss << errorType[type] << error;
ss << errorType[UnderlyingCast(type)] << error;
if (line != 0 && file && function)
ss << " (" << file << ':' << line << ": " << function << ')';

View File

@@ -31,7 +31,7 @@ namespace Nz
* \return Flag
*/
UInt32 Error::GetFlags()
ErrorModeFlags Error::GetFlags()
{
return s_flags;
}
@@ -116,7 +116,7 @@ namespace Nz
* \param flags Flags for the error
*/
void Error::SetFlags(UInt32 flags)
void Error::SetFlags(ErrorModeFlags flags)
{
s_flags = flags;
}
@@ -133,7 +133,7 @@ namespace Nz
void Error::Trigger(ErrorType type, std::string error)
{
if (type == ErrorType_AssertFailed || (s_flags & ErrorFlag_Silent) == 0 || (s_flags & ErrorFlag_SilentDisabled) != 0)
if (type == ErrorType::AssertFailed || (s_flags & ErrorMode::Silent) == 0 || (s_flags & ErrorMode::SilentDisabled) != 0)
Log::WriteError(type, error);
s_lastError = std::move(error);
@@ -142,12 +142,12 @@ namespace Nz
s_lastErrorLine = 0;
#if NAZARA_CORE_EXIT_ON_ASSERT_FAILURE
if (type == ErrorType_AssertFailed)
if (type == ErrorType::AssertFailed)
std::abort();
#endif
if (type == ErrorType_AssertFailed || (type != ErrorType_Warning &&
(s_flags & ErrorFlag_ThrowException) != 0 && (s_flags & ErrorFlag_ThrowExceptionDisabled) == 0))
if (type == ErrorType::AssertFailed || (type != ErrorType::Warning &&
(s_flags & ErrorMode::ThrowException) != 0 && (s_flags & ErrorMode::ThrowExceptionDisabled) == 0))
throw std::runtime_error(s_lastError);
}
@@ -168,7 +168,7 @@ namespace Nz
{
file = GetCurrentFileRelativeToEngine(file);
if (type == ErrorType_AssertFailed || (s_flags & ErrorFlag_Silent) == 0 || (s_flags & ErrorFlag_SilentDisabled) != 0)
if (type == ErrorType::AssertFailed || (s_flags & ErrorMode::Silent) == 0 || (s_flags & ErrorMode::SilentDisabled) != 0)
Log::WriteError(type, error, line, file, function);
s_lastError = std::move(error);
@@ -177,12 +177,12 @@ namespace Nz
s_lastErrorLine = line;
#if NAZARA_CORE_EXIT_ON_ASSERT_FAILURE
if (type == ErrorType_AssertFailed)
if (type == ErrorType::AssertFailed)
std::abort();
#endif
if (type == ErrorType_AssertFailed || (type != ErrorType_Warning &&
(s_flags & ErrorFlag_ThrowException) != 0 && (s_flags & ErrorFlag_ThrowExceptionDisabled) == 0))
if (type == ErrorType::AssertFailed || (type != ErrorType::Warning &&
(s_flags & ErrorMode::ThrowException) != 0 && (s_flags & ErrorMode::ThrowExceptionDisabled) == 0))
throw std::runtime_error(s_lastError);
}
@@ -197,7 +197,7 @@ namespace Nz
return file;
}
UInt32 Error::s_flags = ErrorFlag_None;
ErrorModeFlags Error::s_flags = ErrorMode::None;
std::string Error::s_lastError;
const char* Error::s_lastErrorFunction = "";
const char* Error::s_lastErrorFile = "";

View File

@@ -21,7 +21,7 @@ namespace Nz
* \param replace Replace the entirely the old flag if true, else do a "OR"
*/
ErrorFlags::ErrorFlags(UInt32 flags, bool replace) :
ErrorFlags::ErrorFlags(ErrorModeFlags flags, bool replace) :
m_previousFlags(Error::GetFlags())
{
SetFlags(flags, replace);
@@ -40,8 +40,7 @@ namespace Nz
* \brief Gets the previous flag
* \return Previous flag
*/
UInt32 ErrorFlags::GetPreviousFlags() const
ErrorModeFlags ErrorFlags::GetPreviousFlags() const
{
return m_previousFlags;
}
@@ -52,8 +51,7 @@ namespace Nz
* \param flags Flags for the error
* \param replace Replace the entirely the old flag if true, else do a "OR"
*/
void ErrorFlags::SetFlags(UInt32 flags, bool replace)
void ErrorFlags::SetFlags(ErrorModeFlags flags, bool replace)
{
if (!replace)
flags |= m_previousFlags;

View File

@@ -91,7 +91,7 @@ namespace Nz
{
m_impl.reset();
m_openMode = OpenMode_NotOpen;
m_openMode = OpenMode::NotOpen;
}
}
@@ -226,13 +226,13 @@ namespace Nz
if (m_filePath.empty())
return false;
if (openMode == OpenMode_NotOpen)
if (openMode == OpenMode::NotOpen)
return false;
std::unique_ptr<FileImpl> impl = std::make_unique<FileImpl>(this);
if (!impl->Open(m_filePath, openMode))
{
ErrorFlags flags(ErrorFlag_Silent); // Silent by default
ErrorFlags flags(ErrorMode::Silent); // Silent by default
NazaraError("Failed to open \"" + m_filePath.generic_u8string() + "\": " + Error::GetLastSystemError());
return false;
}
@@ -240,10 +240,10 @@ namespace Nz
m_openMode = openMode;
m_impl = std::move(impl);
if (m_openMode & OpenMode_Text)
m_streamOptions |= StreamOption_Text;
if (m_openMode & OpenMode::Text)
m_streamOptions |= StreamOption::Text;
else
m_streamOptions &= ~StreamOption_Text;
m_streamOptions &= ~StreamOption::Text;
return true;
}
@@ -296,7 +296,7 @@ namespace Nz
{
NazaraAssert(IsOpen(), "File is not open");
return m_impl->SetCursorPos(CursorPosition_AtBegin, offset);
return m_impl->SetCursorPos(CursorPosition::AtBegin, offset);
}
/*!
@@ -383,7 +383,7 @@ namespace Nz
// If we don't have to read, we move forward
UInt64 currentPos = m_impl->GetCursorPos();
m_impl->SetCursorPos(CursorPosition_AtCurrent, size);
m_impl->SetCursorPos(CursorPosition::AtCurrent, size);
return static_cast<std::size_t>(m_impl->GetCursorPos() - currentPos);
}
@@ -429,7 +429,7 @@ namespace Nz
NazaraAssert(hash, "Invalid hash");
File file(originalFile.GetPath());
if (!file.Open(OpenMode_ReadOnly))
if (!file.Open(OpenMode::ReadOnly))
{
NazaraError("Unable to open file");
return false;

View File

@@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/HardwareInfo.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/Error.hpp>
#include <algorithm>
#include <cstring>
@@ -27,55 +28,53 @@ namespace Nz
ProcessorVendor vendorEnum;
};
// Exceptionellement, la valeur "unknown" est intégrée
const char* vendorNames[] =
const char* s_vendorNames[] =
{
"Unknown", // ProcessorVendor_Unknown
"Advanced Micro Devices", // ProcessorVendor_AMD
"Centaur Technology", // ProcessorVendor_Centaur
"Cyrix Corporation", // ProcessorVendor_Cyrix
"Intel Corporation", // ProcessorVendor_Intel
"Kernel-based Virtual Machine", // ProcessorVendor_KVM
"Microsoft Hyper-V", // ProcessorVendor_HyperV
"National Semiconductor", // ProcessorVendor_NSC
"NexGen", // ProcessorVendor_NexGen
"Rise Technology", // ProcessorVendor_Rise
"Silicon Integrated Systems", // ProcessorVendor_SIS
"Transmeta Corporation", // ProcessorVendor_Transmeta
"United Microelectronics Corporation", // ProcessorVendor_UMC
"VIA Technologies", // ProcessorVendor_VIA
"VMware", // ProcessorVendor_VMware
"Vortex86", // ProcessorVendor_Vortex
"Xen" // ProcessorVendor_XenHVM
"Advanced Micro Devices", // ProcessorVendor::AMD
"Centaur Technology", // ProcessorVendor::Centaur
"Cyrix Corporation", // ProcessorVendor::Cyrix
"Intel Corporation", // ProcessorVendor::Intel
"Kernel-based Virtual Machine", // ProcessorVendor::KVM
"Microsoft Hyper-V", // ProcessorVendor::HyperV
"National Semiconductor", // ProcessorVendor::NSC
"NexGen", // ProcessorVendor::NexGen
"Rise Technology", // ProcessorVendor::Rise
"Silicon Integrated Systems", // ProcessorVendor::SIS
"Transmeta Corporation", // ProcessorVendor::Transmeta
"United Microelectronics Corporation", // ProcessorVendor::UMC
"VIA Technologies", // ProcessorVendor::VIA
"VMware", // ProcessorVendor::VMware
"Vortex86", // ProcessorVendor::Vortex
"Xen" // ProcessorVendor::XenHVM
};
static_assert(sizeof(vendorNames)/sizeof(const char*) == ProcessorVendor_Max+2, "Processor vendor name array is incomplete");
static_assert(sizeof(s_vendorNames)/sizeof(const char*) == ProcessorVendorCount, "Processor vendor name array is incomplete");
VendorString vendorStrings[] =
{
// Triés par ordre alphabétique (Majuscules primant sur minuscules)
{"AMDisbetter!", ProcessorVendor_AMD},
{"AuthenticAMD", ProcessorVendor_AMD},
{"CentaurHauls", ProcessorVendor_Centaur},
{"CyrixInstead", ProcessorVendor_Cyrix},
{"GenuineIntel", ProcessorVendor_Intel},
{"GenuineTMx86", ProcessorVendor_Transmeta},
{"Geode by NSC", ProcessorVendor_NSC},
{"KVMKVMKVMKVM", ProcessorVendor_KVM},
{"Microsoft Hv", ProcessorVendor_HyperV},
{"NexGenDriven", ProcessorVendor_NexGen},
{"RiseRiseRise", ProcessorVendor_Rise},
{"SiS SiS SiS ", ProcessorVendor_SIS},
{"TransmetaCPU", ProcessorVendor_Transmeta},
{"UMC UMC UMC ", ProcessorVendor_UMC},
{"VIA VIA VIA ", ProcessorVendor_VIA},
{"VMwareVMware", ProcessorVendor_VMware},
{"Vortex86 SoC", ProcessorVendor_Vortex},
{"XenVMMXenVMM", ProcessorVendor_XenHVM}
{"AMDisbetter!", ProcessorVendor::AMD},
{"AuthenticAMD", ProcessorVendor::AMD},
{"CentaurHauls", ProcessorVendor::Centaur},
{"CyrixInstead", ProcessorVendor::Cyrix},
{"GenuineIntel", ProcessorVendor::Intel},
{"GenuineTMx86", ProcessorVendor::Transmeta},
{"Geode by NSC", ProcessorVendor::NSC},
{"KVMKVMKVMKVM", ProcessorVendor::KVM},
{"Microsoft Hv", ProcessorVendor::HyperV},
{"NexGenDriven", ProcessorVendor::NexGen},
{"RiseRiseRise", ProcessorVendor::Rise},
{"SiS SiS SiS ", ProcessorVendor::SIS},
{"TransmetaCPU", ProcessorVendor::Transmeta},
{"UMC UMC UMC ", ProcessorVendor::UMC},
{"VIA VIA VIA ", ProcessorVendor::VIA},
{"VMwareVMware", ProcessorVendor::VMware},
{"Vortex86 SoC", ProcessorVendor::Vortex},
{"XenVMMXenVMM", ProcessorVendor::XenHVM}
};
ProcessorVendor s_vendorEnum = ProcessorVendor_Unknown;
bool s_capabilities[ProcessorCap_Max+1] = {false};
ProcessorVendor s_vendorEnum = ProcessorVendor::Unknown;
bool s_capabilities[ProcessorCapCount] = {false};
bool s_initialized = false;
char s_brandString[48] = "Not initialized";
@@ -155,7 +154,7 @@ namespace Nz
if (!Initialize())
NazaraError("Failed to initialize HardwareInfo");
return vendorNames[s_vendorEnum+1];
return s_vendorNames[UnderlyingCast(s_vendorEnum)];
}
/*!
@@ -180,15 +179,7 @@ namespace Nz
bool HardwareInfo::HasCapability(ProcessorCap capability)
{
#ifdef NAZARA_DEBUG
if (capability > ProcessorCap_Max)
{
NazaraError("Capability type out of enum");
return false;
}
#endif
return s_capabilities[capability];
return s_capabilities[UnderlyingCast(capability)];
}
/*!
@@ -226,7 +217,7 @@ namespace Nz
UInt32 manufacturerId[3] = {ebx, edx, ecx};
// Identification of conceptor
s_vendorEnum = ProcessorVendor_Unknown;
s_vendorEnum = ProcessorVendor::Unknown;
for (const VendorString& vendorString : vendorStrings)
{
if (std::memcmp(manufacturerId, vendorString.vendor, 12) == 0)
@@ -238,18 +229,18 @@ namespace Nz
if (eax >= 1)
{
// Retrieval of certain capacities of the processor (ECX et EDX, function 1)
// Retrieval of certain capacities of the processor (ECX and EDX, function 1)
HardwareInfoImpl::Cpuid(1, 0, registers);
s_capabilities[ProcessorCap_AVX] = (ecx & (1U << 28)) != 0;
s_capabilities[ProcessorCap_FMA3] = (ecx & (1U << 12)) != 0;
s_capabilities[ProcessorCap_MMX] = (edx & (1U << 23)) != 0;
s_capabilities[ProcessorCap_SSE] = (edx & (1U << 25)) != 0;
s_capabilities[ProcessorCap_SSE2] = (edx & (1U << 26)) != 0;
s_capabilities[ProcessorCap_SSE3] = (ecx & (1U << 0)) != 0;
s_capabilities[ProcessorCap_SSSE3] = (ecx & (1U << 9)) != 0;
s_capabilities[ProcessorCap_SSE41] = (ecx & (1U << 19)) != 0;
s_capabilities[ProcessorCap_SSE42] = (ecx & (1U << 20)) != 0;
s_capabilities[UnderlyingCast(ProcessorCap::AVX)] = (ecx & (1U << 28)) != 0;
s_capabilities[UnderlyingCast(ProcessorCap::FMA3)] = (ecx & (1U << 12)) != 0;
s_capabilities[UnderlyingCast(ProcessorCap::MMX)] = (edx & (1U << 23)) != 0;
s_capabilities[UnderlyingCast(ProcessorCap::SSE)] = (edx & (1U << 25)) != 0;
s_capabilities[UnderlyingCast(ProcessorCap::SSE2)] = (edx & (1U << 26)) != 0;
s_capabilities[UnderlyingCast(ProcessorCap::SSE3)] = (ecx & (1U << 0)) != 0;
s_capabilities[UnderlyingCast(ProcessorCap::SSSE3)] = (ecx & (1U << 9)) != 0;
s_capabilities[UnderlyingCast(ProcessorCap::SSE41)] = (ecx & (1U << 19)) != 0;
s_capabilities[UnderlyingCast(ProcessorCap::SSE42)] = (ecx & (1U << 20)) != 0;
}
// Retrieval of biggest extended function handled (EAX, function 0x80000000)
@@ -261,10 +252,10 @@ namespace Nz
// Retrieval of extended capabilities of the processor (ECX and EDX, function 0x80000001)
HardwareInfoImpl::Cpuid(0x80000001, 0, registers);
s_capabilities[ProcessorCap_x64] = (edx & (1U << 29)) != 0; // Support of 64bits, independent of the OS
s_capabilities[ProcessorCap_FMA4] = (ecx & (1U << 16)) != 0;
s_capabilities[ProcessorCap_SSE4a] = (ecx & (1U << 6)) != 0;
s_capabilities[ProcessorCap_XOP] = (ecx & (1U << 11)) != 0;
s_capabilities[UnderlyingCast(ProcessorCap::x64)] = (edx & (1U << 29)) != 0; // Support of 64bits, independent of the OS
s_capabilities[UnderlyingCast(ProcessorCap::FMA4)] = (ecx & (1U << 16)) != 0;
s_capabilities[UnderlyingCast(ProcessorCap::SSE4a)] = (ecx & (1U << 6)) != 0;
s_capabilities[UnderlyingCast(ProcessorCap::XOP)] = (ecx & (1U << 11)) != 0;
if (maxSupportedExtendedFunction >= 0x80000004)
{

View File

@@ -25,7 +25,7 @@ namespace Nz
*/
MemoryView::MemoryView(void* ptr, UInt64 size) :
Stream(StreamOption_None, OpenMode_ReadWrite),
Stream(StreamOption::None, OpenMode_ReadWrite),
m_ptr(static_cast<UInt8*>(ptr)),
m_pos(0),
m_size(size)
@@ -42,7 +42,7 @@ namespace Nz
*/
MemoryView::MemoryView(const void* ptr, UInt64 size) :
Stream(StreamOption_None, OpenMode_ReadOnly),
Stream(StreamOption::None, OpenMode::ReadOnly),
m_ptr(static_cast<UInt8*>(const_cast<void*>(ptr))), //< Okay, right, const_cast is bad, but this pointer is still read-only
m_pos(0),
m_size(size)

View File

@@ -62,7 +62,7 @@ namespace Nz
{
NazaraAssert(value, "Invalid pointer");
ErrorFlags flags(ErrorFlag_Silent | ErrorFlag_ThrowExceptionDisabled);
ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowExceptionDisabled);
auto it = m_parameters.find(name);
if (it == m_parameters.end())
@@ -73,15 +73,15 @@ namespace Nz
switch (it->second.type)
{
case ParameterType_Boolean:
case ParameterType::Boolean:
*value = it->second.value.boolVal;
return true;
case ParameterType_Integer:
case ParameterType::Integer:
*value = (it->second.value.intVal != 0);
return true;
case ParameterType_String:
case ParameterType::String:
{
if (it->second.value.stringVal == "1" || it->second.value.stringVal == "yes" || it->second.value.stringVal == "true")
{
@@ -97,11 +97,11 @@ namespace Nz
break;
}
case ParameterType_Color:
case ParameterType_Double:
case ParameterType_None:
case ParameterType_Pointer:
case ParameterType_Userdata:
case ParameterType::Color:
case ParameterType::Double:
case ParameterType::None:
case ParameterType::Pointer:
case ParameterType::Userdata:
break;
}
@@ -124,7 +124,7 @@ namespace Nz
{
NazaraAssert(value, "Invalid pointer");
ErrorFlags flags(ErrorFlag_Silent | ErrorFlag_ThrowExceptionDisabled);
ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowExceptionDisabled);
auto it = m_parameters.find(name);
if (it == m_parameters.end())
@@ -135,17 +135,17 @@ namespace Nz
switch (it->second.type)
{
case ParameterType_Color:
case ParameterType::Color:
*value = it->second.value.colorVal;
return true;
case ParameterType_Boolean:
case ParameterType_Double:
case ParameterType_Integer:
case ParameterType_String:
case ParameterType_None:
case ParameterType_Pointer:
case ParameterType_Userdata:
case ParameterType::Boolean:
case ParameterType::Double:
case ParameterType::Integer:
case ParameterType::String:
case ParameterType::None:
case ParameterType::Pointer:
case ParameterType::Userdata:
break;
}
@@ -170,7 +170,7 @@ namespace Nz
{
NazaraAssert(value, "Invalid pointer");
ErrorFlags flags(ErrorFlag_Silent | ErrorFlag_ThrowExceptionDisabled);
ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowExceptionDisabled);
auto it = m_parameters.find(name);
if (it == m_parameters.end())
@@ -181,15 +181,15 @@ namespace Nz
switch (it->second.type)
{
case ParameterType_Double:
case ParameterType::Double:
*value = it->second.value.doubleVal;
return true;
case ParameterType_Integer:
case ParameterType::Integer:
*value = static_cast<double>(it->second.value.intVal);
return true;
case ParameterType_String:
case ParameterType::String:
{
const std::string& str = it->second.value.stringVal;
@@ -206,11 +206,11 @@ namespace Nz
return true;
}
case ParameterType_Boolean:
case ParameterType_Color:
case ParameterType_None:
case ParameterType_Pointer:
case ParameterType_Userdata:
case ParameterType::Boolean:
case ParameterType::Color:
case ParameterType::None:
case ParameterType::Pointer:
case ParameterType::Userdata:
break;
}
@@ -236,7 +236,7 @@ namespace Nz
{
NazaraAssert(value, "Invalid pointer");
ErrorFlags flags(ErrorFlag_Silent | ErrorFlag_ThrowExceptionDisabled);
ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowExceptionDisabled);
auto it = m_parameters.find(name);
if (it == m_parameters.end())
@@ -247,19 +247,19 @@ namespace Nz
switch (it->second.type)
{
case ParameterType_Boolean:
case ParameterType::Boolean:
*value = (it->second.value.boolVal) ? 1 : 0;
return true;
case ParameterType_Double:
case ParameterType::Double:
*value = static_cast<long long>(it->second.value.doubleVal);
return true;
case ParameterType_Integer:
case ParameterType::Integer:
*value = it->second.value.intVal;
return true;
case ParameterType_String:
case ParameterType::String:
{
const std::string& str = it->second.value.stringVal;
@@ -276,10 +276,10 @@ namespace Nz
return true;
}
case ParameterType_Color:
case ParameterType_None:
case ParameterType_Pointer:
case ParameterType_Userdata:
case ParameterType::Color:
case ParameterType::None:
case ParameterType::Pointer:
case ParameterType::Userdata:
break;
}
@@ -325,7 +325,7 @@ namespace Nz
{
NazaraAssert(value, "Invalid pointer");
ErrorFlags flags(ErrorFlag_Silent | ErrorFlag_ThrowExceptionDisabled);
ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowExceptionDisabled);
auto it = m_parameters.find(name);
if (it == m_parameters.end())
@@ -336,20 +336,20 @@ namespace Nz
switch (it->second.type)
{
case ParameterType_Pointer:
case ParameterType::Pointer:
*value = it->second.value.ptrVal;
return true;
case ParameterType_Userdata:
case ParameterType::Userdata:
*value = it->second.value.userdataVal->ptr;
return true;
case ParameterType_Boolean:
case ParameterType_Color:
case ParameterType_Double:
case ParameterType_Integer:
case ParameterType_None:
case ParameterType_String:
case ParameterType::Boolean:
case ParameterType::Color:
case ParameterType::Double:
case ParameterType::Integer:
case ParameterType::None:
case ParameterType::String:
break;
}
@@ -379,7 +379,7 @@ namespace Nz
{
NazaraAssert(value, "Invalid pointer");
ErrorFlags flags(ErrorFlag_Silent | ErrorFlag_ThrowExceptionDisabled);
ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowExceptionDisabled);
auto it = m_parameters.find(name);
if (it == m_parameters.end())
@@ -390,35 +390,35 @@ namespace Nz
switch (it->second.type)
{
case ParameterType_Boolean:
case ParameterType::Boolean:
*value = (it->second.value.boolVal) ? "true" : "false";
return true;
case ParameterType_Color:
case ParameterType::Color:
*value = it->second.value.colorVal.ToString();
return true;
case ParameterType_Double:
case ParameterType::Double:
*value = std::to_string(it->second.value.doubleVal);
return true;
case ParameterType_Integer:
case ParameterType::Integer:
*value = std::to_string(it->second.value.intVal);
return true;
case ParameterType_String:
case ParameterType::String:
*value = it->second.value.stringVal;
return true;
case ParameterType_Pointer:
case ParameterType::Pointer:
*value = PointerToString(it->second.value.ptrVal);
return true;
case ParameterType_Userdata:
case ParameterType::Userdata:
*value = PointerToString(it->second.value.userdataVal->ptr);
return true;
case ParameterType_None:
case ParameterType::None:
*value = std::string();
return true;
}
@@ -444,7 +444,7 @@ namespace Nz
{
NazaraAssert(value, "Invalid pointer");
ErrorFlags flags(ErrorFlag_Silent | ErrorFlag_ThrowExceptionDisabled);
ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowExceptionDisabled);
auto it = m_parameters.find(name);
if (it == m_parameters.end())
@@ -455,7 +455,7 @@ namespace Nz
const auto& parameter = it->second;
if (parameter.type == ParameterType_Userdata)
if (parameter.type == ParameterType::Userdata)
{
*value = parameter.value.userdataVal->ptr;
return true;
@@ -506,7 +506,7 @@ namespace Nz
void ParameterList::SetParameter(const std::string& name)
{
Parameter& parameter = CreateValue(name);
parameter.type = ParameterType_None;
parameter.type = ParameterType::None;
}
/*!
@@ -520,7 +520,7 @@ namespace Nz
void ParameterList::SetParameter(const std::string& name, const Color& value)
{
Parameter& parameter = CreateValue(name);
parameter.type = ParameterType_Color;
parameter.type = ParameterType::Color;
PlacementNew(&parameter.value.colorVal, value);
}
@@ -536,7 +536,7 @@ namespace Nz
void ParameterList::SetParameter(const std::string& name, const std::string& value)
{
Parameter& parameter = CreateValue(name);
parameter.type = ParameterType_String;
parameter.type = ParameterType::String;
PlacementNew(&parameter.value.stringVal, value);
}
@@ -552,7 +552,7 @@ namespace Nz
void ParameterList::SetParameter(const std::string& name, const char* value)
{
Parameter& parameter = CreateValue(name);
parameter.type = ParameterType_String;
parameter.type = ParameterType::String;
PlacementNew(&parameter.value.stringVal, value);
}
@@ -568,7 +568,7 @@ namespace Nz
void ParameterList::SetParameter(const std::string& name, bool value)
{
Parameter& parameter = CreateValue(name);
parameter.type = ParameterType_Boolean;
parameter.type = ParameterType::Boolean;
parameter.value.boolVal = value;
}
@@ -583,7 +583,7 @@ namespace Nz
void ParameterList::SetParameter(const std::string& name, double value)
{
Parameter& parameter = CreateValue(name);
parameter.type = ParameterType_Double;
parameter.type = ParameterType::Double;
parameter.value.doubleVal = value;
}
@@ -598,7 +598,7 @@ namespace Nz
void ParameterList::SetParameter(const std::string& name, long long value)
{
Parameter& parameter = CreateValue(name);
parameter.type = ParameterType_Integer;
parameter.type = ParameterType::Integer;
parameter.value.intVal = value;
}
@@ -616,7 +616,7 @@ namespace Nz
void ParameterList::SetParameter(const std::string& name, void* value)
{
Parameter& parameter = CreateValue(name);
parameter.type = ParameterType_Pointer;
parameter.type = ParameterType::Pointer;
parameter.value.ptrVal = value;
}
@@ -637,28 +637,28 @@ namespace Nz
ss << it->first << ": ";
switch (it->second.type)
{
case ParameterType_Boolean:
case ParameterType::Boolean:
ss << "Boolean(" << parameter.value.boolVal << ")";
break;
case ParameterType_Color:
case ParameterType::Color:
ss << "Color(" << parameter.value.colorVal << ")";
break;
case ParameterType_Double:
case ParameterType::Double:
ss << "Double(" << parameter.value.doubleVal << ")";
break;
case ParameterType_Integer:
case ParameterType::Integer:
ss << "Integer(" << parameter.value.intVal << ")";
break;
case ParameterType_String:
case ParameterType::String:
ss << "std::string(" << parameter.value.stringVal << ")";
break;
case ParameterType_Pointer:
case ParameterType::Pointer:
ss << "Pointer(" << parameter.value.ptrVal << ")";
break;
case ParameterType_Userdata:
case ParameterType::Userdata:
ss << "Userdata(" << parameter.value.userdataVal->ptr << ")";
break;
case ParameterType_None:
case ParameterType::None:
ss << "None";
break;
}
@@ -686,7 +686,7 @@ namespace Nz
void ParameterList::SetParameter(const std::string& name, void* value, Destructor destructor)
{
Parameter& parameter = CreateValue(name);
parameter.type = ParameterType_Userdata;
parameter.type = ParameterType::Userdata;
parameter.value.userdataVal = new Parameter::UserdataValue(destructor, value);
}
@@ -706,28 +706,28 @@ namespace Nz
switch (it->second.type)
{
case ParameterType_Boolean:
case ParameterType_Color:
case ParameterType_Double:
case ParameterType_Integer:
case ParameterType_Pointer:
case ParameterType::Boolean:
case ParameterType::Color:
case ParameterType::Double:
case ParameterType::Integer:
case ParameterType::Pointer:
std::memcpy(&parameter, &it->second, sizeof(Parameter));
break;
case ParameterType_String:
parameter.type = ParameterType_String;
case ParameterType::String:
parameter.type = ParameterType::String;
PlacementNew(&parameter.value.stringVal, it->second.value.stringVal);
break;
case ParameterType_Userdata:
parameter.type = ParameterType_Userdata;
case ParameterType::Userdata:
parameter.type = ParameterType::Userdata;
parameter.value.userdataVal = it->second.value.userdataVal;
++(parameter.value.userdataVal->counter);
break;
case ParameterType_None:
parameter.type = ParameterType_None;
case ParameterType::None:
parameter.type = ParameterType::None;
break;
}
}
@@ -762,11 +762,11 @@ namespace Nz
{
switch (parameter.type)
{
case ParameterType_String:
case ParameterType::String:
PlacementDestroy(&parameter.value.stringVal);
break;
case ParameterType_Userdata:
case ParameterType::Userdata:
{
Parameter::UserdataValue* userdata = parameter.value.userdataVal;
if (--userdata->counter == 0)
@@ -777,12 +777,12 @@ namespace Nz
break;
}
case ParameterType_Boolean:
case ParameterType_Color:
case ParameterType_Double:
case ParameterType_Integer:
case ParameterType_None:
case ParameterType_Pointer:
case ParameterType::Boolean:
case ParameterType::Color:
case ParameterType::Double:
case ParameterType::Integer:
case ParameterType::None:
case ParameterType::Pointer:
break;
}
}

View File

@@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/PluginManager.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/DynLib.hpp>
#include <Nazara/Core/Error.hpp>
#include <memory>
@@ -15,9 +16,9 @@ namespace Nz
using PluginLoad = int (*)();
using PluginUnload = void (*)();
std::filesystem::path s_pluginFiles[] =
const char* s_pluginFiles[] =
{
"PluginAssimp", // Plugin_Assimp
"PluginAssimp", // Plugin::Assimp
};
}
@@ -77,7 +78,7 @@ namespace Nz
bool PluginManager::Mount(Plugin plugin)
{
std::filesystem::path pluginName = s_pluginFiles[plugin];
std::filesystem::path pluginName = s_pluginFiles[UnderlyingCast(plugin)];
#ifdef NAZARA_DEBUG
std::filesystem::path debugPath = pluginName;
@@ -195,7 +196,7 @@ namespace Nz
void PluginManager::Unmount(Plugin plugin)
{
Unmount(s_pluginFiles[plugin]);
Unmount(s_pluginFiles[UnderlyingCast(plugin)]);
}
/*!

View File

@@ -3,11 +3,12 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Posix/FileImpl.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/stat.h>
#include <cstdio>
#include <Nazara/Core/Debug.hpp>
@@ -61,20 +62,20 @@ namespace Nz
if ((mode & OpenMode_ReadWrite) == OpenMode_ReadWrite)
flags = O_CREAT | O_RDWR;
else if ((mode & OpenMode_ReadOnly) == OpenMode_ReadOnly)
else if ((mode & OpenMode::ReadOnly) == OpenMode::ReadOnly)
flags = O_RDONLY;
else if ((mode & OpenMode_WriteOnly) == OpenMode_WriteOnly)
else if ((mode & OpenMode::WriteOnly) == OpenMode::WriteOnly)
flags = O_CREAT | O_WRONLY;
else
return false;
if (mode & OpenMode_Append)
if (mode & OpenMode::Append)
flags |= O_APPEND;
if (mode & OpenMode_MustExist)
if (mode & OpenMode::MustExist)
flags &= ~O_CREAT;
if (mode & OpenMode_Truncate)
if (mode & OpenMode::Truncate)
flags |= O_TRUNC;
int fileDescriptor = Open_def(filePath.generic_u8string().data(), flags, permissions);
@@ -111,7 +112,7 @@ namespace Nz
return false;
}
if (mode & OpenMode_Lock)
if (mode & OpenMode::Lock)
{
initialize_flock(lock);
@@ -147,20 +148,20 @@ namespace Nz
int moveMethod;
switch (pos)
{
case CursorPosition_AtBegin:
case CursorPosition::AtBegin:
moveMethod = SEEK_SET;
break;
case CursorPosition_AtCurrent:
case CursorPosition::AtCurrent:
moveMethod = SEEK_CUR;
break;
case CursorPosition_AtEnd:
case CursorPosition::AtEnd:
moveMethod = SEEK_END;
break;
default:
NazaraInternalError("Cursor position not handled (0x" + NumberToString(pos, 16) + ')');
NazaraInternalError("Cursor position not handled (0x" + NumberToString(UnderlyingCast(pos), 16) + ')');
return false;
}

View File

@@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/StdLogger.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <cstdio>
#include <Nazara/Core/Debug.hpp>
@@ -11,13 +12,13 @@ namespace Nz
namespace
{
const char* errorType[] = {
"Assert failed", // ErrorType_AssertFailed
"Internal error", // ErrorType_Internal
"Error", // ErrorType_Normal
"Warning" // ErrorType_Warning
"Assert failed", // ErrorType::AssertFailed
"Internal error", // ErrorType::Internal
"Error", // ErrorType::Normal
"Warning" // ErrorType::Warning
};
static_assert(sizeof(errorType) / sizeof(const char*) == ErrorType_Max + 1, "Error type array is incomplete");
static_assert(sizeof(errorType) / sizeof(const char*) == ErrorTypeCount, "Error type array is incomplete");
}
/*!
@@ -80,7 +81,7 @@ namespace Nz
void StdLogger::WriteError(ErrorType type, const std::string_view& error, unsigned int line, const char* file, const char* function)
{
fprintf(stderr, "%s: ", errorType[type]);
fprintf(stderr, "%s: ", errorType[UnderlyingCast(type)]);
fwrite(error.data(), sizeof(char), error.size(), stdout);
if (line != 0 && file && function)

View File

@@ -78,7 +78,7 @@ namespace Nz
std::ptrdiff_t pos = ptr - buffer;
if (ptr != buffer)
{
if (m_streamOptions & StreamOption_Text && buffer[pos - 1] == '\r')
if (m_streamOptions & StreamOption::Text && buffer[pos - 1] == '\r')
line.append(buffer, pos - 1);
else
line.append(buffer, pos);
@@ -92,7 +92,7 @@ namespace Nz
else
{
std::size_t length = readSize;
if (m_streamOptions & StreamOption_Text && buffer[length - 1] == '\r')
if (m_streamOptions & StreamOption::Text && buffer[length - 1] == '\r')
{
if (!SetCursorPos(GetCursorPos() - 1))
NazaraWarning("Failed to reset cursor pos");
@@ -112,7 +112,7 @@ namespace Nz
std::size_t pos = line.find('\n');
if (pos <= readSize) // False only if the character is not available (npos being the biggest integer)
{
if (m_streamOptions & StreamOption_Text && pos > 0 && line[pos - 1] == '\r')
if (m_streamOptions & StreamOption::Text && pos > 0 && line[pos - 1] == '\r')
line.resize(pos);
else
line.resize(pos + 1);
@@ -149,7 +149,7 @@ namespace Nz
bool Stream::Write(const std::string_view& string)
{
if (m_streamOptions & StreamOption_Text)
if (m_streamOptions & StreamOption::Text)
{
#if defined(NAZARA_PLATFORM_WINDOWS)
std::string temp(string);

View File

@@ -63,30 +63,30 @@ namespace Nz
DWORD shareMode = FILE_SHARE_READ;
DWORD openMode = 0;
if (mode & OpenMode_ReadOnly)
if (mode & OpenMode::ReadOnly)
{
access |= GENERIC_READ;
if (mode & OpenMode_MustExist || (mode & OpenMode_WriteOnly) == 0)
if (mode & OpenMode::MustExist || (mode & OpenMode::WriteOnly) == 0)
openMode |= OPEN_EXISTING;
}
if (mode & OpenMode_WriteOnly)
if (mode & OpenMode::WriteOnly)
{
if (mode & OpenMode_Append)
if (mode & OpenMode::Append)
access |= FILE_APPEND_DATA;
else
access |= GENERIC_WRITE;
if (mode & OpenMode_Truncate)
if (mode & OpenMode::Truncate)
openMode |= CREATE_ALWAYS;
else if (mode & OpenMode_MustExist)
else if (mode & OpenMode::MustExist)
openMode |= OPEN_EXISTING;
else
openMode |= OPEN_ALWAYS;
}
if ((mode & OpenMode_Lock) == 0)
if ((mode & OpenMode::Lock) == 0)
shareMode |= FILE_SHARE_WRITE;
m_handle = CreateFileW(ToWideString(filePath.generic_u8string()).data(), access, shareMode, nullptr, openMode, 0, nullptr);
@@ -136,20 +136,20 @@ namespace Nz
DWORD moveMethod;
switch (pos)
{
case CursorPosition_AtBegin:
case CursorPosition::AtBegin:
moveMethod = FILE_BEGIN;
break;
case CursorPosition_AtCurrent:
case CursorPosition::AtCurrent:
moveMethod = FILE_CURRENT;
break;
case CursorPosition_AtEnd:
case CursorPosition::AtEnd:
moveMethod = FILE_END;
break;
default:
NazaraInternalError("Cursor position not handled (0x" + NumberToString(pos, 16) + ')');
NazaraInternalError("Cursor position not handled (0x" + NumberToString(UnderlyingCast(pos), 16) + ')');
return false;
}
@@ -167,11 +167,11 @@ namespace Nz
CallOnExit resetCursor([this, cursorPos] ()
{
if (!SetCursorPos(CursorPosition_AtBegin, cursorPos))
if (!SetCursorPos(CursorPosition::AtBegin, cursorPos))
NazaraWarning("Failed to reset cursor position to previous position: " + Error::GetLastSystemError());
});
if (!SetCursorPos(CursorPosition_AtBegin, size))
if (!SetCursorPos(CursorPosition::AtBegin, size))
{
NazaraError("Failed to set file size: failed to move cursor position: " + Error::GetLastSystemError());
return false;