2 * Copyright 2009-2014, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Bruno Albuquerque, bga@bug-br.org.br
9 #ifndef _DYNAMIC_BUFFER_H
10 #define _DYNAMIC_BUFFER_H
13 #include <SupportDefs.h>
16 class DynamicBuffer
: public BDataIO
{
18 DynamicBuffer(size_t initialSize
= 0);
21 DynamicBuffer(const DynamicBuffer
& buffer
);
23 // InitCheck() should be called to guarantee the object initialization
24 // didn't fail. If it does not return B_OK, the initialization failed.
25 status_t
InitCheck() const;
27 // Insert data at the end of the buffer. The buffer will be increased to
28 // accomodate the data if needed.
29 virtual ssize_t
Write(const void* data
, size_t size
);
31 // Remove data from the start of the buffer. Move the buffer start
32 // pointer to point to the data following it.
33 virtual ssize_t
Read(void* data
, size_t size
);
35 // Return a pointer to the underlying buffer. Note this will not
36 // necessarily be a pointer to the start of the allocated memory as the
37 // initial data may be positioned at an offset inside the buffer. In other
38 // words, this returns a pointer to the start of data inside the buffer.
39 unsigned char* Data() const;
41 // Returns the actual buffer size. This is the amount of memory allocated
45 // Number of bytes of data still present in the buffer that can be
46 // extracted through calls to Remove().
47 size_t BytesRemaining() const;
49 // Dump some buffer statistics to stdout.
53 status_t
_GrowToFit(size_t size
, bool exact
= false);
55 unsigned char* fBuffer
;
63 #endif // _DYNAMIC_BUFFER_H