]> git.tdb.fi Git - libs/datafile.git/commitdiff
Use the metadata for type.h in binary write/parse functions
authorMikko Rasa <tdb@tdb.fi>
Wed, 18 Jul 2012 12:56:42 +0000 (15:56 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 18 Jul 2012 12:56:42 +0000 (15:56 +0300)
source/binaryparser.cpp
source/binaryparser.h
source/binarywriter.cpp
source/binarywriter.h

index 73bb5cb664c32ba5ecda25ca9aa047c16e2610bd..53131289a851b04270e377e8abb5b61b49832b5c 100644 (file)
@@ -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());
 }
index 4f33d954602d3c5454f1cd8d8729a2d674cc6a3e..f9b8e542865fac10550c8a5c5105d40819efcd69 100644 (file)
@@ -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
index a8306c2cfd8eb98a6d5e14aac5358c742e0d4e44..c1e53fb5f23e7ca3622697c4e5e829383aeafd2f 100644 (file)
@@ -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));
 }
index 6ad290451b4502c3566a68668a476a40c7595b82..4d18196663d377e9bdf992748a9021e0a845e902 100644 (file)
@@ -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