]> git.tdb.fi Git - libs/datafile.git/commitdiff
Use an Fmt object to store the float format
authorMikko Rasa <tdb@tdb.fi>
Sat, 1 Dec 2012 09:45:04 +0000 (11:45 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 1 Dec 2012 09:45:04 +0000 (11:45 +0200)
source/textwriter.cpp
source/textwriter.h

index c870ba0c20d7888f19725761924171c6b01662d9..f37b7339e462f35f1cc5461c60dbb60a8a8a3b4b 100644 (file)
@@ -10,13 +10,14 @@ namespace Msp {
 namespace DataFile {
 
 TextWriter::TextWriter(Output &o):
-       WriterMode(o),
-       float_format("%#.7g")
-{ }
+       WriterMode(o)
+{
+       float_format.showpoint().precision(7);
+}
 
 void TextWriter::set_float_precision(unsigned fp)
 {
-       float_format = format("%%#.%dg", fp/4-1);
+       float_format.precision(fp/4-1);
 }
 
 void TextWriter::write(const Statement &st)
@@ -39,7 +40,7 @@ void TextWriter::write_(const Statement &st, unsigned level)
                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(format(float_format, i->get<FloatType::Store>()));
+                       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;
index e265d2fbb50d80c71352183928f8ae136fe2824a..fef437930bb0271ff097d78079a421bef7f5ec4f 100644 (file)
@@ -9,7 +9,7 @@ namespace DataFile {
 class TextWriter: public WriterMode
 {
 private:
-       std::string float_format;
+       Fmt float_format;
 
 public:
        TextWriter(Output &o);