X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcollection.h;h=34b1260c4c42b729311964736b2efc02343c03fb;hb=41e78ee91ca058ead90fa1c8ee4339d2ef1b0f31;hp=06b8e348cbe3d2a7e16ce2735971802efa73a863;hpb=43b8dee0bf05dee1b4a07cc001fae0c81ec53a2f;p=libs%2Fdatafile.git diff --git a/source/collection.h b/source/collection.h index 06b8e34..34b1260 100644 --- a/source/collection.h +++ b/source/collection.h @@ -2,10 +2,10 @@ #define MSP_DATAFILE_COLLECTION_H_ #include -#include #include #include "collectionsource.h" #include "loader.h" +#include "meta.h" /* XXX This file is a big mess with too many things in it. However, the dependencies between those things make it difficult to split up. */ @@ -13,20 +13,6 @@ dependencies between those things make it difficult to split up. */ namespace Msp { namespace DataFile { -/** -Helper struct to determine whether a Loader has a Collection typedef. -*/ -template -struct NeedsCollection: public Sfinae -{ - template - static Yes f(typename U::Collection *); - template - static No f(...); - - enum { value = Evaluate(0))>::value }; -}; - class CollectionItemTypeBase; template @@ -131,7 +117,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 +237,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 +487,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