Example of allowing multiple components of the same type to be queried.

This commit is contained in:
2023-04-07 07:46:41 -07:00
parent af005c0e4a
commit 60a5a98ec5
5 changed files with 37 additions and 2 deletions

View File

@ -78,6 +78,27 @@ namespace Dawn {
}
return nullptr;
}
/**
* Returns all components attached to this SceneItem that match the
* queried component type. This method will return an array of shared
* pointers to the components, or an empty array if the item does not have
* any components of the queried type.
*
* @tparam T Type of component to be fetched.
* @return An array of pointers to the components.
*/
template<class T>
std::vector<T*> getComponents() {
std::vector<T*> components;
auto it = this->components.begin();
while(it != this->components.end()) {
T *castedAs = dynamic_cast<T*>(*it);
if(castedAs != nullptr) components.push_back(castedAs);
++it;
}
return components;
}
/**
* Finds a (direct) child of this component that has a matching component.