diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmObjectHandle.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmObjectHandle.h index 5a16fea7ed..b89be1c801 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmObjectHandle.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmObjectHandle.h @@ -35,6 +35,11 @@ public: template void firstAnchestorOrThisOfType(T*& ancestor) const; + /// Traverses all children recursively to find objects of the requested type. This object is also + /// included if it is of the requested type. + template + void descendantsIncludingThisOfType(std::vector& descendants) const; + // PtrReferences /// The PdmPtrField's containing pointers to this PdmObjecthandle /// Use ownerObject() on the fieldHandle to get the PdmObjectHandle @@ -149,5 +154,29 @@ void PdmObjectHandle::firstAnchestorOrThisOfType(T*& ancestor) const } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +template +void PdmObjectHandle::descendantsIncludingThisOfType(std::vector& descendants) const +{ + const T* objectOfType = dynamic_cast(this); + if (objectOfType) + { + descendants.push_back(const_cast(objectOfType)); + } + + for (auto f : m_fields) + { + std::vector childObjects; + f->childObjects(&childObjects); + + for (auto childObject : childObjects) + { + childObject->descendantsIncludingThisOfType(descendants); + } + } +} + } // End of namespace caf