]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/binarywriter.h
Add binary data format
[libs/datafile.git] / source / binarywriter.h
diff --git a/source/binarywriter.h b/source/binarywriter.h
new file mode 100644 (file)
index 0000000..cf8f9fc
--- /dev/null
@@ -0,0 +1,45 @@
+/* $Id$
+
+This file is part of libmspdatafile
+Copyright © 2006  Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#ifndef MSP_DATAFILE_BINARYWRITER_H_
+#define MSP_DATAFILE_BINARYWRITER_H_
+
+#include <map>
+#include "binarydict.h"
+#include "writermode.h"
+
+namespace Msp {
+namespace DataFile {
+
+class BinaryWriter: public WriterMode
+{
+private:
+       typedef std::map<DictEntry, unsigned> Dictionary;
+       typedef std::map<std::string, unsigned> EnumMap;
+
+       Dictionary dict;
+       unsigned next_st_id;
+       EnumMap enums;
+       unsigned next_enum_id;
+
+public:
+       BinaryWriter(std::ostream &o);
+       void write(const Statement &st);
+private:
+       void write_(const Statement &st);
+       DictEntry create_entry(const Statement &st);
+       void collect_keywords(const Statement &st);
+       void write_int(long long n);
+       void write_string(const std::string &s);
+       void write_float(float f);
+       void write_enum(const std::string &e);
+};
+
+} // namespace DataFile
+} // namespace Msp
+
+#endif