Skip to content

Commit

Permalink
Update datalibrary methods for Element and it's derivatives
Browse files Browse the repository at this point in the history
- Rename getChildofTypeFromLibrary to getChildofTypeWithLibrary
- Rename getChildrenOfTypeFromLibrary to getChildrenOfTypeWithLibrary
  • Loading branch information
ashwinbhat committed Oct 11, 2024
1 parent 6aef150 commit 87c59b2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
28 changes: 14 additions & 14 deletions source/MaterialXCore/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ class MX_CORE_API Document : public GraphElement
/// Return the NodeGraph, if any, with the given name.
NodeGraphPtr getNodeGraph(const string& name) const
{
return hasDataLibrary() ? getChildofTypeFromLibrary<NodeGraph>(getDataLibrary(), name) : getChildOfType<NodeGraph>(name);
return getChildOfTypeWithLibrary<NodeGraph>(getDataLibrary(), name);
}

/// Return a vector of all NodeGraph elements in the document.
vector<NodeGraphPtr> getNodeGraphs() const
{
return hasDataLibrary() ? getChildrenOfTypeFromLibrary<NodeGraph>(getDataLibrary()) : getChildrenOfType<NodeGraph>();
return getChildrenOfTypeWithLibrary<NodeGraph>(getDataLibrary());
}

/// Remove the NodeGraph, if any, with the given name.
Expand Down Expand Up @@ -346,13 +346,13 @@ class MX_CORE_API Document : public GraphElement
/// Return the NodeDef, if any, with the given name.
NodeDefPtr getNodeDef(const string& name) const
{
return hasDataLibrary() ? getChildofTypeFromLibrary<NodeDef>(getDataLibrary(), name) : getChildOfType<NodeDef>(name);
return getChildOfTypeWithLibrary<NodeDef>(getDataLibrary(), name);
}

/// Return a vector of all NodeDef elements in the document.
vector<NodeDefPtr> getNodeDefs() const
{
return hasDataLibrary() ? getChildrenOfTypeFromLibrary<NodeDef>(getDataLibrary()) : getChildrenOfType<NodeDef>();
return getChildrenOfTypeWithLibrary<NodeDef>(getDataLibrary());
}

/// Remove the NodeDef, if any, with the given name.
Expand Down Expand Up @@ -381,13 +381,13 @@ class MX_CORE_API Document : public GraphElement
/// Return the AttributeDef, if any, with the given name.
AttributeDefPtr getAttributeDef(const string& name) const
{
return hasDataLibrary() ? getChildofTypeFromLibrary<AttributeDef>(getDataLibrary(), name) : getChildOfType<AttributeDef>(name);
return getChildOfTypeWithLibrary<AttributeDef>(getDataLibrary(), name);
}

/// Return a vector of all AttributeDef elements in the document.
vector<AttributeDefPtr> getAttributeDefs() const
{
return hasDataLibrary() ? getChildrenOfTypeFromLibrary<AttributeDef>(getDataLibrary()) : getChildrenOfType<AttributeDef>();
return getChildrenOfTypeWithLibrary<AttributeDef>(getDataLibrary());
}

/// Remove the AttributeDef, if any, with the given name.
Expand All @@ -413,13 +413,13 @@ class MX_CORE_API Document : public GraphElement
/// Return the AttributeDef, if any, with the given name.
TargetDefPtr getTargetDef(const string& name) const
{
return hasDataLibrary() ? getChildofTypeFromLibrary<TargetDef>(getDataLibrary(), name) : getChildOfType<TargetDef>(name);
return getChildOfTypeWithLibrary<TargetDef>(getDataLibrary(), name);
}

/// Return a vector of all TargetDef elements in the document.
vector<TargetDefPtr> getTargetDefs() const
{
return hasDataLibrary() ? getChildrenOfTypeFromLibrary<TargetDef>(getDataLibrary()) : getChildrenOfType<TargetDef>();
return getChildrenOfTypeWithLibrary<TargetDef>(getDataLibrary());
}

/// Remove the TargetDef, if any, with the given name.
Expand Down Expand Up @@ -509,13 +509,13 @@ class MX_CORE_API Document : public GraphElement
/// Return the Implementation, if any, with the given name.
ImplementationPtr getImplementation(const string& name) const
{
return hasDataLibrary() ? getChildofTypeFromLibrary<Implementation>(getDataLibrary(), name) : getChildOfType<Implementation>(name);
return getChildOfTypeWithLibrary<Implementation>(getDataLibrary(), name);
}

/// Return a vector of all Implementation elements in the document.
vector<ImplementationPtr> getImplementations() const
{
return hasDataLibrary() ? getChildrenOfTypeFromLibrary<Implementation>(getDataLibrary()) : getChildrenOfType<Implementation>();
return getChildrenOfTypeWithLibrary<Implementation>(getDataLibrary());
}

/// Remove the Implementation, if any, with the given name.
Expand Down Expand Up @@ -545,13 +545,13 @@ class MX_CORE_API Document : public GraphElement
/// Return the UnitDef, if any, with the given name.
UnitDefPtr getUnitDef(const string& name) const
{
return hasDataLibrary() ? getChildofTypeFromLibrary<UnitDef>(getDataLibrary(), name) : getChildOfType<UnitDef>(name);
return getChildOfTypeWithLibrary<UnitDef>(getDataLibrary(), name);
}

/// Return a vector of all Member elements in the TypeDef.
vector<UnitDefPtr> getUnitDefs() const
{
return hasDataLibrary() ? getChildrenOfTypeFromLibrary<UnitDef>(getDataLibrary()) : getChildrenOfType<UnitDef>();
return getChildrenOfTypeWithLibrary<UnitDef>(getDataLibrary());
}

/// Remove the UnitDef, if any, with the given name.
Expand All @@ -576,13 +576,13 @@ class MX_CORE_API Document : public GraphElement
/// Return the UnitTypeDef, if any, with the given name.
UnitTypeDefPtr getUnitTypeDef(const string& name) const
{
return hasDataLibrary() ? getChildofTypeFromLibrary<UnitTypeDef>(getDataLibrary(), name) : getChildOfType<UnitTypeDef>(name);
return getChildOfTypeWithLibrary<UnitTypeDef>(getDataLibrary(), name);
}

/// Return a vector of all UnitTypeDef elements in the document.
vector<UnitTypeDefPtr> getUnitTypeDefs() const
{
return hasDataLibrary() ? getChildrenOfTypeFromLibrary<UnitTypeDef>(getDataLibrary()) : getChildrenOfType<UnitTypeDef>();
return getChildrenOfTypeWithLibrary<UnitTypeDef>(getDataLibrary());
}

/// Remove the UnitTypeDef, if any, with the given name.
Expand Down
4 changes: 2 additions & 2 deletions source/MaterialXCore/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ class MX_CORE_API Element : public std::enable_shared_from_this<Element>
/// Return the child element from data library , if any, with the given name and subclass.
/// If a child with the given name exists, but belongs to a different
/// subclass, then an empty shared pointer is returned.
template <class T> shared_ptr<T> getChildofTypeFromLibrary(ConstElementPtr datalibrary, const string& name) const
template <class T> shared_ptr<T> getChildOfTypeWithLibrary(ConstElementPtr datalibrary, const string& name) const
{
ElementPtr child = datalibrary ? datalibrary->getChild(name) : nullptr;
if (!child)
Expand Down Expand Up @@ -487,7 +487,7 @@ class MX_CORE_API Element : public std::enable_shared_from_this<Element>
/// Return a combined vector of all child elements including the Data Library that are instances of the given
/// subclass, optionally filtered by the given category string. The returned
/// vector maintains the order in which children were added.
template <class T> vector<shared_ptr<T>> getChildrenOfTypeFromLibrary(ConstElementPtr datalibrary, const string& category = EMPTY_STRING) const
template <class T> vector<shared_ptr<T>> getChildrenOfTypeWithLibrary(ConstElementPtr datalibrary, const string& category = EMPTY_STRING) const
{
vector<shared_ptr<T>> libraryChildren = datalibrary ? datalibrary->getChildrenOfType<T>(category) : vector<shared_ptr<T>>();
vector<shared_ptr<T>> children = getChildrenOfType<T>(category);
Expand Down
5 changes: 1 addition & 4 deletions source/MaterialXCore/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,7 @@ GeomPropDefPtr Input::getDefaultGeomProp() const
if (!defaultGeomProp.empty())
{
ConstDocumentPtr doc = getDocument();
if (doc->hasDataLibrary())
return doc->getChildofTypeFromLibrary<GeomPropDef>(doc->getDataLibrary(),defaultGeomProp);
else
return doc->getChildOfType<GeomPropDef>(defaultGeomProp);
return doc->getChildOfTypeWithLibrary<GeomPropDef>(doc->getDataLibrary(),defaultGeomProp);
}
return nullptr;
}
Expand Down

0 comments on commit 87c59b2

Please sign in to comment.