]> git.donarmstrong.com Git - bamtools.git/blob - src/api/internal/io/RollingBuffer_p.h
Added FTP support (text-tested, not BAM)
[bamtools.git] / src / api / internal / io / RollingBuffer_p.h
1 #ifndef ROLLINGBUFFER_P_H
2 #define ROLLINGBUFFER_P_H
3
4 #include "api/api_global.h"
5 #include "api/internal/io/ByteArray_p.h"
6 #include <deque>
7 #include <string>
8
9 namespace BamTools {
10 namespace Internal {
11
12 class RollingBuffer {
13
14     // ctors & dtor
15     public:
16         RollingBuffer(size_t growth); // inits buffer, new byte arrays will try to be of size @growth
17         ~RollingBuffer(void);         // dtor
18
19     // RollingBuffer interface
20     public:
21         size_t BlockSize(void) const;          // returns current buffer size
22         bool CanReadLine(void) const;          // checks buffer for carriage return
23         void Chop(size_t n);                   // frees @n bytes from end of buffer
24         void Clear(void);                      // clears entire buffer structure
25         void Free(size_t n);                   // frees @n bytes from front of buffer
26         size_t IndexOf(char c) const;          // checks buffer for @c
27         bool IsEmpty(void) const;              // returns whether buffer contains data
28         size_t Read(char* dest, size_t max);   // returns up to @maxLen bytes into @dest, returns exactly how many bytes were read from buffer
29         size_t ReadLine(char* dest, size_t max);
30         std::string ReadLine(size_t max = 0);
31
32         const char* ReadPointer(void) const;   // returns a C-fxn compatible char* to byte data
33         char* Reserve(size_t n);               // ensures that buffer contains space for @n incoming bytes, returns write-able char*
34         size_t Size(void) const;               // returns current number of bytes stored in buffer
35         void Write(const char* src, size_t n); // reserves space for @n bytes, then appends contents of @src to buffer
36
37     // data members
38     private:
39         size_t m_head;                // index into current data (next char)
40         size_t m_tail;                // index into last data position
41         size_t m_tailBufferIndex;     // m_data::size() - 1
42         size_t m_totalBufferSize;     // total buffer size
43         size_t m_bufferGrowth;        // new buffers are typically initialized with this size
44         std::deque<ByteArray> m_data; // basic 'buffer of buffers'
45 };
46
47 } // namespace Internal
48 } // namespace BamTools
49
50 #endif // ROLLINGBUFFER_P_H