]> git.tdb.fi Git - libs/datafile.git/commitdiff
Add a way to combine multiple loaders
authorMikko Rasa <tdb@tdb.fi>
Sat, 15 Jun 2013 20:22:23 +0000 (23:22 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 15 Jun 2013 20:22:23 +0000 (23:22 +0300)
source/loader.cpp
source/loader.h

index c495c4cab71ed67b11d678e0cacaf02eec0bb312..2cd27e92ac4426f9c0ff04f2c07db411938b103e 100644 (file)
@@ -113,6 +113,13 @@ void Loader::load_statement(const Statement &st)
 
        try
        {
+               if(!aux_loaders.empty() && !has_keyword(st.keyword))
+               {
+                       for(list<Loader *>::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()));
index 604886125614728c2552d486decfa01afa19c804..3ab6d28fcfd194b2029588a03383ddf53adc7194 100644 (file)
@@ -50,6 +50,7 @@ private:
        ActionMap actions;
        const Statement *cur_st;
        bool sub_loaded;
+       std::list<Loader *> 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: