Factor out base/indented_stream.h
This commit is contained in:
48
base/indented_stream.h
Normal file
48
base/indented_stream.h
Normal file
@ -0,0 +1,48 @@
|
||||
#ifndef BASE_INDENTED_STREAM_H
|
||||
#define BASE_INDENTED_STREAM_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace {
|
||||
class indented_stream {
|
||||
public:
|
||||
indented_stream(std::ostream &out)
|
||||
: out_(out),
|
||||
indent_(0) {
|
||||
}
|
||||
|
||||
void indent() {
|
||||
for (unsigned i = 0; i < indent_ * 2; i++)
|
||||
out_ << ' ';
|
||||
}
|
||||
|
||||
void inc() {
|
||||
indent_++;
|
||||
}
|
||||
|
||||
void dec() {
|
||||
indent_--;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
indented_stream &operator <<(T const &t) {
|
||||
out_ << t;
|
||||
return *this;
|
||||
}
|
||||
|
||||
indented_stream &operator <<(std::ostream &(*fp)(std::ostream &)) {
|
||||
out_ << fp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
std::ostream &out_;
|
||||
unsigned indent_;
|
||||
};
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user