From 87c59b2f1f2edf127f76928aac963c1dfc50d830 Mon Sep 17 00:00:00 2001 From: Ashwin Bhat Date: Fri, 11 Oct 2024 14:53:13 -0700 Subject: [PATCH] Update datalibrary methods for Element and it's derivatives - Rename getChildofTypeFromLibrary to getChildofTypeWithLibrary - Rename getChildrenOfTypeFromLibrary to getChildrenOfTypeWithLibrary --- source/MaterialXCore/Document.h | 28 ++++++++++++++-------------- source/MaterialXCore/Element.h | 4 ++-- source/MaterialXCore/Interface.cpp | 5 +---- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/source/MaterialXCore/Document.h b/source/MaterialXCore/Document.h index 946dc1e2dd..bc7cd612dc 100644 --- a/source/MaterialXCore/Document.h +++ b/source/MaterialXCore/Document.h @@ -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(getDataLibrary(), name) : getChildOfType(name); + return getChildOfTypeWithLibrary(getDataLibrary(), name); } /// Return a vector of all NodeGraph elements in the document. vector getNodeGraphs() const { - return hasDataLibrary() ? getChildrenOfTypeFromLibrary(getDataLibrary()) : getChildrenOfType(); + return getChildrenOfTypeWithLibrary(getDataLibrary()); } /// Remove the NodeGraph, if any, with the given name. @@ -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(getDataLibrary(), name) : getChildOfType(name); + return getChildOfTypeWithLibrary(getDataLibrary(), name); } /// Return a vector of all NodeDef elements in the document. vector getNodeDefs() const { - return hasDataLibrary() ? getChildrenOfTypeFromLibrary(getDataLibrary()) : getChildrenOfType(); + return getChildrenOfTypeWithLibrary(getDataLibrary()); } /// Remove the NodeDef, if any, with the given name. @@ -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(getDataLibrary(), name) : getChildOfType(name); + return getChildOfTypeWithLibrary(getDataLibrary(), name); } /// Return a vector of all AttributeDef elements in the document. vector getAttributeDefs() const { - return hasDataLibrary() ? getChildrenOfTypeFromLibrary(getDataLibrary()) : getChildrenOfType(); + return getChildrenOfTypeWithLibrary(getDataLibrary()); } /// Remove the AttributeDef, if any, with the given name. @@ -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(getDataLibrary(), name) : getChildOfType(name); + return getChildOfTypeWithLibrary(getDataLibrary(), name); } /// Return a vector of all TargetDef elements in the document. vector getTargetDefs() const { - return hasDataLibrary() ? getChildrenOfTypeFromLibrary(getDataLibrary()) : getChildrenOfType(); + return getChildrenOfTypeWithLibrary(getDataLibrary()); } /// Remove the TargetDef, if any, with the given name. @@ -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(getDataLibrary(), name) : getChildOfType(name); + return getChildOfTypeWithLibrary(getDataLibrary(), name); } /// Return a vector of all Implementation elements in the document. vector getImplementations() const { - return hasDataLibrary() ? getChildrenOfTypeFromLibrary(getDataLibrary()) : getChildrenOfType(); + return getChildrenOfTypeWithLibrary(getDataLibrary()); } /// Remove the Implementation, if any, with the given name. @@ -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(getDataLibrary(), name) : getChildOfType(name); + return getChildOfTypeWithLibrary(getDataLibrary(), name); } /// Return a vector of all Member elements in the TypeDef. vector getUnitDefs() const { - return hasDataLibrary() ? getChildrenOfTypeFromLibrary(getDataLibrary()) : getChildrenOfType(); + return getChildrenOfTypeWithLibrary(getDataLibrary()); } /// Remove the UnitDef, if any, with the given name. @@ -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(getDataLibrary(), name) : getChildOfType(name); + return getChildOfTypeWithLibrary(getDataLibrary(), name); } /// Return a vector of all UnitTypeDef elements in the document. vector getUnitTypeDefs() const { - return hasDataLibrary() ? getChildrenOfTypeFromLibrary(getDataLibrary()) : getChildrenOfType(); + return getChildrenOfTypeWithLibrary(getDataLibrary()); } /// Remove the UnitTypeDef, if any, with the given name. diff --git a/source/MaterialXCore/Element.h b/source/MaterialXCore/Element.h index 046b9d9ece..efef97011a 100644 --- a/source/MaterialXCore/Element.h +++ b/source/MaterialXCore/Element.h @@ -448,7 +448,7 @@ class MX_CORE_API Element : public std::enable_shared_from_this /// 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 shared_ptr getChildofTypeFromLibrary(ConstElementPtr datalibrary, const string& name) const + template shared_ptr getChildOfTypeWithLibrary(ConstElementPtr datalibrary, const string& name) const { ElementPtr child = datalibrary ? datalibrary->getChild(name) : nullptr; if (!child) @@ -487,7 +487,7 @@ class MX_CORE_API Element : public std::enable_shared_from_this /// 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 vector> getChildrenOfTypeFromLibrary(ConstElementPtr datalibrary, const string& category = EMPTY_STRING) const + template vector> getChildrenOfTypeWithLibrary(ConstElementPtr datalibrary, const string& category = EMPTY_STRING) const { vector> libraryChildren = datalibrary ? datalibrary->getChildrenOfType(category) : vector>(); vector> children = getChildrenOfType(category); diff --git a/source/MaterialXCore/Interface.cpp b/source/MaterialXCore/Interface.cpp index c4d219298c..dc3138921a 100644 --- a/source/MaterialXCore/Interface.cpp +++ b/source/MaterialXCore/Interface.cpp @@ -283,10 +283,7 @@ GeomPropDefPtr Input::getDefaultGeomProp() const if (!defaultGeomProp.empty()) { ConstDocumentPtr doc = getDocument(); - if (doc->hasDataLibrary()) - return doc->getChildofTypeFromLibrary(doc->getDataLibrary(),defaultGeomProp); - else - return doc->getChildOfType(defaultGeomProp); + return doc->getChildOfTypeWithLibrary(doc->getDataLibrary(),defaultGeomProp); } return nullptr; }