From 5fd2c13c3036ea6a767802fdc9a2ab809ef8ec17 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 18 Jul 2012 15:56:42 +0300 Subject: [PATCH] Use the metadata for type.h in binary write/parse functions --- source/binaryparser.cpp | 14 +++++++------- source/binaryparser.h | 10 +++++----- source/binarywriter.cpp | 10 +++++----- source/binarywriter.h | 8 ++++---- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/source/binaryparser.cpp b/source/binaryparser.cpp index 73bb5cb..5313128 100644 --- a/source/binaryparser.cpp +++ b/source/binaryparser.cpp @@ -103,9 +103,9 @@ Statement BinaryParser::parse_statement() return result; } -long long BinaryParser::parse_int() +IntType::Store BinaryParser::parse_int() { - long long result = 0; + IntType::Store result = 0; unsigned bits = 0; while(in) @@ -119,13 +119,13 @@ long long BinaryParser::parse_int() break; } - const long long mask = 1LL<<(bits-1); + const IntType::Store mask = 1LL<<(bits-1); result = (result^mask)-mask; return result; } -float BinaryParser::parse_float() +FloatType::Store BinaryParser::parse_float() { union { @@ -144,12 +144,12 @@ float BinaryParser::parse_float() return f; } -bool BinaryParser::parse_bool() +BoolType::Store BinaryParser::parse_bool() { return in.get(); } -string BinaryParser::parse_string() +StringType::Store BinaryParser::parse_string() { int len = parse_int(); if(len>=0) @@ -164,7 +164,7 @@ string BinaryParser::parse_string() return get_item(strings, -len); } -Symbol BinaryParser::parse_symbol() +SymbolType::Store BinaryParser::parse_symbol() { return get_item(strings, parse_int()); } diff --git a/source/binaryparser.h b/source/binaryparser.h index 4f33d95..f9b8e54 100644 --- a/source/binaryparser.h +++ b/source/binaryparser.h @@ -28,11 +28,11 @@ public: virtual Statement parse(); private: Statement parse_statement(); - long long parse_int(); - float parse_float(); - std::string parse_string(); - bool parse_bool(); - Symbol parse_symbol(); + IntType::Store parse_int(); + FloatType::Store parse_float(); + StringType::Store parse_string(); + BoolType::Store parse_bool(); + SymbolType::Store parse_symbol(); }; } // namespace DataFile diff --git a/source/binarywriter.cpp b/source/binarywriter.cpp index a8306c2..c1e53fb 100644 --- a/source/binarywriter.cpp +++ b/source/binarywriter.cpp @@ -89,9 +89,9 @@ void BinaryWriter::collect_keywords(const Statement &st) collect_keywords(*i); } -void BinaryWriter::write_int(long long n) +void BinaryWriter::write_int(IntType::Store n) { - unsigned i = sizeof(long long)-1; + unsigned i = sizeof(IntType::Store)-1; if(n>=0) for(; (i>0 && (n>>(i*7-1))==0); --i) ; @@ -102,7 +102,7 @@ void BinaryWriter::write_int(long long n) out.put((n>>(i*7) & 0x7F) | (i?0x80:0)); } -void BinaryWriter::write_string(const string &s) +void BinaryWriter::write_string(const StringType::Store &s) { StringMap::const_iterator i = strings.find(s); if(i!=strings.end()) @@ -114,7 +114,7 @@ void BinaryWriter::write_string(const string &s) } } -void BinaryWriter::write_float(float f) +void BinaryWriter::write_float(FloatType::Store f) { union { @@ -132,7 +132,7 @@ void BinaryWriter::write_float(float f) #endif } -void BinaryWriter::write_symbol(const Symbol &s) +void BinaryWriter::write_symbol(const SymbolType::Store &s) { write_int(get_item(strings, s.name)); } diff --git a/source/binarywriter.h b/source/binarywriter.h index 6ad2904..4d18196 100644 --- a/source/binarywriter.h +++ b/source/binarywriter.h @@ -30,10 +30,10 @@ public: private: void write_(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_symbol(const Symbol &s); + 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 -- 2.45.2