Loading...
Searching...
No Matches
childrenPolicies.h
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_USD_SDF_CHILDREN_POLICIES_H
8#define PXR_USD_SDF_CHILDREN_POLICIES_H
9
10// These policies are used as template arguments to SdfChildrenView to
11// determine how the view maps between keys (the child's name or path) and
12// values (the child's SpecHandle).
13
14#include "pxr/pxr.h"
15#include "pxr/usd/sdf/api.h"
16#include "pxr/usd/sdf/path.h"
17#include "pxr/usd/sdf/types.h"
20#include "pxr/usd/sdf/schema.h"
21
22PXR_NAMESPACE_OPEN_SCOPE
23
24SDF_DECLARE_HANDLES(SdfAttributeSpec);
25SDF_DECLARE_HANDLES(SdfPrimSpec);
26SDF_DECLARE_HANDLES(SdfPropertySpec);
27SDF_DECLARE_HANDLES(SdfRelationshipSpec);
28SDF_DECLARE_HANDLES(SdfVariantSpec);
29SDF_DECLARE_HANDLES(SdfVariantSetSpec);
30
31//
32// Token Child Policies
33//
34
35template <class SpecType>
36class Sdf_TokenChildPolicy {
37public:
38 typedef SdfNameKeyPolicy KeyPolicy;
39 typedef KeyPolicy::value_type KeyType;
40 typedef TfToken FieldType;
41 typedef SpecType ValueType;
42
43 static KeyType GetKey(const ValueType &spec) {
44 return spec->GetPath().GetName();
45 }
46
47 static SdfPath GetParentPath(const SdfPath &childPath) {
48 return childPath.GetParentPath();
49 }
50
51 static FieldType GetFieldValue(const SdfPath &childPath) {
52 return childPath.GetNameToken();
53 }
54
55 static bool IsValidIdentifier(const std::string &name) {
56 return SdfSchema::IsValidIdentifier(name);
57 }
58
59};
60
61class Sdf_PrimChildPolicy :
62 public Sdf_TokenChildPolicy<SdfPrimSpecHandle>
63{
64public:
65
66 static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
67 return parentPath.AppendChild(key);
68 }
69
70 static TfToken GetChildrenToken(const SdfPath& parentPath) {
71 return SdfChildrenKeys->PrimChildren;
72 }
73};
74
75class Sdf_PropertyChildPolicy :
76 public Sdf_TokenChildPolicy<SdfPropertySpecHandle>
77{
78public:
79 static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
80 if (parentPath.IsTargetPath()) {
81 return parentPath.AppendRelationalAttribute(key);
82 }
83 else {
84 return parentPath.AppendProperty(key);
85 }
86 }
87
88 static TfToken GetChildrenToken(const SdfPath& parentPath) {
89 return SdfChildrenKeys->PropertyChildren;
90 }
91
92 static bool IsValidIdentifier(const std::string &name) {
93 return SdfSchema::IsValidNamespacedIdentifier(name);
94 }
95};
96
97class Sdf_AttributeChildPolicy :
98 public Sdf_TokenChildPolicy<SdfAttributeSpecHandle>
99{
100public:
101 static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
102 if (parentPath.IsTargetPath()) {
103 return parentPath.AppendRelationalAttribute(key);
104 }
105 else {
106 return parentPath.AppendProperty(key);
107 }
108 }
109
110 static TfToken GetChildrenToken(const SdfPath& parentPath) {
111 return SdfChildrenKeys->PropertyChildren;
112 }
113
114 static bool IsValidIdentifier(const std::string &name) {
115 return SdfSchema::IsValidNamespacedIdentifier(name);
116 }
117};
118
119class Sdf_RelationshipChildPolicy :
120 public Sdf_TokenChildPolicy<SdfRelationshipSpecHandle>
121{
122public:
123
124 static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
125 return parentPath.AppendProperty(key);
126 }
127
128 static TfToken GetChildrenToken(const SdfPath& parentPath) {
129 return SdfChildrenKeys->PropertyChildren;
130 }
131
132 static bool IsValidIdentifier(const std::string &name) {
133 return SdfSchema::IsValidNamespacedIdentifier(name);
134 }
135};
136
137class Sdf_MapperArgChildPolicy :
138 public Sdf_TokenChildPolicy<SdfSpecHandle>
139{
140public:
141
142 static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
143 return parentPath.AppendMapperArg(key);
144 }
145
146 static TfToken GetChildrenToken(const SdfPath& parentPath) {
147 return SdfChildrenKeys->MapperArgChildren;
148 }
149};
150
151class Sdf_ExpressionChildPolicy :
152 public Sdf_TokenChildPolicy<SdfSpecHandle>
153{
154public:
155 static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
156 return parentPath.AppendExpression();
157 }
158
159 static TfToken GetChildrenToken(const SdfPath& parentPath) {
160 return SdfChildrenKeys->ExpressionChildren;
161 }
162};
163
164class Sdf_VariantChildPolicy :
165 public Sdf_TokenChildPolicy<SdfVariantSpecHandle>
166{
167public:
168
169 static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
170 std::string variantSet = parentPath.GetVariantSelection().first;
171 return parentPath.GetParentPath().AppendVariantSelection(
172 TfToken(variantSet), key);
173 }
174
175 static SdfPath GetParentPath(const SdfPath &childPath) {
176 // Construct a path with the same variant set but an empty variant
177 std::string variantSet = childPath.GetVariantSelection().first;
178 return childPath.GetParentPath().AppendVariantSelection(variantSet, "");
179 }
180
181 static TfToken GetChildrenToken(const SdfPath& parentPath) {
182 return SdfChildrenKeys->VariantChildren;
183 }
184};
185
186class Sdf_VariantSetChildPolicy :
187 public Sdf_TokenChildPolicy<SdfVariantSetSpecHandle>
188{
189public:
190
191 static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
192 return parentPath.AppendVariantSelection(key, "");
193 }
194
195 static TfToken GetChildrenToken(const SdfPath& parentPath) {
196 return SdfChildrenKeys->VariantSetChildren;
197 }
198};
199
200//
201// Path Child Policies
202//
203
204template <class SpecType>
205class Sdf_PathChildPolicy
206{
207public:
208 typedef SdfPathKeyPolicy KeyPolicy;
209 typedef KeyPolicy::value_type KeyType;
210 typedef SpecType ValueType;
211 typedef SdfPath FieldType;
212
213 static SdfPath GetParentPath(const SdfPath &childPath) {
214 return childPath.GetParentPath();
215 }
216
217 static KeyType GetKey(const ValueType &value) {
218 return value->GetPath().GetTargetPath();
219 }
220
221 static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
222 return parentPath.AppendTarget(key);
223 }
224
225 static FieldType GetFieldValue(const SdfPath &childPath) {
226 return childPath.GetTargetPath();
227 }
228
229 static bool IsValidIdentifier(const FieldType &path) {
230 return true;
231 }
232
233 static bool IsValidIdentifier(const std::string &path) {
234 return SdfPath::IsValidPathString(path);
235 }
236};
237
238class Sdf_MapperChildPolicy :
239 public Sdf_PathChildPolicy<SdfSpecHandle>
240{
241public:
242 static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
243 SdfPath targetPath = key.MakeAbsolutePath(parentPath.GetPrimPath());
244 return parentPath.AppendMapper(targetPath);
245 }
246
247 static FieldType GetFieldValue(const SdfPath &childPath) {
248 SdfPath targetPath = childPath.GetTargetPath();
249 return targetPath.MakeAbsolutePath(childPath.GetPrimPath());
250 }
251
252 static TfToken GetChildrenToken(const SdfPath& parentPath) {
253 return SdfChildrenKeys->MapperChildren;
254 }
255};
256
257class Sdf_AttributeConnectionChildPolicy :
258 public Sdf_PathChildPolicy<SdfSpecHandle> {
259public:
260 static TfToken GetChildrenToken(const SdfPath& parentPath) {
261 return SdfChildrenKeys->ConnectionChildren;
262 }
263};
264
265class Sdf_RelationshipTargetChildPolicy :
266 public Sdf_PathChildPolicy<SdfSpecHandle> {
267
268public:
269 static TfToken GetChildrenToken(const SdfPath& parentPath) {
270 return SdfChildrenKeys->RelationshipTargetChildren;
271 }
272};
273
274PXR_NAMESPACE_CLOSE_SCOPE
275
276#endif // PXR_USD_SDF_CHILDREN_POLICIES_H
A subclass of SdfPropertySpec that holds typed data.
Definition: attributeSpec.h:42
Key policy for std::string names.
Definition: proxyPolicies.h:26
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
SDF_API SdfPath MakeAbsolutePath(const SdfPath &anchor) const
Returns the absolute form of this path using anchor as the relative basis.
SDF_API SdfPath GetParentPath() const
Return the path that identifies this path's namespace parent.
SDF_API std::pair< std::string, std::string > GetVariantSelection() const
Returns the variant selection for this path, if this is a variant selection path.
SDF_API SdfPath AppendExpression() const
Creates a path by appending an expression element.
SDF_API SdfPath AppendRelationalAttribute(TfToken const &attrName) const
Creates a path by appending an element for attrName to this path.
SDF_API SdfPath AppendMapper(const SdfPath &targetPath) const
Creates a path by appending a mapper element for targetPath.
SDF_API bool IsTargetPath() const
Returns whether the path identifies a relationship or connection target.
SDF_API const SdfPath & GetTargetPath() const
Returns the relational attribute or mapper target path for this path.
SDF_API const TfToken & GetNameToken() const
Returns the name of the prim, property or relational attribute identified by the path,...
SDF_API SdfPath AppendVariantSelection(const std::string &variantSet, const std::string &variant) const
Creates a path by appending an element for variantSet and variant to this path.
SDF_API SdfPath AppendProperty(TfToken const &propName) const
Creates a path by appending an element for propName to this path.
SDF_API SdfPath AppendMapperArg(TfToken const &argName) const
Creates a path by appending an element for argName.
SDF_API SdfPath AppendChild(TfToken const &childName) const
Creates a path by appending an element for childName to this path.
static SDF_API bool IsValidPathString(const std::string &pathString, std::string *errMsg=0)
Return true if pathString is a valid path string, meaning that passing the string to the SdfPath cons...
SDF_API SdfPath AppendTarget(const SdfPath &targetPath) const
Creates a path by appending an element for targetPath.
SDF_API SdfPath GetPrimPath() const
Creates a path by stripping all relational attributes, targets, properties, and variant selections fr...
Key policy for SdfPath; converts all SdfPaths to absolute.
Definition: proxyPolicies.h:66
Represents a prim description in an SdfLayer object.
Definition: primSpec.h:58
Base class for SdfAttributeSpec and SdfRelationshipSpec.
Definition: propertySpec.h:47
A property that contains a reference to one or more SdfPrimSpec instances.
Represents a coherent set of alternate representations for part of a scene.
Represents a single variant in a variant set.
Definition: variantSpec.h:39
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Basic Sdf data types.