#include "otreestream.hpp" namespace binparse { int treebuf::sync() { return this->sbuf->pubsync(); } int treebuf::overflow(int c) { if (c != std::char_traits::eof()) { if (this->need_prefix && !this->prefix.empty() && this->prefix.size() != this->sbuf->sputn(&this->prefix[0], this->prefix.size())) { return std::char_traits::eof(); } this->need_prefix = c == '\n'; } return this->sbuf->sputc(c); } treebuf::treebuf(std::streambuf* sbuf) : sbuf(sbuf) , need_prefix(true) {} void treebuf::indent() { prefix += "\t"; } void treebuf::unindent() { prefix = std::string(prefix.begin(), prefix.end()-1); } otreestream::otreestream(std::ostream& out) : treebuf(out.rdbuf()) , std::ios(static_cast(this)) , std::ostream(static_cast(this)) { } indent::indent(std::ostream& os) : tb(dynamic_cast(os)) { tb.indent(); } indent::~indent() { tb.unindent(); } }