ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IndentPrintWriter.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file IndentPrintWriter.cc
1 // Copyright FreeHEP, 2005.
2 
3 #include <fstream>
4 
6 
7 using namespace std;
8 
12 namespace cheprep {
13 
14 IndentPrintWriter::IndentPrintWriter(ostream* outstream, int level)
15  : out(outstream),
16  closed(false),
17  indentLevel(level),
18  indented(false),
19  indentString(" ") {
20 }
21 
23 }
24 
26  if (!closed) {
27  out->flush();
28  closed = true;
29  }
30 }
31 
33  if (!indented) doIndent();
34  *out << s;
35  return *this;
36 }
37 
38 IndentPrintWriter& IndentPrintWriter::operator<< (ostream& (*)(ostream&)) {
39  *out << endl;
40  indented = false;
41  return *this;
42 }
43 
44 void IndentPrintWriter::println(const string & s) {
45  *this << s << endl;
46 }
47 
48 void IndentPrintWriter::print(const string & s) {
49  *this << s;
50 }
51 
53  *out << endl;
54  indented = false;
55 }
56 
58  for (int i=0; i<indentLevel; i++) {
59  *out << indentString;
60  }
61  indented = true;
62 }
63 
65  indentLevel++;
66 }
67 
69  indentLevel--;
70 }
71 
73  return indentLevel;
74 }
75 
76 void IndentPrintWriter::setIndent(const int level) {
77  indentLevel = level;
78 }
79 
81  return indentString;
82 }
83 
84 void IndentPrintWriter::setIndentString(const string & anIndent) {
85  indentString = anIndent;
86 }
87 
88 } // cheprep