]> git.tdb.fi Git - libs/datafile.git/blob - source/binarywriter.h
1a11ae5df9d4f17e4080c678b8a7f10d75f16fd2
[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
26 public:
27         BinaryWriter(IO::Base &o);
28
29         virtual void write(const Statement &st);
30 private:
31         void write_(const Statement &st);
32         void collect_keywords(const Statement &st);
33         void write_int(IntType::Store n);
34         void write_string(const StringType::Store &s);
35         void write_float(FloatType::Store f);
36         void write_symbol(const SymbolType::Store &s);
37 };
38
39 } // namespace DataFile
40 } // namespace Msp
41
42 #endif