]> git.tdb.fi Git - libs/datafile.git/blob - source/writer.h
Move the definition of Input's operator bool to the header
[libs/datafile.git] / source / writer.h
1 #ifndef MSP_DATAFILE_WRITER_H_
2 #define MSP_DATAFILE_WRITER_H_
3
4 #include <map>
5 #include <msp/core/noncopyable.h>
6 #include <msp/io/base.h>
7 #include "mspdatafile_api.h"
8 #include "output.h"
9
10 namespace Msp {
11 namespace DataFile {
12
13 struct Statement;
14 class WriterMode;
15
16 /**
17 Frontend for writing data.
18 */
19 class MSPDATAFILE_API Writer: private NonCopyable
20 {
21 private:
22         Output out;
23         WriterMode *mode = nullptr;
24         bool binary = false;
25
26 public:
27         Writer(IO::Base &o);
28         ~Writer();
29
30         /**
31         Writes a statement to the output.  This function always writes a complete
32         statement, so it's not possible to add substatements later.
33         */
34         void write(const Statement &st);
35
36         /**
37         Sets binary or text mode.  While it is possible to enter and exit binary
38         mode multiple times, doing so produces sub-optimal output.
39
40         @param  b  true for binary mode, false for text
41         */
42         void set_binary(bool b);
43
44         /** Enables output compression.  Once enabled, it won't be possible to
45         disable compression. */
46         void set_compressed();
47
48         /** Sets the precision of floating point numbers in bits.  Depending on the
49         mode not all values may be valid, but any value between 16 and 64 that is
50         divisible by 8 is guaranteed to work. */
51         void set_float_precision(unsigned);
52 };
53
54 } // namespace DataFile
55 } // namespace Msp
56
57 #endif