- Simple dynamic buffer class implementation.
- Will be used by the new (R5 compatible) NetBuffer class. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28918 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2009, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Bruno Albuquerque, [email protected]
|
||||
*/
|
||||
|
||||
#ifndef _DYNAMIC_BUFFER_H
|
||||
#define _DYNAMIC_BUFFER_H
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
class DynamicBuffer {
|
||||
public:
|
||||
DynamicBuffer(size_t _initialSize = 0);
|
||||
~DynamicBuffer();
|
||||
|
||||
// InitCheck() should be called to guarantee the object initialization
|
||||
// didn't fail. If it does not return B_OK, the initialization failed.
|
||||
status_t InitCheck() const;
|
||||
|
||||
// Insert data at the end of the buffer. The buffer will be increased to
|
||||
// accomodate the data if needed.
|
||||
status_t Insert(const void* _data, size_t _size);
|
||||
|
||||
// Remove data from the start of the buffer. Move the buffer start
|
||||
// pointer to point to the data following it.
|
||||
status_t Remove(void* _data, size_t _size);
|
||||
|
||||
// Return a pointer to the underlying buffer. Note this will not
|
||||
// necessarily be a pointer to the start of the allocated memory as the
|
||||
// initial data may be positioned at an offset inside the buffer. In other
|
||||
// words, this returns a pointer to the start of data inside the buffer.
|
||||
unsigned char* Data() const;
|
||||
|
||||
// Returns the actual buffer size. This is the amount of memory allocated
|
||||
// for the buffer.
|
||||
size_t Size() const;
|
||||
|
||||
// Number of bytes of data still present in the buffer that can be
|
||||
// extracted through calls to Remove().
|
||||
size_t BytesRemaining() const;
|
||||
|
||||
// Dump some buffer statistics to stdout.
|
||||
void PrintToStream();
|
||||
|
||||
private:
|
||||
status_t _GrowToFit(size_t _size);
|
||||
|
||||
unsigned char* fBuffer;
|
||||
size_t fBufferSize;
|
||||
size_t fDataStart;
|
||||
size_t fDataEnd;
|
||||
|
||||
status_t fInit;
|
||||
};
|
||||
|
||||
#endif // _DYNAMIC_BUFFER_H
|
||||
Reference in New Issue
Block a user