klee
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PrintContext.h
Go to the documentation of this file.
1 #ifndef PRINTCONTEXT_H_
2 #define PRINTCONTEXT_H_
3 
4 #include "klee/Expr.h"
5 #include "llvm/Support/raw_ostream.h"
6 #include <sstream>
7 #include <string>
8 #include <stack>
9 
17 class PrintContext {
18 private:
19  llvm::raw_ostream &os;
20  std::string newline;
21 
26  std::stack<unsigned int> indentStack;
27 
28 public:
30  unsigned pos;
31 
32  PrintContext(llvm::raw_ostream &_os) : os(_os), newline("\n"), indentStack(), pos()
33  {
34  indentStack.push(pos);
35  }
36 
37  void setNewline(const std::string &_newline) {
38  newline = _newline;
39  }
40 
41  void breakLine(unsigned indent=0) {
42  os << newline;
43  if (indent)
44  os.indent(indent) << ' ';
45  pos = indent;
46  }
47 
51  {
52  breakLine(indentStack.top());
53  return *this;
54  }
55 
59  {
60  indentStack.push(pos);
61  return *this;
62  }
63 
67  {
68  indentStack.pop();
69  return *this;
70  }
71 
74  void write(const std::string &s) {
75  os << s;
76  pos += s.length();
77  }
78 
79  template <typename T>
81  std::string str;
82  llvm::raw_string_ostream ss(str);
83  ss << elt;
84  write(ss.str());
85  return *this;
86  }
87 
88 };
89 
90 
91 #endif /* PRINTCONTEXT_H_ */
void breakLine(unsigned indent=0)
Definition: PrintContext.h:41
PrintContext & popIndent()
Definition: PrintContext.h:66
PrintContext & pushIndent()
Definition: PrintContext.h:58
void setNewline(const std::string &_newline)
Definition: PrintContext.h:37
void write(const std::string &s)
Definition: PrintContext.h:74
PrintContext & operator<<(T elt)
Definition: PrintContext.h:80
llvm::raw_ostream & os
Definition: PrintContext.h:19
std::stack< unsigned int > indentStack
Definition: PrintContext.h:26
PrintContext & breakLineI()
Definition: PrintContext.h:50
PrintContext(llvm::raw_ostream &_os)
Definition: PrintContext.h:32
std::string newline
Definition: PrintContext.h:20
unsigned pos
Number of characters on the current line.
Definition: PrintContext.h:30