Files
NazaraEngine/include/Nazara/Core/ByteArray.hpp
Lynix 9b3f4e794a Added Image
Added pixel format support
Added MemoryStream
Added Rect
Added ResourceLoader
Added generic loader (bmp, gif, hdr, jpg, jpeg, pic, png, psd, tga)
Added PCX loader
Added utility module initializer
Fixed Config.hpp include
Prerequesites.hpp now overwrites _WIN32_WINNT when defined
version is less than requiered version
Renderer's initialisation will implicitly initialize utility module
Removed RENDERER_SINGLETON option
Shaders are now resources
2012-05-21 21:54:13 +02:00

128 lines
3.0 KiB
C++

// 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
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Hashable.hpp>
#define NAZARA_CLASS_BYTEARRAY
#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();
NzByteArray& Append(const NzByteArray& byteArray);
void Clear();
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);
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 short referenceCount, unsigned int bufferSize, unsigned int arraySize, nzUInt8* ptr) :
capacity(bufferSize),
size(arraySize),
refCount(referenceCount),
buffer(ptr)
{
}
unsigned int capacity;
unsigned int size;
unsigned short refCount;
nzUInt8* buffer;
NazaraMutex(mutex)
};
static SharedArray emptyArray;
static unsigned int npos;
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_CLASS_BYTEARRAY
#endif // NAZARA_BYTEARRAY_HPP