]> git.tdb.fi Git - libs/datafile.git/blob - source/binarywriter.h
Add ability to put raw files in a pack
[libs/datafile.git] / source / binarywriter.h
1 #ifndef MSP_DATAFILE_BINARYWRITER_H_
2 #define MSP_DATAFILE_BINARYWRITER_H_
3
4 #include <map>
5 #include "binarydict.h"
6 #include "type.h"
7 #include "writermode.h"
8
9 namespace Msp {
10 namespace DataFile {
11
12 /**
13 Writes data in binary format.
14 */
15 class BinaryWriter: public WriterMode
16 {
17 private:
18         typedef std::map<DictEntry, int> Dictionary;
19         typedef std::map<std::string, unsigned> StringMap;
20
21         Dictionary dict;
22         unsigned next_kwd_id;
23         StringMap strings;
24         unsigned next_str_id;
25         unsigned float_precision;
26
27 public:
28         BinaryWriter(Output &o);
29
30         virtual void set_float_precision(unsigned);
31         virtual void write(const Statement &st);
32 private:
33         void write_(const Statement &st);
34         void collect_keywords(const Statement &st);
35         void write_int(IntType::Store n);
36         void write_string(const StringType::Store &s);
37         void write_float(FloatType::Store f);
38         void write_symbol(const SymbolType::Store &s);
39 };
40
41 } // namespace DataFile
42 } // namespace Msp
43
44 #endif