X-Git-Url: http://git.tdb.fi/?p=libs%2Fdatafile.git;a=blobdiff_plain;f=source%2Fcollection.h;fp=source%2Fcollection.h;h=89e801ffa87850ebcba5b5452c03a4a15a4dbf0b;hp=06b8e348cbe3d2a7e16ce2735971802efa73a863;hb=01dfbb71bc10eddf5496e899e87e2b0d25951aa6;hpb=193d36c8ce13cf2c5cd055fbd008f3003dda0a3e diff --git a/source/collection.h b/source/collection.h index 06b8e34..89e801f 100644 --- a/source/collection.h +++ b/source/collection.h @@ -131,7 +131,7 @@ public: T &get(const std::string &name) { typedef typename RemoveConst::Type NCT; - return extract(get_var(name, get_type())); + return extract(get_var(name, get_type(name))); } private: @@ -251,9 +251,10 @@ protected: CollectionItemType &add_type(); private: - /// Returns the descriptor for a type, or null if one isn't defined. + /** Returns the descriptor for a type, or null if one isn't defined. An + optional name can be given to prioritize matching types. */ template - CollectionItemTypeBase *get_type() const; + CollectionItemTypeBase *get_type(const std::string & = std::string()) const; /// Gets a descriptor with the same type as another descriptor. CollectionItemTypeBase *get_type(const CollectionItemTypeBase &) const; @@ -500,15 +501,20 @@ CollectionItemType &Collection::add_type() } template -CollectionItemTypeBase *Collection::get_type() const +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; + CollectionItemTypeBase *type = 0; for(TypeList::const_iterator j=types.begin(); j!=types.end(); ++j) if((*j)->can_extract()) - return *j; - return 0; + { + if(!name.empty() && (*j)->match_name(name)) + return *j; + type = *j; + } + return type; } } // namespace DataFile