X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcollection.h;h=3d5b7f0a6abce95bc8aa5d6ec05749be3ec6f8b2;hb=8955db30f9cd1c1566b349da29e669f065f84e36;hp=b2c91d6879c82ef486b9b29b78f0f4054779dd59;hpb=ae5c70255ce06515224299985672c540d0b237a7;p=libs%2Fdatafile.git diff --git a/source/collection.h b/source/collection.h index b2c91d6..3d5b7f0 100644 --- a/source/collection.h +++ b/source/collection.h @@ -55,34 +55,27 @@ public: template friend class CollectionItemType; private: - template::value> - struct Add; - Collection &coll; public: Loader(Collection &); Collection &get_object() const { return coll; } private: - template - void coll_item(const std::string &n) - { - RefPtr it = new T; - load_sub(*it, dynamic_cast(coll)); - coll.add(n, it.get()); - it.release(); - } - template void item(const std::string &n) { RefPtr it = new T; - load_sub(*it); + ItemLoader ldr(*it, coll); + load_sub_with(ldr); coll.add(n, it.get()); it.release(); } }; +protected: + template::value> + class ItemLoader; + private: typedef std::map ItemMap; typedef std::list TypeList; @@ -272,19 +265,22 @@ protected: CollectionItemType &add_type(); }; - -template -struct Collection::Loader::Add +template +class Collection::ItemLoader: public T::Loader { - static void add(Loader &loader, const std::string &kwd) - { loader.add(kwd, &Loader::item); } +public: + ItemLoader(T &o, Collection &): + T::Loader(o) + { } }; -template -struct Collection::Loader::Add +template +class Collection::ItemLoader: public T::Loader { - static void add(Loader &loader, const std::string &kwd) - { loader.add(kwd, &Loader::coll_item); } +public: + ItemLoader(T &o, Collection &c): + T::Loader(o, dynamic_cast(c)) + { } }; @@ -383,7 +379,7 @@ private: { return RefPtr(0); } virtual void add_to_loader(Collection::Loader &loader, const std::string &kwd) - { Collection::Loader::Add::add(loader, kwd); } + { loader.add(kwd, &Collection::Loader::item); } }; CreatorBase *creat;