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

@@ -368,7 +368,7 @@ namespace Nz
// Flush bits in case a writing is in progress
context.FlushBits();
if (context.endianness != Endianness_Unknown && context.endianness != GetPlatformEndianness())
if (context.endianness != Endianness::Unknown && context.endianness != GetPlatformEndianness())
SwapBytes(&value, sizeof(T));
return context.stream->Write(&value, sizeof(T)) == sizeof(T);
@@ -447,7 +447,7 @@ namespace Nz
if (context.stream->Read(value, sizeof(T)) == sizeof(T))
{
if (context.endianness != Endianness_Unknown && context.endianness != GetPlatformEndianness())
if (context.endianness != Endianness::Unknown && context.endianness != GetPlatformEndianness())
SwapBytes(value, sizeof(T));
return true;

View File

@@ -15,9 +15,9 @@ namespace Nz
inline constexpr Endianness GetPlatformEndianness()
{
#if defined(NAZARA_BIG_ENDIAN)
return Endianness_BigEndian;
return Endianness::BigEndian;
#elif defined(NAZARA_LITTLE_ENDIAN)
return Endianness_LittleEndian;
return Endianness::LittleEndian;
#endif
}

View File

@@ -11,193 +11,213 @@
namespace Nz
{
enum CoordSys
enum class CoordSys
{
CoordSys_Global,
CoordSys_Local,
Global,
Local,
CoordSys_Max = CoordSys_Local
Max = Local
};
enum CursorPosition
enum class CursorPosition
{
CursorPosition_AtBegin, // beginning of the file
CursorPosition_AtCurrent, // Position of the cursor
CursorPosition_AtEnd, // End of the file
AtBegin, // beginning of the file
AtCurrent, // Position of the cursor
AtEnd, // End of the file
CursorPosition_Max = CursorPosition_AtEnd
Max = AtEnd
};
enum Endianness
enum class Endianness
{
Endianness_Unknown = -1,
Unknown = -1,
Endianness_BigEndian,
Endianness_LittleEndian,
BigEndian,
LittleEndian,
Endianness_Max = Endianness_LittleEndian
Max = LittleEndian
};
enum ErrorFlag
enum class ErrorMode
{
ErrorFlag_None = 0,
None,
ErrorFlag_Silent = 0x1,
ErrorFlag_SilentDisabled = 0x2,
ErrorFlag_ThrowException = 0x4,
ErrorFlag_ThrowExceptionDisabled = 0x8,
Silent,
SilentDisabled,
ThrowException,
ThrowExceptionDisabled,
ErrorFlag_Max = ErrorFlag_ThrowExceptionDisabled * 2 - 1
Max = ThrowExceptionDisabled
};
enum ErrorType
template<>
struct EnumAsFlags<ErrorMode>
{
ErrorType_AssertFailed,
ErrorType_Internal,
ErrorType_Normal,
ErrorType_Warning,
ErrorType_Max = ErrorType_Warning
static constexpr ErrorMode max = ErrorMode::Max;
};
enum HashType
{
HashType_CRC32,
HashType_CRC64,
HashType_Fletcher16,
HashType_MD5,
HashType_SHA1,
HashType_SHA224,
HashType_SHA256,
HashType_SHA384,
HashType_SHA512,
HashType_Whirlpool,
using ErrorModeFlags = Flags<ErrorMode>;
HashType_Max = HashType_Whirlpool
enum class ErrorType
{
AssertFailed,
Internal,
Normal,
Warning,
Max = Warning
};
enum OpenMode
constexpr std::size_t ErrorTypeCount = static_cast<std::size_t>(ErrorType::Max) + 1;
enum class HashType
{
OpenMode_NotOpen, // Use the current mod of opening
CRC32,
CRC64,
Fletcher16,
MD5,
SHA1,
SHA224,
SHA256,
SHA384,
SHA512,
Whirlpool,
OpenMode_Append, // Disable writing on existing parts and put the cursor at the end
OpenMode_Lock, // Disable modifying the file before it is open
OpenMode_MustExist, // Fail if the file doesn't exists, even if opened in write mode
OpenMode_ReadOnly, // Open in read only
OpenMode_Text, // Open in text mod
OpenMode_Truncate, // Create the file if it doesn't exist and empty it if it exists
OpenMode_WriteOnly, // Open in write only, create the file if it doesn't exist
Max = Whirlpool
};
OpenMode_Max = OpenMode_WriteOnly
constexpr std::size_t HashTypeCount = static_cast<std::size_t>(HashType::Max) + 1;
enum class OpenMode
{
NotOpen, // Use the current mod of opening
Append, // Disable writing on existing parts and put the cursor at the end
Lock, // Disable modifying the file before it is open
MustExist, // Fail if the file doesn't exists, even if opened in write mode
ReadOnly, // Open in read only
Text, // Open in text mod
Truncate, // Create the file if it doesn't exist and empty it if it exists
WriteOnly, // Open in write only, create the file if it doesn't exist
Max = WriteOnly
};
template<>
struct EnumAsFlags<OpenMode>
{
static constexpr OpenMode max = OpenMode_Max;
static constexpr OpenMode max = OpenMode::Max;
};
using OpenModeFlags = Flags<OpenMode>;
constexpr OpenModeFlags OpenMode_ReadWrite = OpenMode_ReadOnly | OpenMode_WriteOnly;
constexpr OpenModeFlags OpenMode_ReadWrite = OpenMode::ReadOnly | OpenMode::WriteOnly;
enum ParameterType
enum class ParameterType
{
ParameterType_Boolean,
ParameterType_Color,
ParameterType_Double,
ParameterType_Integer,
ParameterType_None,
ParameterType_Pointer,
ParameterType_String,
ParameterType_Userdata,
Boolean,
Color,
Double,
Integer,
None,
Pointer,
String,
Userdata,
ParameterType_Max = ParameterType_Userdata
Max = Userdata
};
enum Plugin
enum class Plugin
{
Plugin_Assimp,
Assimp,
Plugin_Count
Max = Assimp
};
enum PrimitiveType
{
PrimitiveType_Box,
PrimitiveType_Cone,
PrimitiveType_Plane,
PrimitiveType_Sphere,
constexpr std::size_t PluginCount = static_cast<std::size_t>(Plugin::Max) + 1;
PrimitiveType_Max = PrimitiveType_Sphere
enum class PrimitiveType
{
Box,
Cone,
Plane,
Sphere,
Max = Sphere
};
enum ProcessorCap
{
ProcessorCap_x64,
ProcessorCap_AVX,
ProcessorCap_FMA3,
ProcessorCap_FMA4,
ProcessorCap_MMX,
ProcessorCap_XOP,
ProcessorCap_SSE,
ProcessorCap_SSE2,
ProcessorCap_SSE3,
ProcessorCap_SSSE3,
ProcessorCap_SSE41,
ProcessorCap_SSE42,
ProcessorCap_SSE4a,
constexpr std::size_t PrimitiveTypeCount = static_cast<std::size_t>(PrimitiveType::Max) + 1;
ProcessorCap_Max = ProcessorCap_SSE4a
enum class ProcessorCap
{
x64,
AVX,
FMA3,
FMA4,
MMX,
XOP,
SSE,
SSE2,
SSE3,
SSSE3,
SSE41,
SSE42,
SSE4a,
Max = SSE4a
};
enum ProcessorVendor
constexpr std::size_t ProcessorCapCount = static_cast<std::size_t>(ProcessorCap::Max) + 1;
enum class ProcessorVendor
{
ProcessorVendor_Unknown = -1,
Unknown = -1,
ProcessorVendor_AMD,
ProcessorVendor_Centaur,
ProcessorVendor_Cyrix,
ProcessorVendor_Intel,
ProcessorVendor_KVM,
ProcessorVendor_HyperV,
ProcessorVendor_NSC,
ProcessorVendor_NexGen,
ProcessorVendor_Rise,
ProcessorVendor_SIS,
ProcessorVendor_Transmeta,
ProcessorVendor_UMC,
ProcessorVendor_VIA,
ProcessorVendor_VMware,
ProcessorVendor_Vortex,
ProcessorVendor_XenHVM,
AMD,
Centaur,
Cyrix,
Intel,
KVM,
HyperV,
NSC,
NexGen,
Rise,
SIS,
Transmeta,
UMC,
VIA,
VMware,
Vortex,
XenHVM,
ProcessorVendor_Max = ProcessorVendor_XenHVM
Max = XenHVM
};
enum SphereType
{
SphereType_Cubic,
SphereType_Ico,
SphereType_UV,
constexpr std::size_t ProcessorVendorCount = static_cast<std::size_t>(ProcessorVendor::Max) + 1;
SphereType_Max = SphereType_UV
enum class SphereType
{
Cubic,
Ico,
UV,
Max = UV
};
enum StreamOption
enum class StreamOption
{
StreamOption_None,
None,
StreamOption_Sequential,
StreamOption_Text,
Sequential,
Text,
StreamOption_Max = StreamOption_Text
Max = Text
};
template<>
struct EnumAsFlags<StreamOption>
{
static constexpr StreamOption max = StreamOption_Max;
static constexpr StreamOption max = StreamOption::Max;
};
using StreamOptionFlags = Flags<StreamOption>;

View File

@@ -13,14 +13,14 @@
#include <string>
#if NAZARA_CORE_ENABLE_ASSERTS || defined(NAZARA_DEBUG)
#define NazaraAssert(a, err) if (!(a)) Nz::Error::Trigger(Nz::ErrorType_AssertFailed, err, __LINE__, __FILE__, NAZARA_FUNCTION)
#define NazaraAssert(a, err) if (!(a)) Nz::Error::Trigger(Nz::ErrorType::AssertFailed, err, __LINE__, __FILE__, NAZARA_FUNCTION)
#else
#define NazaraAssert(a, err) for (;;) break
#endif
#define NazaraError(err) Nz::Error::Trigger(Nz::ErrorType_Normal, err, __LINE__, __FILE__, NAZARA_FUNCTION)
#define NazaraInternalError(err) Nz::Error::Trigger(Nz::ErrorType_Internal, err, __LINE__, __FILE__, NAZARA_FUNCTION)
#define NazaraWarning(err) Nz::Error::Trigger(Nz::ErrorType_Warning, err, __LINE__, __FILE__, NAZARA_FUNCTION)
#define NazaraError(err) Nz::Error::Trigger(Nz::ErrorType::Normal, err, __LINE__, __FILE__, NAZARA_FUNCTION)
#define NazaraInternalError(err) Nz::Error::Trigger(Nz::ErrorType::Internal, err, __LINE__, __FILE__, NAZARA_FUNCTION)
#define NazaraWarning(err) Nz::Error::Trigger(Nz::ErrorType::Warning, err, __LINE__, __FILE__, NAZARA_FUNCTION)
namespace Nz
{
@@ -30,12 +30,12 @@ namespace Nz
Error() = delete;
~Error() = delete;
static UInt32 GetFlags();
static ErrorModeFlags GetFlags();
static std::string GetLastError(const char** file = nullptr, unsigned int* line = nullptr, const char** function = nullptr);
static unsigned int GetLastSystemErrorCode();
static std::string GetLastSystemError(unsigned int code = GetLastSystemErrorCode());
static void SetFlags(UInt32 flags);
static void SetFlags(ErrorModeFlags flags);
static void Trigger(ErrorType type, std::string error);
static void Trigger(ErrorType type, std::string error, unsigned int line, const char* file, const char* function);
@@ -43,7 +43,7 @@ namespace Nz
private:
static const char* GetCurrentFileRelativeToEngine(const char* file);
static UInt32 s_flags;
static ErrorModeFlags s_flags;
static std::string s_lastError;
static const char* s_lastErrorFunction;
static const char* s_lastErrorFile;

View File

@@ -8,26 +8,27 @@
#define NAZARA_ERRORFLAGS_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Enums.hpp>
namespace Nz
{
class NAZARA_CORE_API ErrorFlags
{
public:
ErrorFlags(UInt32 flags, bool replace = false);
ErrorFlags(ErrorModeFlags flags, bool replace = false);
ErrorFlags(const ErrorFlags&) = delete;
ErrorFlags(ErrorFlags&&) = delete;
~ErrorFlags();
UInt32 GetPreviousFlags() const;
ErrorModeFlags GetPreviousFlags() const;
void SetFlags(UInt32 flags, bool replace = false);
void SetFlags(ErrorModeFlags flags, bool replace = false);
ErrorFlags& operator=(const ErrorFlags&) = delete;
ErrorFlags& operator=(ErrorFlags&&) = delete;
private:
UInt32 m_previousFlags;
ErrorModeFlags m_previousFlags;
};
}

View File

@@ -48,8 +48,8 @@ namespace Nz
bool IsOpen() const;
bool Open(OpenModeFlags openMode = OpenMode_NotOpen);
bool Open(const std::filesystem::path& filePath, OpenModeFlags openMode = OpenMode_NotOpen);
bool Open(OpenModeFlags openMode = OpenMode::NotOpen);
bool Open(const std::filesystem::path& filePath, OpenModeFlags openMode = OpenMode::NotOpen);
bool SetCursorPos(CursorPosition pos, Int64 offset = 0);
bool SetCursorPos(UInt64 offset) override;

View File

@@ -13,7 +13,7 @@ namespace Nz
* \brief Constructs a MemoryStream object by default
*/
inline MemoryStream::MemoryStream() :
Stream(StreamOption_None, OpenMode_ReadWrite),
Stream(StreamOption::None, OpenMode_ReadWrite),
m_pos(0)
{
}

View File

@@ -24,7 +24,7 @@ namespace Nz
{
matrix = transformMatrix;
textureCoords = uvCoords;
type = PrimitiveType_Box;
type = PrimitiveType::Box;
box.lengths = lengths;
box.subdivision = subdivision;
}
@@ -56,7 +56,7 @@ namespace Nz
{
matrix = transformMatrix;
textureCoords = uvCoords;
type = PrimitiveType_Cone;
type = PrimitiveType::Cone;
cone.length = length;
cone.radius = radius;
cone.subdivision = subdivision;
@@ -89,9 +89,9 @@ namespace Nz
{
matrix = transformMatrix;
textureCoords = uvCoords;
type = PrimitiveType_Sphere;
type = PrimitiveType::Sphere;
sphere.size = size;
sphere.type = SphereType_Cubic;
sphere.type = SphereType::Cubic;
sphere.cubic.subdivision = subdivision;
}
@@ -121,9 +121,9 @@ namespace Nz
{
matrix = transformMatrix;
textureCoords = uvCoords;
type = PrimitiveType_Sphere;
type = PrimitiveType::Sphere;
sphere.size = size;
sphere.type = SphereType_Ico;
sphere.type = SphereType::Ico;
sphere.ico.recursionLevel = recursionLevel;
}
@@ -153,7 +153,7 @@ namespace Nz
{
matrix = transformMatrix;
textureCoords = uvCoords;
type = PrimitiveType_Plane;
type = PrimitiveType::Plane;
plane.size = size;
plane.subdivision = subdivision;
}
@@ -198,9 +198,9 @@ namespace Nz
{
matrix = transformMatrix;
textureCoords = uvCoords;
type = PrimitiveType_Sphere;
type = PrimitiveType::Sphere;
sphere.size = size;
sphere.type = SphereType_UV;
sphere.type = SphereType::UV;
sphere.uv.sliceCount = sliceCount;
sphere.uv.stackCount = stackCount;
}

View File

@@ -89,7 +89,7 @@ namespace Nz
if (loader.streamChecker && !file.IsOpen())
{
if (!file.Open(OpenMode_ReadOnly))
if (!file.Open(OpenMode::ReadOnly))
{
NazaraError("Failed to load file: unable to open \"" + filePath.generic_u8string() + '"');
return nullptr;

View File

@@ -89,7 +89,7 @@ namespace Nz
{
File file(filePath.generic_u8string());
if (!file.Open(OpenMode_WriteOnly | OpenMode_Truncate))
if (!file.Open(OpenMode::WriteOnly | OpenMode::Truncate))
{
NazaraError("Failed to save to file: unable to open \"" + filePath.generic_u8string() + "\" in write mode");
return false;

View File

@@ -20,7 +20,7 @@ namespace Nz
struct NAZARA_CORE_API SerializationContext
{
MovablePtr<Stream> stream;
Endianness endianness = Endianness_BigEndian; //< Default to Big Endian encoding
Endianness endianness = Endianness::BigEndian; //< Default to Big Endian encoding
UInt8 readBitPos = 8; //< 8 means no bit is currently read
UInt8 readByte; //< Undefined value, will be initialized at the first bit read
UInt8 writeBitPos = 8; //< 8 means no bit is currently wrote

View File

@@ -56,7 +56,7 @@ namespace Nz
Stream& operator=(Stream&&) noexcept = default;
protected:
inline Stream(StreamOptionFlags streamOptions = StreamOption_None, OpenModeFlags openMode = OpenMode_NotOpen);
inline Stream(StreamOptionFlags streamOptions = StreamOption::None, OpenModeFlags openMode = OpenMode::NotOpen);
virtual void FlushStream() = 0;
virtual std::size_t ReadBlock(void* buffer, std::size_t size) = 0;

View File

@@ -29,9 +29,9 @@ namespace Nz
inline void Stream::EnableTextMode(bool textMode)
{
if (textMode)
m_streamOptions |= StreamOption_Text;
m_streamOptions |= StreamOption::Text;
else
m_streamOptions &= ~StreamOption_Text;
m_streamOptions &= ~StreamOption::Text;
}
/*!
@@ -74,7 +74,7 @@ namespace Nz
inline bool Stream::IsReadable() const
{
return (m_openMode & OpenMode_ReadOnly) != 0;
return (m_openMode & OpenMode::ReadOnly) != 0;
}
/*!
@@ -84,7 +84,7 @@ namespace Nz
inline bool Stream::IsSequential() const
{
return (m_streamOptions & StreamOption_Sequential) != 0;
return (m_streamOptions & StreamOption::Sequential) != 0;
}
/*!
@@ -94,7 +94,7 @@ namespace Nz
inline bool Stream::IsTextModeEnabled() const
{
return (m_streamOptions & StreamOption_Text) != 0;
return (m_streamOptions & StreamOption::Text) != 0;
}
/*!
@@ -104,7 +104,7 @@ namespace Nz
inline bool Stream::IsWritable() const
{
return (m_openMode & OpenMode_WriteOnly) != 0;
return (m_openMode & OpenMode::WriteOnly) != 0;
}
/*!