X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcollection.cpp;h=6d7306357712c2b737f9ff5d8232a6888b5daffb;hb=b26fbba2bf5d53554325762b8022c501b3b8c8fb;hp=3e9e4f18d7c676e1ee3008c858e14d4735568e2a;hpb=41230218ca007b56932fd34b79b6f3e3e70764f6;p=libs%2Fdatafile.git diff --git a/source/collection.cpp b/source/collection.cpp index 3e9e4f1..6d73063 100644 --- a/source/collection.cpp +++ b/source/collection.cpp @@ -17,10 +17,19 @@ Collection::~Collection() } const Variant &Collection::get_var(const string &name, const CollectionItemTypeBase *type) +{ + const Variant *var = find_var(name, type); + if(var) + return *var; + + throw key_error(name); +} + +const Variant *Collection::find_var(const string &name, const CollectionItemTypeBase *type) { ItemMap::iterator i = items.find(name); if(i!=items.end()) - return i->second; + return &i->second; if(type) { @@ -38,13 +47,14 @@ const Variant &Collection::get_var(const string &name, const CollectionItemTypeB if(!loaded && fallback) if(CollectionItemTypeBase *fb_type = fallback->get_type(*type)) if(fallback->get_status(name, *fb_type)) - return fallback->get_var(name, fb_type); + return fallback->find_var(name, fb_type); } - return get_item(items, name); + i = items.find(name); + return (i!=items.end() ? &i->second : 0); } -void Collection::gather_items(list *vars, list *names, const CollectionItemTypeBase &type, bool include_sources) const +void Collection::gather_items(vector *vars, list *names, const CollectionItemTypeBase &type, bool include_sources) const { for(ItemMap::const_iterator i=items.begin(); i!=items.end(); ++i) if(type.check_item_type(i->second)) @@ -92,7 +102,7 @@ CollectionItemTypeBase *Collection::get_type_for_item(const Variant &var) const return 0; } -void Collection::add_source(CollectionSource &s) +void Collection::add_source(const CollectionSource &s) { sources.push_back(&s); }