X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcollection.h;h=34b1260c4c42b729311964736b2efc02343c03fb;hb=41e78ee91ca058ead90fa1c8ee4339d2ef1b0f31;hp=50905ce0d14972d65b24ac37dc74cdd6b5e21be9;hpb=41230218ca007b56932fd34b79b6f3e3e70764f6;p=libs%2Fdatafile.git diff --git a/source/collection.h b/source/collection.h index 50905ce..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 @@ -83,7 +69,7 @@ public: private: typedef std::map ItemMap; typedef std::list TypeList; - typedef std::list SourceList; + typedef std::list SourceList; TypeList types; ItemMap items; @@ -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; @@ -264,7 +251,7 @@ private: protected: /** Adds a source for automatically loading items. Sources are consulted in the order they are added. */ - void add_source(CollectionSource &); + void add_source(const CollectionSource &); public: /** Opens a raw resource, without interpreting it as object data. Null is @@ -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