First commit
This commit is contained in:
124
include/Nazara/Core/ByteArray.hpp
Normal file
124
include/Nazara/Core/ByteArray.hpp
Normal file
@@ -0,0 +1,124 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_BYTEARRAY_HPP
|
||||
#define NAZARA_BYTEARRAY_HPP
|
||||
|
||||
#define NAZARA_BYTEARRAY
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Hashable.hpp>
|
||||
#include <Nazara/Core/ThreadSafety.hpp>
|
||||
|
||||
class NzAbstractHash;
|
||||
class NzHashDigest;
|
||||
|
||||
class NAZARA_API NzByteArray : public NzHashable
|
||||
{
|
||||
public:
|
||||
struct SharedArray;
|
||||
|
||||
NzByteArray();
|
||||
NzByteArray(const nzUInt8* buffer, unsigned int bufferLength);
|
||||
NzByteArray(const NzByteArray& buffer);
|
||||
NzByteArray(NzByteArray&& buffer);
|
||||
NzByteArray(SharedArray* sharedArray);
|
||||
~NzByteArray();
|
||||
|
||||
unsigned int Capacity() const;
|
||||
|
||||
void Clear();
|
||||
|
||||
const nzUInt8* GetBuffer() const;
|
||||
unsigned int GetSize() const;
|
||||
|
||||
NzByteArray& Insert(int pos, const nzUInt8* buffer, unsigned int bufferLength);
|
||||
NzByteArray& Insert(int pos, const NzByteArray& byteArray);
|
||||
|
||||
bool IsEmpty() const;
|
||||
|
||||
void Reserve(unsigned int bufferSize);
|
||||
|
||||
NzByteArray& Resize(int size, nzUInt8 byte = '\0');
|
||||
NzByteArray Resized(int size, nzUInt8 byte = '\0') const;
|
||||
|
||||
NzByteArray SubArray(int startPos, int endPos = -1) const;
|
||||
|
||||
void Swap(NzByteArray& byteArray);
|
||||
|
||||
NzByteArray& Trim(nzUInt8 byte = '\0');
|
||||
NzByteArray Trimmed(nzUInt8 byte = '\0') const;
|
||||
|
||||
// Méthodes compatibles STD
|
||||
nzUInt8* begin();
|
||||
const nzUInt8* begin() const;
|
||||
nzUInt8* end();
|
||||
const nzUInt8* end() const;
|
||||
void push_front(nzUInt8 c);
|
||||
void push_back(nzUInt8 c);
|
||||
/*nzUInt8* rbegin();
|
||||
const nzUInt8* rbegin() const;
|
||||
nzUInt8* rend();
|
||||
const nzUInt8* rend() const;*/
|
||||
|
||||
typedef const nzUInt8& const_reference;
|
||||
typedef nzUInt8* iterator;
|
||||
//typedef nzUInt8* reverse_iterator;
|
||||
typedef nzUInt8 value_type;
|
||||
// Méthodes compatibles STD
|
||||
|
||||
nzUInt8& operator[](unsigned int pos);
|
||||
nzUInt8 operator[](unsigned int pos) const;
|
||||
|
||||
NzByteArray& operator=(const NzByteArray& byteArray);
|
||||
NzByteArray& operator=(NzByteArray&& byteArray);
|
||||
|
||||
NzByteArray operator+(const NzByteArray& byteArray) const;
|
||||
NzByteArray& operator+=(const NzByteArray& byteArray);
|
||||
|
||||
static int Compare(const NzByteArray& first, const NzByteArray& second);
|
||||
|
||||
struct NAZARA_API SharedArray
|
||||
{
|
||||
SharedArray() :
|
||||
refCount(1)
|
||||
{
|
||||
}
|
||||
|
||||
SharedArray(unsigned int bufferSize, unsigned int arraySize, unsigned short referenceCount, nzUInt8* ptr) :
|
||||
allocatedSize(bufferSize),
|
||||
size(arraySize),
|
||||
refCount(referenceCount),
|
||||
buffer(ptr)
|
||||
{
|
||||
}
|
||||
|
||||
unsigned int allocatedSize;
|
||||
unsigned int size;
|
||||
unsigned short refCount;
|
||||
nzUInt8* buffer;
|
||||
|
||||
NazaraMutex(mutex)
|
||||
};
|
||||
|
||||
static SharedArray emptyArray;
|
||||
|
||||
private:
|
||||
void EnsureOwnership();
|
||||
bool FillHash(NzHashImpl* hash) const;
|
||||
void ReleaseArray();
|
||||
|
||||
SharedArray* m_sharedArray;
|
||||
};
|
||||
|
||||
namespace std
|
||||
{
|
||||
NAZARA_API void swap(NzByteArray& lhs, NzByteArray& rhs);
|
||||
}
|
||||
|
||||
#undef NAZARA_BYTEARRAY
|
||||
|
||||
#endif // NAZARA_BYTEARRAY_HPP
|
||||
45
include/Nazara/Core/Clock.hpp
Normal file
45
include/Nazara/Core/Clock.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CLOCK_HPP
|
||||
#define NAZARA_CLOCK_HPP
|
||||
|
||||
#define NAZARA_CLOCK
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/ThreadSafety.hpp>
|
||||
|
||||
class NAZARA_API NzClock
|
||||
{
|
||||
public:
|
||||
NzClock();
|
||||
|
||||
float GetSeconds() const;
|
||||
nzUInt64 GetMicroseconds() const;
|
||||
nzUInt64 GetMilliseconds() const;
|
||||
|
||||
bool IsPaused() const;
|
||||
|
||||
void Pause();
|
||||
void Restart();
|
||||
void Unpause();
|
||||
|
||||
private:
|
||||
NazaraMutexAttrib(m_mutex, mutable)
|
||||
|
||||
nzUInt64 m_elapsedTime;
|
||||
nzUInt64 m_refTime;
|
||||
bool m_paused;
|
||||
};
|
||||
|
||||
typedef nzUInt64 (*NzClockFunction)();
|
||||
|
||||
extern NAZARA_API NzClockFunction NzGetMicroseconds;
|
||||
extern NAZARA_API NzClockFunction NzGetMilliseconds;
|
||||
|
||||
#undef NAZARA_CLOCK
|
||||
|
||||
#endif // NAZARA_CLOCK_HPP
|
||||
79
include/Nazara/Core/Config.hpp
Normal file
79
include/Nazara/Core/Config.hpp
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
Nazara Engine
|
||||
|
||||
Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CONFIG_CORE_HPP
|
||||
#define NAZARA_CONFIG_CORE_HPP
|
||||
|
||||
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
|
||||
|
||||
// Appelle exit dès qu'une assertion est invalide
|
||||
#define NAZARA_CORE_EXIT_ON_ASSERT_FAILURE 1
|
||||
|
||||
// Teste les assertions
|
||||
#define NAZARA_CORE_ENABLE_ASSERTS 0
|
||||
|
||||
// Taille du buffer lors d'une lecture complète d'un fichier (ex: Hash)
|
||||
#define NAZARA_CORE_FILE_BUFFERSIZE 4096
|
||||
|
||||
// Le moteur doit-il incorporer les Unicode Character Data (Nécessaires pour faire fonctionner le flag NzString::HandleUTF8)
|
||||
#define NAZARA_CORE_INCLUDE_UNICODEDATA 0
|
||||
|
||||
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
|
||||
#define NAZARA_CORE_MEMORYLEAKTRACKER 0
|
||||
|
||||
// Standardise les séparateurs des dossiers selon le système d'exploitation courant
|
||||
#define NAZARA_CORE_NORMALIZE_DIRECTORY_SEPARATORS 1
|
||||
|
||||
// Précision des réels lors de la transformation en texte (Max. chiffres après la virgule)
|
||||
#define NAZARA_CORE_REAL_PRECISION 6
|
||||
|
||||
// Redirige la sortie du log sur le flux d'erreur standard (cerr) en cas d'erreur d'écriture (ou d'ouverture du fichier)
|
||||
#define NAZARA_CORE_REDIRECT_TO_CERR_ON_LOG_FAILURE 1
|
||||
|
||||
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
|
||||
#define NAZARA_CORE_SAFE 1
|
||||
|
||||
// Protége le noyau des accès concurrentiels
|
||||
#define NAZARA_CORE_THREADSAFE 1
|
||||
|
||||
#if NAZARA_CORE_THREADSAFE
|
||||
#define NAZARA_THREADSAFETY_APPLICATION 1 // NzApplication
|
||||
#define NAZARA_THREADSAFETY_CLOCK 0 // NzClock
|
||||
#define NAZARA_THREADSAFETY_DIRECTORY 1 // NzDirectory
|
||||
#define NAZARA_THREADSAFETY_DYNLIB 1 // NzDynLib
|
||||
#define NAZARA_THREADSAFETY_FILE 1 // NzFile
|
||||
#define NAZARA_THREADSAFETY_HASHDIGEST 0 // NzHashDigest
|
||||
#define NAZARA_THREADSAFETY_LOG 1 // NzLog
|
||||
#define NAZARA_THREADSAFETY_STRING 1 // NzString
|
||||
#define NAZARA_THREADSAFETY_STRINGSTREAM 0 // NzStringStream
|
||||
#endif
|
||||
|
||||
/*
|
||||
// Règle le temps entre le réveil du thread des timers et l'activation d'un timer (En millisecondes)
|
||||
#define NAZARA_CORE_TIMER_WAKEUPTIME 10
|
||||
*/
|
||||
|
||||
#endif // NAZARA_CONFIG_CORE_HPP
|
||||
11
include/Nazara/Core/Debug.hpp
Normal file
11
include/Nazara/Core/Debug.hpp
Normal file
@@ -0,0 +1,11 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#if NAZARA_CORE_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
|
||||
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
|
||||
|
||||
#define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete
|
||||
#define new new(__FILE__, __LINE__)
|
||||
#endif
|
||||
40
include/Nazara/Core/Debug/MemoryLeakTracker.hpp
Normal file
40
include/Nazara/Core/Debug/MemoryLeakTracker.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_DEBUG_MEMORYLEAKTRACKER_HPP
|
||||
#define NAZARA_DEBUG_MEMORYLEAKTRACKER_HPP
|
||||
|
||||
#define NAZARA_DEBUG_MEMORYLEAKTRACKER
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
class NAZARA_API NzMemoryManager
|
||||
{
|
||||
public:
|
||||
NzMemoryManager();
|
||||
~NzMemoryManager();
|
||||
|
||||
static void* Allocate(std::size_t size, bool multi, const char* file = nullptr, unsigned int line = 0);
|
||||
static void Free(void* pointer, bool multi);
|
||||
static void NextFree(const char* file, unsigned int line);
|
||||
|
||||
private:
|
||||
static void EnsureInitialization();
|
||||
static void Initialize();
|
||||
static char* TimeInfo();
|
||||
static void Uninitialize();
|
||||
};
|
||||
|
||||
NAZARA_API void* operator new(std::size_t size, const char* file, unsigned int line);
|
||||
NAZARA_API void* operator new[](std::size_t size, const char* file, unsigned int line);
|
||||
NAZARA_API void operator delete(void* ptr, const char* file, unsigned int line) throw();
|
||||
NAZARA_API void operator delete[](void* ptr, const char* file, unsigned int line) throw();
|
||||
|
||||
#undef NAZARA_DEBUG_MEMORYLEAKTRACKER
|
||||
|
||||
#endif // NAZARA_DEBUG_MEMORYLEAKTRACKER_HPP
|
||||
8
include/Nazara/Core/DebugOff.hpp
Normal file
8
include/Nazara/Core/DebugOff.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#if NAZARA_CORE_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
|
||||
#undef delete
|
||||
#undef new
|
||||
#endif
|
||||
64
include/Nazara/Core/Directory.hpp
Normal file
64
include/Nazara/Core/Directory.hpp
Normal file
@@ -0,0 +1,64 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_DIRECTORY_HPP
|
||||
#define NAZARA_DIRECTORY_HPP
|
||||
|
||||
#define NAZARA_DIRECTORY
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Core/ThreadSafety.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
|
||||
|
||||
class NzDirectoryImpl;
|
||||
|
||||
class NAZARA_API NzDirectory
|
||||
{
|
||||
public:
|
||||
NzDirectory();
|
||||
NzDirectory(const NzString& dirPath);
|
||||
~NzDirectory();
|
||||
|
||||
void Close();
|
||||
|
||||
NzString GetResultName() const;
|
||||
NzString GetResultPath() const;
|
||||
nzUInt64 GetResultSize() const;
|
||||
|
||||
bool IsResultDirectory() const;
|
||||
|
||||
bool NextResult(bool skipDots = true);
|
||||
|
||||
bool Open();
|
||||
|
||||
void SetDirectory(const NzString& dirPath);
|
||||
|
||||
static bool Copy(const NzString& sourcePath, const NzString& destPath);
|
||||
static bool Create(const NzString& dirPath, bool recursive = false);
|
||||
static bool Exists(const NzString& dirPath);
|
||||
static NzString GetCurrent();
|
||||
static bool Remove(const NzString& dirPath, bool emptyDirectory = false);
|
||||
static bool SetCurrent(const NzString& dirPath);
|
||||
|
||||
private:
|
||||
NazaraMutexAttrib(m_mutex, mutable)
|
||||
|
||||
NzString m_dirPath;
|
||||
NzDirectoryImpl* m_impl;
|
||||
};
|
||||
|
||||
#undef NAZARA_DIRECTORY
|
||||
|
||||
#endif // NAZARA_DIRECTORY_HPP
|
||||
45
include/Nazara/Core/DynLib.hpp
Normal file
45
include/Nazara/Core/DynLib.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_DYNLIB_HPP
|
||||
#define NAZARA_DYNLIB_HPP
|
||||
|
||||
#define NAZARA_DYNLIB
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Core/ThreadSafety.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
|
||||
class NzDynLibImpl;
|
||||
typedef int (*NzDynLibFunc)(); // Type "générique" de pointeur sur fonction
|
||||
|
||||
class NzDynLib : NzNonCopyable
|
||||
{
|
||||
friend class NzDynLibImpl;
|
||||
|
||||
public:
|
||||
NzDynLib(const NzString& libraryPath);
|
||||
~NzDynLib();
|
||||
|
||||
NzString GetLastError() const;
|
||||
NzDynLibFunc GetSymbol(const NzString& symbol) const;
|
||||
bool Load();
|
||||
void Unload();
|
||||
|
||||
private:
|
||||
void SetLastError(const NzString& error);
|
||||
|
||||
NazaraMutexAttrib(m_mutex, mutable)
|
||||
|
||||
NzString m_lastError;
|
||||
NzString m_path;
|
||||
NzDynLibImpl* m_impl;
|
||||
};
|
||||
|
||||
#undef NAZARA_DYNLIB
|
||||
|
||||
#endif // NAZARA_DYNLIB_HPP
|
||||
50
include/Nazara/Core/Endianness.hpp
Normal file
50
include/Nazara/Core/Endianness.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ENDIANNESS_HPP
|
||||
#define NAZARA_ENDIANNESS_HPP
|
||||
|
||||
#define NAZARA_ENDIANNESS
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
|
||||
#if defined(NAZARA_ENDIANNESS_BIGENDIAN)
|
||||
#define NAZARA_ENDIANNESS_DETECTED 1
|
||||
#define NazaraEndianness nzEndianness_BigEndian
|
||||
#elif defined(NAZARA_ENDIANNESS_LITTLEENDIAN)
|
||||
#define NAZARA_ENDIANNESS_DETECTED 1
|
||||
#define NazaraEndianness nzEndianness_LittleEndian
|
||||
#else
|
||||
#if defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || (defined(__MIPS__) && defined(__MISPEB__)) || \
|
||||
defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || defined(__sparc__) || defined(__hppa__)
|
||||
#define NAZARA_ENDIANNESS_DETECTED 1
|
||||
#define NAZARA_ENDIANNESS_BIGENDIAN
|
||||
#define NazaraEndianness nzEndianness_BigEndian
|
||||
#elif defined(__i386__) || defined(__i386) || defined(__X86__) || defined (__x86_64)
|
||||
#define NAZARA_ENDIANNESS_DETECTED 1
|
||||
#define NAZARA_ENDIANNESS_LITTLEENDIAN
|
||||
#define NazaraEndianness nzEndianness_LittleEndian
|
||||
#else
|
||||
#define NAZARA_ENDIANNESS_DETECTED 0
|
||||
#define NazaraEndianness NzGetPlatformEndianness()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
enum nzEndianness
|
||||
{
|
||||
nzEndianness_BigEndian,
|
||||
nzEndianness_LittleEndian,
|
||||
nzEndianness_Unknown
|
||||
};
|
||||
|
||||
inline void NzByteSwap(void* buffer, unsigned int size);
|
||||
inline nzEndianness NzGetPlatformEndianness();
|
||||
|
||||
#include <Nazara/Core/Endianness.inl>
|
||||
|
||||
#undef NAZARA_ENDIANNESS
|
||||
|
||||
#endif // NAZARA_ENDIANNESS_HPP
|
||||
38
include/Nazara/Core/Endianness.inl
Normal file
38
include/Nazara/Core/Endianness.inl
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
inline void NzByteSwap(void* buffer, unsigned int size)
|
||||
{
|
||||
nzUInt8* bytes = reinterpret_cast<nzUInt8*>(buffer);
|
||||
unsigned int i = 0;
|
||||
unsigned int j = size-1;
|
||||
|
||||
while (i < j)
|
||||
std::swap(bytes[i++], bytes[j--]);
|
||||
}
|
||||
|
||||
inline nzEndianness NzGetPlatformEndianness()
|
||||
{
|
||||
#if NAZARA_ENDIANNESS_DETECTED
|
||||
return NazaraEndianness;
|
||||
#else
|
||||
static nzEndianness endianness = nzEndianness_Unknown;
|
||||
static bool tested = false;
|
||||
if (!tested)
|
||||
{
|
||||
nzUInt32 i = 1;
|
||||
nzUInt8* p = reinterpret_cast<nzUInt8*>(&i);
|
||||
|
||||
// Méthode de récupération de l'endianness au runtime
|
||||
if (p[0] == 1)
|
||||
endianness = nzEndianness_LittleEndian;
|
||||
else if (p[3] == 1)
|
||||
endianness = nzEndianness_BigEndian;
|
||||
|
||||
tested = true;
|
||||
}
|
||||
|
||||
return endianness;
|
||||
#endif
|
||||
}
|
||||
39
include/Nazara/Core/Error.hpp
Normal file
39
include/Nazara/Core/Error.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ERROR_HPP
|
||||
#define NAZARA_ERROR_HPP
|
||||
|
||||
#define NAZARA_ERROR
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
|
||||
#if NAZARA_CORE_ENABLE_ASSERTS || defined(NAZARA_DEBUG)
|
||||
#define NazaraAssert(a, err) if (!(a)) NzError(nzErrorType_AssertFailed, err, __LINE__, __FILE__, NAZARA_FUNCTION)
|
||||
#else
|
||||
#define NazaraAssert(a, err)
|
||||
#endif
|
||||
|
||||
#define NazaraError(err) NzError(nzErrorType_Normal, err, __LINE__, __FILE__, NAZARA_FUNCTION)
|
||||
#define NazaraInternalError(err) NzError(nzErrorType_Internal, err, __LINE__, __FILE__, NAZARA_FUNCTION)
|
||||
#define NazaraWarning(err) NzError(nzErrorType_Warning, err, __LINE__, __FILE__, NAZARA_FUNCTION)
|
||||
|
||||
enum nzErrorType
|
||||
{
|
||||
nzErrorType_AssertFailed,
|
||||
nzErrorType_Internal,
|
||||
nzErrorType_Normal,
|
||||
nzErrorType_Warning
|
||||
};
|
||||
|
||||
NAZARA_API void NzError(nzErrorType type, const NzString& error, unsigned int line, const char* file, const char* function);
|
||||
NAZARA_API unsigned int NzGetLastSystemErrorCode();
|
||||
NAZARA_API NzString NzGetLastSystemError(unsigned int code = NzGetLastSystemErrorCode());
|
||||
|
||||
#undef NAZARA_ERROR
|
||||
|
||||
#endif // NAZARA_ERROR_HPP
|
||||
120
include/Nazara/Core/File.hpp
Normal file
120
include/Nazara/Core/File.hpp
Normal file
@@ -0,0 +1,120 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_FILE_HPP
|
||||
#define NAZARA_FILE_HPP
|
||||
|
||||
#define NAZARA_FILE
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Directory.hpp>
|
||||
#include <Nazara/Core/Endianness.hpp>
|
||||
#include <Nazara/Core/Hashable.hpp>
|
||||
#include <Nazara/Core/HashDigest.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Core/ThreadSafety.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
|
||||
class NzFileImpl;
|
||||
|
||||
class NAZARA_API NzFile : public NzHashable, 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(NzFile&& file);
|
||||
~NzFile();
|
||||
|
||||
bool Copy(const NzString& newFilePath);
|
||||
void Close();
|
||||
|
||||
bool Delete();
|
||||
|
||||
bool EndOfFile() const;
|
||||
|
||||
bool Exists() const;
|
||||
|
||||
void Flush();
|
||||
|
||||
time_t GetCreationTime() const;
|
||||
nzUInt64 GetCursorPos() const;
|
||||
NzString GetDirectoryPath() const;
|
||||
NzString GetFilePath() const;
|
||||
NzString GetFileName() const;
|
||||
time_t GetLastAccessTime() const;
|
||||
time_t GetLastWriteTime() const;
|
||||
NzString GetLine(unsigned int lineSize = 0);
|
||||
nzUInt64 GetSize() const;
|
||||
|
||||
bool IsOpen() const;
|
||||
|
||||
bool Open(unsigned long openMode = Current);
|
||||
|
||||
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(nzUInt64 offset);
|
||||
void SetEndianness(nzEndianness endianness);
|
||||
bool SetFile(const NzString& filePath);
|
||||
bool SetOpenMode(unsigned int openMode);
|
||||
|
||||
bool Write(const NzString& string);
|
||||
std::size_t Write(const void* buffer, std::size_t typeSize, unsigned int count);
|
||||
|
||||
NzFile& operator=(const NzString& filePath);
|
||||
NzFile& operator=(NzFile&& file);
|
||||
|
||||
static NzString AbsolutePath(const NzString& filePath);
|
||||
static bool Copy(const NzString& sourcePath, const NzString& targetPath);
|
||||
static bool Delete(const NzString& filePath);
|
||||
static bool Exists(const NzString& filePath);
|
||||
static time_t GetCreationTime(const NzString& filePath);
|
||||
static time_t GetLastAccessTime(const NzString& filePath);
|
||||
static time_t GetLastWriteTime(const NzString& filePath);
|
||||
static NzHashDigest GetHash(const NzString& filePath, nzHash hash);
|
||||
static NzHashDigest GetHash(const NzString& filePath, NzHashImpl* hash);
|
||||
static nzUInt64 GetSize(const NzString& filePath);
|
||||
static bool IsAbsolute(const NzString& path);
|
||||
static NzString NormalizePath(const NzString& filePath);
|
||||
static NzString NormalizeSeparators(const NzString& filePath);
|
||||
static bool Rename(const NzString& sourcePath, const NzString& targetPath);
|
||||
|
||||
private:
|
||||
bool FillHash(NzHashImpl* hash) const;
|
||||
|
||||
NazaraMutexAttrib(m_mutex, mutable)
|
||||
|
||||
nzEndianness m_endianness;
|
||||
NzString m_filePath;
|
||||
NzFileImpl* m_impl;
|
||||
unsigned int m_openMode;
|
||||
};
|
||||
|
||||
#undef NAZARA_FILE
|
||||
|
||||
#endif // NAZARA_FILE_HPP
|
||||
18
include/Nazara/Core/Format.hpp
Normal file
18
include/Nazara/Core/Format.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_FORMAT_HPP
|
||||
#define NAZARA_FORMAT_HPP
|
||||
|
||||
#define NAZARA_FORMAT
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
|
||||
template<typename... Args> NzString NzFormat(const NzString& str, Args... args);
|
||||
|
||||
#undef NAZARA_FORMAT
|
||||
|
||||
#endif // NAZARA_FORMAT_HPP
|
||||
33
include/Nazara/Core/Hash.hpp
Normal file
33
include/Nazara/Core/Hash.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_HASH_HPP
|
||||
#define NAZARA_HASH_HPP
|
||||
|
||||
#define NAZARA_HASH
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Hashable.hpp>
|
||||
#include <Nazara/Core/HashDigest.hpp>
|
||||
#include <Nazara/Core/HashImpl.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
|
||||
class NAZARA_API NzHash : NzNonCopyable
|
||||
{
|
||||
public:
|
||||
NzHash(nzHash hash);
|
||||
NzHash(NzHashImpl* hashImpl);
|
||||
~NzHash();
|
||||
|
||||
NzHashDigest Hash(const NzHashable& hashable);
|
||||
|
||||
private:
|
||||
NzHashImpl* m_impl;
|
||||
};
|
||||
|
||||
#undef NAZARA_HASH
|
||||
|
||||
#endif // NAZARA_HASH_HPP
|
||||
37
include/Nazara/Core/Hash/CRC32.hpp
Normal file
37
include/Nazara/Core/Hash/CRC32.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_HASH_CRC32_HPP
|
||||
#define NAZARA_HASH_CRC32_HPP
|
||||
|
||||
#define NAZARA_HASH_CRC32
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/HashDigest.hpp>
|
||||
#include <Nazara/Core/HashImpl.hpp>
|
||||
|
||||
struct NzHashCRC32_state;
|
||||
|
||||
class NAZARA_API NzHashCRC32 : public NzHashImpl
|
||||
{
|
||||
public:
|
||||
NzHashCRC32(nzUInt32 polynomial = 0x04c11db7);
|
||||
virtual ~NzHashCRC32();
|
||||
|
||||
void Append(const nzUInt8* data, unsigned int len);
|
||||
void Begin();
|
||||
NzHashDigest End();
|
||||
|
||||
static unsigned int GetDigestLength();
|
||||
static NzString GetHashName();
|
||||
|
||||
private:
|
||||
NzHashCRC32_state* m_state;
|
||||
};
|
||||
|
||||
#undef NAZARA_HASH_CRC32
|
||||
|
||||
#endif // NAZARA_HASH_CRC32_HPP
|
||||
38
include/Nazara/Core/Hash/Fletcher16.hpp
Normal file
38
include/Nazara/Core/Hash/Fletcher16.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_HASH_FLETCHER16_HPP
|
||||
#define NAZARA_HASH_FLETCHER16_HPP
|
||||
|
||||
#define NAZARA_HASH_FLETCHER16
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/HashDigest.hpp>
|
||||
#include <Nazara/Core/HashImpl.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
|
||||
struct NzHashFletcher16_state;
|
||||
|
||||
class NAZARA_API NzHashFletcher16 : public NzHashImpl
|
||||
{
|
||||
public:
|
||||
NzHashFletcher16();
|
||||
virtual ~NzHashFletcher16();
|
||||
|
||||
void Append(const nzUInt8* data, unsigned int len);
|
||||
void Begin();
|
||||
NzHashDigest End();
|
||||
|
||||
static unsigned int GetDigestLength();
|
||||
static NzString GetHashName();
|
||||
|
||||
private:
|
||||
NzHashFletcher16_state* m_state;
|
||||
};
|
||||
|
||||
#undef NAZARA_HASH_FLETCHER16
|
||||
|
||||
#endif // NAZARA_HASH_FLETCHER16_HPP
|
||||
37
include/Nazara/Core/Hash/MD5.hpp
Normal file
37
include/Nazara/Core/Hash/MD5.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_HASH_MD5_HPP
|
||||
#define NAZARA_HASH_MD5_HPP
|
||||
|
||||
#define NAZARA_HASH_MD5
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/HashDigest.hpp>
|
||||
#include <Nazara/Core/HashImpl.hpp>
|
||||
|
||||
struct NzHashMD5_state;
|
||||
|
||||
class NAZARA_API NzHashMD5 : public NzHashImpl
|
||||
{
|
||||
public:
|
||||
NzHashMD5();
|
||||
virtual ~NzHashMD5();
|
||||
|
||||
void Append(const nzUInt8* data, unsigned int len);
|
||||
void Begin();
|
||||
NzHashDigest End();
|
||||
|
||||
static unsigned int GetDigestLength();
|
||||
static NzString GetHashName();
|
||||
|
||||
private:
|
||||
NzHashMD5_state* m_state;
|
||||
};
|
||||
|
||||
#undef NAZARA_HASH_MD5
|
||||
|
||||
#endif // NAZARA_HASH_MD5_HPP
|
||||
35
include/Nazara/Core/Hash/Whirlpool.hpp
Normal file
35
include/Nazara/Core/Hash/Whirlpool.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#ifndef NAZARA_HASH_WHIRLPOOL_HPP
|
||||
#define NAZARA_HASH_WHIRLPOOL_HPP
|
||||
|
||||
#define NAZARA_HASH_WHIRLPOOL
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/HashDigest.hpp>
|
||||
#include <Nazara/Core/HashImpl.hpp>
|
||||
|
||||
struct NzHashWhirlpool_state;
|
||||
|
||||
class NAZARA_API NzHashWhirlpool : public NzHashImpl
|
||||
{
|
||||
public:
|
||||
NzHashWhirlpool();
|
||||
virtual ~NzHashWhirlpool();
|
||||
|
||||
void Append(const nzUInt8* data, unsigned int len);
|
||||
void Begin();
|
||||
NzHashDigest End();
|
||||
|
||||
static unsigned int GetDigestLength();
|
||||
static NzString GetHashName();
|
||||
|
||||
private:
|
||||
NzHashWhirlpool_state* m_state;
|
||||
};
|
||||
|
||||
#undef NAZARA_HASH_WHIRLPOOL
|
||||
|
||||
#endif // NAZARA_HASH_WHIRLPOOL_HPP
|
||||
55
include/Nazara/Core/HashDigest.hpp
Normal file
55
include/Nazara/Core/HashDigest.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_HASHDIGEST_HPP
|
||||
#define NAZARA_HASHDIGEST_HPP
|
||||
|
||||
#define NAZARA_HASHDIGEST
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <ostream>
|
||||
|
||||
class NAZARA_API NzHashDigest
|
||||
{
|
||||
public:
|
||||
NzHashDigest();
|
||||
NzHashDigest(NzString hashName, const nzUInt8* digest, unsigned int length);
|
||||
NzHashDigest(const NzHashDigest& rhs);
|
||||
NzHashDigest(NzHashDigest&& rhs);
|
||||
~NzHashDigest();
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
const nzUInt8* GetDigest() const;
|
||||
unsigned int GetDigestLength() const;
|
||||
NzString GetHashName() const;
|
||||
|
||||
NzString ToHex() const;
|
||||
|
||||
nzUInt8 operator[](unsigned short pos) const;
|
||||
|
||||
NzHashDigest& operator=(const NzHashDigest& rhs);
|
||||
NzHashDigest& operator=(NzHashDigest&& rhs);
|
||||
|
||||
bool operator==(const NzHashDigest& rhs) const;
|
||||
bool operator!=(const NzHashDigest& rhs) const;
|
||||
bool operator<(const NzHashDigest& rhs) const;
|
||||
bool operator<=(const NzHashDigest& rhs) const;
|
||||
bool operator>(const NzHashDigest& rhs) const;
|
||||
bool operator>=(const NzHashDigest& rhs) const;
|
||||
|
||||
NAZARA_API friend std::ostream& operator<<(std::ostream& out, const NzHashDigest& string);
|
||||
|
||||
private:
|
||||
NzString m_hashName;
|
||||
nzUInt8* m_digest;
|
||||
unsigned short m_digestLength;
|
||||
};
|
||||
|
||||
#undef NAZARA_HASHDIGEST
|
||||
|
||||
#endif // NAZARA_HASHDIGEST_HPP
|
||||
30
include/Nazara/Core/HashImpl.hpp
Normal file
30
include/Nazara/Core/HashImpl.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_HASHIMPL_HPP
|
||||
#define NAZARA_HASHIMPL_HPP
|
||||
|
||||
#define NAZARA_HASHIMPL
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
|
||||
class NzHashDigest;
|
||||
|
||||
class NAZARA_API NzHashImpl : NzNonCopyable
|
||||
{
|
||||
public:
|
||||
NzHashImpl() = default;
|
||||
virtual ~NzHashImpl() {}
|
||||
|
||||
virtual void Append(const nzUInt8* data, unsigned int len) = 0;
|
||||
virtual void Begin() = 0;
|
||||
virtual NzHashDigest End() = 0;
|
||||
};
|
||||
|
||||
#undef NAZARA_HASHIMPL
|
||||
|
||||
#endif // NAZARA_HASHIMPL_HPP
|
||||
39
include/Nazara/Core/Hashable.hpp
Normal file
39
include/Nazara/Core/Hashable.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef HASHABLE_HPP_INCLUDED
|
||||
#define HASHABLE_HPP_INCLUDED
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
|
||||
enum nzHash
|
||||
{
|
||||
nzHash_CRC32,
|
||||
nzHash_Fletcher16,
|
||||
nzHash_MD5,
|
||||
nzHash_Whirlpool
|
||||
};
|
||||
|
||||
class NzHash;
|
||||
class NzHashDigest;
|
||||
class NzHashImpl;
|
||||
|
||||
class NAZARA_API NzHashable
|
||||
{
|
||||
friend class NzHash;
|
||||
|
||||
public:
|
||||
NzHashable() = default;
|
||||
virtual ~NzHashable() {}
|
||||
|
||||
NzHashDigest GetHash(nzHash hash) const;
|
||||
NzHashDigest GetHash(NzHashImpl* impl) const;
|
||||
|
||||
private:
|
||||
virtual bool FillHash(NzHashImpl* impl) const = 0;
|
||||
};
|
||||
|
||||
#endif // HASHABLE_HPP_INCLUDED
|
||||
28
include/Nazara/Core/Lock.hpp
Normal file
28
include/Nazara/Core/Lock.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_LOCK_HPP
|
||||
#define NAZARA_LOCK_HPP
|
||||
|
||||
#define NAZARA_LOCK
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
|
||||
class NzMutex;
|
||||
|
||||
class NAZARA_API NzLock
|
||||
{
|
||||
public:
|
||||
NzLock(NzMutex& mutex);
|
||||
~NzLock();
|
||||
|
||||
private:
|
||||
NzMutex& m_mutex;
|
||||
};
|
||||
|
||||
#undef NAZARA_LOCK
|
||||
|
||||
#endif // NAZARA_LOCK_HPP
|
||||
55
include/Nazara/Core/Log.hpp
Normal file
55
include/Nazara/Core/Log.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_LOG_HPP
|
||||
#define NAZARA_LOG_HPP
|
||||
|
||||
#define NAZARA_LOG
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Core/ThreadSafety.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
|
||||
#define NazaraLog NzLog::Instance()
|
||||
|
||||
class NzFile;
|
||||
|
||||
class NAZARA_API NzLog : NzNonCopyable
|
||||
{
|
||||
public:
|
||||
void Enable(bool enable);
|
||||
void EnableAppend(bool enable);
|
||||
void EnableDateTime(bool enable);
|
||||
|
||||
NzString GetFile() const;
|
||||
|
||||
bool IsEnabled() const;
|
||||
|
||||
void SetFile(const NzString& filePath);
|
||||
|
||||
void Write(const NzString& string);
|
||||
void WriteError(nzErrorType type, const NzString& error, unsigned int line, const NzString& file, const NzString& func);
|
||||
|
||||
static NzLog* Instance();
|
||||
|
||||
private:
|
||||
NzLog();
|
||||
~NzLog();
|
||||
|
||||
NazaraMutexAttrib(m_mutex, mutable)
|
||||
|
||||
NzString m_filePath;
|
||||
NzFile* m_file;
|
||||
bool m_append;
|
||||
bool m_enabled;
|
||||
bool m_writeTime;
|
||||
};
|
||||
|
||||
#undef NAZARA_LOGGER
|
||||
|
||||
#endif // NAZARA_LOGGER_HPP
|
||||
36
include/Nazara/Core/Mutex.hpp
Normal file
36
include/Nazara/Core/Mutex.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_MUTEX_HPP
|
||||
#define NAZARA_MUTEX_HPP
|
||||
|
||||
#define NAZARA_MUTEX
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
|
||||
class NzMutexImpl;
|
||||
class NzThreadCondition;
|
||||
|
||||
class NAZARA_API NzMutex : NzNonCopyable
|
||||
{
|
||||
friend class NzThreadCondition;
|
||||
|
||||
public:
|
||||
NzMutex();
|
||||
~NzMutex();
|
||||
|
||||
void Lock();
|
||||
bool TryLock();
|
||||
void Unlock();
|
||||
|
||||
private:
|
||||
NzMutexImpl* m_impl;
|
||||
};
|
||||
|
||||
#undef NAZARA_MUTEX
|
||||
|
||||
#endif // NAZARA_MUTEX_HPP
|
||||
34
include/Nazara/Core/Semaphore.hpp
Normal file
34
include/Nazara/Core/Semaphore.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SEMAPHORE_HPP
|
||||
#define NAZARA_SEMAPHORE_HPP
|
||||
|
||||
#define NAZARA_SEMAPHORE
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
|
||||
class NzSemaphoreImpl;
|
||||
|
||||
class NAZARA_API NzSemaphore : NzNonCopyable
|
||||
{
|
||||
public:
|
||||
NzSemaphore(unsigned int count);
|
||||
~NzSemaphore();
|
||||
|
||||
unsigned int GetCount() const;
|
||||
void Post();
|
||||
void Wait();
|
||||
bool Wait(nzUInt32 timeout);
|
||||
|
||||
private:
|
||||
NzSemaphoreImpl* m_impl;
|
||||
};
|
||||
|
||||
#undef NAZARA_SEMAPHORE
|
||||
|
||||
#endif // NAZARA_SEMAPHORE_HPP
|
||||
323
include/Nazara/Core/String.hpp
Normal file
323
include/Nazara/Core/String.hpp
Normal file
@@ -0,0 +1,323 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_STRING_HPP
|
||||
#define NAZARA_STRING_HPP
|
||||
|
||||
#define NAZARA_STRING
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Hashable.hpp>
|
||||
#include <Nazara/Core/ThreadSafety.hpp>
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class NzAbstractHash;
|
||||
class NzHashDigest;
|
||||
|
||||
class NAZARA_API NzString : public NzHashable
|
||||
{
|
||||
public:
|
||||
enum Flags
|
||||
{
|
||||
None = 0x00, // Mode par défaut
|
||||
CaseInsensitive = 0x01, // Insensible à la casse
|
||||
HandleUtf8 = 0x02 // Traite les octets comme une suite de caractères UTF-8
|
||||
};
|
||||
|
||||
struct SharedString;
|
||||
|
||||
NzString();
|
||||
NzString(char character);
|
||||
NzString(const char* string);
|
||||
NzString(const std::string& string);
|
||||
NzString(const NzString& string);
|
||||
NzString(NzString&& string);
|
||||
NzString(SharedString* sharedString);
|
||||
~NzString();
|
||||
|
||||
NzString& Append(char character);
|
||||
NzString& Append(const char* string);
|
||||
NzString& Append(const NzString& string);
|
||||
|
||||
void Clear();
|
||||
|
||||
bool Contains(char character, int start = 0, nzUInt32 flags = None) const;
|
||||
bool Contains(const char* string, int start = 0, nzUInt32 flags = None) const;
|
||||
bool Contains(const NzString& string, int start = 0, nzUInt32 flags = None) const;
|
||||
|
||||
unsigned int Count(char character, int start = 0, nzUInt32 flags = None) const;
|
||||
unsigned int Count(const char* string, int start = 0, nzUInt32 flags = None) const;
|
||||
unsigned int Count(const NzString& string, int start = 0, nzUInt32 flags = None) const;
|
||||
unsigned int CountAny(const char* string, int start = 0, nzUInt32 flags = None) const;
|
||||
unsigned int CountAny(const NzString& string, int start = 0, nzUInt32 flags = None) const;
|
||||
|
||||
bool EndsWith(char character, nzUInt32 flags = None) const;
|
||||
bool EndsWith(const char* string, nzUInt32 flags = None) const;
|
||||
bool EndsWith(const NzString& string, nzUInt32 flags = None) const;
|
||||
|
||||
unsigned int Find(char character, int start = 0, nzUInt32 flags = None) const;
|
||||
unsigned int Find(const char* string, int start = 0, nzUInt32 flags = None) const;
|
||||
unsigned int Find(const NzString& string, int start = 0, nzUInt32 flags = None) const;
|
||||
unsigned int FindAny(const char* string, int start = 0, nzUInt32 flags = None) const;
|
||||
unsigned int FindAny(const NzString& string, int start = 0, nzUInt32 flags = None) const;
|
||||
unsigned int FindLast(char character, int start = -1, nzUInt32 flags = None) const;
|
||||
unsigned int FindLast(const char *string, int start = -1, nzUInt32 flags = None) const;
|
||||
unsigned int FindLast(const NzString& string, int start = -1, nzUInt32 flags = None) const;
|
||||
unsigned int FindLastAny(const char* string, int start = -1, nzUInt32 flags = None) const;
|
||||
unsigned int FindLastAny(const NzString& string, int start = -1, nzUInt32 flags = None) const;
|
||||
unsigned int FindLastWord(const char* string, int start = -1, nzUInt32 flags = None) const;
|
||||
unsigned int FindLastWord(const NzString& string, int start = -1, nzUInt32 flags = None) const;
|
||||
unsigned int FindWord(const char* string, int start = 0, nzUInt32 flags = None) const;
|
||||
unsigned int FindWord(const NzString& string, int start = 0, nzUInt32 flags = None) const;
|
||||
|
||||
char* GetBuffer();
|
||||
unsigned int GetCapacity() const;
|
||||
const char* GetConstBuffer() const;
|
||||
unsigned int GetLength() const;
|
||||
unsigned int GetSize() const;
|
||||
char* GetUtf8Buffer(unsigned int* size = nullptr) const;
|
||||
char16_t* GetUtf16Buffer(unsigned int* size = nullptr) const;
|
||||
char32_t* GetUtf32Buffer(unsigned int* size = nullptr) const;
|
||||
wchar_t* GetWideBuffer(unsigned int* size = nullptr) const;
|
||||
|
||||
NzString GetWord(unsigned int index, nzUInt32 flags = None) const;
|
||||
unsigned int GetWordPosition(unsigned int index, nzUInt32 flags = None) const;
|
||||
|
||||
NzString& Insert(int pos, char character);
|
||||
NzString& Insert(int pos, const char* string);
|
||||
NzString& Insert(int pos, const NzString& string);
|
||||
|
||||
bool IsEmpty() const;
|
||||
bool IsNull() const;
|
||||
bool IsNumber(nzUInt8 radix = 10, nzUInt32 flags = CaseInsensitive) const;
|
||||
|
||||
bool Match(const char* pattern) const;
|
||||
bool Match(const NzString& pattern) const;
|
||||
|
||||
NzString& Prepend(char character);
|
||||
NzString& Prepend(const char* string);
|
||||
NzString& Prepend(const NzString& string);
|
||||
|
||||
unsigned int Replace(char oldCharacter, char newCharacter, int start = 0, nzUInt32 flags = None);
|
||||
unsigned int Replace(const char* oldString, const char* replaceString, int start = 0, nzUInt32 flags = None);
|
||||
unsigned int Replace(const NzString& oldString, const NzString& replaceString, int start = 0, nzUInt32 flags = None);
|
||||
unsigned int ReplaceAny(const char* oldCharacters, char replaceCharacter, int start = 0, nzUInt32 flags = None);
|
||||
unsigned int ReplaceAny(const char* oldCharacters, const char* replaceString, int start = 0, nzUInt32 flags = None);
|
||||
unsigned int ReplaceAny(const NzString& oldCharacters, const NzString& replaceString, int start = 0, nzUInt32 flags = None);
|
||||
|
||||
void Reserve(unsigned int bufferSize);
|
||||
|
||||
NzString& Resize(int size, char character = ' ');
|
||||
NzString Resized(int size, char character = ' ') const;
|
||||
|
||||
NzString& Reverse();
|
||||
NzString Reversed() const;
|
||||
|
||||
NzString Simplified(nzUInt32 flags = None) const;
|
||||
NzString& Simplify(nzUInt32 flags = None);
|
||||
|
||||
unsigned int Split(std::vector<NzString>& result, char separation = ' ', int start = 0, nzUInt32 flags = None) const;
|
||||
unsigned int Split(std::vector<NzString>& result, const char* separation, int start = 0, nzUInt32 flags = None) const;
|
||||
unsigned int Split(std::vector<NzString>& result, const NzString& separation, int start = 0, nzUInt32 flags = None) const;
|
||||
unsigned int SplitAny(std::vector<NzString>& result, const char* separations, int start = 0, nzUInt32 flags = None) const;
|
||||
unsigned int SplitAny(std::vector<NzString>& result, const NzString& separations, int start = 0, nzUInt32 flags = None) const;
|
||||
|
||||
bool StartsWith(char character, nzUInt32 flags = None) const;
|
||||
bool StartsWith(const char* string, nzUInt32 flags = None) const;
|
||||
bool StartsWith(const NzString& string, nzUInt32 flags = None) const;
|
||||
|
||||
NzString Substr(int startPos, int endPos = -1) const;
|
||||
NzString SubstrFrom(char character, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const;
|
||||
NzString SubstrFrom(const char *string, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const;
|
||||
NzString SubstrFrom(const NzString& string, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const;
|
||||
NzString SubstrTo(char character, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const;
|
||||
NzString SubstrTo(const char *string, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const;
|
||||
NzString SubstrTo(const NzString& string, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const;
|
||||
|
||||
void Swap(NzString& str);
|
||||
|
||||
bool ToBool(bool* value, nzUInt32 flags = None) const;
|
||||
bool ToDouble(double* value) const;
|
||||
bool ToInteger(long long* value, nzUInt8 radix = 10) const;
|
||||
NzString ToLower(nzUInt32 flags = None) const;
|
||||
NzString ToUpper(nzUInt32 flags = None) const;
|
||||
|
||||
NzString& Trim(nzUInt32 flags = None);
|
||||
NzString& Trim(char character, nzUInt32 flags = None);
|
||||
NzString Trimmed(nzUInt32 flags = None) const;
|
||||
NzString Trimmed(char character, nzUInt32 flags = None) const;
|
||||
|
||||
// Méthodes compatibles STD
|
||||
char* begin();
|
||||
const char* begin() const;
|
||||
char* end();
|
||||
const char* end() const;
|
||||
void push_front(char c);
|
||||
void push_back(char c);
|
||||
/*char* rbegin();
|
||||
const char* rbegin() const;
|
||||
char* rend();
|
||||
const char* rend() const;*/
|
||||
|
||||
typedef const char& const_reference;
|
||||
typedef char* iterator;
|
||||
//typedef char* reverse_iterator;
|
||||
typedef char value_type;
|
||||
// Méthodes compatibles STD
|
||||
|
||||
operator std::string() const;
|
||||
|
||||
char& operator[](unsigned int pos);
|
||||
char operator[](unsigned int pos) const;
|
||||
|
||||
NzString& operator=(char character);
|
||||
NzString& operator=(const char* string);
|
||||
NzString& operator=(const std::string& string);
|
||||
NzString& operator=(const NzString& string);
|
||||
NzString& operator=(NzString&& string);
|
||||
|
||||
NzString operator+(char character) const;
|
||||
NzString operator+(const char* string) const;
|
||||
NzString operator+(const std::string& string) const;
|
||||
NzString operator+(const NzString& string) const;
|
||||
|
||||
NzString& operator+=(char character);
|
||||
NzString& operator+=(const char* string);
|
||||
NzString& operator+=(const std::string& string);
|
||||
NzString& operator+=(const NzString& string);
|
||||
|
||||
bool operator==(char character) const;
|
||||
bool operator==(const char* string) const;
|
||||
bool operator==(const std::string& string) const;
|
||||
|
||||
bool operator!=(char character) const;
|
||||
bool operator!=(const char* string) const;
|
||||
bool operator!=(const std::string& string) const;
|
||||
|
||||
bool operator<(char character) const;
|
||||
bool operator<(const char* string) const;
|
||||
bool operator<(const std::string& string) const;
|
||||
|
||||
bool operator<=(char character) const;
|
||||
bool operator<=(const char* string) const;
|
||||
bool operator<=(const std::string& string) const;
|
||||
|
||||
bool operator>(char character) const;
|
||||
bool operator>(const char* string) const;
|
||||
bool operator>(const std::string& string) const;
|
||||
|
||||
bool operator>=(char character) const;
|
||||
bool operator>=(const char* string) const;
|
||||
bool operator>=(const std::string& string) const;
|
||||
|
||||
static NzString Boolean(bool boolean);
|
||||
static int Compare(const NzString& first, const NzString& second);
|
||||
static NzString Number(float number);
|
||||
static NzString Number(double number);
|
||||
static NzString Number(long double number);
|
||||
static NzString Number(signed char number, nzUInt8 radix = 10);
|
||||
static NzString Number(unsigned char number, nzUInt8 radix = 10);
|
||||
static NzString Number(short number, nzUInt8 radix = 10);
|
||||
static NzString Number(unsigned short number, nzUInt8 radix = 10);
|
||||
static NzString Number(int number, nzUInt8 radix = 10);
|
||||
static NzString Number(unsigned int number, nzUInt8 radix = 10);
|
||||
static NzString Number(long number, nzUInt8 radix = 10);
|
||||
static NzString Number(unsigned long number, nzUInt8 radix = 10);
|
||||
static NzString Number(long long number, nzUInt8 radix = 10);
|
||||
static NzString Number(unsigned long long number, nzUInt8 radix = 10);
|
||||
static NzString Pointer(const void* ptr);
|
||||
static NzString Unicode(char32_t character);
|
||||
static NzString Unicode(const char* u8String);
|
||||
static NzString Unicode(const char16_t* u16String);
|
||||
static NzString Unicode(const char32_t* u32String);
|
||||
static NzString Unicode(const wchar_t* wString);
|
||||
|
||||
NAZARA_API friend std::istream& operator>>(std::istream& in, NzString& string);
|
||||
NAZARA_API friend std::ostream& operator<<(std::ostream& out, const NzString& string);
|
||||
|
||||
NAZARA_API friend NzString operator+(char character, const NzString& string);
|
||||
NAZARA_API friend NzString operator+(const char* string, const NzString& nstring);
|
||||
NAZARA_API friend NzString operator+(const std::string& string, const NzString& nstring);
|
||||
|
||||
NAZARA_API friend bool operator==(const NzString& first, const NzString& second);
|
||||
NAZARA_API friend bool operator!=(const NzString& first, const NzString& second);
|
||||
NAZARA_API friend bool operator<(const NzString& first, const NzString& second);
|
||||
NAZARA_API friend bool operator<=(const NzString& first, const NzString& second);
|
||||
NAZARA_API friend bool operator>(const NzString& first, const NzString& second);
|
||||
NAZARA_API friend bool operator>=(const NzString& first, const NzString& second);
|
||||
|
||||
NAZARA_API friend bool operator==(char character, const NzString& nstring);
|
||||
NAZARA_API friend bool operator==(const char* string, const NzString& nstring);
|
||||
NAZARA_API friend bool operator==(const std::string& string, const NzString& nstring);
|
||||
|
||||
NAZARA_API friend bool operator!=(char character, const NzString& nstring);
|
||||
NAZARA_API friend bool operator!=(const char* string, const NzString& nstring);
|
||||
NAZARA_API friend bool operator!=(const std::string& string, const NzString& nstring);
|
||||
|
||||
NAZARA_API friend bool operator<(char character, const NzString& nstring);
|
||||
NAZARA_API friend bool operator<(const char* string, const NzString& nstring);
|
||||
NAZARA_API friend bool operator<(const std::string& string, const NzString& nstring);
|
||||
|
||||
NAZARA_API friend bool operator<=(char character, const NzString& nstring);
|
||||
NAZARA_API friend bool operator<=(const char* string, const NzString& nstring);
|
||||
NAZARA_API friend bool operator<=(const std::string& string, const NzString& nstring);
|
||||
|
||||
NAZARA_API friend bool operator>(char character, const NzString& nstring);
|
||||
NAZARA_API friend bool operator>(const char* string, const NzString& nstring);
|
||||
NAZARA_API friend bool operator>(const std::string& string, const NzString& nstring);
|
||||
|
||||
NAZARA_API friend bool operator>=(char character, const NzString& nstring);
|
||||
NAZARA_API friend bool operator>=(const char* string, const NzString& nstring);
|
||||
NAZARA_API friend bool operator>=(const std::string& string, const NzString& nstring);
|
||||
|
||||
struct NAZARA_API SharedString
|
||||
{
|
||||
SharedString() :
|
||||
refCount(1)
|
||||
{
|
||||
}
|
||||
|
||||
SharedString(unsigned int bufferSize, unsigned int stringSize, unsigned short referenceCount, char* str) :
|
||||
allocatedSize(bufferSize),
|
||||
size(stringSize),
|
||||
refCount(referenceCount),
|
||||
string(str)
|
||||
{
|
||||
}
|
||||
|
||||
unsigned int allocatedSize;
|
||||
unsigned int size;
|
||||
unsigned short refCount;
|
||||
char* string;
|
||||
|
||||
NazaraMutex(mutex)
|
||||
};
|
||||
|
||||
static SharedString emptyString;
|
||||
static unsigned int npos;
|
||||
|
||||
private:
|
||||
void EnsureOwnership();
|
||||
bool FillHash(NzHashImpl* hash) const;
|
||||
void ReleaseString();
|
||||
|
||||
SharedString* m_sharedString;
|
||||
};
|
||||
|
||||
namespace std
|
||||
{
|
||||
NAZARA_API istream& getline(istream& is, NzString& str);
|
||||
NAZARA_API istream& getline(istream& is, NzString& str, char delim);
|
||||
NAZARA_API void swap(NzString& lhs, NzString& rhs);
|
||||
}
|
||||
|
||||
#undef NAZARA_STRING
|
||||
|
||||
#endif // NAZARA_STRING_HPP
|
||||
|
||||
56
include/Nazara/Core/StringStream.hpp
Normal file
56
include/Nazara/Core/StringStream.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_STRINGSTREAM_HPP
|
||||
#define NAZARA_STRINGSTREAM_HPP
|
||||
|
||||
#define NAZARA_STRINGSTREAM
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Core/ThreadSafety.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class NAZARA_API NzStringStream
|
||||
{
|
||||
public:
|
||||
NzStringStream();
|
||||
NzStringStream(const NzString& str);
|
||||
|
||||
NzString ToString() const;
|
||||
|
||||
NzStringStream& operator<<(bool boolean);
|
||||
NzStringStream& operator<<(short number);
|
||||
NzStringStream& operator<<(unsigned short number);
|
||||
NzStringStream& operator<<(int number);
|
||||
NzStringStream& operator<<(unsigned int number);
|
||||
NzStringStream& operator<<(long number);
|
||||
NzStringStream& operator<<(unsigned long number);
|
||||
NzStringStream& operator<<(long long number);
|
||||
NzStringStream& operator<<(unsigned long long number);
|
||||
NzStringStream& operator<<(float number);
|
||||
NzStringStream& operator<<(double number);
|
||||
NzStringStream& operator<<(long double number);
|
||||
NzStringStream& operator<<(char character);
|
||||
NzStringStream& operator<<(unsigned char character);
|
||||
NzStringStream& operator<<(const char* string);
|
||||
NzStringStream& operator<<(const std::string& string);
|
||||
NzStringStream& operator<<(const NzString& string);
|
||||
NzStringStream& operator<<(const void* ptr);
|
||||
|
||||
operator NzString() const;
|
||||
|
||||
private:
|
||||
NazaraMutexAttrib(m_mutex, mutable)
|
||||
|
||||
std::vector<NzString> m_strings;
|
||||
unsigned int m_bufferSize;
|
||||
};
|
||||
|
||||
#undef NAZARA_STRINGSTREAM
|
||||
|
||||
#endif // NAZARA_STRINGSTREAM_HPP
|
||||
69
include/Nazara/Core/Thread.hpp
Normal file
69
include/Nazara/Core/Thread.hpp
Normal file
@@ -0,0 +1,69 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// Inspiré du code de la SFML par Laurent Gomila
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_THREAD_HPP
|
||||
#define NAZARA_THREAD_HPP
|
||||
|
||||
#define NAZARA_THREAD
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Utility/Functor.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
|
||||
class NzThreadImpl;
|
||||
|
||||
class NAZARA_API NzThread : NzNonCopyable
|
||||
{
|
||||
friend class NzThreadImpl;
|
||||
|
||||
public:
|
||||
class NAZARA_API Id
|
||||
{
|
||||
friend class NzThread;
|
||||
friend class NzThreadImpl;
|
||||
|
||||
public:
|
||||
Id() : m_handle(nullptr) {}
|
||||
Id(Id&& rhs) = default;
|
||||
~Id();
|
||||
|
||||
Id& operator=(Id&& rhs) = default;
|
||||
bool operator==(const Id& rhs) const;
|
||||
bool operator!=(const Id& rhs) const;
|
||||
|
||||
private:
|
||||
Id(void* handle) : m_handle(handle) {}
|
||||
Id(const NzThreadImpl* thread);
|
||||
|
||||
void* m_handle;
|
||||
};
|
||||
|
||||
template<typename F> NzThread(F function);
|
||||
template<typename F, typename... Args> NzThread(F function, Args... args);
|
||||
~NzThread();
|
||||
|
||||
Id GetId() const;
|
||||
bool IsCurrent() const;
|
||||
void Launch(bool independent = false);
|
||||
void Join();
|
||||
void Terminate();
|
||||
|
||||
static Id GetCurrentId();
|
||||
static void Sleep(nzUInt32 time);
|
||||
|
||||
private:
|
||||
NzFunctor* m_func;
|
||||
NzThreadImpl* m_impl;
|
||||
bool m_independent;
|
||||
};
|
||||
|
||||
#include <Nazara/Core/Thread.inl>
|
||||
|
||||
#undef NAZARA_THREAD
|
||||
|
||||
#endif // NAZARA_THREAD_HPP
|
||||
19
include/Nazara/Core/Thread.inl
Normal file
19
include/Nazara/Core/Thread.inl
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
template<typename F> NzThread::NzThread(F function) :
|
||||
m_func(new NzFunctorWithoutArgs<F>(function)),
|
||||
m_impl(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename F, typename... Args> NzThread::NzThread(F function, Args... args) :
|
||||
m_func(new NzFunctorWithArgs<F, Args...>(function, args...)),
|
||||
m_impl(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
35
include/Nazara/Core/ThreadCondition.hpp
Normal file
35
include/Nazara/Core/ThreadCondition.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_THREADCONDITION_HPP
|
||||
#define NAZARA_THREADCONDITION_HPP
|
||||
|
||||
#define NAZARA_THREADCONDITION
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
|
||||
class NzMutex;
|
||||
class NzThreadConditionImpl;
|
||||
|
||||
class NAZARA_API NzThreadCondition
|
||||
{
|
||||
public:
|
||||
NzThreadCondition();
|
||||
~NzThreadCondition();
|
||||
|
||||
void Signal();
|
||||
void SignalAll();
|
||||
|
||||
void Wait(NzMutex* mutex);
|
||||
bool Wait(NzMutex* mutex, nzUInt32 timeout);
|
||||
|
||||
private:
|
||||
NzThreadConditionImpl* m_impl;
|
||||
};
|
||||
|
||||
#undef NAZARA_THREADCONDITION
|
||||
|
||||
#endif // NAZARA_THREADCONDITION_HPP
|
||||
43
include/Nazara/Core/ThreadSafety.hpp
Normal file
43
include/Nazara/Core/ThreadSafety.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// Pas de header guard
|
||||
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
|
||||
#undef NazaraLock
|
||||
#undef NazaraMutex
|
||||
#undef NazaraMutexAttrib
|
||||
#undef NazaraMutexLock
|
||||
#undef NazaraMutexUnlock
|
||||
#undef NazaraNamedLock
|
||||
|
||||
#if NAZARA_CORE_THREADSAFE && (\
|
||||
(NAZARA_THREADSAFETY_BYTEARRAY && (defined(NAZARA_BYTEARRAY) || defined(NAZARA_BYTEARRAY_CPP))) || \
|
||||
(NAZARA_THREADSAFETY_CLOCK && (defined(NAZARA_CLOCK) || defined(NAZARA_CLOCK_CPP))) || \
|
||||
(NAZARA_THREADSAFETY_DIRECTORY && (defined(NAZARA_DIRECTORY) || defined(NAZARA_DIRECTORY_CPP))) || \
|
||||
(NAZARA_THREADSAFETY_DYNLIB && (defined(NAZARA_DYNLIB) || defined(NAZARA_DYNLIB_CPP))) || \
|
||||
(NAZARA_THREADSAFETY_FILE && (defined(NAZARA_FILE) || defined(NAZARA_FILE_CPP))) || \
|
||||
(NAZARA_THREADSAFETY_HASHDIGEST && (defined(NAZARA_HASHDIGEST) || defined(NAZARA_HASHDIGEST_CPP))) || \
|
||||
(NAZARA_THREADSAFETY_LOG && (defined(NAZARA_LOG) || defined(NAZARA_LOG_CPP))) || \
|
||||
(NAZARA_THREADSAFETY_STRING && (defined(NAZARA_STRING) || defined(NAZARA_STRING_CPP))) || \
|
||||
(NAZARA_THREADSAFETY_STRINGSTREAM && (defined(NAZARA_STRINGSTREAM) || defined(NAZARA_STRINGSTREAM_CPP))))
|
||||
|
||||
#include <Nazara/Core/Lock.hpp>
|
||||
#include <Nazara/Core/Mutex.hpp>
|
||||
|
||||
#define NazaraLock(mutex) NzLock lock_mutex(mutex);
|
||||
#define NazaraMutex(name) NzMutex name;
|
||||
#define NazaraMutexAttrib(name, attribute) attribute NzMutex name;
|
||||
#define NazaraMutexLock(mutex) mutex.Lock();
|
||||
#define NazaraMutexUnlock(mutex) mutex.Unlock();
|
||||
#define NazaraNamedLock(mutex, name) NzLock lock_##name(mutex);
|
||||
#else
|
||||
#define NazaraLock(mutex)
|
||||
#define NazaraMutex(name)
|
||||
#define NazaraMutexAttrib(name, attribute)
|
||||
#define NazaraMutexLock(mutex)
|
||||
#define NazaraMutexUnlock(mutex)
|
||||
#define NazaraNamedLock(mutex, name)
|
||||
#endif
|
||||
110
include/Nazara/Core/Unicode.hpp
Normal file
110
include/Nazara/Core/Unicode.hpp
Normal file
@@ -0,0 +1,110 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_UNICODE_HPP
|
||||
#define NAZARA_UNICODE_HPP
|
||||
|
||||
#define NAZARA_UNICODE
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
|
||||
namespace NzUnicode
|
||||
{
|
||||
/*
|
||||
Catégorie Unicode:
|
||||
-Les valeurs de 0x01 à 0x80 indiquent la catégorie.
|
||||
-Les valeurs de 0x100 à 0x10000 indiquent la sous-catégorie.
|
||||
*/
|
||||
enum Category : nzUInt16
|
||||
{
|
||||
// Catégorie non-reconnue par Nazara
|
||||
Category_NoCategory = 0,
|
||||
|
||||
// Lettres
|
||||
Category_Letter = 0x01, // L
|
||||
Category_Letter_Lowercase = Category_Letter | 0x0100, // Ll
|
||||
Category_Letter_Modifier = Category_Letter | 0x0200, // Lm
|
||||
Category_Letter_Other = Category_Letter | 0x0400, // Lo
|
||||
Category_Letter_Titlecase = Category_Letter | 0x0800, // Lt
|
||||
Category_Letter_Uppercase = Category_Letter | 0x1000, // Lu
|
||||
|
||||
// Marques
|
||||
Category_Mark = 0x02, // M
|
||||
Category_Mark_Enclosing = Category_Mark | 0x100, // Me
|
||||
Category_Mark_NonSpacing = Category_Mark | 0x200, // Mn
|
||||
Category_Mark_SpacingCombining = Category_Mark | 0x400, // Mc
|
||||
|
||||
// Nombres
|
||||
Category_Number = 0x04, // N
|
||||
Category_Number_DecimalDigit = Category_Number | 0x100, // Nd
|
||||
Category_Number_Letter = Category_Number | 0x200, // Nl
|
||||
Category_Number_Other = Category_Number | 0x400, // No
|
||||
|
||||
// Autres
|
||||
Category_Other = 0x08, // C
|
||||
Category_Other_Control = Category_Other | 0x0100, // Cc
|
||||
Category_Other_Format = Category_Other | 0x0200, // Cf
|
||||
Category_Other_NotAssigned = Category_Other | 0x0400, // Cn
|
||||
Category_Other_PrivateUse = Category_Other | 0x0800, // Co
|
||||
Category_Other_Surrogate = Category_Other | 0x1000, // Cs
|
||||
|
||||
// Ponctuations
|
||||
Category_Punctuation = 0x10, // P
|
||||
Category_Punctuation_Close = Category_Punctuation | 0x0100, // Pe
|
||||
Category_Punctuation_Connector = Category_Punctuation | 0x0200, // Pc
|
||||
Category_Punctuation_Dash = Category_Punctuation | 0x0400, // Pd
|
||||
Category_Punctuation_FinalQuote = Category_Punctuation | 0x0800, // Pf
|
||||
Category_Punctuation_InitialQuote = Category_Punctuation | 0x1000, // Pi
|
||||
Category_Punctuation_Open = Category_Punctuation | 0x2000, // Ps
|
||||
Category_Punctuation_Other = Category_Punctuation | 0x4000, // Po
|
||||
|
||||
// Espacements
|
||||
Category_Separator = 0x20, // Z
|
||||
Category_Separator_Line = Category_Separator | 0x0100, // Zl
|
||||
Category_Separator_Paragraph = Category_Separator | 0x0200, // Zp
|
||||
Category_Separator_Space = Category_Separator | 0x0400, // Zs
|
||||
|
||||
// Symboles
|
||||
Category_Symbol = 0x40, // S
|
||||
Category_Symbol_Currency = Category_Symbol | 0x0100, // Sc
|
||||
Category_Symbol_Math = Category_Symbol | 0x0200, // Sm
|
||||
Category_Symbol_Modifier = Category_Symbol | 0x0400, // Sk
|
||||
Category_Symbol_Other = Category_Symbol | 0x0800 // So
|
||||
};
|
||||
|
||||
enum Direction : nzUInt8
|
||||
{
|
||||
Direction_Arabic_Letter, // AL
|
||||
Direction_Arabic_Number, // AN
|
||||
Direction_Boundary_Neutral, // BN
|
||||
Direction_Common_Separator, // CS
|
||||
Direction_European_Number, // EN
|
||||
Direction_European_Separator, // ES
|
||||
Direction_European_Terminator, // ET
|
||||
Direction_Left_To_Right, // L
|
||||
Direction_Left_To_Right_Embedding, // LRE
|
||||
Direction_Left_To_Right_Override, // LRO
|
||||
Direction_Nonspacing_Mark, // NSM
|
||||
Direction_Other_Neutral, // ON
|
||||
Direction_Paragraph_Separator, // B
|
||||
Direction_Pop_Directional_Format, // PDF
|
||||
Direction_Right_To_Left, // R
|
||||
Direction_Right_To_Left_Embedding, // RLE
|
||||
Direction_Right_To_Left_Override, // RLO
|
||||
Direction_Segment_Separator, // S
|
||||
Direction_White_Space // WS
|
||||
};
|
||||
|
||||
Category GetCategory(char32_t character);
|
||||
Direction GetDirection(char32_t character);
|
||||
char32_t GetLowercase(char32_t character);
|
||||
char32_t GetTitlecase(char32_t character);
|
||||
char32_t GetUppercase(char32_t character);
|
||||
}
|
||||
|
||||
#undef NAZARA_UNICODE
|
||||
|
||||
#endif // NAZARA_UNICODE_HPP
|
||||
Reference in New Issue
Block a user