X-Git-Url: http://git.tdb.fi/?p=libs%2Fdatafile.git;a=blobdiff_plain;f=source%2Fcollection.cpp;h=87982e8f4baa5df80ec1dbe257e33ba4b83af594;hp=bf1c5edc211e93b33f1dacc833e0ac1a38657a5e;hb=698d4ae13da87b7c53aa96bca99c3deaff397eec;hpb=e93ac3d7eb94842161f0669cf78b4e2173dc0488 diff --git a/source/collection.cpp b/source/collection.cpp index bf1c5ed..87982e8 100644 --- a/source/collection.cpp +++ b/source/collection.cpp @@ -11,6 +11,30 @@ Collection::~Collection() delete *i; } +const Variant &Collection::get_var(const string &name, const CollectionItemTypeBase *type) +{ + ItemMap::iterator i = items.find(name); + if(i!=items.end()) + return i->second; + + if(type) + { + bool loaded = false; + if(type->can_create()) + { + type->create_item(*this, name); + loaded = items.count(name); + } + for(SourceList::iterator j=sources.begin(); (!loaded && j!=sources.end()); ++j) + { + (*j)->load(*this, *type, name); + loaded = items.count(name); + } + } + + return get_item(items, name); +} + void Collection::add_source(CollectionSource &s) { sources.push_back(&s);