From 3dbcb25384d638d17e464c0a039e088d8fdfc57f Mon Sep 17 00:00:00 2001 From: Gawaboumga Date: Fri, 21 Aug 2015 11:22:35 +0200 Subject: [PATCH] Transfert enumeration from file to enums Former-commit-id: 0d9e191373affda50d0eb6c2376c7a23720e591b --- examples/HardwareInfo/main.cpp | 2 +- include/Nazara/Core/Enums.hpp | 28 ++++++++++++++- include/Nazara/Core/File.hpp | 28 +++------------ include/Nazara/Core/ResourceLoader.inl | 2 +- src/Nazara/Audio/Loaders/sndfile/Loader.cpp | 2 +- src/Nazara/Core/File.cpp | 34 +++++++++---------- src/Nazara/Core/Log.cpp | 2 +- src/Nazara/Core/Posix/FileImpl.cpp | 24 ++++++------- src/Nazara/Core/Posix/FileImpl.hpp | 2 +- src/Nazara/Core/Win32/FileImpl.cpp | 24 ++++++------- src/Nazara/Core/Win32/FileImpl.hpp | 2 +- src/Nazara/Graphics/Loaders/OBJ/Loader.cpp | 4 ++- src/Nazara/Lua/LuaInstance.cpp | 2 +- src/Nazara/Renderer/ShaderStage.cpp | 2 +- .../Renderer/UberShaderPreprocessor.cpp | 2 +- .../Utility/Loaders/FreeType/Loader.cpp | 2 +- 16 files changed, 85 insertions(+), 77 deletions(-) diff --git a/examples/HardwareInfo/main.cpp b/examples/HardwareInfo/main.cpp index d1a12dade..bcc76c4c3 100644 --- a/examples/HardwareInfo/main.cpp +++ b/examples/HardwareInfo/main.cpp @@ -100,7 +100,7 @@ int main() std::cout << oss.str() << std::endl; NzFile reportFile("RapportHardwareInfo.txt"); - if (reportFile.Open(NzFile::Text | NzFile::Truncate | NzFile::WriteOnly)) + if (reportFile.Open(nzOpenMode_Text | nzOpenMode_Truncate | nzOpenMode_WriteOnly)) { reportFile.Write(oss.str()); // Conversion implicite en NzString reportFile.Close(); diff --git a/include/Nazara/Core/Enums.hpp b/include/Nazara/Core/Enums.hpp index 81ccae4e0..94d8584ad 100644 --- a/include/Nazara/Core/Enums.hpp +++ b/include/Nazara/Core/Enums.hpp @@ -15,6 +15,15 @@ enum nzCoordSys nzCoordSys_Max = nzCoordSys_Local }; +enum nzCursorPosition +{ + nzCursorPosition_AtBegin, // Début du fichier + nzCursorPosition_AtCurrent, // Position du pointeur + nzCursorPosition_AtEnd, // Fin du fichier + + nzCursorPosition_Max = nzCursorPosition_AtEnd +}; + enum nzEndianness { nzEndianness_Unknown = -1, @@ -57,7 +66,24 @@ enum nzHash nzHash_SHA256, nzHash_SHA384, nzHash_SHA512, - nzHash_Whirlpool + nzHash_Whirlpool, + + nzHash_Max = nzHash_Whirlpool +}; + +enum nzOpenModeFlags +{ + nzOpenMode_Current = 0x00, // Utilise le mode d'ouverture actuel + + nzOpenMode_Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin + nzOpenMode_Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert + nzOpenMode_ReadOnly = 0x04, // Ouvre uniquement en lecture + nzOpenMode_ReadWrite = 0x08, // Ouvre en lecture/écriture + nzOpenMode_Text = 0x10, // Ouvre en mode texte + nzOpenMode_Truncate = 0x20, // Créé le fichier s'il n'existe pas et le vide s'il existe + nzOpenMode_WriteOnly = 0x40, // Ouvre uniquement en écriture, créé le fichier s'il n'existe pas + + nzOpenMode_Max = nzOpenMode_WriteOnly }; enum nzParameterType diff --git a/include/Nazara/Core/File.hpp b/include/Nazara/Core/File.hpp index 556acfb3b..d11ed32ea 100644 --- a/include/Nazara/Core/File.hpp +++ b/include/Nazara/Core/File.hpp @@ -30,29 +30,9 @@ class NzFileImpl; class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable { public: - enum CursorPosition - { - AtBegin, // Début du fichier - AtCurrent, // Position du pointeur - AtEnd // Fin du fichier - }; - - enum OpenMode - { - Current = 0x00, // Utilise le mode d'ouverture actuel - - Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin - Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert - ReadOnly = 0x04, // Ouvre uniquement en lecture - ReadWrite = 0x08, // Ouvre en lecture/écriture - Text = 0x10, // Ouvre en mode texte - Truncate = 0x20, // Créé le fichier s'il n'existe pas et le vide s'il existe - WriteOnly = 0x40 // Ouvre uniquement en écriture, créé le fichier s'il n'existe pas - }; - NzFile(); NzFile(const NzString& filePath); - NzFile(const NzString& filePath, unsigned long openMode); + NzFile(const NzString& filePath, unsigned int openMode); NzFile(NzFile&& file) noexcept; ~NzFile(); @@ -79,14 +59,14 @@ class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable bool IsOpen() const; - bool Open(unsigned long openMode = Current); - bool Open(const NzString& filePath, unsigned long openMode = Current); + bool Open(unsigned int openMode = nzOpenMode_Current); + bool Open(const NzString& filePath, unsigned int openMode = nzOpenMode_Current); std::size_t Read(void* buffer, std::size_t size); std::size_t Read(void* buffer, std::size_t typeSize, unsigned int count); bool Rename(const NzString& newFilePath); - bool SetCursorPos(CursorPosition pos, nzInt64 offset = 0); + bool SetCursorPos(nzCursorPosition pos, nzInt64 offset = 0); bool SetCursorPos(nzUInt64 offset); void SetEndianness(nzEndianness endianness); bool SetFile(const NzString& filePath); diff --git a/include/Nazara/Core/ResourceLoader.inl b/include/Nazara/Core/ResourceLoader.inl index 6622be2f4..11d9a0a63 100644 --- a/include/Nazara/Core/ResourceLoader.inl +++ b/include/Nazara/Core/ResourceLoader.inl @@ -57,7 +57,7 @@ bool NzResourceLoader::LoadFromFile(Type* resource, const NzSt if (checkFunc && !file.IsOpen()) { - if (!file.Open(NzFile::ReadOnly)) + if (!file.Open(nzOpenMode_ReadOnly)) { NazaraError("Failed to load file: unable to open \"" + filePath + '"'); return false; diff --git a/src/Nazara/Audio/Loaders/sndfile/Loader.cpp b/src/Nazara/Audio/Loaders/sndfile/Loader.cpp index 140798a80..159e9e88b 100644 --- a/src/Nazara/Audio/Loaders/sndfile/Loader.cpp +++ b/src/Nazara/Audio/Loaders/sndfile/Loader.cpp @@ -110,7 +110,7 @@ namespace // Nous devons gérer nous-même le flux car il doit rester ouvert après le passage du loader // (les flux automatiquement ouverts par le ResourceLoader étant fermés après celui-ci) std::unique_ptr file(new NzFile); - if (!file->Open(filePath, NzFile::ReadOnly)) + if (!file->Open(filePath, nzOpenMode_ReadOnly)) { NazaraError("Failed to open stream from file: " + NzError::GetLastError()); return false; diff --git a/src/Nazara/Core/File.cpp b/src/Nazara/Core/File.cpp index 1acee0122..f6c45c6c8 100644 --- a/src/Nazara/Core/File.cpp +++ b/src/Nazara/Core/File.cpp @@ -32,22 +32,22 @@ NzFile::NzFile() : m_endianness(nzEndianness_Unknown), m_impl(nullptr), -m_openMode(0) +m_openMode(nzOpenMode_Current) { } NzFile::NzFile(const NzString& filePath) : m_endianness(nzEndianness_Unknown), m_impl(nullptr), -m_openMode(0) +m_openMode(nzOpenMode_Current) { SetFile(filePath); } -NzFile::NzFile(const NzString& filePath, unsigned long openMode) : +NzFile::NzFile(const NzString& filePath, unsigned int openMode) : m_endianness(nzEndianness_Unknown), m_impl(nullptr), -m_openMode(0) +m_openMode(openMode) { Open(filePath, openMode); } @@ -133,7 +133,7 @@ void NzFile::Flush() return; } - if ((m_openMode & ReadWrite) == 0 && (m_openMode & WriteOnly) == 0) + if ((m_openMode & nzOpenMode_ReadWrite) == 0 && (m_openMode & nzOpenMode_WriteOnly) == 0) { NazaraError("Cannot flush file without write access"); return; @@ -225,7 +225,7 @@ std::size_t NzFile::Read(void* buffer, std::size_t size) return 0; } - if ((m_openMode & ReadOnly) == 0 && (m_openMode & ReadWrite) == 0) + if ((m_openMode & nzOpenMode_ReadOnly) == 0 && (m_openMode & nzOpenMode_ReadWrite) == 0) { NazaraError("File not opened with read access"); return 0; @@ -242,7 +242,7 @@ std::size_t NzFile::Read(void* buffer, std::size_t size) // Si nous ne devons rien lire, nous avançons simplement nzUInt64 currentPos = m_impl->GetCursorPos(); - m_impl->SetCursorPos(NzFile::AtCurrent, size); + m_impl->SetCursorPos(nzCursorPosition_AtCurrent, size); return static_cast(m_impl->GetCursorPos()-currentPos); } @@ -281,7 +281,7 @@ bool NzFile::Rename(const NzString& newFilePath) return success; } -bool NzFile::Open(unsigned long openMode) +bool NzFile::Open(unsigned int openMode) { NazaraLock(m_mutex) @@ -306,13 +306,13 @@ bool NzFile::Open(unsigned long openMode) m_impl = impl.release(); - if (m_openMode & Text) + if (m_openMode & nzOpenMode_Text) m_streamOptions |= nzStreamOption_Text; return true; } -bool NzFile::Open(const NzString& filePath, unsigned long openMode) +bool NzFile::Open(const NzString& filePath, unsigned int openMode) { NazaraLock(m_mutex) @@ -322,7 +322,7 @@ bool NzFile::Open(const NzString& filePath, unsigned long openMode) return Open(openMode); } -bool NzFile::SetCursorPos(CursorPosition pos, nzInt64 offset) +bool NzFile::SetCursorPos(nzCursorPosition pos, nzInt64 offset) { NazaraLock(m_mutex) @@ -349,7 +349,7 @@ bool NzFile::SetCursorPos(nzUInt64 offset) } #endif - return m_impl->SetCursorPos(AtBegin, offset); + return m_impl->SetCursorPos(nzCursorPosition_AtBegin, offset); } void NzFile::SetEndianness(nzEndianness endianness) @@ -389,7 +389,7 @@ bool NzFile::SetOpenMode(unsigned int openMode) { NazaraLock(m_mutex) - if (openMode == 0 || openMode == m_openMode) + if (openMode == nzOpenMode_Current || openMode == m_openMode) return true; if (IsOpen()) @@ -406,7 +406,7 @@ bool NzFile::SetOpenMode(unsigned int openMode) m_impl = impl.release(); - if (m_openMode & Text) + if (m_openMode & nzOpenMode_Text) m_streamOptions |= nzStreamOption_Text; } @@ -417,7 +417,7 @@ bool NzFile::SetOpenMode(unsigned int openMode) bool NzFile::Write(const NzByteArray& byteArray) { - unsigned int size = byteArray.GetSize(); + NzByteArray::size_type size = byteArray.GetSize(); return Write(byteArray.GetConstBuffer(), 1, size) == size; } @@ -455,7 +455,7 @@ std::size_t NzFile::Write(const void* buffer, std::size_t typeSize, unsigned int return 0; } - if ((m_openMode & ReadWrite) == 0 && (m_openMode & WriteOnly) == 0) + if ((m_openMode & nzOpenMode_ReadWrite) == 0 && (m_openMode & nzOpenMode_WriteOnly) == 0) { NazaraError("File not opened with write access"); return 0; @@ -721,7 +721,7 @@ bool NzFile::Rename(const NzString& sourcePath, const NzString& targetPath) bool NzFile::FillHash(NzAbstractHash* hash) const { NzFile file(m_filePath); - if (!file.Open(NzFile::ReadOnly)) + if (!file.Open(nzOpenMode_ReadOnly)) { NazaraError("Unable to open file"); return false; diff --git a/src/Nazara/Core/Log.cpp b/src/Nazara/Core/Log.cpp index 51622d100..a2602228a 100644 --- a/src/Nazara/Core/Log.cpp +++ b/src/Nazara/Core/Log.cpp @@ -114,7 +114,7 @@ void NzLog::Write(const NzString& string) if (m_enabled) { if (!m_file) - m_file = new NzFile(m_filePath, NzFile::Text | NzFile::WriteOnly | ((m_append) ? NzFile::Append : NzFile::Truncate)); + m_file = new NzFile(m_filePath, nzOpenMode_Text | nzOpenMode_WriteOnly | ((m_append) ? nzOpenMode_Append : nzOpenMode_Truncate)); NzString line; diff --git a/src/Nazara/Core/Posix/FileImpl.cpp b/src/Nazara/Core/Posix/FileImpl.cpp index 56c3084da..b33dce80b 100644 --- a/src/Nazara/Core/Posix/FileImpl.cpp +++ b/src/Nazara/Core/Posix/FileImpl.cpp @@ -51,33 +51,33 @@ bool NzFileImpl::Open(const NzString& filePath, unsigned int mode) int flags; mode_t permissions = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; - if (mode & NzFile::ReadOnly) + if (mode & nzOpenMode_ReadOnly) flags = O_RDONLY; - else if (mode & NzFile::ReadWrite) + else if (mode & nzOpenMode_ReadWrite) { flags = O_CREAT | O_RDWR; - if (mode & NzFile::Append) + if (mode & nzOpenMode_Append) flags |= O_APPEND; - if (mode & NzFile::Truncate) + if (mode & nzOpenMode_Truncate) flags |= O_TRUNC; } - else if (mode & NzFile::WriteOnly) + else if (mode & nzOpenMode_WriteOnly) { flags = O_CREAT | O_WRONLY; - if (mode & NzFile::Append) + if (mode & nzOpenMode_Append) flags |= O_APPEND; - if (mode & NzFile::Truncate) + if (mode & nzOpenMode_Truncate) flags |= O_TRUNC; } else return false; ///TODO: lock -// if ((mode & NzFile::Lock) == 0) +// if ((mode & nzOpenMode_Lock) == 0) // shareMode |= FILE_SHARE_WRITE; m_fileDescriptor = open64(filePath.GetConstBuffer(), flags, permissions); @@ -98,20 +98,20 @@ std::size_t NzFileImpl::Read(void* buffer, std::size_t size) return 0; } -bool NzFileImpl::SetCursorPos(NzFile::CursorPosition pos, nzInt64 offset) +bool NzFileImpl::SetCursorPos(nzCursorPosition pos, nzInt64 offset) { int moveMethod; switch (pos) { - case NzFile::AtBegin: + case nzCursorPosition_AtBegin: moveMethod = SEEK_SET; break; - case NzFile::AtCurrent: + case nzCursorPosition_AtCurrent: moveMethod = SEEK_CUR; break; - case NzFile::AtEnd: + case nzCursorPosition_AtEnd: moveMethod = SEEK_END; break; diff --git a/src/Nazara/Core/Posix/FileImpl.hpp b/src/Nazara/Core/Posix/FileImpl.hpp index b6d22aca5..eda3f5400 100644 --- a/src/Nazara/Core/Posix/FileImpl.hpp +++ b/src/Nazara/Core/Posix/FileImpl.hpp @@ -35,7 +35,7 @@ class NzFileImpl : NzNonCopyable nzUInt64 GetCursorPos() const; bool Open(const NzString& filePath, unsigned int mode); std::size_t Read(void* buffer, std::size_t size); - bool SetCursorPos(NzFile::CursorPosition pos, nzInt64 offset); + bool SetCursorPos(nzCursorPosition pos, nzInt64 offset); std::size_t Write(const void* buffer, std::size_t size); static bool Copy(const NzString& sourcePath, const NzString& targetPath); diff --git a/src/Nazara/Core/Win32/FileImpl.cpp b/src/Nazara/Core/Win32/FileImpl.cpp index 4ba16d90a..a2e4ef192 100644 --- a/src/Nazara/Core/Win32/FileImpl.cpp +++ b/src/Nazara/Core/Win32/FileImpl.cpp @@ -57,31 +57,31 @@ bool NzFileImpl::Open(const NzString& filePath, unsigned int mode) DWORD access; DWORD shareMode = FILE_SHARE_READ; DWORD openMode; - if (mode & NzFile::ReadOnly) + if (mode & nzOpenMode_ReadOnly) { access = GENERIC_READ; openMode = OPEN_EXISTING; } - else if (mode & NzFile::ReadWrite) + else if (mode & nzOpenMode_ReadWrite) { - if (mode & NzFile::Append) + if (mode & nzOpenMode_Append) access = FILE_APPEND_DATA; else access = GENERIC_READ | GENERIC_WRITE; - if (mode & NzFile::Truncate) + if (mode & nzOpenMode_Truncate) openMode = CREATE_ALWAYS; else openMode = OPEN_ALWAYS; } - else if (mode & NzFile::WriteOnly) + else if (mode & nzOpenMode_WriteOnly) { - if (mode & NzFile::Append) + if (mode & nzOpenMode_Append) access = FILE_APPEND_DATA; else access = GENERIC_WRITE; - if (mode & NzFile::Truncate) + if (mode & nzOpenMode_Truncate) openMode = CREATE_ALWAYS; else openMode = OPEN_ALWAYS; @@ -89,7 +89,7 @@ bool NzFileImpl::Open(const NzString& filePath, unsigned int mode) else return false; - if ((mode & NzFile::Lock) == 0) + if ((mode & nzOpenMode_Lock) == 0) shareMode |= FILE_SHARE_WRITE; m_handle = CreateFileW(filePath.GetWideString().data(), access, shareMode, nullptr, openMode, 0, nullptr); @@ -134,20 +134,20 @@ std::size_t NzFileImpl::Read(void* buffer, std::size_t size) return 0; } -bool NzFileImpl::SetCursorPos(NzFile::CursorPosition pos, nzInt64 offset) +bool NzFileImpl::SetCursorPos(nzCursorPosition pos, nzInt64 offset) { DWORD moveMethod; switch (pos) { - case NzFile::AtBegin: + case nzCursorPosition_AtBegin: moveMethod = FILE_BEGIN; break; - case NzFile::AtCurrent: + case nzCursorPosition_AtCurrent: moveMethod = FILE_CURRENT; break; - case NzFile::AtEnd: + case nzCursorPosition_AtEnd: moveMethod = FILE_END; break; diff --git a/src/Nazara/Core/Win32/FileImpl.hpp b/src/Nazara/Core/Win32/FileImpl.hpp index 15420b8db..b9c667595 100644 --- a/src/Nazara/Core/Win32/FileImpl.hpp +++ b/src/Nazara/Core/Win32/FileImpl.hpp @@ -28,7 +28,7 @@ class NzFileImpl : NzNonCopyable nzUInt64 GetCursorPos() const; bool Open(const NzString& filePath, unsigned int mode); std::size_t Read(void* buffer, std::size_t size); - bool SetCursorPos(NzFile::CursorPosition pos, nzInt64 offset); + bool SetCursorPos(nzCursorPosition pos, nzInt64 offset); std::size_t Write(const void* buffer, std::size_t size); static bool Copy(const NzString& sourcePath, const NzString& targetPath); diff --git a/src/Nazara/Graphics/Loaders/OBJ/Loader.cpp b/src/Nazara/Graphics/Loaders/OBJ/Loader.cpp index 190517f72..c2721f74c 100644 --- a/src/Nazara/Graphics/Loaders/OBJ/Loader.cpp +++ b/src/Nazara/Graphics/Loaders/OBJ/Loader.cpp @@ -38,7 +38,7 @@ namespace bool LoadMaterials(NzModel* model, const NzString& filePath, const NzMaterialParams& parameters, const NzString* materials, const NzOBJParser::Mesh* meshes, unsigned int meshCount) { NzFile file(filePath); - if (!file.Open(NzFile::ReadOnly | NzFile::Text)) + if (!file.Open(nzOpenMode_ReadOnly | nzOpenMode_Text)) { NazaraError("Failed to open MTL file (" + file.GetPath() + ')'); return false; @@ -121,6 +121,8 @@ namespace model->SetMaterial(meshes[i].material, it->second); } + + return true; } bool Load(NzModel* model, NzInputStream& stream, const NzModelParameters& parameters) diff --git a/src/Nazara/Lua/LuaInstance.cpp b/src/Nazara/Lua/LuaInstance.cpp index 3aa8f9a23..efb2a1ee1 100644 --- a/src/Nazara/Lua/LuaInstance.cpp +++ b/src/Nazara/Lua/LuaInstance.cpp @@ -393,7 +393,7 @@ bool NzLuaInstance::Execute(const NzString& code) bool NzLuaInstance::ExecuteFromFile(const NzString& filePath) { NzFile file(filePath); - if (!file.Open(NzFile::ReadOnly | NzFile::Text)) + if (!file.Open(nzOpenMode_ReadOnly | nzOpenMode_Text)) { NazaraError("Failed to open file"); return false; diff --git a/src/Nazara/Renderer/ShaderStage.cpp b/src/Nazara/Renderer/ShaderStage.cpp index c45757192..24b8248fb 100644 --- a/src/Nazara/Renderer/ShaderStage.cpp +++ b/src/Nazara/Renderer/ShaderStage.cpp @@ -174,7 +174,7 @@ bool NzShaderStage::SetSourceFromFile(const NzString& filePath) #endif NzFile file(filePath); - if (!file.Open(NzFile::ReadOnly | NzFile::Text)) + if (!file.Open(nzOpenMode_ReadOnly | nzOpenMode_Text)) { NazaraError("Failed to open \"" + filePath + '"'); return false; diff --git a/src/Nazara/Renderer/UberShaderPreprocessor.cpp b/src/Nazara/Renderer/UberShaderPreprocessor.cpp index efcc492c5..078fb892f 100644 --- a/src/Nazara/Renderer/UberShaderPreprocessor.cpp +++ b/src/Nazara/Renderer/UberShaderPreprocessor.cpp @@ -151,7 +151,7 @@ void NzUberShaderPreprocessor::SetShader(nzShaderStage stage, const NzString& so bool NzUberShaderPreprocessor::SetShaderFromFile(nzShaderStage stage, const NzString& filePath, const NzString& shaderFlags, const NzString& requiredFlags) { NzFile file(filePath); - if (!file.Open(NzFile::ReadOnly | NzFile::Text)) + if (!file.Open(nzOpenMode_ReadOnly | nzOpenMode_Text)) { NazaraError("Failed to open \"" + filePath + '"'); return false; diff --git a/src/Nazara/Utility/Loaders/FreeType/Loader.cpp b/src/Nazara/Utility/Loaders/FreeType/Loader.cpp index b16c89d02..9d1eac832 100644 --- a/src/Nazara/Utility/Loaders/FreeType/Loader.cpp +++ b/src/Nazara/Utility/Loaders/FreeType/Loader.cpp @@ -280,7 +280,7 @@ namespace bool SetFile(const NzString& filePath) { std::unique_ptr file(new NzFile); - if (!file->Open(filePath, NzFile::ReadOnly)) + if (!file->Open(filePath, nzOpenMode_ReadOnly)) { NazaraError("Failed to open stream from file: " + NzError::GetLastError()); return false;