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 <cstddef>
6
#include <ostream>
7
#include <string>
8
#include <utility>
9
10
#include <hilti/rt/type-info.h>
11
12
#include "options.h"
13
15
class
TextPrinter
{
16
public
:
23
TextPrinter
(std::ostream& output,
OutputOptions
options) : _output(output), _options(options){};
24
30
void
print
(
const
hilti::rt::type_info::Value
& v);
31
32
private
:
33
// Return output stream.
34
std::ostream& out() {
return
_output; }
35
36
// Insert current indentation into output stream.
37
void
outputIndent() { out() << std::string(
static_cast<
std::basic_string<char>::size_type
>
(_level) * 2,
' '
); }
38
39
// Increase indentation level while executing callback function.
40
void
indent(
const
std::function<
void
()>& func) {
41
++_level;
42
func();
43
--_level;
44
}
45
46
std::ostream& _output;
// output stream
47
OutputOptions
_options;
// formatting options
48
int
_level = 0;
// indentation level
49
};
TextPrinter
Definition:
printer-text.h:15
OutputOptions
Definition:
options.h:8
TextPrinter::TextPrinter
TextPrinter(std::ostream &output, OutputOptions options)
Definition:
printer-text.h:23
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