-/* $Id$
-
-This file is part of libmspdatafile
-Copyright © 2006 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
#include <msp/io/print.h>
#include <msp/strings/utils.h>
+#include "output.h"
#include "statement.h"
#include "textwriter.h"
namespace Msp {
namespace DataFile {
-TextWriter::TextWriter(IO::Base &o):
+TextWriter::TextWriter(Output &o):
WriterMode(o)
-{ }
+{
+ float_format.showpoint().precision(7);
+}
+
+void TextWriter::set_float_precision(unsigned fp)
+{
+ float_format.precision(fp/4-1);
+}
void TextWriter::write(const Statement &st)
{
{
string indent(level, '\t');
- IO::print(out, "%s%s", indent, st.keyword);
+ out.write(format("%s%s", indent, st.keyword));
for(ValueArray::const_iterator i = st.args.begin(); i!=st.args.end(); ++i)
{
out.put(' ');
- if(i->get_type()==STRING)
- IO::print(out, "\"%s\"", c_escape(i->get_raw(), false));
- else if(i->get_type()==BOOLEAN)
- out.write(i->get<bool>() ? "true" : "false");
- else
- out.write(i->get_raw());
+ if(i->get_signature()==StringType::signature)
+ out.write(format("\"%s\"", c_escape(i->get<StringType::Store>(), false)));
+ else if(i->get_signature()==BoolType::signature)
+ out.write(i->get<BoolType::Store>() ? "true" : "false");
+ else if(i->get_signature()==IntType::signature)
+ out.write(lexical_cast<string>(i->get<IntType::Store>()));
+ else if(i->get_signature()==FloatType::signature)
+ out.write(lexical_cast<string>(i->get<FloatType::Store>(), float_format));
+ else if(i->get_signature()==SymbolType::signature)
+ {
+ string name = i->get<SymbolType::Store>().name;
+ if(isdigit(name[0]))
+ out.write("\\"+name);
+ else
+ out.write(name);
+ }
}
if(!st.sub.empty())
{
- IO::print(out, "\n%s{\n", indent);
+ out.write(format("\n%s{\n", indent));
for(list<Statement>::const_iterator i = st.sub.begin(); i!=st.sub.end(); ++i)
write_(*i, level+1);
- IO::print(out, "%s}", indent);
+ out.write(format("%s}", indent));
}
- out.write(";\n", 2);
+ out.write(";\n");
}
} // namespace DataFile