+ i = items.find(name);
+ return (i!=items.end() ? &i->second : 0);
+}
+
+void Collection::gather_items(vector<const Variant *> *vars, list<string> *names, const CollectionItemTypeBase &type, bool include_sources) const
+{
+ for(const auto &kvp: items)
+ if(type.check_item_type(kvp.second))
+ {
+ if(vars)
+ vars->push_back(&kvp.second);
+ if(names)
+ names->push_back(kvp.first);
+ }
+
+ if(include_sources && names)
+ gather_names_from_sources(*names, type);
+}
+
+unsigned Collection::get_status(const string &name, const CollectionItemTypeBase &type) const
+{
+ ItemMap::const_iterator i = items.find(name);
+ if(i==items.end())
+ {
+ auto j = find_if(sources, [&name, &type](const CollectionSource *s){ return s->is_loadable(type, name); });
+ if(j!=sources.end())
+ return 2;
+ if(fallback)
+ if(CollectionItemTypeBase *fb_type = fallback->get_type(type))
+ return fallback->get_status(name, *fb_type);
+ return 0;
+ }
+
+ return type.check_item_type(i->second);
+}
+
+CollectionItemTypeBase *Collection::get_type(const CollectionItemTypeBase &type) const
+{
+ for(CollectionItemTypeBase *t: types)
+ if(t->is_same_type(type))
+ return t;
+ return 0;
+}
+
+CollectionItemTypeBase *Collection::get_type_for_item(const Variant &var) const
+{
+ for(CollectionItemTypeBase *t: types)
+ if(t->check_item_type(var))
+ return t;
+ return 0;
+}
+
+void Collection::add_source(const CollectionSource &s)
+{
+ sources.push_back(&s);
+}
+
+IO::Seekable *Collection::open_raw(const string &name) const
+{
+ for(const CollectionSource *s: sources)
+ if(IO::Seekable *io = s->open(name))
+ return io;
+
+ return 0;
+}
+
+void Collection::gather_names_from_sources(list<string> &names, const CollectionItemTypeBase &type) const
+{
+ set<string> new_names;
+ for(const CollectionSource *s: sources)
+ for(const string &n: s->get_names(type))
+ if(!items.count(n))
+ new_names.insert(n);
+ names.insert(names.end(), new_names.begin(), new_names.end());
+}
+
+void Collection::load_items_from_sources(const CollectionItemTypeBase &type)
+{
+ for(const CollectionSource *s: sources)
+ for(const string &n: s->get_names(type))
+ if(!items.count(n))
+ {
+ bool loaded = false;
+ if(type.can_create())
+ {
+ type.create_item(*this, n);
+ loaded = items.count(n);
+ }
+ if(!loaded)
+ s->load(*this, type, n);
+ }
+}
+
+void Collection::set_fallback(Collection *f)
+{
+ fallback = f;