]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd/IndentStream.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / tools / rbd / IndentStream.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_RBD_INDENT_STREAM_H
5 #define CEPH_RBD_INDENT_STREAM_H
6
7 #include "include/int_types.h"
8 #include <iostream>
9 #include <streambuf>
10 #include <iomanip>
11
12 namespace rbd {
13
14 class IndentBuffer : public std::streambuf {
15 public:
16 IndentBuffer(size_t indent, size_t initial_offset, size_t line_length,
17 std::streambuf *streambuf)
18 : m_indent(indent), m_initial_offset(initial_offset),
19 m_line_length(line_length), m_streambuf(streambuf),
20 m_delim(" "), m_indent_prefix(m_indent, ' ') {
21 }
22
23 void set_delimiter(const std::string &delim) {
24 m_delim = delim;
25 }
26
27 protected:
28 int overflow (int c) override;
29
30 private:
31 size_t m_indent;
32 size_t m_initial_offset;
33 size_t m_line_length;
34 std::streambuf *m_streambuf;
35
36 std::string m_delim;
37 std::string m_indent_prefix;
38 std::string m_buffer;
39
40 void flush_line();
41 };
42
43 class IndentStream : public std::ostream {
44 public:
45 IndentStream(size_t indent, size_t initial_offset, size_t line_length,
46 std::ostream &os)
47 : std::ostream(&m_indent_buffer),
48 m_indent_buffer(indent, initial_offset, line_length, os.rdbuf()) {
49 }
50
51 void set_delimiter(const std::string &delim) {
52 m_indent_buffer.set_delimiter(delim);
53 }
54 private:
55 IndentBuffer m_indent_buffer;
56 };
57
58 } // namespace rbd
59
60 #endif // CEPH_RBD_INDENT_STREAM_ITERATOR_H