X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcollection.cpp;h=f86adf65c71ace3370e7a57537eaa4fe6cd8243a;hb=fbf76ed98dbd2cca6785efe2dd489d717fa5dce6;hp=129c0a84f76808c14f0a8164b853e0c56d6ccb97;hpb=a887b3f7518605c22e4b70eeb9fe136acb2ea632;p=libs%2Fdatafile.git diff --git a/source/collection.cpp b/source/collection.cpp index 129c0a8..f86adf6 100644 --- a/source/collection.cpp +++ b/source/collection.cpp @@ -16,11 +16,27 @@ Collection::~Collection() delete *i; } +void Collection::add_var(const string &name, const CollectionItemTypeBase *type, const Variant &var) +{ + insert_unique(items, name, var); + if(type) + type->notify_item(*this, name, var); +} + 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 +54,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