X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcollection.h;h=34b1260c4c42b729311964736b2efc02343c03fb;hb=41e78ee91ca058ead90fa1c8ee4339d2ef1b0f31;hp=612a0af01879deaac213f1883db29df76d3cd57d;hpb=5e677b2b3eeb2b3c41216a329f7b1363aade0aed;p=libs%2Fdatafile.git diff --git a/source/collection.h b/source/collection.h index 612a0af..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; @@ -284,6 +271,8 @@ protected: /** Sets a fallback collection, which will be consulted if an item is not found. */ void set_fallback(Collection *); + + Collection *get_fallback() const { return fallback; } }; template @@ -498,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