]> git.tdb.fi Git - libs/datafile.git/blob - source/binarywriter.h
Some more code reformatting
[libs/datafile.git] / source / binarywriter.h
1 /* $Id$
2
3 This file is part of libmspdatafile
4 Copyright © 2007-2008, 2010  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_DATAFILE_BINARYWRITER_H_
9 #define MSP_DATAFILE_BINARYWRITER_H_
10
11 #include <map>
12 #include "binarydict.h"
13 #include "writermode.h"
14
15 namespace Msp {
16 namespace DataFile {
17
18 /**
19 Writes data in binary format.
20 */
21 class BinaryWriter: public WriterMode
22 {
23 private:
24         typedef std::map<DictEntry, unsigned> Dictionary;
25         typedef std::map<std::string, unsigned> StringMap;
26
27         Dictionary dict;
28         unsigned next_kwd_id;
29         StringMap strings;
30         unsigned next_str_id;
31
32 public:
33         BinaryWriter(IO::Base &o);
34
35         virtual void write(const Statement &st);
36 private:
37         void write_(const Statement &st);
38         void collect_keywords(const Statement &st);
39         void write_int(long long n);
40         void write_string(const std::string &s);
41         void write_float(float f);
42         void write_enum(const std::string &e);
43 };
44
45 } // namespace DataFile
46 } // namespace Msp
47
48 #endif