3 This file is part of libmspdatafile
4 Copyright © 2007-2008, 2010 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/io/print.h>
9 #include <msp/strings/utils.h>
10 #include "statement.h"
11 #include "textwriter.h"
18 TextWriter::TextWriter(IO::Base &o):
22 void TextWriter::write(const Statement &st)
27 void TextWriter::write_(const Statement &st, unsigned level)
29 string indent(level, '\t');
31 IO::print(out, "%s%s", indent, st.keyword);
32 for(ValueArray::const_iterator i = st.args.begin(); i!=st.args.end(); ++i)
35 if(i->get_signature()==StringType::signature)
36 IO::print(out, "\"%s\"", c_escape(i->get<StringType::Store>(), false));
37 else if(i->get_signature()==BoolType::signature)
38 out.write(i->get<BoolType::Store>() ? "true" : "false");
39 else if(i->get_signature()==IntType::signature)
40 out.write(lexical_cast(i->get<IntType::Store>()));
41 else if(i->get_signature()==FloatType::signature)
42 out.write(format("%15g", (i->get<FloatType::Store>())));
43 else if(i->get_signature()==SymbolType::signature)
45 string name = i->get<SymbolType::Store>().name;
54 IO::print(out, "\n%s{\n", indent);
55 for(list<Statement>::const_iterator i = st.sub.begin(); i!=st.sub.end(); ++i)
57 IO::print(out, "%s}", indent);
62 } // namespace DataFile