static SdfPath _AppendNode(const SdfPath &path, const Sdf_PathNodeConstRefPtr &node) { switch (node->GetNodeType()) { case Sdf_PathNode::PrimNode: return path.AppendChild(node->GetName()); case Sdf_PathNode::PrimPropertyNode: return path.AppendProperty(node->GetName()); case Sdf_PathNode::PrimVariantSelectionNode: { const Sdf_PathNode::VariantSelectionType& selection = node->GetVariantSelection(); return path.AppendVariantSelection(selection.first.GetString(), selection.second.GetString()); } case Sdf_PathNode::TargetNode: return path.AppendTarget( node->GetTargetPath()); case Sdf_PathNode::RelationalAttributeNode: return path.AppendRelationalAttribute(node->GetName()); case Sdf_PathNode::MapperNode: return path.AppendMapper(node->GetTargetPath()); case Sdf_PathNode::MapperArgNode: return path.AppendMapperArg(node->GetName()); case Sdf_PathNode::ExpressionNode: return path.AppendExpression(); default: // CODE_COVERAGE_OFF // Should never get here. All reasonable cases are // handled above. TF_CODING_ERROR("Unexpected node type %i", node->GetNodeType()); return SdfPath::EmptyPath(); // CODE_COVERAGE_ON } }
SdfAttributeSpecHandle SdfAttributeSpec::_New( const SdfRelationshipSpecHandle& owner, const SdfPath& path, const std::string& name, const SdfValueTypeName& typeName, SdfVariability variability, bool custom) { if (not owner) { TF_CODING_ERROR("NULL owner"); return TfNullPtr; } if (not typeName) { TF_CODING_ERROR("Cannot create attribute spec <%s> with invalid type", owner->GetPath().AppendTarget(path). AppendProperty(TfToken(name)).GetText()); return TfNullPtr; } SdfChangeBlock block; // Determine the path of the relationship target SdfPath absPath = path.MakeAbsolutePath(owner->GetPath().GetPrimPath()); SdfPath targetPath = owner->GetPath().AppendTarget(absPath); // Check to make sure that the name is valid if (not Sdf_ChildrenUtils<Sdf_AttributeChildPolicy>::IsValidName(name)) { TF_CODING_ERROR( "Cannot create attribute on %s with invalid name: %s", targetPath.GetText(), name.c_str()); return TfNullPtr; } // Create the relationship target if it doesn't already exist. Note // that this does not automatically get added to the relationship's // target path list. SdfSpecHandle targetSpec = owner->_FindOrCreateTargetSpec(path); // AttributeSpecs are considered initially to have only required fields // only if they are not custom. bool hasOnlyRequiredFields = (not custom); // Create the relational attribute spec SdfPath attrPath = targetPath.AppendRelationalAttribute(TfToken(name)); if (not Sdf_ChildrenUtils<Sdf_AttributeChildPolicy>::CreateSpec( owner->GetLayer(), attrPath, SdfSpecTypeAttribute, hasOnlyRequiredFields)) { return TfNullPtr; } SdfAttributeSpecHandle spec = owner->GetLayer()->GetAttributeAtPath(attrPath); // Avoid expensive dormancy checks in the case of binary-backed data. SdfAttributeSpec *specPtr = get_pointer(spec); if (TF_VERIFY(specPtr)) { specPtr->SetField(SdfFieldKeys->Custom, custom); specPtr->SetField(SdfFieldKeys->TypeName, typeName.GetAsToken()); specPtr->SetField(SdfFieldKeys->Variability, variability); } return spec; }