+ typedef RefPtr<typename RemoveConst<T>::Type> RPNCT;
+
+ for(ItemMap::const_iterator i=items.begin(); i!=items.end(); ++i)
+ if(i->second.check_type<RPNCT>())
+ if(i->second.value<RPNCT>().get()==d)
+ return i->first;
+
+ // XXX Need better exception class
+ throw std::runtime_error("Item not found in collection");
+ }
+
+protected:
+ /** Adds a type to the collection. The returned descriptor object reference
+ can be used to define how objects of that type can be loaded. */
+ template<typename T>
+ CollectionItemType<T> &add_type();
+};
+
+template<typename T>
+class Collection::ItemLoader<T, false>: public T::Loader
+{
+public:
+ ItemLoader(T &o, Collection &):
+ T::Loader(o)
+ { }
+};
+
+template<typename T>
+class Collection::ItemLoader<T, true>: public T::Loader
+{
+public:
+ ItemLoader(T &o, Collection &c):
+ T::Loader(o, dynamic_cast<typename T::Loader::Collection &>(c))
+ { }
+};