From 9763e39e6e09e747b87940920e778ac269dd8b15 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 15 Jun 2013 23:22:23 +0300 Subject: [PATCH] Add a way to combine multiple loaders --- source/loader.cpp | 18 ++++++++++++++++++ source/loader.h | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/source/loader.cpp b/source/loader.cpp index c495c4c..2cd27e9 100644 --- a/source/loader.cpp +++ b/source/loader.cpp @@ -113,6 +113,13 @@ void Loader::load_statement(const Statement &st) try { + if(!aux_loaders.empty() && !has_keyword(st.keyword)) + { + for(list::const_iterator i=aux_loaders.begin(); i!=aux_loaders.end(); ++i) + if((*i)->has_keyword(st.keyword)) + return (*i)->load_statement(st); + } + LoaderAction *act = find_action(ActionKey(st.keyword, st.get_signature())); if(act) { @@ -154,6 +161,17 @@ 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_keyword(const string &kwd) const +{ + ActionMap::const_iterator i = actions.lower_bound(ActionKey(kwd, string())); + return i!=actions.end() && i->first.keyword==kwd; +} + LoaderAction *Loader::find_action(const ActionKey &key) const { ActionMap::const_iterator begin = actions.lower_bound(ActionKey(key.keyword, string())); diff --git a/source/loader.h b/source/loader.h index 6048861..3ab6d28 100644 --- a/source/loader.h +++ b/source/loader.h @@ -50,6 +50,7 @@ private: ActionMap actions; const Statement *cur_st; bool sub_loaded; + std::list aux_loaders; protected: bool check_sub_loads; @@ -131,6 +132,11 @@ protected: private: void add(const std::string &, LoaderAction *); +protected: + void add_auxiliary_loader(Loader &); + +private: + bool has_keyword(const std::string &) const; LoaderAction *find_action(const ActionKey &) const; protected: -- 2.45.2