]> git.tdb.fi Git - libs/datafile.git/blob - source/writer.cpp
Add a test case for comments
[libs/datafile.git] / source / writer.cpp
1 #include <msp/io/zlibcompressed.h>
2 #include "binarywriter.h"
3 #include "statement.h"
4 #include "textwriter.h"
5 #include "writer.h"
6
7 using namespace std;
8
9 namespace Msp {
10 namespace DataFile {
11
12 Writer::Writer(IO::Base &o):
13         out(o),
14         mode(new TextWriter(out)),
15         binary(false)
16 { }
17
18 Writer::~Writer()
19 {
20         delete mode;
21 }
22
23 void Writer::write(const Statement &st)
24 {
25         mode->write(st);
26 }
27
28 void Writer::set_binary(bool b)
29 {
30         if(b==binary)
31                 return;
32
33         binary = b;
34
35         Statement st;
36         if(binary)
37                 st.keyword = "__bin";
38         else
39                 st.keyword = "__text";
40
41         mode->write(st);
42
43         delete mode;
44         if(binary)
45                 mode = new BinaryWriter(out);
46         else
47                 mode = new TextWriter(out);
48 }
49
50 void Writer::set_compressed()
51 {
52         Statement st;
53         st.keyword = "__z";
54         mode->write(st);
55
56         out.set_compressed();
57 }
58
59 void Writer::set_float_precision(unsigned fp)
60 {
61         mode->set_float_precision(fp);
62 }
63
64 } // namespace DataFile
65 } // namespace Msp