X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Ftextwriter.cpp;fp=source%2Ftextwriter.cpp;h=68111c0d3038c9b6b4b0f1f0a70df6b436d0c167;hb=27630d44298cb67e075c166f4421288cc8ca117e;hp=0000000000000000000000000000000000000000;hpb=c4930d8d15a5a248ca921e0ed3f9bca8aa18b322;p=libs%2Fdatafile.git diff --git a/source/textwriter.cpp b/source/textwriter.cpp new file mode 100644 index 0000000..68111c0 --- /dev/null +++ b/source/textwriter.cpp @@ -0,0 +1,51 @@ +/* $Id$ + +This file is part of libmspdatafile +Copyright © 2006 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#include "statement.h" +#include "textwriter.h" + +using namespace std; + +namespace Msp { +namespace DataFile { + +TextWriter::TextWriter(ostream &o): + WriterMode(o) +{ } + +void TextWriter::write(const Statement &st) +{ + write_(st, 0); +} + +void TextWriter::write_(const Statement &st, unsigned level) +{ + string indent(level, '\t'); + + out<get_type()==STRING) + out<<'\"'<get_raw()<<'\"'; + else if(i->get_type()==BOOLEAN) + out<<(i->get() ? "true" : "false"); + else + out<get_raw(); + } + if(!st.sub.empty()) + { + out<<'\n'<::const_iterator i=st.sub.begin(); i!=st.sub.end(); ++i) + write_(*i, level+1); + out<