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