template<typename T>
CollectionItemType<T> &add_type();
+ /** Returns a mutable reference to an existing type descriptor. This can be
+ used to e.g. override the creator function of a type added by a base class. */
+ template<typename T>
+ CollectionItemType<T> &modify_type();
+
private:
/** Returns the descriptor for a type, or null if one isn't defined. An
optional name can be given to prioritize matching types. */
return *type;
}
+template<typename T>
+CollectionItemType<T> &Collection::modify_type()
+{
+ for(TypeList::const_iterator j=types.begin(); j!=types.end(); ++j)
+ if(CollectionItemType<T> *t = dynamic_cast<CollectionItemType<T> *>(*j))
+ return *t;
+
+ throw std::logic_error("type not found in collection");
+}
+
template<typename T>
CollectionItemTypeBase *Collection::get_type(const std::string &name) const
{