1 // ***************************************************************************
2 // RollingBuffer_p.h (c) 2011 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 7 December 2011 (DB)
6 // ---------------------------------------------------------------------------
7 // Provides a dynamic I/O FIFO byte queue, which removes bytes as they are
8 // read from the front of the buffer and grows to accept bytes being written
11 // implementation note: basically a 'smart' wrapper around 1..* ByteArrays
12 // ***************************************************************************
14 #ifndef ROLLINGBUFFER_P_H
15 #define ROLLINGBUFFER_P_H
21 // This file is not part of the BamTools API. It exists purely as an
22 // implementation detail. This header file may change from version to version
23 // without notice, or even be removed.
27 #include "api/api_global.h"
28 #include "api/internal/io/ByteArray_p.h"
39 RollingBuffer(size_t growth);
42 // RollingBuffer interface
45 // returns current buffer size
46 size_t BlockSize(void) const;
47 // checks buffer for new line
48 bool CanReadLine(void) const;
49 // frees @n bytes from end of buffer
51 // clears entire buffer structure
53 // frees @n bytes from front of buffer
55 // checks buffer for @c
56 size_t IndexOf(char c) const;
57 // returns whether buffer contains data
58 bool IsEmpty(void) const;
59 // reads up to @maxLen bytes into @dest
60 // returns exactly how many bytes were read from buffer
61 size_t Read(char* dest, size_t max);
62 // reads until newline (or up to @maxLen bytes)
63 // returns exactly how many bytes were read from buffer
64 size_t ReadLine(char* dest, size_t max);
65 // returns a C-fxn compatible char* to byte data
66 const char* ReadPointer(void) const;
67 // ensures that buffer contains space for @n incoming bytes, returns write-able char*
68 char* Reserve(size_t n);
69 // returns current number of bytes stored in buffer
70 size_t Size(void) const;
71 // reserves space for @n bytes, then appends contents of @src to buffer
72 void Write(const char* src, size_t n);
76 size_t m_head; // index into current data (next char)
77 size_t m_tail; // index into last data position
78 size_t m_tailBufferIndex; // m_data::size() - 1
79 size_t m_totalBufferSize; // total buffer size
80 size_t m_bufferGrowth; // new buffers are typically initialized with this size
81 std::deque<ByteArray> m_data; // basic 'buffer of buffers'
84 } // namespace Internal
85 } // namespace BamTools
87 #endif // ROLLINGBUFFER_P_H