Stream.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_SBUFSTREAM_H
10#define SQUID_SBUFSTREAM_H
11
12#include "base/PackableStream.h"
13#include "sbuf/SBuf.h"
14
20class SBufStream : public std::ostream
21{
22public:
28 SBufStream(const SBuf &aBuf):
29 std::ostream(nullptr), // initialize the parent; no stream buffer yet
30 sink_(aBuf),
31 streamBuffer_(sink_) // initialize the stream buffer
32 {
33 rdbuf(&streamBuffer_); // supply the now-initialized stream buffer
34 clear(); // clear the badbit that a nullptr stream buffer has triggered
35 }
36
39
42 flush();
43 return sink_;
44 }
45
48 flush();
49 sink_.clear();
50 return *this;
51 }
52
53private:
58};
59
61template <typename... Args>
62inline
63SBuf ToSBuf(Args&&... args)
64{
65 SBufStream out;
66 (out << ... << args);
67 return out.buf();
68}
69
70#endif /* SQUID_SBUFSTREAM_H */
71
SBuf buf()
bytes written so far
Definition: Stream.h:41
SBufStream()
Create an empty SBufStream.
Definition: Stream.h:38
SBuf sink_
buffer for (flushed) bytes written to the stream
Definition: Stream.h:55
SBufStream(const SBuf &aBuf)
Definition: Stream.h:28
SBufStream & clearBuf()
Clear the stream's backing store.
Definition: Stream.h:47
AppendingStreamBuf< SBuf > streamBuffer_
writes raw (post-formatting) bytes to the sink_
Definition: Stream.h:57
Definition: SBuf.h:94
void clear()
Definition: SBuf.cc:175
STL namespace.
SBuf ToSBuf(Args &&... args)
slowly stream-prints all arguments into a freshly allocated SBuf
Definition: Stream.h:63

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors