|
| | Printer (Printer &&other) noexcept |
| | Move-constructs, transferring the region.
|
| Printer & | operator= (Printer &&other) noexcept |
| | Move-assigns, transferring the region.
|
|
| Printer (const Printer &)=delete |
|
Printer & | operator= (const Printer &)=delete |
| bool | should_print () const |
| | Whether printing to this printer gives output.
|
| void | text (std::string_view text) |
| | Write text that does not break.
|
| template<typename T> |
| void | repr (const T &value) |
| | Write the C++ representation of a value.
|
| void | reflow (std::string_view text) |
| | Write text that some other formatter made, with its bracket structure recovered.
|
| void | breakable (std::string_view separator=" ") |
| | Write a point where the line can break.
|
| void | if_break (std::string_view text) |
| | Write text only when the innermost group breaks.
|
|
void | hard_break () |
| | Write a new line, then the current indentation.
|
| void | begin_group (std::size_t indent, std::string_view open) |
| | Write open and start a group.
|
| void | end_group (std::string_view close) |
| | End the innermost group and write close.
|
| template<typename F> |
| void | group (std::size_t indent, std::string_view open, std::string_view close, F &&body) |
| | Write a group: open, what body writes, then close.
|
| template<typename Range, typename F> |
| void | seq (std::string_view open, std::string_view close, const Range &items, F &&print_item) |
| | Write a list of items, separated by commas.
|
|
void | separator () |
| | Write the separator between two items: , and breakable(" ").
|
| void | shift_indent (std::ptrdiff_t delta) |
| | Change the indentation of the break points that follow.
|
| void | comment (std::string_view text) |
| | Write // <text> at the end of the current line.
|
| Speculation | speculate () |
| | Start a speculative region on this printer.
|
| Printer | deferred () |
| | Make a child region at the current position.
|
Writes to the document that a failure report shows.
When a test fails, Hegel prints each drawn value as a C++ declaration, auto x = <value>;. A printable generator writes the <value> part itself, through a Printer, while it draws: see generators::IPrintableGenerator and generators::AnyGenerator::print_with.
Hegel for C++ only says what to print and where a line can break. libhegel lays the document out: a group fits on one line, or each of its break points becomes a new line.
document.printer().seq("{", "}", std::vector<int>{1000, 2000, 3000},
std::string out = std::move(document).finish();
A document of its own, outside a test case.
Definition printer.h:326
Writes to the document that a failure report shows.
Definition printer.h:55
void repr(const T &value)
Write the C++ representation of a value.
Definition repr.h:713
A Printer is move-only and has one owner (one thread) at a time. A no-op printer (noop()) discards everything, which lets one drawing body serve a silent draw and a printed draw. A printer whose region is dead (see deferred()) also discards everything. A misuse of the protocol, such as end_group() with no open group, throws std::logic_error.
| Printer hegel::Printer::deferred |
( |
| ) |
|
Make a child region at the current position.
What the child gets later, from any thread that owns it, shows at this position when the document is read. A generator uses this to print a value whose representation is known only after the draw, as randoms() does with the values it gives. The child is dead (its writes are discarded) after the document is read, or when a speculative region that it is in is aborted. The child of a no-op or dead printer is a no-op printer.
- Returns
- The child region.
| void hegel::Printer::reflow |
( |
std::string_view | text | ) |
|
Write text that some other formatter made, with its bracket structure recovered.
The engine finds the groups of (...), [...] and {...} in text and their , separated items, so the text can break like structured output.
- Parameters
-
| text | The formatted text. It can contain newlines. |
template<typename T>
| void hegel::Printer::repr |
( |
const T & | value | ) |
|
Write the C++ representation of a value.
The representation is a C++ expression (std::vector<int>{1, 2}, std::string("a"), 1.5f) with groups and break points, so the engine can break a wide value across lines. A type prints itself through a void print_to(hegel::Printer&) const member, a reflectable aggregate (C++20) prints its fields, and other types print the text of their operator<<, through reflow(). See hegel::is_representable_v. Nothing is formatted unless should_print().
- Template Parameters
-
- Parameters
-
template<typename Range, typename F>
| void hegel::Printer::seq |
( |
std::string_view | open, |
|
|
std::string_view | close, |
|
|
const Range & | items, |
|
|
F && | print_item ) |
|
inline |
Write a list of items, separated by commas.
On one line when it fits ({1, 2}). Else each item is on a line of its own, indented four columns, and close is on a line of its own. This is the layout of the containers that Hegel prints.
- Template Parameters
-
- Parameters
-
| open | Text written before the items. |
| close | Text written after the items. |
| items | The items. |
| print_item | Writes one item. |