X-Git-Url: http://git.tdb.fi/?p=libs%2Fdatafile.git;a=blobdiff_plain;f=source%2Fcollection.h;h=005abd0db39e3c54c8b934ea784e5431164d70e4;hp=bc84d624b2948c4c9bb46eb1716581de22b8da62;hb=7f49649f70becbb4345ad0b936c5e00194d9dc82;hpb=a8a205c6a1780780ed7724cf1e401d94b23c898d diff --git a/source/collection.h b/source/collection.h index bc84d62..005abd0 100644 --- a/source/collection.h +++ b/source/collection.h @@ -237,6 +237,11 @@ protected: template CollectionItemType &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 + CollectionItemType &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. */ @@ -488,6 +493,16 @@ CollectionItemType &Collection::add_type() return *type; } +template +CollectionItemType &Collection::modify_type() +{ + for(TypeList::const_iterator j=types.begin(); j!=types.end(); ++j) + if(CollectionItemType *t = dynamic_cast *>(*j)) + return *t; + + throw std::logic_error("type not found in collection"); +} + template CollectionItemTypeBase *Collection::get_type(const std::string &name) const {