- Fixed style violations pointed by stippi.
- Use std:nothrow for new calls. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28919 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
class DynamicBuffer {
|
class DynamicBuffer {
|
||||||
public:
|
public:
|
||||||
DynamicBuffer(size_t _initialSize = 0);
|
DynamicBuffer(size_t initialSize = 0);
|
||||||
~DynamicBuffer();
|
~DynamicBuffer();
|
||||||
|
|
||||||
// InitCheck() should be called to guarantee the object initialization
|
// InitCheck() should be called to guarantee the object initialization
|
||||||
@@ -23,11 +23,11 @@ public:
|
|||||||
|
|
||||||
// Insert data at the end of the buffer. The buffer will be increased to
|
// Insert data at the end of the buffer. The buffer will be increased to
|
||||||
// accomodate the data if needed.
|
// accomodate the data if needed.
|
||||||
status_t Insert(const void* _data, size_t _size);
|
status_t Insert(const void* data, size_t size);
|
||||||
|
|
||||||
// Remove data from the start of the buffer. Move the buffer start
|
// Remove data from the start of the buffer. Move the buffer start
|
||||||
// pointer to point to the data following it.
|
// pointer to point to the data following it.
|
||||||
status_t Remove(void* _data, size_t _size);
|
status_t Remove(void* data, size_t size);
|
||||||
|
|
||||||
// Return a pointer to the underlying buffer. Note this will not
|
// Return a pointer to the underlying buffer. Note this will not
|
||||||
// necessarily be a pointer to the start of the allocated memory as the
|
// necessarily be a pointer to the start of the allocated memory as the
|
||||||
@@ -47,7 +47,7 @@ public:
|
|||||||
void PrintToStream();
|
void PrintToStream();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t _GrowToFit(size_t _size);
|
status_t _GrowToFit(size_t size);
|
||||||
|
|
||||||
unsigned char* fBuffer;
|
unsigned char* fBuffer;
|
||||||
size_t fBufferSize;
|
size_t fBufferSize;
|
||||||
|
|||||||
@@ -12,17 +12,17 @@
|
|||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
|
||||||
DynamicBuffer::DynamicBuffer(size_t _initialSize) :
|
DynamicBuffer::DynamicBuffer(size_t initialSize) :
|
||||||
fBuffer(NULL),
|
fBuffer(NULL),
|
||||||
fBufferSize(0),
|
fBufferSize(0),
|
||||||
fDataStart(0),
|
fDataStart(0),
|
||||||
fDataEnd(0),
|
fDataEnd(0),
|
||||||
fInit(B_NO_INIT)
|
fInit(B_NO_INIT)
|
||||||
{
|
{
|
||||||
if (_initialSize > 0) {
|
if (initialSize > 0) {
|
||||||
fBuffer = new unsigned char[_initialSize];
|
fBuffer = new (std::nothrow) unsigned char[initialSize];
|
||||||
if (fBuffer != NULL) {
|
if (fBuffer != NULL) {
|
||||||
fBufferSize = _initialSize;
|
fBufferSize = initialSize;
|
||||||
fInit = B_OK;
|
fInit = B_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,33 +46,33 @@ DynamicBuffer::InitCheck() const
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
DynamicBuffer::Insert(const void* _data, size_t _size)
|
DynamicBuffer::Insert(const void* data, size_t size)
|
||||||
{
|
{
|
||||||
if (fInit != B_OK)
|
if (fInit != B_OK)
|
||||||
return fInit;
|
return fInit;
|
||||||
|
|
||||||
status_t result = _GrowToFit(_size);
|
status_t result = _GrowToFit(size);
|
||||||
if (result != B_OK)
|
if (result != B_OK)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
memcpy(fBuffer + fDataEnd, _data, _size);
|
memcpy(fBuffer + fDataEnd, data, size);
|
||||||
fDataEnd += _size;
|
fDataEnd += size;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
DynamicBuffer::Remove(void* _data, size_t _size)
|
DynamicBuffer::Remove(void* data, size_t size)
|
||||||
{
|
{
|
||||||
if (fInit != B_OK)
|
if (fInit != B_OK)
|
||||||
return fInit;
|
return fInit;
|
||||||
|
|
||||||
if (fDataStart + _size > fDataEnd)
|
if (fDataStart + size > fDataEnd)
|
||||||
return B_BUFFER_OVERFLOW;
|
return B_BUFFER_OVERFLOW;
|
||||||
|
|
||||||
memcpy(_data, fBuffer + fDataStart, _size);
|
memcpy(_data, fBuffer + fDataStart, size);
|
||||||
fDataStart += _size;
|
fDataStart += size;
|
||||||
|
|
||||||
if (fDataStart == fDataEnd)
|
if (fDataStart == fDataEnd)
|
||||||
fDataStart = fDataEnd = 0;
|
fDataStart = fDataEnd = 0;
|
||||||
@@ -114,14 +114,14 @@ DynamicBuffer::PrintToStream()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
DynamicBuffer::_GrowToFit(size_t _size)
|
DynamicBuffer::_GrowToFit(size_t size)
|
||||||
{
|
{
|
||||||
if (_size <= fBufferSize - fDataEnd)
|
if (_size <= fBufferSize - fDataEnd)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
size_t newSize = (fBufferSize + _size) * 2;
|
size_t newSize = (fBufferSize + size) * 2;
|
||||||
|
|
||||||
unsigned char* newBuffer = new unsigned char[newSize];
|
unsigned char* newBuffer = new (std::nothrow) unsigned char[newSize];
|
||||||
if (newBuffer == NULL)
|
if (newBuffer == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user