X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbinaryparser.cpp;h=4ed2877a4424c2389c890473a0e71918418516ba;hb=HEAD;hp=e2ced82098e7b1472944dd4a2b626bef32211459;hpb=e063c8e0aa04f0b09962be8b6c586c1d021a929f;p=libs%2Fdatafile.git diff --git a/source/binaryparser.cpp b/source/binaryparser.cpp index e2ced82..11e0bad 100644 --- a/source/binaryparser.cpp +++ b/source/binaryparser.cpp @@ -1,10 +1,10 @@ #include -#include #include #include #include "argumentstore.h" #include "binaryparser.h" #include "binfloat.h" +#include "except.h" #include "input.h" #include "loaderaction.h" @@ -13,31 +13,8 @@ using namespace std; namespace Msp { namespace DataFile { -class bad_definition: public runtime_error -{ -public: - bad_definition(const std::string &w): - runtime_error(w) - { } - - virtual ~bad_definition() throw() { } -}; - -class nesting_error: public logic_error -{ -public: - nesting_error(const std::string &w): - logic_error(w) - { } - - virtual ~nesting_error() throw() { } -}; - - BinaryParser::BinaryParser(Input &i, const string &s): - ParserMode(i, s), - float_precision(32), - cur_info(0) + ParserMode(i, s) { dict[-1] = StatementInfo("__kwd", "iss"); dict[-2] = StatementInfo("__str", "is"); @@ -50,7 +27,7 @@ Statement BinaryParser::parse() if(cur_info) { key = &cur_info->key; - cur_info = 0; + cur_info = nullptr; } else { @@ -82,7 +59,7 @@ Statement BinaryParser::parse() result.args.push_back(parse_bool()); break; case SymbolType::signature: - result.args.push_back(parse_symbol()); + result.args.push_back(Value(parse_symbol())); break; } } @@ -111,8 +88,8 @@ void BinaryParser::process_control_statement(const Statement &st) const string &kw = st.args[1].get(); const string &args = st.args[2].get(); - for(string::const_iterator i=args.begin(); i!=args.end(); ++i) - for(unsigned j=0; valid_signatures[j]!=*i; ++j) + for(char c: args) + for(unsigned j=0; valid_signatures[j]!=c; ++j) if(!valid_signatures[j]) throw bad_definition("__kwd"); @@ -140,14 +117,14 @@ const StatementKey *BinaryParser::peek(unsigned level) for(unsigned i=sub_remaining.back(); i-->0; ) parse(); sub_remaining.pop_back(); - cur_info = 0; + cur_info = nullptr; } if(!sub_remaining.empty() && sub_remaining.back()==0) { // No more substatements on this level - cur_info = 0; - return 0; + cur_info = nullptr; + return nullptr; } if(cur_info) @@ -155,7 +132,7 @@ const StatementKey *BinaryParser::peek(unsigned level) int id = parse_int(); if(!in) - return 0; + return nullptr; cur_info = &get_item(dict, id); return &cur_info->key; @@ -190,7 +167,7 @@ bool BinaryParser::parse_and_load(unsigned level, Loader &ldr, const LoaderActio if(!sub_remaining.empty()) --sub_remaining.back(); sub_remaining.push_back(parse_int()); - cur_info = 0; + cur_info = nullptr; act.execute(ldr, args); @@ -221,7 +198,7 @@ IntType::Store BinaryParser::parse_int() FloatType::Store BinaryParser::parse_float() { - UInt64 encoded = 0; + uint64_t encoded = 0; for(unsigned i=0; i