Skip to content

Commit

Permalink
App: add overloaded template method getExtension()
Browse files Browse the repository at this point in the history
This allows it to write more elegant code like:
auto ext = obj->getExtension<>(GroupExtension);
instead of
auto ext = dynamic_cast<GroupExtension*>(obj->getExtension(GroupExtension::getExtensionClassTypeId(), true, true));
  • Loading branch information
wwmayer authored and davesrocketshop committed Mar 16, 2024
1 parent c19dedf commit 93cb44f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/App/ExtensionContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ class AppExport ExtensionContainer : public App::PropertyContainer
bool hasExtensions() const;
App::Extension* getExtension(Base::Type, bool derived = true, bool no_except=false) const;
App::Extension* getExtension(const std::string& name) const; //this version does not check derived classes
// this version checks for derived types and doesn't throw
template<typename ExtensionT>
ExtensionT* getExtension() const {
return static_cast<ExtensionT*>(getExtension(ExtensionT::getExtensionClassTypeId(), true, true));
}

//returns first of type (or derived from) and throws otherwise
template<typename ExtensionT>
Expand Down

0 comments on commit 93cb44f

Please sign in to comment.