X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcollection.cpp;h=2333aaf2726082a6214d2b950aa4570ebc1ea64b;hb=62038f6100d131b760a2ac090933b7b998419bc9;hp=5ac12ab7d366c3406cfc59206b42b166875557d5;hpb=76c532f3f5ff079cf7b2016343a1ff73d497c50f;p=libs%2Fdatafile.git diff --git a/source/collection.cpp b/source/collection.cpp index 5ac12ab..2333aaf 100644 --- a/source/collection.cpp +++ b/source/collection.cpp @@ -11,26 +11,41 @@ Collection::~Collection() delete *i; } -void Collection::add_future(const string &name) +const Variant &Collection::get_var(const string &name, const CollectionItemTypeBase *type) { - for(TypeList::const_iterator i=types.begin(); i!=types.end(); ++i) - if((*i)->match_name(name)) + 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) { - insert_unique(items, name, (*i)->create_future()); - return; + (*j)->load(*this, *type, name); + loaded = items.count(name); } + } + + return get_item(items, name); } -void Collection::add_future_with_keyword(const string &name, const string &keyword) +CollectionItemTypeBase *Collection::get_type_for_item(const Variant &var) const { for(TypeList::const_iterator i=types.begin(); i!=types.end(); ++i) - if((*i)->get_keyword()==keyword) - { - insert_unique(items, name, (*i)->create_future()); - return; - } + if((*i)->check_item_type(var)) + return *i; + return 0; +} - throw runtime_error("Collection::add_future_with_keyword"); +void Collection::add_source(CollectionSource &s) +{ + sources.push_back(&s); } @@ -42,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)