X-Git-Url: http://git.tdb.fi/?p=libs%2Fdatafile.git;a=blobdiff_plain;f=source%2Fcollection.cpp;h=6d7306357712c2b737f9ff5d8232a6888b5daffb;hp=129c0a84f76808c14f0a8164b853e0c56d6ccb97;hb=b26fbba2bf5d53554325762b8022c501b3b8c8fb;hpb=0881c95bef812d94d8086225c2736b4f15b4c8dc diff --git a/source/collection.cpp b/source/collection.cpp index 129c0a8..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,10 +47,11 @@ 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(vector *vars, list *names, const CollectionItemTypeBase &type, bool include_sources) const