+
+template<typename T>
+T &Collection::extract(const Variant &var) const
+{
+ if(!var.check_type<RefPtr<T> >())
+ if(CollectionItemTypeBase *type = get_type_for_item(var))
+ if(T *item = type->extract<T>(var))
+ return *item;
+
+ return *var.value<RefPtr<T> >();
+}
+
+template<typename T>
+typename CollectionItemTypeChooser<T>::Type &Collection::add_type()
+{
+ typename CollectionItemTypeChooser<T>::Type *type = new typename CollectionItemTypeChooser<T>::Type;
+ types.push_back(type);
+ return *type;
+}
+
+template<typename T>
+typename CollectionItemTypeChooser<T>::Type &Collection::modify_type()
+{
+ for(CollectionItemTypeBase *t: types)
+ if(CollectionItemType<T> *tt = dynamic_cast<CollectionItemType<T> *>(t))
+ return *tt;
+
+ throw std::logic_error("type not found in collection");
+}
+
+template<typename T>
+CollectionItemTypeBase *Collection::get_type(const std::string &name) const
+{
+ for(CollectionItemTypeBase *t: types)
+ if(dynamic_cast<CollectionItemType<T> *>(t))
+ return t;
+ CollectionItemTypeBase *type = 0;
+ for(CollectionItemTypeBase *t: types)
+ if(t->can_extract<T>())
+ {
+ if(!name.empty() && t->match_name(name))
+ return t;
+ type = t;
+ }
+ return type;
+}
+