Skip to content
Flecs v4.1
stringstream.hpp
Go to the documentation of this file.
1/**
2 * @file addons/cpp/utils/stringstream.hpp
3 * @brief Wrapper around ecs_strbuf_t that provides a simple stringstream-like API.
4 */
5
6namespace flecs {
7
8/** Simple stringstream wrapper around ecs_strbuf_t. */
10 /** Default constructor. */
11 explicit stringstream()
12 : buf_({}) { }
13
14 /** Destructor. Reset the internal buffer. */
16 ecs_strbuf_reset(&buf_);
17 }
18
19 /** Move constructor. */
21 ecs_strbuf_reset(&buf_);
22 buf_ = str.buf_;
23 str.buf_ = {};
24 }
25
26 /** Move assignment operator. */
28 ecs_strbuf_reset(&buf_);
29 buf_ = str.buf_;
30 str.buf_ = {};
31 return *this;
32 }
33
34 /** Ban implicit copies/allocations. */
36 /** Ban implicit copies/allocations. */
37 stringstream(const stringstream& str) = delete;
38
39 /** Append a C string to the stream. */
40 stringstream& operator<<(const char* str) {
41 ecs_strbuf_appendstr(&buf_, str);
42 return *this;
43 }
44
45 /** Get the accumulated string as an owned flecs::string. */
47 return flecs::string(ecs_strbuf_get(&buf_));
48 }
49
50private:
51 ecs_strbuf_t buf_;
52};
53
54}
Owned string wrapper.
Definition string.hpp:15
stringstream & operator=(stringstream &&str) noexcept
Move assignment operator.
stringstream(const stringstream &str)=delete
Ban implicit copies/allocations.
stringstream & operator=(const stringstream &str)=delete
Ban implicit copies/allocations.
stringstream()
Default constructor.
stringstream(stringstream &&str) noexcept
Move constructor.
flecs::string str()
Get the accumulated string as an owned flecs::string.
stringstream & operator<<(const char *str)
Append a C string to the stream.
~stringstream()
Destructor.