From 7f49649f70becbb4345ad0b936c5e00194d9dc82 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 7 Jun 2019 20:27:17 +0300 Subject: [PATCH] Allow modifying existing types in a collection --- source/collection.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 { -- 2.43.0