]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/collection.cpp
Add support for fallback collections
[libs/datafile.git] / source / collection.cpp
index fbe894a8bb4b073c0baa227655bd2d3ecf3781e3..070991948d33d7315074ec6bb480cc06344d45cc 100644 (file)
@@ -5,6 +5,10 @@ using namespace std;
 namespace Msp {
 namespace DataFile {
 
+Collection::Collection():
+       fallback(0)
+{ }
+
 Collection::~Collection()
 {
        for(TypeList::iterator i = types.begin(); i!=types.end(); ++i)
@@ -30,6 +34,16 @@ const Variant &Collection::get_var(const string &name, const CollectionItemTypeB
                        (*j)->load(*this, *type, name);
                        loaded = items.count(name);
                }
+               if(!loaded && fallback)
+               {
+                       for(TypeList::const_iterator j=fallback->types.begin(); j!=fallback->types.end(); ++j)
+                               if((*j)->is_same_type(*type))
+                               {
+                                       if(fallback->get_status(name, **j))
+                                               return fallback->get_var(name, *j);
+                                       break;
+                               }
+               }
        }
 
        return get_item(items, name);
@@ -99,6 +113,11 @@ void Collection::load_items_from_sources(const CollectionItemTypeBase &type)
        }
 }
 
+void Collection::set_fallback(Collection *f)
+{
+       fallback = f;
+}
+
 
 Collection::Loader::Loader(Collection &c):
        coll(c)