X-Git-Url: http://git.tdb.fi/?p=libs%2Fdatafile.git;a=blobdiff_plain;f=source%2Fcollection.cpp;h=984fb74da8e7a6007645e6f85aa002b8ae6f894a;hp=fbe894a8bb4b073c0baa227655bd2d3ecf3781e3;hb=9b1656018f783eb4aad2fbdc1de1404691e89bb1;hpb=bcbe8b90de68e18260313b8f0e8a8dd9c7661903 diff --git a/source/collection.cpp b/source/collection.cpp index fbe894a..984fb74 100644 --- a/source/collection.cpp +++ b/source/collection.cpp @@ -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); @@ -77,6 +91,15 @@ void Collection::add_source(CollectionSource &s) sources.push_back(&s); } +IO::Seekable *Collection::open_from_sources(const string &name) +{ + for(SourceList::const_iterator i=sources.begin(); i!=sources.end(); ++i) + if(IO::Seekable *io = (*i)->open(name)) + return io; + + throw IO::file_not_found(name); +} + void Collection::gather_names_from_sources(list &names, const CollectionItemTypeBase &type) const { for(SourceList::const_iterator i=sources.begin(); i!=sources.end(); ++i) @@ -99,6 +122,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)