X-Git-Url: http://git.tdb.fi/?p=libs%2Fdatafile.git;a=blobdiff_plain;f=source%2Floader.cpp;h=bffa9fd31c6ccf5018535139aa119f859d3c36b0;hp=1250d0fa608cad151ebfc3671bc08d12ed914a44;hb=d248c63a252b0efcbcd9ef11cf7f8e22e594403e;hpb=bf2cb951aa1a160049fb976c5ad6adb744b0c5c2 diff --git a/source/loader.cpp b/source/loader.cpp index 1250d0f..bffa9fd 100644 --- a/source/loader.cpp +++ b/source/loader.cpp @@ -70,7 +70,7 @@ public: class invalid_signature: public runtime_error { public: - invalid_signature(const std::string &k, const std::string & s): + invalid_signature(const std::string &k, const std::string &s): runtime_error(format("%s %s", k, s)) { } @@ -113,7 +113,16 @@ void Loader::load_statement(const Statement &st) try { - LoaderAction *act = find_action(ActionKey(st.keyword, st.get_signature())); + ActionKey key(st.keyword, st.get_signature()); + + if(!aux_loaders.empty() && !has_action(key)) + { + for(list::const_iterator i=aux_loaders.begin(); i!=aux_loaders.end(); ++i) + if((*i)->has_action(key)) + return (*i)->load_statement(st); + } + + LoaderAction *act = find_action(key); if(act) { sub_loaded = false; @@ -154,6 +163,20 @@ void Loader::add(const string &kwd, LoaderAction *act) actions[key] = act; } +void Loader::add_auxiliary_loader(Loader &ldr) +{ + aux_loaders.push_back(&ldr); +} + +bool Loader::has_action(const ActionKey &key) const +{ + ActionMap::const_iterator i = actions.lower_bound(ActionKey(key.keyword, string())); + for(; (i!=actions.end() && i->first.keyword==key.keyword); ++i) + if(signature_match(key.signature, i->first.signature)) + return true; + return false; +} + LoaderAction *Loader::find_action(const ActionKey &key) const { ActionMap::const_iterator begin = actions.lower_bound(ActionKey(key.keyword, string())); @@ -176,13 +199,6 @@ const string &Loader::get_source() const return cur_st->source; } -void Loader::error(const string &msg) const -{ - if(!cur_st) - throw logic_error("!cur_st"); - throw data_error(cur_st->source, cur_st->line, msg); -} - Loader::ActionKey::ActionKey(const string &k, const string &s): keyword(k),