Skip to content

Commit

Permalink
Wrap game feature in shared pointer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Holt59 committed Jun 8, 2024
1 parent 2ac1d95 commit ce0d751
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/game_features/igamefeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,20 @@ class IGameFeatures
* @return the feature of the given type, if one exists, otherwise a null pointer.
*/
template <BaseGameFeature T>
T* gameFeature() const
std::shared_ptr<T> gameFeature() const
{
// gameFeatureImpl ensure that the returned pointer is of the right type (or
// nullptr), so reinterpret_cast should be fine here
return dynamic_cast<T*>(gameFeatureImpl(typeid(T)));
return std::dynamic_pointer_cast<T>(gameFeatureImpl(typeid(T)));
}

public:
virtual ~IGameFeatures() = default;

protected:
virtual GameFeature* gameFeatureImpl(std::type_info const& info) const = 0;
virtual int unregisterFeaturesImpl(std::type_info const& info) = 0;
virtual std::shared_ptr<GameFeature>
gameFeatureImpl(std::type_info const& info) const = 0;
virtual int unregisterFeaturesImpl(std::type_info const& info) = 0;
};

} // namespace MOBase
Expand Down

0 comments on commit ce0d751

Please sign in to comment.