]> git.tdb.fi Git - libs/datafile.git/commitdiff
Refactor symbol handling in binary format
authorMikko Rasa <tdb@tdb.fi>
Wed, 18 Jul 2012 12:00:36 +0000 (15:00 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 18 Jul 2012 12:00:36 +0000 (15:00 +0300)
source/binaryparser.cpp
source/binaryparser.h
source/binarywriter.cpp
source/binarywriter.h

index 550319f46d0a7af21bd939b477adaac1047101c8..73bb5cb664c32ba5ecda25ca9aa047c16e2610bd 100644 (file)
@@ -89,7 +89,7 @@ Statement BinaryParser::parse_statement()
                        result.args.push_back(parse_bool());
                        break;
                case SymbolType::signature:
-                       result.args.push_back(Symbol(parse_enum()));
+                       result.args.push_back(parse_symbol());
                        break;
                }
        }
@@ -164,7 +164,7 @@ string BinaryParser::parse_string()
                return get_item(strings, -len);
 }
 
-string BinaryParser::parse_enum()
+Symbol BinaryParser::parse_symbol()
 {
        return get_item(strings, parse_int());
 }
index 2cdfbbeaba296e919ff68abb92015eb2647fbf38..4f33d954602d3c5454f1cd8d8729a2d674cc6a3e 100644 (file)
@@ -4,6 +4,7 @@
 #include <map>
 #include "binarydict.h"
 #include "parsermode.h"
+#include "type.h"
 
 namespace Msp {
 namespace DataFile {
@@ -31,7 +32,7 @@ private:
        float parse_float();
        std::string parse_string();
        bool parse_bool();
-       std::string parse_enum();
+       Symbol parse_symbol();
 };
 
 } // namespace DataFile
index 2ff96a457524c7a1e28a13c6e098de535bf0e006..a8306c2cfd8eb98a6d5e14aac5358c742e0d4e44 100644 (file)
@@ -34,7 +34,7 @@ void BinaryWriter::write_(const Statement &st)
                case StringType::signature: write_string(j->get<StringType::Store>()); break;
                case BoolType::signature:   write_int   (j->get<BoolType::Store>()); break;
                case FloatType::signature:  write_float (j->get<FloatType::Store>()); break;
-               case SymbolType::signature: write_enum  (j->get<SymbolType::Store>()); break;
+               case SymbolType::signature: write_symbol(j->get<SymbolType::Store>()); break;
                }
 
        write_int(st.sub.size());
@@ -132,9 +132,9 @@ void BinaryWriter::write_float(float f)
 #endif
 }
 
-void BinaryWriter::write_enum(const string &e)
+void BinaryWriter::write_symbol(const Symbol &s)
 {
-       write_int(get_item(strings, e));
+       write_int(get_item(strings, s.name));
 }
 
 } // namespace DataFile
index f028f39d96f811775a30a9d9a0fa2b730a3fe9e2..6ad290451b4502c3566a68668a476a40c7595b82 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <map>
 #include "binarydict.h"
+#include "type.h"
 #include "writermode.h"
 
 namespace Msp {
@@ -32,7 +33,7 @@ private:
        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_symbol(const Symbol &s);
 };
 
 } // namespace DataFile