]> git.tdb.fi Git - libs/datafile.git/blob - source/binarywriter.h
Add binary data format
[libs/datafile.git] / source / binarywriter.h
1 /* $Id$
2
3 This file is part of libmspdatafile
4 Copyright © 2006  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 class BinaryWriter: public WriterMode
19 {
20 private:
21         typedef std::map<DictEntry, unsigned> Dictionary;
22         typedef std::map<std::string, unsigned> EnumMap;
23
24         Dictionary dict;
25         unsigned next_st_id;
26         EnumMap enums;
27         unsigned next_enum_id;
28
29 public:
30         BinaryWriter(std::ostream &o);
31         void write(const Statement &st);
32 private:
33         void write_(const Statement &st);
34         DictEntry create_entry(const Statement &st);
35         void collect_keywords(const Statement &st);
36         void write_int(long long n);
37         void write_string(const std::string &s);
38         void write_float(float f);
39         void write_enum(const std::string &e);
40 };
41
42 } // namespace DataFile
43 } // namespace Msp
44
45 #endif