Spicy
spicy
toolchain
bin
spicy-dump
printer-text.h
1
// Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2
3
#pragma once
4
5
#include <ostream>
6
#include <string>
7
#include <utility>
8
9
#include <hilti/rt/type-info.h>
10
11
#include "options.h"
12
14
class
TextPrinter
{
15
public
:
22
TextPrinter
(std::ostream& output,
OutputOptions
options) : _output(output), _options(
std
::move(options)){};
23
29
void
print
(
const
hilti::rt::type_info::Value
& v);
30
31
private
:
32
// Return output stream.
33
std::ostream& out() {
return
_output; }
34
35
// Insert current indentation into output stream.
36
void
outputIndent() { out() << std::string(_level * 2,
' '
); }
37
38
// Increase indentation level while executing callback function.
39
void
indent(
const
std::function<
void
()>& func) {
40
++_level;
41
func();
42
--_level;
43
}
44
45
std::ostream& _output;
// output stream
46
OutputOptions
_options;
// formatting options
47
int
_level = 0;
// indentation level
48
};
TextPrinter
Definition:
printer-text.h:14
OutputOptions
Definition:
options.h:8
std
Definition:
optional.h:79
TextPrinter::TextPrinter
TextPrinter(std::ostream &output, OutputOptions options)
Definition:
printer-text.h:22
hilti::rt::type_info::Value
Definition:
type-info.h:82
TextPrinter::print
void print(const hilti::rt::type_info::Value &v)
Definition:
printer-text.cc:11
Generated by
1.8.13