From eed15dceed29d1bb378082e08114ea81005203c1 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 19 Aug 2012 00:16:50 +0300 Subject: [PATCH] Proper loading of collection-enabled objects in DirectoryCollection --- source/directorycollection.h | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/source/directorycollection.h b/source/directorycollection.h index 54bf62a..e9a9463 100644 --- a/source/directorycollection.h +++ b/source/directorycollection.h @@ -13,6 +13,9 @@ A Collection that can automatically load items from files in a directory. class DirectoryCollection: public Collection { private: + template::value> + class ItemLoader; + std::list dirs; public: @@ -36,7 +39,10 @@ private: if(lookup_file(name, file)) { RefPtr item = new T; - load(*item, file.str()); + ItemLoader ldr(*item, *this); + IO::BufferedFile in(file.str()); + Parser parser(in, file.str()); + ldr.load(parser); return item.release(); } else @@ -47,6 +53,24 @@ protected: bool lookup_file(const std::string &, FS::Path &) const; }; +template +class DirectoryCollection::ItemLoader: public T::Loader +{ +public: + ItemLoader(T &o, Collection &): + T::Loader(o) + { } +}; + +template +class DirectoryCollection::ItemLoader: public T::Loader +{ +public: + ItemLoader(T &o, Collection &c): + T::Loader(o, dynamic_cast(c)) + { } +}; + } // namespace DataFile } // namespace Msp -- 2.45.2