slang-netlist  0.11.0
Loading...
Searching...
No Matches
FormatBuffer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <fmt/format.h>
4
5#include <iterator>
6#include <string>
7#include <string_view>
8
9namespace slang::netlist {
10
14public:
16 void append(std::string_view str) { buf.append(str); }
17
19 void append(char ch) { buf.push_back(ch); }
20
22 template <typename... Args>
23 void format(fmt::format_string<Args...> fmt, Args &&...args) {
24 fmt::format_to(std::back_inserter(buf), fmt, std::forward<Args>(args)...);
25 }
26
28 auto size() const -> size_t { return buf.size(); }
29
31 auto data() const -> const char * { return buf.data(); }
32
34 auto empty() const -> bool { return buf.empty(); }
35
37 void clear() { buf.clear(); }
38
40 auto str() const -> std::string { return buf; }
41
42private:
43 std::string buf;
44};
45
46} // namespace slang::netlist
Definition FormatBuffer.hpp:13
void clear()
Discard the buffered contents.
Definition FormatBuffer.hpp:37
auto str() const -> std::string
A copy of the buffered contents as a string.
Definition FormatBuffer.hpp:40
auto size() const -> size_t
The number of characters buffered.
Definition FormatBuffer.hpp:28
void append(char ch)
Append a single character.
Definition FormatBuffer.hpp:19
auto data() const -> const char *
A pointer to the buffered characters.
Definition FormatBuffer.hpp:31
void format(fmt::format_string< Args... > fmt, Args &&...args)
Append the result of formatting fmt with args.
Definition FormatBuffer.hpp:23
auto empty() const -> bool
Whether the buffer is empty.
Definition FormatBuffer.hpp:34
void append(std::string_view str)
Append a string.
Definition FormatBuffer.hpp:16
Definition FormatBuffer.hpp:9