X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcollection.cpp;h=2333aaf2726082a6214d2b950aa4570ebc1ea64b;hb=a7272165a9dc6a1e9c408e77f96530a7d3aa24e1;hp=a16ae5a9dc2e7a9f70f638093348b59c8bd561eb;hpb=495920e971324d29bd4933b8a319fb5668ca5562;p=libs%2Fdatafile.git diff --git a/source/collection.cpp b/source/collection.cpp index a16ae5a..2333aaf 100644 --- a/source/collection.cpp +++ b/source/collection.cpp @@ -11,20 +11,41 @@ Collection::~Collection() delete *i; } -void Collection::add_future(const std::string &name) +const Variant &Collection::get_var(const string &name, const CollectionItemTypeBase *type) { - if(items.count(name)) - throw key_error(typeid(ItemMap)); + ItemMap::iterator i = items.find(name); + if(i!=items.end()) + return i->second; - for(TypeList::const_iterator i=types.begin(); i!=types.end(); ++i) - if((*i)->match_name(name)) + 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) { - items.insert(ItemMap::value_type(name, (*i)->create_future())); - return; + (*j)->load(*this, *type, name); + loaded = items.count(name); } + } + + return get_item(items, name); +} + +CollectionItemTypeBase *Collection::get_type_for_item(const Variant &var) const +{ + for(TypeList::const_iterator i=types.begin(); i!=types.end(); ++i) + if((*i)->check_item_type(var)) + return *i; + return 0; +} - /* XXX throw something? If we do, DirectoryCollection needs some way to - check if a name matches any item type. */ +void Collection::add_source(CollectionSource &s) +{ + sources.push_back(&s); } @@ -36,13 +57,10 @@ Collection::Loader::Loader(Collection &c): } -CollectionItemTypeBase::CollectionItemTypeBase(): - tag(0) -{ } - CollectionItemTypeBase::~CollectionItemTypeBase() { - delete tag; + for(vector::iterator i=extractors.begin(); i!=extractors.end(); ++i) + delete *i; } void CollectionItemTypeBase::set_keyword(const string &k)