X-Git-Url: http://git.tdb.fi/?p=libs%2Fdatafile.git;a=blobdiff_plain;f=source%2Fcollection.h;h=98b359e5eaedd28604a5d1f0a0085f470a657219;hp=473b58ed76329cf72d971f728d29ba0aae296760;hb=256b44a5009467171af53316141277027bcc0ba4;hpb=7e81da8d9a6e689e271f4f0450a69d8a14f515bb diff --git a/source/collection.h b/source/collection.h index 473b58e..98b359e 100644 --- a/source/collection.h +++ b/source/collection.h @@ -85,12 +85,10 @@ public: private: typedef std::map ItemMap; - typedef std::vector TypeList; - typedef std::vector SourceList; - TypeList types; + std::vector types; ItemMap items; - SourceList sources; + std::vector sources; Collection *fallback; public: @@ -166,8 +164,8 @@ private: std::list extract_list(const std::vector &vars) const { std::list result; - for(std::vector::const_iterator i=vars.begin(); i!=vars.end(); ++i) - result.push_back(&extract(**i)); + for(const Variant *v: vars) + result.push_back(&extract(*v)); return result; } @@ -257,10 +255,10 @@ public: { typedef RefPtr::type> RPNCT; - for(ItemMap::const_iterator i=items.begin(); i!=items.end(); ++i) - if(i->second.check_type()) - if(i->second.value().get()==d) - return i->first; + for(const auto &kvp: items) + if(kvp.second.check_type()) + if(kvp.second.value().get()==d) + return kvp.first; // XXX Need better exception class throw std::runtime_error("Item not found in collection"); @@ -371,8 +369,8 @@ public: template bool can_extract() const { - for(std::vector::const_iterator i=extractors.begin(); i!=extractors.end(); ++i) - if(dynamic_cast *>(*i)) + for(ExtractorBase *e: extractors) + if(dynamic_cast *>(e)) return true; return false; } @@ -380,8 +378,8 @@ public: template T *extract(const Variant &var) const { - for(std::vector::const_iterator i=extractors.begin(); i!=extractors.end(); ++i) - if(Extractor *ex = dynamic_cast *>(*i)) + for(ExtractorBase *e: extractors) + if(Extractor *ex = dynamic_cast *>(e)) return &ex->extract(var); return 0; } @@ -454,8 +452,8 @@ public: ~CollectionItemType() { delete creat; - for(typename std::vector::const_iterator i=notif.begin(); i!=notif.end(); ++i) - delete *i; + for(NotifyeeBase *n: notif) + delete n; } /** Sets a datafile keyword for this item type. The Collection's loader @@ -535,8 +533,8 @@ public: virtual void notify_item(Collection &coll, const std::string &name, const Variant &var) const { RefPtr obj = var.value >(); - for(typename std::vector::const_iterator i=notif.begin(); i!=notif.end(); ++i) - (*i)->notify(coll, name, *obj); + for(NotifyeeBase *n: notif) + n->notify(coll, name, *obj); } }; @@ -581,9 +579,9 @@ typename CollectionItemTypeChooser::Type &Collection::add_type() template typename CollectionItemTypeChooser::Type &Collection::modify_type() { - for(TypeList::const_iterator j=types.begin(); j!=types.end(); ++j) - if(CollectionItemType *t = dynamic_cast *>(*j)) - return *t; + for(CollectionItemTypeBase *t: types) + if(CollectionItemType *tt = dynamic_cast *>(t)) + return *tt; throw std::logic_error("type not found in collection"); } @@ -591,16 +589,16 @@ typename CollectionItemTypeChooser::Type &Collection::modify_type() template CollectionItemTypeBase *Collection::get_type(const std::string &name) const { - for(TypeList::const_iterator j=types.begin(); j!=types.end(); ++j) - if(dynamic_cast *>(*j)) - return *j; + for(CollectionItemTypeBase *t: types) + if(dynamic_cast *>(t)) + return t; CollectionItemTypeBase *type = 0; - for(TypeList::const_iterator j=types.begin(); j!=types.end(); ++j) - if((*j)->can_extract()) + for(CollectionItemTypeBase *t: types) + if(t->can_extract()) { - if(!name.empty() && (*j)->match_name(name)) - return *j; - type = *j; + if(!name.empty() && t->match_name(name)) + return t; + type = t; } return type; }