Skip to content

Commit

Permalink
Remove overrides from mx::Document
Browse files Browse the repository at this point in the history
Remove getChildOfType and getChildrenOfType from Document and introduce datalibrary handling in Element.
  • Loading branch information
ashwinbhat committed Oct 15, 2024
1 parent 8abdd31 commit 5d950cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 28 deletions.
27 changes: 0 additions & 27 deletions source/MaterialXCore/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,33 +121,6 @@ class MX_CORE_API Document : public GraphElement
/// nodes, and include both Input and Output elements.
vector<PortElementPtr> getMatchingPorts(const string& nodeName) const;

/// Return the child element, if any, with the given document and data library
template <class T> shared_ptr<T> getChildOfType(const string& name) const
{
ElementPtr child = hasDataLibrary() ? getDataLibrary()->getChild(name) : nullptr;
if (!child)
{
child = getChild(name);
}
return child ? child->asA<T>() : shared_ptr<T>();
}

/// Return a vector of all child elements within the document and data library
template <class T> vector<shared_ptr<T>> getChildrenOfType(const string& category = EMPTY_STRING) const
{
vector<shared_ptr<T>> children = hasDataLibrary() ? getDataLibrary()->getChildrenOfType<T>(category) : vector<shared_ptr<T>>();
for (ElementPtr child : _childOrder)
{
shared_ptr<T> instance = child->asA<T>();
if (!instance)
continue;
if (!category.empty() && child->getCategory() != category)
continue;
children.push_back(instance);
}
return children;
}

/// @}
/// @name GeomInfo Elements
/// @{
Expand Down
16 changes: 15 additions & 1 deletion source/MaterialXCore/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,27 @@ ElementPtr Element::changeChildCategory(ElementPtr child, const string& category

template <class T> shared_ptr<T> Element::getChildOfType(const string& name) const
{
ElementPtr child = getChild(name);
ElementPtr child = nullptr;
if (isA<Document>() && asA<Document>()->hasDataLibrary())
{
child = asA<Document>()->getDataLibrary()->getChild(name);
}

if (!child)
{
child = getChild(name);
}
return child ? child->asA<T>() : shared_ptr<T>();
}

template <class T> vector<shared_ptr<T>> Element::getChildrenOfType(const string& category) const
{
vector<shared_ptr<T>> children;
if (isA<Document>() && asA<Document>()->hasDataLibrary())
{
children = asA<Document>()->getDataLibrary()->getChildrenOfType<T>(category);
}

for (ElementPtr child : _childOrder)
{
shared_ptr<T> instance = child->asA<T>();
Expand Down

0 comments on commit 5d950cc

Please sign in to comment.