libcwdversion 2.0.0
The C++ Debugging Support Library
Loading...
Searching...
No Matches
BufferStream.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2003-2005, 2018, 2020, 2023, 2026 Carlo Wood
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
9
10#ifndef LIBCWD_PRIVATE_BUFFERSTREAM_H
11#define LIBCWD_PRIVATE_BUFFERSTREAM_H
12
13#include "libcwd/config.h"
14
15#ifndef HIDE_FROM_DOXYGEN
16namespace libcwd::_private_ {
17
18// This is a pseudo stringstream that allows the stringbuf to be changed on
19// the fly.
20class BufferStream : public std::ostream
21{
22 public:
23 using char_type = char;
24 using traits_type = std::char_traits<char>;
25 using allocator_type = ::std::allocator<char_type>;
26 using int_type = traits_type::int_type;
27 using pos_type = traits_type::pos_type;
28 using off_type = traits_type::off_type;
29 using string_type = std::basic_string<char_type, traits_type, allocator_type>;
30 using stringbuf_type = std::basic_stringbuf<char_type, traits_type, allocator_type>;
31
32 private:
33 stringbuf_type* stringbuf_;
34
35 public:
36 explicit BufferStream(stringbuf_type* sb) : std::basic_ostream<char, std::char_traits<char>>(sb), stringbuf_(sb) { }
37 ~BufferStream() { }
38
39 stringbuf_type* rdbuf() const { return stringbuf_; }
40 string_type str() const { return stringbuf_->str(); }
41 void str(string_type const& s) { stringbuf_->str(s); }
42};
43
44} // namespace libcwd::_private_
45#endif // HIDE_FROM_DOXYGEN
46
47#endif // LIBCWD_PRIVATE_BUFFERSTREAM_H