MPD 0.20.6

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

BufferedReader.hxx
Go to the documentation of this file.
1 /*
2 * Copyright 2003-2017 The Music Player Daemon Project
3 * http://www.musicpd.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef MPD_BUFFERED_READER_HXX
21 #define MPD_BUFFERED_READER_HXX
22
23 #include "check.h"
24 #include "Compiler.h"
25 #include "util/DynamicFifoBuffer.hxx"
26
27 #include <stddef.h>
28
29 class Reader;
30
31 class BufferedReader {
32 static constexpr size_t MAX_SIZE = 512 * 1024;
33
34 Reader &reader;
35
36 DynamicFifoBuffer<char> buffer;
37
38 bool eof = false;
39
40 unsigned line_number = 0;
41
42 public:
43 explicit BufferedReader(Reader &_reader)
44 :reader(_reader), buffer(4096) {}
45
50 void Reset() {
51 buffer.Clear();
52 eof = false;
53 line_number = 0;
54 }
55
56 bool Fill(bool need_more);
57
58 gcc_pure
59 WritableBuffer<void> Read() const {
60 return buffer.Read().ToVoid();
61 }
62
68 gcc_pure
69 void *ReadFull(size_t size);
70
71 void Consume(size_t n) {
72 buffer.Consume(n);
73 }
74
79 size_t ReadFromBuffer(WritableBuffer<void> dest);
80
86 void ReadFull(WritableBuffer<void> dest);
87
88 char *ReadLine();
89
90 unsigned GetLineNumber() const {
91 return line_number;
92 }
93 };
94
95 #endif
Reader
An interface that can read bytes from a stream until the stream ends.
Definition: Reader.hxx:35
check.h
BufferedReader::ReadFull
gcc_pure void * ReadFull(size_t size)
Read a buffer of exactly the given size (without consuming it).
BufferedReader::BufferedReader
BufferedReader(Reader &_reader)
Definition: BufferedReader.hxx:43
ForeignFifoBuffer::Clear
void Clear()
Definition: ForeignFifoBuffer.hxx:133
BufferedReader::GetLineNumber
unsigned GetLineNumber() const
Definition: BufferedReader.hxx:90
ForeignFifoBuffer::Consume
void Consume(size_type n)
Marks a chunk as consumed.
Definition: ForeignFifoBuffer.hxx:200
BufferedReader::Reset
void Reset()
Reset the internal state.
Definition: BufferedReader.hxx:50
BufferedReader::Fill
bool Fill(bool need_more)
BufferedReader::ReadFromBuffer
size_t ReadFromBuffer(WritableBuffer< void > dest)
Read (and consume) data from the input buffer into the given buffer.
BufferedReader::ReadLine
char * ReadLine()
Compiler.h
WritableBuffer< void >
Definition: WritableBuffer.hxx:45
WritableBuffer::ToVoid
constexpr WritableBuffer< void > ToVoid() const
Definition: WritableBuffer.hxx:122
ForeignFifoBuffer::Read
constexpr Range Read() const
Return a buffer range which may be read.
Definition: ForeignFifoBuffer.hxx:193
BufferedReader::Consume
void Consume(size_t n)
Definition: BufferedReader.hxx:71
BufferedReader::Read
gcc_pure WritableBuffer< void > Read() const
Definition: BufferedReader.hxx:59
DynamicFifoBuffer.hxx
DynamicFifoBuffer< char >
gcc_pure
#define gcc_pure
Definition: Compiler.h:116
BufferedReader
Definition: BufferedReader.hxx:31