summaryrefslogtreecommitdiff
path: root/src/verify_report.h
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-09-16 17:38:43 +0200
committerCarl Hetherington <cth@carlh.net>2025-09-16 23:49:13 +0200
commit02dd03b4ef42db0a43b2011b5c34446f6f987c12 (patch)
tree1d78e3b1b5bc63cf38d72edc9cba485bd9727c0d /src/verify_report.h
parentb33a97e3aa7dd3a0ddd3687762ff42a9a9e1079f (diff)
Extract StreamFormatter.
Diffstat (limited to 'src/verify_report.h')
-rw-r--r--src/verify_report.h52
1 files changed, 5 insertions, 47 deletions
diff --git a/src/verify_report.h b/src/verify_report.h
index 612918eb..7be8d9d9 100644
--- a/src/verify_report.h
+++ b/src/verify_report.h
@@ -36,67 +36,25 @@ namespace dcp {
class Formatter
{
public:
- Formatter(boost::filesystem::path file)
- : _file(file, "w")
- {}
-
class Wrap
{
public:
- Wrap() = default;
-
- Wrap(Formatter* formatter, std::string const& close)
- : _formatter(formatter)
- , _close(close)
- {}
-
- Wrap(Formatter* formatter, std::string const& close, std::function<void ()> closer)
- : _formatter(formatter)
- , _close(close)
- , _closer(closer)
- {}
-
- Wrap(Wrap&& other)
- {
- std::swap(_formatter, other._formatter);
- std::swap(_close, other._close);
- std::swap(_closer, other._closer);
- }
-
- ~Wrap()
- {
- if (_formatter) {
- _formatter->file().puts(_close.c_str());
- }
- if (_closer) {
- _closer();
- }
- }
-
- private:
- Formatter* _formatter = nullptr;
- std::string _close;
- std::function<void ()> _closer = nullptr;
+ virtual ~Wrap() {}
};
- virtual Wrap document() { return {}; }
+ virtual std::unique_ptr<Wrap> document() { return {}; }
virtual void heading(std::string const& text) = 0;
virtual void subheading(std::string const& text) = 0;
- virtual Wrap body() { return {}; }
+ virtual std::unique_ptr<Wrap> body() { return {}; }
- virtual Wrap unordered_list() = 0;
+ virtual std::unique_ptr<Wrap> unordered_list() = 0;
virtual void list_item(std::string const& text, boost::optional<std::string> type = {}) = 0;
virtual std::function<std::string (std::string)> process_string() = 0;
virtual std::function<std::string (std::string)> fixed_width() = 0;
- dcp::File& file() {
- return _file;
- }
-
-protected:
- dcp::File _file;
+ virtual void finish() {}
};