mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Added firstAncestorOfType
This commit is contained in:
@@ -31,6 +31,10 @@ public:
|
||||
/// The field referencing this object as a child
|
||||
PdmFieldHandle* parentField() const;
|
||||
|
||||
///
|
||||
template <typename T>
|
||||
void firstAncestorOfType(T*& ancestor) const;
|
||||
|
||||
// PtrReferences
|
||||
/// The PdmPtrField's containing pointers to this PdmObjecthandle
|
||||
/// Use ownerObject() on the fieldHandle to get the PdmObjectHandle
|
||||
@@ -89,5 +93,26 @@ private:
|
||||
std::set<PdmObjectHandle**> m_pointersReferencingMe;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
void PdmObjectHandle::firstAncestorOfType(T*& ancestor) const
|
||||
{
|
||||
PdmObjectHandle* parentObject = this->parentField()->ownerObject();
|
||||
while (parentObject)
|
||||
{
|
||||
T* objectOfType = dynamic_cast<T*>(parentObject);
|
||||
if (objectOfType)
|
||||
{
|
||||
ancestor = objectOfType;
|
||||
return;
|
||||
}
|
||||
|
||||
parentObject = parentObject->parentField()->ownerObject();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // End of namespace caf
|
||||
|
||||
|
||||
Reference in New Issue
Block a user