ParsingBuffer.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9#ifndef SQUID_SRC_STORE_PARSINGBUFFER_H
10#define SQUID_SRC_STORE_PARSINGBUFFER_H
11
12#include "sbuf/SBuf.h"
13#include "StoreIOBuffer.h"
14
15#include <optional>
16
17namespace Store
18{
19
36{
37public:
39 ParsingBuffer() = default;
40
42 explicit ParsingBuffer(StoreIOBuffer &);
43
45 const char *c_str() { terminate(); return memory(); }
46
48 SBuf toSBuf() const;
49
51 size_t contentSize() const;
52
54 size_t spaceSize() const;
55
57 size_t capacity() const;
58
64 StoreIOBuffer content() const;
65
72
77 StoreIOBuffer makeSpace(size_t pageSize);
78
85
87 void appended(const char *, size_t);
88
90 void consume(size_t);
91
97
99 void print(std::ostream &) const;
100
101private:
102 const char *memory() const;
103 void terminate();
104 void growSpace(size_t);
105
106private:
109
112
115 std::optional<SBuf> extraMemory_;
116};
117
118inline std::ostream &
119operator <<(std::ostream &os, const ParsingBuffer &b)
120{
121 b.print(os);
122 return os;
123}
124
125} // namespace Store
126
127#endif /* SQUID_SRC_STORE_PARSINGBUFFER_H */
128
Definition: SBuf.h:94
void consume(size_t)
get rid of previously appended() prefix of a given size
const char * c_str()
a NUL-terminated version of content(); same lifetime as content()
Definition: ParsingBuffer.h:45
void growSpace(size_t)
makes sure we have the requested number of bytes, allocates enough memory if needed
StoreIOBuffer readerSuppliedMemory_
externally allocated buffer we were seeded with (or a zero-size one)
size_t contentSize() const
the total number of append()ed bytes that were not consume()d
void print(std::ostream &) const
summarizes object state (for debugging)
StoreIOBuffer packBack()
StoreIOBuffer space()
const char * memory() const
a read-only content start (or nil for some zero-size buffers)
std::optional< SBuf > extraMemory_
StoreIOBuffer content() const
ParsingBuffer()=default
creates buffer without any space or content
SBuf toSBuf() const
export content() into SBuf, avoiding content copying when possible
StoreIOBuffer makeSpace(size_t pageSize)
size_t spaceSize() const
the number of bytes in the space() buffer
size_t capacity() const
the maximum number of bytes we can store without allocating more space
StoreIOBuffer makeInitialSpace()
Definition: ParsingBuffer.h:84
size_t readerSuppliedMemoryContentSize_
append()ed to readerSuppliedMemory_ bytes that were not consume()d
void appended(const char *, size_t)
remember the new bytes received into the previously provided space()
std::ostream & operator<<(std::ostream &os, const ParsingBuffer &b)

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors