#include "../Include/NaosBuffer.hpp" using namespace Naos; //------------------------------------------------------------------------------------------------- Buffer::Buffer(): mSize(MAX_BUFFER_SIZE), mPosition(0), mData(new char[MAX_BUFFER_SIZE]) { assert(mData); } //------------------------------------------------------------------------------------------------- Buffer::Buffer(char* _data, size_t _size): mSize(_size), mPosition(0), mData(new char[_size]) { memcpy(mData, _data, _size); assert(mData); } //------------------------------------------------------------------------------------------------- Buffer::Buffer(const Buffer& _buffer): mSize(_buffer.mSize), mPosition(_buffer.mPosition), mData(new char[mSize]) { // On copie les données du buffer _buffer vers le buffer actuel. memcpy(mData, _buffer.mData, mSize); assert(mData); } //------------------------------------------------------------------------------------------------- Buffer::~Buffer() { delete[] mData; } //------------------------------------------------------------------------------------------------- Buffer& Buffer::operator = (const Buffer& _rhs) { if(mSize <= _rhs.mSize) { delete[] mData; mData = NULL; mData = new char[_rhs.mSize]; mSize = _rhs.mSize; } else { OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS, "Cannot copy the buffer, the size of the original buffer is too small", "Buffer::operator ="); } mPosition = _rhs.mPosition; memcpy(mData, _rhs.mData, mSize); return* this; } //------------------------------------------------------------------------------------------------- void Buffer::setSize(size_t _size) { // On copie les données du buffer courant vers des données temporaires. void* tempData = new char[mSize]; memcpy(tempData, mData, mSize); // On supprime les données courantes. mSize = _size; delete[] mData; mData = NULL; // Puis on recréer les données courante avec les données temporaire. mData = new char[mSize]; memcpy(mData, tempData, mSize); // Puis on supprime les données temporaire. delete[] tempData; tempData = NULL; } //------------------------------------------------------------------------------------------------- void Buffer::setPosition(unsigned int _position) { if(_position <= mSize) { mPosition = _position; } } //------------------------------------------------------------------------------------------------- template Buffer& Buffer::operator << (const T* _data) { if(mPosition + sizeof(T) <= mSize) { } }