Big f***ing cleanup part 1
This commit is contained in:
@@ -31,6 +31,33 @@ namespace Nz
|
||||
template<typename T> void HashCombine(std::size_t& seed, const T& v);
|
||||
template<typename T> T ReverseBits(T integer);
|
||||
|
||||
template<typename T>
|
||||
struct AlwaysFalse : std::false_type {};
|
||||
|
||||
template<typename... Args>
|
||||
struct OverloadResolver
|
||||
{
|
||||
template<typename R, typename T>
|
||||
constexpr auto operator()(R(T::* ptr)(Args...)) const noexcept
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
template<typename R, typename T>
|
||||
constexpr auto operator()(R(T::* ptr)(Args...) const) const noexcept
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
template<typename R>
|
||||
constexpr auto operator()(R(*ptr)(Args...)) const noexcept
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename... Args> constexpr OverloadResolver<Args...> Overload = {};
|
||||
|
||||
template<typename T>
|
||||
struct PointedType
|
||||
{
|
||||
|
||||
@@ -9,12 +9,6 @@
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
|
||||
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_CLOCK
|
||||
#include <Nazara/Core/ThreadSafety.hpp>
|
||||
#else
|
||||
#include <Nazara/Core/ThreadSafetyOff.hpp>
|
||||
#endif
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API Clock
|
||||
@@ -39,8 +33,6 @@ namespace Nz
|
||||
Clock& operator=(Clock&& clock) = default;
|
||||
|
||||
private:
|
||||
NazaraMutexAttrib(m_mutex, mutable)
|
||||
|
||||
UInt64 m_elapsedTime;
|
||||
UInt64 m_refTime;
|
||||
bool m_paused;
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CONDITIONVARIABLE_HPP
|
||||
#define NAZARA_CONDITIONVARIABLE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ConditionVariableImpl;
|
||||
class Mutex;
|
||||
|
||||
class NAZARA_CORE_API ConditionVariable
|
||||
{
|
||||
public:
|
||||
ConditionVariable();
|
||||
ConditionVariable(const ConditionVariable&) = delete;
|
||||
ConditionVariable(ConditionVariable&& condition) noexcept = default;
|
||||
~ConditionVariable();
|
||||
|
||||
void Signal();
|
||||
void SignalAll();
|
||||
|
||||
void Wait(Mutex* mutex);
|
||||
bool Wait(Mutex* mutex, UInt32 timeout);
|
||||
|
||||
ConditionVariable& operator=(const ConditionVariable&) = delete;
|
||||
ConditionVariable& operator=(ConditionVariable&& condition) noexcept = default;
|
||||
|
||||
private:
|
||||
MovablePtr<ConditionVariableImpl> m_impl;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/ConditionVariable.inl>
|
||||
|
||||
#endif // NAZARA_CONDITIONVARIABLE_HPP
|
||||
@@ -1,14 +0,0 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \class Nz::ConditionVariable
|
||||
*/
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
@@ -58,17 +58,6 @@
|
||||
// Activate the security tests based on the code (Advised for development)
|
||||
#define NAZARA_CORE_SAFE 1
|
||||
|
||||
// Protect the classes against data race
|
||||
#define NAZARA_CORE_THREADSAFE 1
|
||||
|
||||
// Classes to protect against data race
|
||||
#define NAZARA_THREADSAFETY_CLOCK 0 // Clock
|
||||
#define NAZARA_THREADSAFETY_DIRECTORY 1 // Directory
|
||||
#define NAZARA_THREADSAFETY_DYNLIB 1 // DynLib
|
||||
#define NAZARA_THREADSAFETY_FILE 1 // File
|
||||
#define NAZARA_THREADSAFETY_LOG 1 // Log
|
||||
#define NAZARA_THREADSAFETY_REFCOUNTED 1 // RefCounted
|
||||
|
||||
// Number of spinlocks to use with the Windows critical sections (0 to disable)
|
||||
#define NAZARA_CORE_WINDOWS_CS_SPINLOCKS 4096
|
||||
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_DIRECTORY_HPP
|
||||
#define NAZARA_DIRECTORY_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
|
||||
#if defined(NAZARA_PLATFORM_WINDOWS)
|
||||
#define NAZARA_DIRECTORY_SEPARATOR '\\'
|
||||
#elif defined(NAZARA_PLATFORM_LINUX)
|
||||
#define NAZARA_DIRECTORY_SEPARATOR '/'
|
||||
#else
|
||||
#error OS not handled
|
||||
#define NAZARA_DIRECTORY_SEPARATOR '/'
|
||||
#endif
|
||||
|
||||
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_DIRECTORY
|
||||
#include <Nazara/Core/ThreadSafety.hpp>
|
||||
#else
|
||||
#include <Nazara/Core/ThreadSafetyOff.hpp>
|
||||
#endif
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class DirectoryImpl;
|
||||
|
||||
class NAZARA_CORE_API Directory
|
||||
{
|
||||
public:
|
||||
Directory();
|
||||
Directory(const String& dirPath);
|
||||
Directory(const Directory&) = delete;
|
||||
Directory(Directory&&) noexcept = default;
|
||||
~Directory();
|
||||
|
||||
void Close();
|
||||
|
||||
bool Exists() const;
|
||||
|
||||
String GetPath() const;
|
||||
String GetPattern() const;
|
||||
String GetResultName() const;
|
||||
String GetResultPath() const;
|
||||
UInt64 GetResultSize() const;
|
||||
|
||||
bool IsOpen() const;
|
||||
bool IsResultDirectory() const;
|
||||
|
||||
bool NextResult(bool skipDots = true);
|
||||
|
||||
bool Open();
|
||||
|
||||
void SetPath(const String& dirPath);
|
||||
void SetPattern(const String& pattern);
|
||||
|
||||
static bool Copy(const String& sourcePath, const String& destPath);
|
||||
static bool Create(const String& dirPath, bool recursive = false);
|
||||
static bool Exists(const String& dirPath);
|
||||
static String GetCurrent();
|
||||
static const char* GetCurrentFileRelativeToEngine(const char* currentFile);
|
||||
static bool Remove(const String& dirPath, bool emptyDirectory = false);
|
||||
static bool SetCurrent(const String& dirPath);
|
||||
|
||||
Directory& operator=(const Directory&) = delete;
|
||||
Directory& operator=(Directory&&) noexcept = delete;
|
||||
|
||||
private:
|
||||
NazaraMutexAttrib(m_mutex, mutable)
|
||||
|
||||
String m_dirPath;
|
||||
String m_pattern;
|
||||
MovablePtr<DirectoryImpl> m_impl;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DIRECTORY_HPP
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <filesystem>
|
||||
|
||||
#if defined(NAZARA_PLATFORM_WINDOWS)
|
||||
#define NAZARA_DYNLIB_EXTENSION ".dll"
|
||||
@@ -21,12 +21,6 @@
|
||||
#error OS not handled
|
||||
#endif
|
||||
|
||||
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_DYNLIB
|
||||
#include <Nazara/Core/ThreadSafety.hpp>
|
||||
#else
|
||||
#include <Nazara/Core/ThreadSafetyOff.hpp>
|
||||
#endif
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
using DynLibFunc = int (*)(); // "Generic" type of pointer to function
|
||||
@@ -38,25 +32,23 @@ namespace Nz
|
||||
public:
|
||||
DynLib();
|
||||
DynLib(const DynLib&) = delete;
|
||||
DynLib(DynLib&&) noexcept = default;
|
||||
DynLib(DynLib&&) noexcept;
|
||||
~DynLib();
|
||||
|
||||
String GetLastError() const;
|
||||
DynLibFunc GetSymbol(const String& symbol) const;
|
||||
std::string GetLastError() const;
|
||||
DynLibFunc GetSymbol(const char* symbol) const;
|
||||
|
||||
bool IsLoaded() const;
|
||||
|
||||
bool Load(const String& libraryPath);
|
||||
bool Load(const std::filesystem::path& libraryPath);
|
||||
void Unload();
|
||||
|
||||
DynLib& operator=(const DynLib&) = delete;
|
||||
DynLib& operator=(DynLib&& lib) noexcept = default;
|
||||
DynLib& operator=(DynLib&& lib) noexcept;
|
||||
|
||||
private:
|
||||
NazaraMutexAttrib(m_mutex, mutable)
|
||||
|
||||
mutable String m_lastError;
|
||||
MovablePtr<DynLibImpl> m_impl;
|
||||
mutable std::string m_lastError;
|
||||
std::unique_ptr<DynLibImpl> m_impl;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Nz
|
||||
static UInt32 GetFlags();
|
||||
static String GetLastError(const char** file = nullptr, unsigned int* line = nullptr, const char** function = nullptr);
|
||||
static unsigned int GetLastSystemErrorCode();
|
||||
static String GetLastSystemError(unsigned int code = GetLastSystemErrorCode());
|
||||
static std::string GetLastSystemError(unsigned int code = GetLastSystemErrorCode());
|
||||
|
||||
static void SetFlags(UInt32 flags);
|
||||
|
||||
@@ -41,6 +41,8 @@ namespace Nz
|
||||
static void Trigger(ErrorType type, const String& error, unsigned int line, const char* file, const char* function);
|
||||
|
||||
private:
|
||||
static const char* GetCurrentFileRelativeToEngine(const char* file);
|
||||
|
||||
static UInt32 s_flags;
|
||||
static String s_lastError;
|
||||
static const char* s_lastErrorFunction;
|
||||
|
||||
@@ -13,14 +13,9 @@
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
#include <Nazara/Core/Stream.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
|
||||
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_FILE
|
||||
#include <Nazara/Core/ThreadSafety.hpp>
|
||||
#else
|
||||
#include <Nazara/Core/ThreadSafetyOff.hpp>
|
||||
#endif
|
||||
|
||||
#include <ctime>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -30,13 +25,13 @@ namespace Nz
|
||||
{
|
||||
public:
|
||||
File();
|
||||
File(const String& filePath);
|
||||
File(const String& filePath, OpenModeFlags openMode);
|
||||
File(const std::filesystem::path& filePath);
|
||||
File(const std::filesystem::path& filePath, OpenModeFlags openMode);
|
||||
File(const File&) = delete;
|
||||
File(File&& file) noexcept = default;
|
||||
File(File&& file) noexcept;
|
||||
~File();
|
||||
|
||||
bool Copy(const String& newFilePath);
|
||||
void Copy(const std::filesystem::path& newFilePath);
|
||||
void Close();
|
||||
|
||||
bool Delete();
|
||||
@@ -46,56 +41,35 @@ namespace Nz
|
||||
|
||||
bool Exists() const;
|
||||
|
||||
time_t GetCreationTime() const;
|
||||
UInt64 GetCursorPos() const override;
|
||||
String GetDirectory() const override;
|
||||
String GetFileName() const;
|
||||
time_t GetLastAccessTime() const;
|
||||
time_t GetLastWriteTime() const;
|
||||
String GetPath() const override;
|
||||
std::filesystem::path GetDirectory() const override;
|
||||
std::filesystem::path GetFileName() const;
|
||||
std::filesystem::path GetPath() const override;
|
||||
UInt64 GetSize() const override;
|
||||
|
||||
bool IsOpen() const;
|
||||
|
||||
bool Open(OpenModeFlags openMode = OpenMode_NotOpen);
|
||||
bool Open(const String& filePath, OpenModeFlags openMode = OpenMode_NotOpen);
|
||||
|
||||
bool Rename(const String& newFilePath);
|
||||
bool Open(const std::filesystem::path& filePath, OpenModeFlags openMode = OpenMode_NotOpen);
|
||||
|
||||
bool SetCursorPos(CursorPosition pos, Int64 offset = 0);
|
||||
bool SetCursorPos(UInt64 offset) override;
|
||||
bool SetFile(const String& filePath);
|
||||
bool SetFile(const std::filesystem::path& filePath);
|
||||
bool SetSize(UInt64 size);
|
||||
|
||||
File& operator=(const String& filePath);
|
||||
File& operator=(const File&) = delete;
|
||||
File& operator=(File&& file) noexcept = default;
|
||||
File& operator=(File&& file) noexcept;
|
||||
|
||||
static String AbsolutePath(const String& filePath);
|
||||
static inline ByteArray ComputeHash(HashType hash, const String& filePath);
|
||||
static inline ByteArray ComputeHash(AbstractHash* hash, const String& filePath);
|
||||
static bool Copy(const String& sourcePath, const String& targetPath);
|
||||
static bool Delete(const String& filePath);
|
||||
static bool Exists(const String& filePath);
|
||||
static time_t GetCreationTime(const String& filePath);
|
||||
static String GetDirectory(const String& filePath);
|
||||
static time_t GetLastAccessTime(const String& filePath);
|
||||
static time_t GetLastWriteTime(const String& filePath);
|
||||
static UInt64 GetSize(const String& filePath);
|
||||
static bool IsAbsolute(const String& filePath);
|
||||
static String NormalizePath(const String& filePath);
|
||||
static String NormalizeSeparators(const String& filePath);
|
||||
static bool Rename(const String& sourcePath, const String& targetPath);
|
||||
static inline ByteArray ComputeHash(HashType hash, const std::filesystem::path& filePath);
|
||||
static inline ByteArray ComputeHash(AbstractHash* hash, const std::filesystem::path& filePath);
|
||||
|
||||
private:
|
||||
NazaraMutexAttrib(m_mutex, mutable)
|
||||
|
||||
void FlushStream() override;
|
||||
std::size_t ReadBlock(void* buffer, std::size_t size) override;
|
||||
std::size_t WriteBlock(const void* buffer, std::size_t size) override;
|
||||
|
||||
String m_filePath;
|
||||
MovablePtr<FileImpl> m_impl;
|
||||
std::filesystem::path m_filePath;
|
||||
std::unique_ptr<FileImpl> m_impl;
|
||||
};
|
||||
|
||||
NAZARA_CORE_API bool HashAppend(AbstractHash* hash, const File& originalFile);
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Nz
|
||||
* \param filePath Path for the file
|
||||
*/
|
||||
|
||||
inline ByteArray File::ComputeHash(HashType hash, const String& filePath)
|
||||
inline ByteArray File::ComputeHash(HashType hash, const std::filesystem::path& filePath)
|
||||
{
|
||||
return ComputeHash(AbstractHash::Get(hash).get(), filePath);
|
||||
}
|
||||
@@ -28,7 +28,7 @@ namespace Nz
|
||||
* \param filePath Path for the file
|
||||
*/
|
||||
|
||||
inline ByteArray File::ComputeHash(AbstractHash* hash, const String& filePath)
|
||||
inline ByteArray File::ComputeHash(AbstractHash* hash, const std::filesystem::path& filePath)
|
||||
{
|
||||
return Nz::ComputeHash(hash, File(filePath));
|
||||
}
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/AbstractLogger.hpp>
|
||||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Core/StdLogger.hpp>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -35,7 +36,8 @@ namespace Nz
|
||||
FileLogger& operator=(FileLogger&&) noexcept = default;
|
||||
|
||||
private:
|
||||
File m_outputFile;
|
||||
std::fstream m_outputFile;
|
||||
std::filesystem::path m_outputPath;
|
||||
StdLogger m_stdLogger;
|
||||
bool m_forceStdOutput;
|
||||
bool m_stdReplicationEnabled;
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_LOCKGUARD_HPP
|
||||
#define NAZARA_LOCKGUARD_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Mutex;
|
||||
|
||||
class LockGuard
|
||||
{
|
||||
public:
|
||||
inline LockGuard(Mutex& mutex, bool lock = true);
|
||||
inline ~LockGuard();
|
||||
|
||||
inline void Lock();
|
||||
inline bool TryLock();
|
||||
inline void Unlock();
|
||||
|
||||
private:
|
||||
Mutex& m_mutex;
|
||||
bool m_locked;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/LockGuard.inl>
|
||||
|
||||
#endif // NAZARA_LOCKGUARD_HPP
|
||||
@@ -1,83 +0,0 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/LockGuard.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Mutex.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \class Nz::LockGuard
|
||||
* \brief Core class that represents a mutex wrapper that provides a convenient RAII-style mechanism
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs a LockGuard object with a mutex
|
||||
*
|
||||
* \param mutex Mutex to lock
|
||||
* \param lock Should the mutex be locked by the constructor
|
||||
*/
|
||||
inline LockGuard::LockGuard(Mutex& mutex, bool lock) :
|
||||
m_mutex(mutex),
|
||||
m_locked(false)
|
||||
{
|
||||
if (lock)
|
||||
{
|
||||
m_mutex.Lock();
|
||||
m_locked = true;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destructs a LockGuard object and unlocks the mutex if it was previously locked
|
||||
*/
|
||||
inline LockGuard::~LockGuard()
|
||||
{
|
||||
if (m_locked)
|
||||
m_mutex.Unlock();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Locks the underlying mutex
|
||||
*
|
||||
* \see Mutex::Lock
|
||||
*/
|
||||
inline void LockGuard::Lock()
|
||||
{
|
||||
NazaraAssert(!m_locked, "Mutex is already locked");
|
||||
|
||||
m_mutex.Lock();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Tries to lock the underlying mutex
|
||||
*
|
||||
* \see Mutex::TryLock
|
||||
*
|
||||
* \return true if the lock was acquired successfully
|
||||
*/
|
||||
inline bool LockGuard::TryLock()
|
||||
{
|
||||
NazaraAssert(!m_locked, "Mutex is already locked");
|
||||
|
||||
return m_mutex.TryLock();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Unlocks the underlying mutex
|
||||
*
|
||||
* \see Mutex::Unlock
|
||||
*/
|
||||
inline void LockGuard::Unlock()
|
||||
{
|
||||
NazaraAssert(m_locked, "Mutex is not locked");
|
||||
|
||||
m_mutex.Unlock();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
@@ -11,12 +11,6 @@
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
|
||||
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_LOG
|
||||
#include <Nazara/Core/ThreadSafety.hpp>
|
||||
#else
|
||||
#include <Nazara/Core/ThreadSafetyOff.hpp>
|
||||
#endif
|
||||
|
||||
#ifdef NAZARA_DEBUG
|
||||
#define NazaraDebug(txt) NazaraNotice(txt)
|
||||
#else
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_MUTEX_HPP
|
||||
#define NAZARA_MUTEX_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class MutexImpl;
|
||||
|
||||
class NAZARA_CORE_API Mutex
|
||||
{
|
||||
friend class ConditionVariable;
|
||||
|
||||
public:
|
||||
Mutex();
|
||||
Mutex(const Mutex&) = delete;
|
||||
Mutex(Mutex&&) noexcept = default;
|
||||
~Mutex();
|
||||
|
||||
void Lock();
|
||||
bool TryLock();
|
||||
void Unlock();
|
||||
|
||||
Mutex& operator=(const Mutex&) = delete;
|
||||
Mutex& operator=(Mutex&&) noexcept = default;
|
||||
|
||||
private:
|
||||
MovablePtr<MutexImpl> m_impl;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Mutex.inl>
|
||||
|
||||
#endif // NAZARA_MUTEX_HPP
|
||||
@@ -1,17 +0,0 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Mutex.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \class Nz::Mutex
|
||||
*/
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <filesystem>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -24,23 +24,32 @@ namespace Nz
|
||||
PluginManager() = delete;
|
||||
~PluginManager() = delete;
|
||||
|
||||
static void AddDirectory(const String& directoryPath);
|
||||
static void AddDirectory(const std::filesystem::path& directoryPath);
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static bool Mount(Plugin plugin);
|
||||
static bool Mount(const String& pluginPath, bool appendExtension = true);
|
||||
static bool Mount(const std::filesystem::path& pluginPath, bool appendExtension = true);
|
||||
|
||||
static void RemoveDirectory(const String& directoryPath);
|
||||
static void RemoveDirectory(const std::filesystem::path& directoryPath);
|
||||
|
||||
static void Unmount(Plugin plugin);
|
||||
static void Unmount(const String& pluginPath);
|
||||
static void Unmount(const std::filesystem::path& pluginPath);
|
||||
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
static std::set<String> s_directories;
|
||||
static std::unordered_map<String, DynLib*> s_plugins;
|
||||
// https://stackoverflow.com/questions/51065244/is-there-no-standard-hash-for-stdfilesystempath
|
||||
struct PathHash
|
||||
{
|
||||
std::size_t operator()(const std::filesystem::path& p) const
|
||||
{
|
||||
return hash_value(p);
|
||||
}
|
||||
};
|
||||
|
||||
static std::set<std::filesystem::path> s_directories;
|
||||
static std::unordered_map<std::filesystem::path, std::unique_ptr<DynLib>, PathHash> s_plugins;
|
||||
static bool s_initialized;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10,12 +10,6 @@
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <atomic>
|
||||
|
||||
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_REFCOUNTED
|
||||
#include <Nazara/Core/ThreadSafety.hpp>
|
||||
#else
|
||||
#include <Nazara/Core/ThreadSafetyOff.hpp>
|
||||
#endif
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API RefCounted
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#define NAZARA_RESOURCE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <filesystem>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -20,15 +20,15 @@ namespace Nz
|
||||
Resource(Resource&&) noexcept = default;
|
||||
virtual ~Resource();
|
||||
|
||||
const String& GetFilePath() const;
|
||||
const std::filesystem::path& GetFilePath() const;
|
||||
|
||||
void SetFilePath(const String& filePath);
|
||||
void SetFilePath(const std::filesystem::path& filePath);
|
||||
|
||||
Resource& operator=(const Resource&) = default;
|
||||
Resource& operator=(Resource&&) noexcept = default;
|
||||
|
||||
private:
|
||||
String m_filePath;
|
||||
std::filesystem::path m_filePath;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceParameters.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <filesystem>
|
||||
#include <list>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
@@ -29,8 +29,8 @@ namespace Nz
|
||||
friend Type;
|
||||
|
||||
public:
|
||||
using ExtensionGetter = bool (*)(const String& extension);
|
||||
using FileLoader = ObjectRef<Type> (*)(const String& filePath, const Parameters& parameters);
|
||||
using ExtensionGetter = bool (*)(const std::string& extension);
|
||||
using FileLoader = ObjectRef<Type> (*)(const std::filesystem::path& filePath, const Parameters& parameters);
|
||||
using MemoryLoader = ObjectRef<Type> (*)(const void* data, std::size_t size, const Parameters& parameters);
|
||||
using StreamChecker = Ternary (*)(Stream& stream, const Parameters& parameters);
|
||||
using StreamLoader = ObjectRef<Type> (*)(Stream& stream, const Parameters& parameters);
|
||||
@@ -38,9 +38,9 @@ namespace Nz
|
||||
ResourceLoader() = delete;
|
||||
~ResourceLoader() = delete;
|
||||
|
||||
static bool IsExtensionSupported(const String& extension);
|
||||
static bool IsExtensionSupported(const std::string& extension);
|
||||
|
||||
static ObjectRef<Type> LoadFromFile(const String& filePath, const Parameters& parameters = Parameters());
|
||||
static ObjectRef<Type> LoadFromFile(const std::filesystem::path& filePath, const Parameters& parameters = Parameters());
|
||||
static ObjectRef<Type> LoadFromMemory(const void* data, std::size_t size, const Parameters& parameters = Parameters());
|
||||
static ObjectRef<Type> LoadFromStream(Stream& stream, const Parameters& parameters = Parameters());
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Core/MemoryView.hpp>
|
||||
#include <Nazara/Core/Stream.hpp>
|
||||
#include <Nazara/Core/StringExt.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
@@ -24,7 +25,7 @@ namespace Nz
|
||||
* \param extension Extension of the file
|
||||
*/
|
||||
template<typename Type, typename Parameters>
|
||||
bool ResourceLoader<Type, Parameters>::IsExtensionSupported(const String& extension)
|
||||
bool ResourceLoader<Type, Parameters>::IsExtensionSupported(const std::string& extension)
|
||||
{
|
||||
for (Loader& loader : Type::s_loaders)
|
||||
{
|
||||
@@ -53,19 +54,21 @@ namespace Nz
|
||||
* \remark Produces a NazaraError if all loaders failed or no loader was found
|
||||
*/
|
||||
template<typename Type, typename Parameters>
|
||||
ObjectRef<Type> ResourceLoader<Type, Parameters>::LoadFromFile(const String& filePath, const Parameters& parameters)
|
||||
ObjectRef<Type> ResourceLoader<Type, Parameters>::LoadFromFile(const std::filesystem::path& filePath, const Parameters& parameters)
|
||||
{
|
||||
NazaraAssert(parameters.IsValid(), "Invalid parameters");
|
||||
|
||||
String path = File::NormalizePath(filePath);
|
||||
String ext = path.SubStringFrom('.', -1, true).ToLower();
|
||||
if (ext.IsEmpty())
|
||||
std::string ext = ToLower(filePath.extension().generic_u8string());
|
||||
if (ext.empty())
|
||||
{
|
||||
NazaraError("Failed to get file extension from \"" + filePath + '"');
|
||||
NazaraError("Failed to get file extension from \"" + filePath.generic_u8string() + '"');
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
File file(path); // Open only if needed
|
||||
if (ext[0] == '.')
|
||||
ext.erase(ext.begin());
|
||||
|
||||
File file(filePath.generic_u8string()); // Open only if needed
|
||||
|
||||
bool found = false;
|
||||
for (Loader& loader : Type::s_loaders)
|
||||
@@ -82,7 +85,7 @@ namespace Nz
|
||||
{
|
||||
if (!file.Open(OpenMode_ReadOnly))
|
||||
{
|
||||
NazaraError("Failed to load file: unable to open \"" + filePath + '"');
|
||||
NazaraError("Failed to load file: unable to open \"" + filePath.generic_u8string() + '"');
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,19 +25,28 @@ namespace Nz
|
||||
|
||||
static void Clear();
|
||||
|
||||
static ObjectRef<Type> Get(const String& filePath);
|
||||
static ObjectRef<Type> Get(const std::filesystem::path& filePath);
|
||||
static const Parameters& GetDefaultParameters();
|
||||
|
||||
static void Purge();
|
||||
static void Register(const String& filePath, ObjectRef<Type> resource);
|
||||
static void Register(const std::filesystem::path& filePath, ObjectRef<Type> resource);
|
||||
static void SetDefaultParameters(const Parameters& params);
|
||||
static void Unregister(const String& filePath);
|
||||
static void Unregister(const std::filesystem::path& filePath);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
using ManagerMap = std::unordered_map<String, ObjectRef<Type>>;
|
||||
// https://stackoverflow.com/questions/51065244/is-there-no-standard-hash-for-stdfilesystempath
|
||||
struct PathHash
|
||||
{
|
||||
std::size_t operator()(const std::filesystem::path& p) const
|
||||
{
|
||||
return hash_value(p);
|
||||
}
|
||||
};
|
||||
|
||||
using ManagerMap = std::unordered_map<std::filesystem::path, ObjectRef<Type>, PathHash>;
|
||||
using ManagerParams = Parameters;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -31,20 +31,20 @@ namespace Nz
|
||||
* \param filePath Path to the asset that will be loaded
|
||||
*/
|
||||
template<typename Type, typename Parameters>
|
||||
ObjectRef<Type> ResourceManager<Type, Parameters>::Get(const String& filePath)
|
||||
ObjectRef<Type> ResourceManager<Type, Parameters>::Get(const std::filesystem::path& filePath)
|
||||
{
|
||||
String absolutePath = File::AbsolutePath(filePath);
|
||||
std::filesystem::path absolutePath = std::filesystem::canonical(filePath);
|
||||
auto it = Type::s_managerMap.find(absolutePath);
|
||||
if (it == Type::s_managerMap.end())
|
||||
{
|
||||
ObjectRef<Type> resource = Type::LoadFromFile(absolutePath, GetDefaultParameters());
|
||||
if (!resource)
|
||||
{
|
||||
NazaraError("Failed to load resource from file: " + absolutePath);
|
||||
NazaraError("Failed to load resource from file: " + absolutePath.generic_u8string());
|
||||
return ObjectRef<Type>();
|
||||
}
|
||||
|
||||
NazaraDebug("Loaded resource from file " + absolutePath);
|
||||
NazaraDebug("Loaded resource from file " + absolutePath.generic_u8string());
|
||||
|
||||
it = Type::s_managerMap.insert(std::make_pair(absolutePath, resource)).first;
|
||||
}
|
||||
@@ -74,7 +74,7 @@ namespace Nz
|
||||
const ObjectRef<Type>& ref = it->second;
|
||||
if (ref->GetReferenceCount() == 1) // Are we the only ones to own the resource ?
|
||||
{
|
||||
NazaraDebug("Purging resource from file " + ref->GetFilePath());
|
||||
NazaraDebug("Purging resource from file " + ref->GetFilePath().generic_u8string());
|
||||
Type::s_managerMap.erase(it++); // Then we erase it
|
||||
}
|
||||
else
|
||||
@@ -89,9 +89,9 @@ namespace Nz
|
||||
* \param resource Object to associate with
|
||||
*/
|
||||
template<typename Type, typename Parameters>
|
||||
void ResourceManager<Type, Parameters>::Register(const String& filePath, ObjectRef<Type> resource)
|
||||
void ResourceManager<Type, Parameters>::Register(const std::filesystem::path& filePath, ObjectRef<Type> resource)
|
||||
{
|
||||
String absolutePath = File::AbsolutePath(filePath);
|
||||
std::filesystem::path absolutePath = std::filesystem::canonical(filePath);
|
||||
|
||||
Type::s_managerMap[absolutePath] = resource;
|
||||
}
|
||||
@@ -113,9 +113,9 @@ namespace Nz
|
||||
* \param filePath Path for the resource
|
||||
*/
|
||||
template<typename Type, typename Parameters>
|
||||
void ResourceManager<Type, Parameters>::Unregister(const String& filePath)
|
||||
void ResourceManager<Type, Parameters>::Unregister(const std::filesystem::path& filePath)
|
||||
{
|
||||
String absolutePath = File::AbsolutePath(filePath);
|
||||
std::filesystem::path absolutePath = std::filesystem::canonical(filePath);
|
||||
|
||||
Type::s_managerMap.erase(absolutePath);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceParameters.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <filesystem>
|
||||
#include <list>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
@@ -27,18 +28,18 @@ namespace Nz
|
||||
friend Type;
|
||||
|
||||
public:
|
||||
using ExtensionGetter = bool (*)(const String& extension);
|
||||
using FormatQuerier = bool (*)(const String& format);
|
||||
using FileSaver = bool (*)(const Type& resource, const String& filePath, const Parameters& parameters);
|
||||
using StreamSaver = bool (*)(const Type& resource, const String& format, Stream& stream, const Parameters& parameters);
|
||||
using ExtensionGetter = bool (*)(const std::string& extension);
|
||||
using FormatQuerier = bool (*)(const std::string& format);
|
||||
using FileSaver = bool (*)(const Type& resource, const std::filesystem::path& filePath, const Parameters& parameters);
|
||||
using StreamSaver = bool (*)(const Type& resource, const std::string& format, Stream& stream, const Parameters& parameters);
|
||||
|
||||
ResourceSaver() = delete;
|
||||
~ResourceSaver() = delete;
|
||||
|
||||
static bool IsFormatSupported(const String& extension);
|
||||
static bool IsFormatSupported(const std::string& extension);
|
||||
|
||||
static bool SaveToFile(const Type& resource, const String& filePath, const Parameters& parameters = Parameters());
|
||||
static bool SaveToStream(const Type& resource, Stream& stream, const String& format, const Parameters& parameters = Parameters());
|
||||
static bool SaveToFile(const Type& resource, const std::filesystem::path& filePath, const Parameters& parameters = Parameters());
|
||||
static bool SaveToStream(const Type& resource, Stream& stream, const std::string& format, const Parameters& parameters = Parameters());
|
||||
|
||||
static void RegisterSaver(FormatQuerier formatQuerier, StreamSaver streamSaver, FileSaver fileSaver = nullptr);
|
||||
static void UnregisterSaver(FormatQuerier formatQuerier, StreamSaver streamSaver, FileSaver fileSaver = nullptr);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Core/MemoryView.hpp>
|
||||
#include <Nazara/Core/Stream.hpp>
|
||||
#include <Nazara/Core/StringExt.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
@@ -24,7 +25,7 @@ namespace Nz
|
||||
* \param extension Extension of the file
|
||||
*/
|
||||
template<typename Type, typename Parameters>
|
||||
bool ResourceSaver<Type, Parameters>::IsFormatSupported(const String& extension)
|
||||
bool ResourceSaver<Type, Parameters>::IsFormatSupported(const std::string& extension)
|
||||
{
|
||||
for (Saver& saver : Type::s_savers)
|
||||
{
|
||||
@@ -51,19 +52,18 @@ namespace Nz
|
||||
* \see SaveToStream
|
||||
*/
|
||||
template<typename Type, typename Parameters>
|
||||
bool ResourceSaver<Type, Parameters>::SaveToFile(const Type& resource, const String& filePath, const Parameters& parameters)
|
||||
bool ResourceSaver<Type, Parameters>::SaveToFile(const Type& resource, const std::filesystem::path& filePath, const Parameters& parameters)
|
||||
{
|
||||
NazaraAssert(parameters.IsValid(), "Invalid parameters");
|
||||
|
||||
String path = File::NormalizePath(filePath);
|
||||
String ext = path.SubStringFrom('.', -1, true).ToLower();
|
||||
if (ext.IsEmpty())
|
||||
std::string ext = ToLower(filePath.extension().generic_u8string());
|
||||
if (ext.empty())
|
||||
{
|
||||
NazaraError("Failed to get file extension from \"" + filePath + '"');
|
||||
NazaraError("Failed to get file extension from \"" + filePath.generic_u8string() + '"');
|
||||
return false;
|
||||
}
|
||||
|
||||
File file(path); // Opened only is required
|
||||
File file(filePath.generic_u8string()); // Opened only is required
|
||||
|
||||
bool found = false;
|
||||
for (Saver& saver : Type::s_savers)
|
||||
@@ -86,7 +86,7 @@ namespace Nz
|
||||
{
|
||||
if (!file.Open(OpenMode_WriteOnly | OpenMode_Truncate))
|
||||
{
|
||||
NazaraError("Failed to save to file: unable to open \"" + filePath + "\" in write mode");
|
||||
NazaraError("Failed to save to file: unable to open \"" + filePath.generic_u8string() + "\" in write mode");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ namespace Nz
|
||||
* \see SaveToFile
|
||||
*/
|
||||
template<typename Type, typename Parameters>
|
||||
bool ResourceSaver<Type, Parameters>::SaveToStream(const Type& resource, Stream& stream, const String& format, const Parameters& parameters)
|
||||
bool ResourceSaver<Type, Parameters>::SaveToStream(const Type& resource, Stream& stream, const std::string& format, const Parameters& parameters)
|
||||
{
|
||||
NazaraAssert(stream.IsWritable(), "Stream is not writable");
|
||||
NazaraAssert(parameters.IsValid(), "Invalid parameters");
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SEMAPHORE_HPP
|
||||
#define NAZARA_SEMAPHORE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class SemaphoreImpl;
|
||||
|
||||
class NAZARA_CORE_API Semaphore
|
||||
{
|
||||
public:
|
||||
Semaphore(unsigned int count);
|
||||
Semaphore(const Semaphore&) = delete;
|
||||
Semaphore(Semaphore&&) noexcept = default;
|
||||
~Semaphore();
|
||||
|
||||
unsigned int GetCount() const;
|
||||
|
||||
void Post();
|
||||
|
||||
void Wait();
|
||||
bool Wait(UInt32 timeout);
|
||||
|
||||
Semaphore& operator=(const Semaphore&) = delete;
|
||||
Semaphore& operator=(Semaphore&&) noexcept = default;
|
||||
|
||||
private:
|
||||
MovablePtr<SemaphoreImpl> m_impl;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_SEMAPHORE_HPP
|
||||
@@ -46,7 +46,7 @@ namespace Nz
|
||||
operator T*() const;
|
||||
T& operator*() const;
|
||||
T* operator->() const;
|
||||
T& operator[](int index) const;
|
||||
T& operator[](std::size_t index) const;
|
||||
|
||||
SparsePtr& operator=(const SparsePtr& ptr) = default;
|
||||
|
||||
|
||||
@@ -247,7 +247,7 @@ namespace Nz
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
T& SparsePtr<T>::operator[](int index) const
|
||||
T& SparsePtr<T>::operator[](std::size_t index) const
|
||||
{
|
||||
return *reinterpret_cast<T*>(m_ptr + index * m_stride);
|
||||
}
|
||||
|
||||
@@ -10,11 +10,12 @@
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Endianness.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <filesystem>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ByteArray;
|
||||
class String; //< Do not include String.hpp in this file
|
||||
|
||||
class NAZARA_CORE_API Stream
|
||||
{
|
||||
@@ -30,15 +31,15 @@ namespace Nz
|
||||
inline void Flush();
|
||||
|
||||
virtual UInt64 GetCursorPos() const = 0;
|
||||
virtual String GetDirectory() const;
|
||||
virtual String GetPath() const;
|
||||
virtual std::filesystem::path GetDirectory() const;
|
||||
virtual std::filesystem::path GetPath() const;
|
||||
inline OpenModeFlags GetOpenMode() const;
|
||||
inline StreamOptionFlags GetStreamOptions() const;
|
||||
|
||||
virtual UInt64 GetSize() const = 0;
|
||||
|
||||
inline std::size_t Read(void* buffer, std::size_t size);
|
||||
virtual String ReadLine(unsigned int lineSize = 0);
|
||||
virtual std::string ReadLine(unsigned int lineSize = 0);
|
||||
|
||||
inline bool IsReadable() const;
|
||||
inline bool IsSequential() const;
|
||||
|
||||
61
include/Nazara/Core/StringExt.hpp
Normal file
61
include/Nazara/Core/StringExt.hpp
Normal file
@@ -0,0 +1,61 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_STRING_EXT_HPP
|
||||
#define NAZARA_CORE_STRING_EXT_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Unicode.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct CaseIndependent {};
|
||||
struct UnicodeAware {};
|
||||
|
||||
// std::string is assumed to contains UTF-8
|
||||
NAZARA_CORE_API std::string FromUtf16String(const char16_t* u16str);
|
||||
NAZARA_CORE_API std::string FromUtf16String(const std::u16string_view& u16str);
|
||||
|
||||
NAZARA_CORE_API std::string FromUtf32String(const char32_t* u32str);
|
||||
NAZARA_CORE_API std::string FromUtf32String(const std::u32string_view& u32str);
|
||||
|
||||
NAZARA_CORE_API std::string FromWideString(const wchar_t* wstr);
|
||||
NAZARA_CORE_API std::string FromWideString(const std::wstring_view& str);
|
||||
|
||||
inline bool IsNumber(const char* str);
|
||||
inline bool IsNumber(const std::string_view& str);
|
||||
|
||||
template<typename... Args> bool StartsWith(const std::string_view& str, const char* s, Args&&... args);
|
||||
inline bool StartsWith(const std::string_view& str, const std::string_view& s);
|
||||
NAZARA_CORE_API bool StartsWith(const std::string_view& str, const std::string_view& s, CaseIndependent);
|
||||
NAZARA_CORE_API bool StartsWith(const std::string_view& str, const std::string_view& s, CaseIndependent, UnicodeAware);
|
||||
|
||||
inline std::string ToLower(const char* str);
|
||||
NAZARA_CORE_API std::string ToLower(const std::string_view& str);
|
||||
|
||||
inline std::string ToLower(const char* str, UnicodeAware);
|
||||
NAZARA_CORE_API std::string ToLower(const std::string_view& str, UnicodeAware);
|
||||
|
||||
inline std::string ToUpper(const char* str);
|
||||
NAZARA_CORE_API std::string ToUpper(const std::string_view& str);
|
||||
|
||||
inline std::string ToUpper(const char* str, UnicodeAware);
|
||||
NAZARA_CORE_API std::string ToUpper(const std::string_view& str, UnicodeAware);
|
||||
|
||||
inline std::u16string ToUtf16String(const char* str);
|
||||
NAZARA_CORE_API std::u16string ToUtf16String(const std::string_view& str);
|
||||
|
||||
inline std::u32string ToUtf32String(const char* str);
|
||||
NAZARA_CORE_API std::u32string ToUtf32String(const std::string_view& str);
|
||||
|
||||
inline std::wstring ToWideString(const char* str);
|
||||
NAZARA_CORE_API std::wstring ToWideString(const std::string_view& str);
|
||||
}
|
||||
|
||||
#include <Nazara/Core/StringExt.inl>
|
||||
|
||||
#endif // NAZARA_ALGORITHM_CORE_HPP
|
||||
82
include/Nazara/Core/StringExt.inl
Normal file
82
include/Nazara/Core/StringExt.inl
Normal file
@@ -0,0 +1,82 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/StringExt.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
bool IsNumber(const char* str)
|
||||
{
|
||||
std::size_t size = std::strlen(str);
|
||||
return IsNumber(std::string_view(str, size));
|
||||
}
|
||||
|
||||
bool IsNumber(const std::string_view& str)
|
||||
{
|
||||
return !str.empty() && std::find_if(str.begin(), str.end(), [](unsigned char c) { return !std::isdigit(c); }) == str.end();
|
||||
}
|
||||
|
||||
template<typename... Args> bool StartsWith(const std::string_view& str, const char* s, Args&&... args)
|
||||
{
|
||||
std::size_t size = std::strlen(s);
|
||||
return StartsWith(str, std::string_view(s, size), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
bool StartsWith(const std::string_view& str, const std::string_view& s)
|
||||
{
|
||||
//FIXME: Replace with proper C++20 value once it's available
|
||||
#if __cplusplus > 201703L
|
||||
// C++20
|
||||
return str.starts_with(s);
|
||||
#else
|
||||
return str.compare(0, s.size(), s.data()) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline std::string ToLower(const char* str)
|
||||
{
|
||||
std::size_t size = std::strlen(str);
|
||||
return ToLower(std::string_view(str, size));
|
||||
}
|
||||
|
||||
inline std::string ToLower(const char* str, UnicodeAware)
|
||||
{
|
||||
std::size_t size = std::strlen(str);
|
||||
return ToLower(std::string_view(str, size), UnicodeAware{});
|
||||
}
|
||||
|
||||
inline std::string ToUpper(const char* str)
|
||||
{
|
||||
std::size_t size = std::strlen(str);
|
||||
return ToUpper(std::string_view(str, size));
|
||||
}
|
||||
|
||||
inline std::string ToUpper(const char* str, UnicodeAware)
|
||||
{
|
||||
std::size_t size = std::strlen(str);
|
||||
return ToUpper(std::string_view(str, size), UnicodeAware{});
|
||||
}
|
||||
|
||||
inline std::u16string ToUtf16String(const char* str)
|
||||
{
|
||||
std::size_t size = std::strlen(str);
|
||||
return ToUtf16String(std::string_view(str, size));
|
||||
}
|
||||
|
||||
inline std::u32string ToUtf32String(const char* str)
|
||||
{
|
||||
std::size_t size = std::strlen(str);
|
||||
return ToUtf32String(std::string_view(str, size));
|
||||
}
|
||||
|
||||
inline std::wstring ToWideString(const char* str)
|
||||
{
|
||||
std::size_t size = std::strlen(str);
|
||||
return ToWideString(std::string_view(str, size));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
@@ -1,75 +0,0 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_THREAD_HPP
|
||||
#define NAZARA_THREAD_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Functor.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
#include <iosfwd>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class String;
|
||||
class ThreadImpl;
|
||||
|
||||
class NAZARA_CORE_API Thread
|
||||
{
|
||||
public:
|
||||
class Id;
|
||||
|
||||
Thread();
|
||||
template<typename F> Thread(F function);
|
||||
template<typename F, typename... Args> Thread(F function, Args&&... args);
|
||||
template<typename C> Thread(void (C::*function)(), C* object);
|
||||
Thread(const Thread&) = delete;
|
||||
Thread(Thread&& other) noexcept = default;
|
||||
~Thread();
|
||||
|
||||
void Detach();
|
||||
Id GetId() const;
|
||||
bool IsJoinable() const;
|
||||
void Join();
|
||||
void SetName(const String& name);
|
||||
|
||||
Thread& operator=(const Thread&) = delete;
|
||||
Thread& operator=(Thread&& thread) noexcept = default;
|
||||
|
||||
static unsigned int HardwareConcurrency();
|
||||
static void SetCurrentThreadName(const String& name);
|
||||
static void Sleep(UInt32 milliseconds);
|
||||
|
||||
private:
|
||||
void CreateImpl(Functor* functor);
|
||||
|
||||
MovablePtr<ThreadImpl> m_impl;
|
||||
};
|
||||
|
||||
class NAZARA_CORE_API Thread::Id
|
||||
{
|
||||
friend Thread;
|
||||
|
||||
public:
|
||||
NAZARA_CORE_API friend bool operator==(const Id& lhs, const Id& rhs);
|
||||
NAZARA_CORE_API friend bool operator!=(const Id& lhs, const Id& rhs);
|
||||
NAZARA_CORE_API friend bool operator<(const Id& lhs, const Id& rhs);
|
||||
NAZARA_CORE_API friend bool operator<=(const Id& lhs, const Id& rhs);
|
||||
NAZARA_CORE_API friend bool operator>(const Id& lhs, const Id& rhs);
|
||||
NAZARA_CORE_API friend bool operator>=(const Id& lhs, const Id& rhs);
|
||||
|
||||
NAZARA_CORE_API friend std::ostream& operator<<(std::ostream& o, const Id& id);
|
||||
|
||||
private:
|
||||
explicit Id(ThreadImpl* thread);
|
||||
|
||||
ThreadImpl* m_id = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Thread.inl>
|
||||
|
||||
#endif // NAZARA_THREAD_HPP
|
||||
@@ -1,55 +0,0 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <utility>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \class Nz::Thread
|
||||
* \brief Core class that represents a thread
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Thread object with a function
|
||||
*
|
||||
* \param function Task the thread will execute in parallel
|
||||
*/
|
||||
|
||||
template<typename F>
|
||||
Thread::Thread(F function)
|
||||
{
|
||||
CreateImpl(new FunctorWithoutArgs<F>(function));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Thread object with a function and its parameters
|
||||
*
|
||||
* \param function Task the thread will execute in parallel
|
||||
* \param args Arguments of the function
|
||||
*/
|
||||
|
||||
template<typename F, typename... Args>
|
||||
Thread::Thread(F function, Args&&... args)
|
||||
{
|
||||
CreateImpl(new FunctorWithArgs<F, Args...>(function, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Thread object with a member function and its object
|
||||
*
|
||||
* \param function Task the thread will execute in parallel
|
||||
* \param object Object on which the method will be called
|
||||
*/
|
||||
|
||||
template<typename C>
|
||||
Thread::Thread(void (C::*function)(), C* object)
|
||||
{
|
||||
CreateImpl(new MemberWithoutArgs<C>(function, object));
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
@@ -1,23 +0,0 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// No header guard
|
||||
|
||||
#include <Nazara/Core/LockGuard.hpp>
|
||||
#include <Nazara/Core/Mutex.hpp>
|
||||
|
||||
// These macroes can change for any file which uses it in the same unit of compilation
|
||||
#undef NazaraLock
|
||||
#undef NazaraMutex
|
||||
#undef NazaraMutexAttrib
|
||||
#undef NazaraMutexLock
|
||||
#undef NazaraMutexUnlock
|
||||
#undef NazaraNamedLock
|
||||
|
||||
#define NazaraLock(mutex) Nz::LockGuard lock_mutex(mutex);
|
||||
#define NazaraMutex(name) Nz::Mutex name;
|
||||
#define NazaraMutexAttrib(name, attribute) attribute Mutex name;
|
||||
#define NazaraMutexLock(mutex) mutex.Lock();
|
||||
#define NazaraMutexUnlock(mutex) mutex.Unlock();
|
||||
#define NazaraNamedLock(mutex, name) Nz::LockGuard lock_##name(mutex);
|
||||
@@ -1,21 +0,0 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// No header guard
|
||||
|
||||
// These macroes can change for any file which uses it in the same unit of compilation
|
||||
#undef NazaraLock
|
||||
#undef NazaraMutex
|
||||
#undef NazaraMutexAttrib
|
||||
#undef NazaraMutexLock
|
||||
#undef NazaraMutexUnlock
|
||||
#undef NazaraNamedLock
|
||||
|
||||
#define NazaraLock(mutex)
|
||||
#define NazaraMutex(name)
|
||||
#define NazaraMutexAttrib(name, attribute)
|
||||
#define NazaraMutexLock(mutex)
|
||||
#define NazaraMutexUnlock(mutex)
|
||||
#define NazaraNamedLock(mutex, name)
|
||||
|
||||
Reference in New Issue
Block a user