Fwk : Add function to get all referenced PdmObjects

This commit is contained in:
Magne Sjaastad 2021-05-25 11:11:10 +02:00
parent 86bdf5722a
commit a4a6c30370
2 changed files with 35 additions and 0 deletions

View File

@ -56,6 +56,36 @@ caf::PdmObject* cafTreeNode::referencedObject() const
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<caf::PdmObject*> cafTreeNode::allReferencedObjects() const
{
std::vector<caf::PdmObject*> objects;
allReferencedObjectsRecursively( this, objects );
return objects;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void cafTreeNode::allReferencedObjectsRecursively( const cafTreeNode* node, std::vector<caf::PdmObject*>& objects )
{
if ( auto obj = node->referencedObject() )
{
objects.push_back( obj );
return;
}
for ( auto c : node->childNodes() )
{
allReferencedObjectsRecursively( c, objects );
}
}
//--------------------------------------------------------------------------------------------------
///
///

View File

@ -46,6 +46,11 @@ public:
virtual caf::PdmObject* referencedObject() const;
std::vector<caf::PdmObject*> allReferencedObjects() const;
private:
static void allReferencedObjectsRecursively( const cafTreeNode* node, std::vector<caf::PdmObject*>& objects );
protected:
caf::PdmChildArrayField<cafTreeNode*> m_childNodes;
};