]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/PrebufferedStreambuf.h
1 #ifndef CEPH_COMMON_PREBUFFEREDSTREAMBUF_H
2 #define CEPH_COMMON_PREBUFFEREDSTREAMBUF_H
7 * streambuf using existing buffer, overflowing into a std::string
9 * A simple streambuf that uses a preallocated buffer for small
10 * strings, and overflows into a std::string when necessary. If the
11 * preallocated buffer size is chosen well, we can optimize for the
12 * common case and overflow to a slower heap-allocated buffer when
15 class PrebufferedStreambuf
16 : public std::basic_streambuf
<char, std::basic_string
<char>::traits_type
>
20 std::string m_overflow
;
22 typedef std::char_traits
<char> traits_ty
;
23 typedef traits_ty::int_type int_type
;
24 typedef traits_ty::pos_type pos_type
;
25 typedef traits_ty::off_type off_type
;
28 PrebufferedStreambuf(char *buf
, size_t len
);
30 // called when the buffer fills up
31 int_type
overflow(int_type c
) override
;
33 // called when we read and need more data
34 int_type
underflow() override
;
36 /// return a string copy (inefficiently)
37 std::string
get_str() const;
39 // returns current size of content
42 // extracts up to avail chars of content
43 int snprintf(char* dst
, size_t avail
) const;