klee
PrintContext.h
Go to the documentation of this file.
1//===-- PrintContext.h ------------------------------------------*- C++ -*-===//
2//
3// The KLEE Symbolic Virtual Machine
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef KLEE_PRINTCONTEXT_H
11#define KLEE_PRINTCONTEXT_H
12
13#include "klee/Expr/Expr.h"
14
15#include "llvm/Support/raw_ostream.h"
16
17#include <sstream>
18#include <string>
19#include <stack>
20
29private:
30 llvm::raw_ostream &os;
31 std::string newline;
32
37 std::stack<unsigned int> indentStack;
38
39public:
41 unsigned pos;
42
43 PrintContext(llvm::raw_ostream &_os) : os(_os), newline("\n"), indentStack(), pos()
44 {
45 indentStack.push(pos);
46 }
47
48 void setNewline(const std::string &_newline) {
49 newline = _newline;
50 }
51
52 void breakLine(unsigned indent=0) {
53 os << newline;
54 if (indent)
55 os.indent(indent) << ' ';
56 pos = indent;
57 }
58
62 {
64 return *this;
65 }
66
70 {
71 indentStack.push(pos);
72 return *this;
73 }
74
78 {
79 indentStack.pop();
80 return *this;
81 }
82
85 void write(const std::string &s) {
86 os << s;
87 pos += s.length();
88 }
89
90 template <typename T>
92 std::string str;
93 llvm::raw_string_ostream ss(str);
94 ss << elt;
95 write(ss.str());
96 return *this;
97 }
98
99};
100
101
102#endif /* KLEE_PRINTCONTEXT_H */
PrintContext & popIndent()
Definition: PrintContext.h:77
std::stack< unsigned int > indentStack
Definition: PrintContext.h:37
std::string newline
Definition: PrintContext.h:31
PrintContext & operator<<(T elt)
Definition: PrintContext.h:91
PrintContext & breakLineI()
Definition: PrintContext.h:61
llvm::raw_ostream & os
Definition: PrintContext.h:30
unsigned pos
Number of characters on the current line.
Definition: PrintContext.h:41
void breakLine(unsigned indent=0)
Definition: PrintContext.h:52
PrintContext(llvm::raw_ostream &_os)
Definition: PrintContext.h:43
PrintContext & pushIndent()
Definition: PrintContext.h:69
void setNewline(const std::string &_newline)
Definition: PrintContext.h:48
void write(const std::string &s)
Definition: PrintContext.h:85