From: Mikko Rasa Date: Wed, 18 Jul 2012 12:00:36 +0000 (+0300) Subject: Refactor symbol handling in binary format X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=6f94aaece716a31e75166e261cc47579288892b4;p=libs%2Fdatafile.git Refactor symbol handling in binary format --- diff --git a/source/binaryparser.cpp b/source/binaryparser.cpp index 550319f..73bb5cb 100644 --- a/source/binaryparser.cpp +++ b/source/binaryparser.cpp @@ -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()); } diff --git a/source/binaryparser.h b/source/binaryparser.h index 2cdfbbe..4f33d95 100644 --- a/source/binaryparser.h +++ b/source/binaryparser.h @@ -4,6 +4,7 @@ #include #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 diff --git a/source/binarywriter.cpp b/source/binarywriter.cpp index 2ff96a4..a8306c2 100644 --- a/source/binarywriter.cpp +++ b/source/binarywriter.cpp @@ -34,7 +34,7 @@ void BinaryWriter::write_(const Statement &st) case StringType::signature: write_string(j->get()); break; case BoolType::signature: write_int (j->get()); break; case FloatType::signature: write_float (j->get()); break; - case SymbolType::signature: write_enum (j->get()); break; + case SymbolType::signature: write_symbol(j->get()); 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 diff --git a/source/binarywriter.h b/source/binarywriter.h index f028f39..6ad2904 100644 --- a/source/binarywriter.h +++ b/source/binarywriter.h @@ -3,6 +3,7 @@ #include #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