Geant4  10.01
IndentPrintWriter.cc
Go to the documentation of this file.
1 // Copyright FreeHEP, 2005.
2 
3 #include <fstream>
4 
5 #include "cheprep/IndentPrintWriter.h"
6 
7 using namespace std;
8 
13 namespace cheprep {
14 
15 IndentPrintWriter::IndentPrintWriter(ostream* outstream, int level)
16  : out(outstream),
17  closed(false),
18  indentLevel(level),
19  indented(false),
20  indentString(" ") {
21 }
22 
23 IndentPrintWriter::~IndentPrintWriter() {
24 }
25 
26 void IndentPrintWriter::close() {
27  if (!closed) {
28  out->flush();
29  closed = true;
30  }
31 }
32 
33 IndentPrintWriter& IndentPrintWriter::operator<< (const std::string & s) {
34  if (!indented) doIndent();
35  *out << s;
36  return *this;
37 }
38 
39 IndentPrintWriter& IndentPrintWriter::operator<< (ostream& (*)(ostream&)) {
40  *out << endl;
41  indented = false;
42  return *this;
43 }
44 
45 void IndentPrintWriter::println(const string & s) {
46  *this << s << endl;
47 }
48 
49 void IndentPrintWriter::print(const string & s) {
50  *this << s;
51 }
52 
53 void IndentPrintWriter::println() {
54  *out << endl;
55  indented = false;
56 }
57 
58 void IndentPrintWriter::doIndent() {
59  for (int i=0; i<indentLevel; i++) {
60  *out << indentString;
61  }
62  indented = true;
63 }
64 
65 void IndentPrintWriter::indent() {
66  indentLevel++;
67 }
68 
69 void IndentPrintWriter::outdent() {
70  indentLevel--;
71 }
72 
73 int IndentPrintWriter::getIndent() const {
74  return indentLevel;
75 }
76 
77 void IndentPrintWriter::setIndent(const int level) {
78  indentLevel = level;
79 }
80 
81 string IndentPrintWriter::getIndentString() const {
82  return indentString;
83 }
84 
85 void IndentPrintWriter::setIndentString(const string & anIndent) {
86  indentString = anIndent;
87 }
88 
89 } // cheprep
static const double s
Definition: G4SIunits.hh:150
std::ostream & operator<<(std::ostream &ostr, const G4String &astr)
Definition: pyG4String.cc:40
void print(const std::vector< T > &data)
Definition: DicomRun.hh:109