X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcollection.h;h=0cd799abf060e399a20c55027371917e14f563c5;hb=f19f861eb6858f396d574f0d45c5e967221a384b;hp=d0e8a1a8bb9b25c636ab23a8c1e4bbdcfa5c04a7;hpb=465ac6c7ceda80ce7e2f6e3f7b6901ce0921406e;p=libs%2Fdatafile.git diff --git a/source/collection.h b/source/collection.h index d0e8a1a..0cd799a 100644 --- a/source/collection.h +++ b/source/collection.h @@ -3,6 +3,7 @@ #include #include +#include #include #include "collectionsource.h" #include "loader.h" @@ -49,7 +50,7 @@ that are not present. Items retrieted from the fallback collection are shared between the collections, and are only deleted when all collections in the chain have been destroyed. */ -class Collection +class Collection: private NonCopyable { public: /** @@ -91,8 +92,6 @@ private: SourceList sources; Collection *fallback; - Collection(const Collection &); - Collection &operator=(const Collection &); public: Collection(); virtual ~Collection(); @@ -135,8 +134,27 @@ public: return extract(get_var(name, get_type(name))); } + /** Finds a typed object in the collection. Returns null if the name does + not exist. Throws if the name exists but the object is of an incorrect + type. */ + template + T *find(const std::string &name) const + { + ItemMap::const_iterator i = items.find(name); + return (i!=items.end() ? extract::Type>(i->second) : 0); + } + + template + T *find(const std::string &name) + { + typedef typename RemoveConst::Type NCT; + const Variant *var = find_var(name, get_type(name)); + return (var ? &extract(*var) : 0); + } + private: const Variant &get_var(const std::string &, const CollectionItemTypeBase *); + const Variant *find_var(const std::string &, const CollectionItemTypeBase *); template T &extract(const Variant &var) const; @@ -279,10 +297,6 @@ public: object when done with it. */ IO::Seekable *open_raw(const std::string &) const; -protected: - // Deprecated. Use open_raw instead. - DEPRECATED IO::Seekable *open_from_sources(const std::string &n) { return open_raw(n); } - private: void gather_names_from_sources(std::list &, const CollectionItemTypeBase &) const;