#include <Pt/Mcp/ContentType.h>
Writer for one MCP content block around a Formatter. More...
Public Member Functions | |
| virtual | ~ContentFormatter () |
| Destroys the formatter. | |
| Pt::Formatter & | beginContent (std::ostream &os) |
| Writes the opening bytes of the content block to os. | |
| void | finishContent (std::ostream &os) |
| Flushes buffered output and writes the closing bytes to os. | |
Protected Member Functions | |
| ContentFormatter () | |
| Creates an idle content formatter. | |
| virtual void | onBeginContent ()=0 |
| Writes the opening bytes of the concrete content block. | |
| virtual Pt::Formatter & | onBeginFormat ()=0 |
| Returns the Formatter the decomposed result is drained into. | |
| virtual void | onFinishContent ()=0 |
| Writes the closing bytes of the concrete content block. | |
| void | write (const char *s, std::size_t n) |
| Writes n raw bytes from s to the output stream. | |
| std::ostream & | output () const |
| Returns the output stream passed to beginContent(). | |
ContentFormatter is the per-request writer the result-content group described. beginContent() writes the opening bytes of the content array and of the concrete block (for example a text member), then returns the Pt::Formatter the decomposed result is drained into. finishContent() flushes buffered output and writes the closing bytes. The formatter is not itself a Pt::Formatter; it wraps one.
Instances come from ContentType::getFormatter() and must be released with ContentType::releaseFormatter(). Subclass this type to implement a custom block: onBeginContent() writes the type-specific opening JSON, onBeginFormat() returns the inner formatter, and onFinishContent() writes the closing JSON. write() and output() are for those overrides.
| Pt::Formatter & beginContent | ( | std::ostream & | os | ) |
Returns the Pt::Formatter the result is to be decomposed into.
|
protectedpure virtual |
Implementations write the type-specific opening JSON, for example the start of a text or image member.
|
protectedpure virtual |
Called by beginContent() after onBeginContent() has written the opening bytes.