X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcollection.h;h=3d5b7f0a6abce95bc8aa5d6ec05749be3ec6f8b2;hb=8955db30f9cd1c1566b349da29e669f065f84e36;hp=66c50fe69d2c86e85ce38ac1e2b4bb73fd8672b3;hpb=495920e971324d29bd4933b8a319fb5668ca5562;p=libs%2Fdatafile.git diff --git a/source/collection.h b/source/collection.h index 66c50fe..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; @@ -146,7 +139,7 @@ public: { typedef typename RemoveConst::Type NCT; - T *ptr = get_item(items, name).value >(); + T *ptr = get_item(items, name).value >().get(); if(!ptr) throw key_error(typeid(ItemMap)); return *ptr; @@ -159,7 +152,7 @@ public: private: template - void collect_items(std::list *objects, std::list *names, std::list *future_names) + void collect_items(std::list *objects, std::list *names, std::list *future_names) const { typedef RefPtr::Type> RPNCT; @@ -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;