mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Added function called firstAncestorOfType() to get parent recursively(ancestor) of a given type.
p4#: 21416
This commit is contained in:
@@ -136,6 +136,10 @@ public:
|
||||
template <typename T>
|
||||
void parentObjectsOfType(std::vector<T*>& objects) const;
|
||||
|
||||
///
|
||||
template <typename T>
|
||||
void firstAncestorOfType(T*& ancestor) const;
|
||||
|
||||
/// Method to be called from the Ui classes creating Auto Gui to get the group information
|
||||
/// supplied by the \sa defineUiOrdering method that can be reimplemented
|
||||
void uiOrdering(QString uiConfigName, PdmUiOrdering& uiOrdering) ;
|
||||
@@ -243,5 +247,34 @@ void PdmObject::parentObjectsOfType(std::vector<T*>& objects) const
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
void PdmObject::firstAncestorOfType(T*& ancestor) const
|
||||
{
|
||||
std::vector<PdmObject*> parents;
|
||||
this->parentObjects(parents);
|
||||
|
||||
while (parents.size() > 0)
|
||||
{
|
||||
CVF_ASSERT(parents.size() == 1);
|
||||
|
||||
PdmObject* firstParent = parents[0];
|
||||
CVF_ASSERT(firstParent);
|
||||
|
||||
T* objectOfType = dynamic_cast<T*>(firstParent);
|
||||
if (objectOfType)
|
||||
{
|
||||
ancestor = objectOfType;
|
||||
return;
|
||||
}
|
||||
|
||||
// Get next level parents
|
||||
parents.clear();
|
||||
firstParent->parentObjects(parents);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // End of namespace caf
|
||||
|
||||
Reference in New Issue
Block a user