]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/binarywriter.h
Add an abstraction layer for output
[libs/datafile.git] / source / binarywriter.h
index cf8f9fcaa016c35bfedb9172a6c0c76c940b00d5..81b4a46dfe70d0c9851498afbd794ce13e1c9944 100644 (file)
@@ -1,42 +1,41 @@
-/* $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 "type.h"
 #include "writermode.h"
 
 namespace Msp {
 namespace DataFile {
 
+/**
+Writes data in binary format.
+*/
 class BinaryWriter: public WriterMode
 {
 private:
-       typedef std::map<DictEntry, unsigned> Dictionary;
-       typedef std::map<std::string, unsigned> EnumMap;
+       typedef std::map<DictEntry, int> Dictionary;
+       typedef std::map<std::string, unsigned> StringMap;
 
        Dictionary dict;
-       unsigned next_st_id;
-       EnumMap enums;
-       unsigned next_enum_id;
+       unsigned next_kwd_id;
+       StringMap strings;
+       unsigned next_str_id;
+       unsigned float_precision;
 
 public:
-       BinaryWriter(std::ostream &o);
-       void write(const Statement &st);
+       BinaryWriter(Output &o);
+
+       virtual void set_float_precision(unsigned);
+       virtual 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);
+       void write_int(IntType::Store n);
+       void write_string(const StringType::Store &s);
+       void write_float(FloatType::Store f);
+       void write_symbol(const SymbolType::Store &s);
 };
 
 } // namespace DataFile