X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbinaryparser.cpp;h=e4282aea8f64ae3cf23eec698f885ab2bcd823b6;hb=256b44a5009467171af53316141277027bcc0ba4;hp=051133f79a32cecb540c021f87b6930f5e168566;hpb=3b78eeb8b92dc3524d6a0456b4daf0a0f3dbf813;p=libs%2Fdatafile.git diff --git a/source/binaryparser.cpp b/source/binaryparser.cpp index 051133f..e4282ae 100644 --- a/source/binaryparser.cpp +++ b/source/binaryparser.cpp @@ -5,6 +5,7 @@ #include "argumentstore.h" #include "binaryparser.h" #include "binfloat.h" +#include "except.h" #include "input.h" #include "loaderaction.h" @@ -13,27 +14,6 @@ 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), @@ -48,7 +28,10 @@ Statement BinaryParser::parse() { const StatementKey *key; if(cur_info) + { key = &cur_info->key; + cur_info = 0; + } else { int id = parse_int(); @@ -84,15 +67,16 @@ Statement BinaryParser::parse() } } - if(!sub_remaining.empty()) - --sub_remaining.back(); + unsigned upper_nsub = (sub_remaining.empty() ? 0 : sub_remaining.back()); unsigned nsub = parse_int(); for(unsigned j = 0; j0) + sub_remaining.back() = upper_nsub-1; + result.valid = true; - cur_info = 0; return result; } @@ -107,8 +91,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");