Added experimental implementation of ByteArrays

Former-commit-id: c95729bb45059c199344471a61042d98090034c8
This commit is contained in:
Lynix
2013-06-18 21:07:53 +02:00
parent ebf402f138
commit c1e57c829c
2 changed files with 363 additions and 152 deletions

View File

@@ -10,12 +10,7 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Hashable.hpp>
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_BYTEARRAY
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
#endif
#include <atomic>
class NzAbstractHash;
class NzHashDigest;
@@ -26,45 +21,49 @@ class NAZARA_API NzByteArray : public NzHashable
struct SharedArray;
NzByteArray();
NzByteArray(const nzUInt8* buffer, unsigned int bufferLength);
NzByteArray(const nzUInt8* buffer, unsigned int length);
NzByteArray(const NzByteArray& buffer);
NzByteArray(NzByteArray&& buffer) noexcept;
NzByteArray(SharedArray* sharedArray);
~NzByteArray();
NzByteArray& Append(nzUInt8 byte);
NzByteArray& Append(const nzUInt8* buffer, unsigned int length);
NzByteArray& Append(const NzByteArray& byteArray);
void Clear();
void Clear(bool keepBuffer = false);
nzUInt8* GetBuffer();
unsigned int GetCapacity() const;
const nzUInt8* GetConstBuffer() const;
unsigned int GetSize() const;
NzByteArray& Insert(int pos, const nzUInt8* buffer, unsigned int bufferLength);
NzByteArray& Insert(int pos, const NzByteArray& byteArray);
NzByteArray& Insert(int pos, nzUInt8 byte);
NzByteArray& Insert(int pos, const nzUInt8* buffer, unsigned int length);
NzByteArray& Insert(int pos, const NzByteArray& array);
bool IsEmpty() const;
NzByteArray& Prepend(nzUInt8 byte);
NzByteArray& Prepend(const nzUInt8* buffer, unsigned int length);
NzByteArray& Prepend(const NzByteArray& array);
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;
NzByteArray SubArray(int startPos, int endPos = -1) const;
void Swap(NzByteArray& byteArray);
NzByteArray& Trim(nzUInt8 byte = '\0');
NzByteArray Trimmed(nzUInt8 byte = '\0') const;
void Swap(NzByteArray& array);
// 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);
void push_front(nzUInt8 byte);
void push_back(nzUInt8 byte);
/*nzUInt8* rbegin();
const nzUInt8* rbegin() const;
nzUInt8* rend();
@@ -82,29 +81,33 @@ class NAZARA_API NzByteArray : public NzHashable
NzByteArray& operator=(const NzByteArray& byteArray);
NzByteArray& operator=(NzByteArray&& byteArray) noexcept;
NzByteArray operator+(nzUInt8 byte) const;
NzByteArray operator+(const NzByteArray& byteArray) const;
NzByteArray& operator+=(nzUInt8 byte);
NzByteArray& operator+=(const NzByteArray& byteArray);
static int Compare(const NzByteArray& first, const NzByteArray& second);
struct NAZARA_API SharedArray
{
SharedArray() = default;
SharedArray() :
refCount(1)
{
}
SharedArray(unsigned short referenceCount, unsigned int bufferSize, unsigned int arraySize, nzUInt8* ptr) :
capacity(bufferSize),
size(arraySize),
refCount(referenceCount),
buffer(ptr)
buffer(ptr),
refCount(referenceCount)
{
}
unsigned int capacity;
unsigned int size;
unsigned short refCount = 1;
nzUInt8* buffer;
NazaraMutex(mutex)
std::atomic_ushort refCount;
};
static SharedArray emptyArray;