HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
childrenPolicies.h
Go to the documentation of this file.
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 
23 
30 
31 //
32 // Token Child Policies
33 //
34 
35 template <class SpecType>
37 public:
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 
62  public Sdf_TokenChildPolicy<SdfPrimSpecHandle>
63 {
64 public:
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 
76  public Sdf_TokenChildPolicy<SdfPropertySpecHandle>
77 {
78 public:
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) {
94  }
95 };
96 
98  public Sdf_TokenChildPolicy<SdfAttributeSpecHandle>
99 {
100 public:
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) {
116  }
117 };
118 
120  public Sdf_TokenChildPolicy<SdfRelationshipSpecHandle>
121 {
122 public:
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) {
134  }
135 };
136 
138  public Sdf_TokenChildPolicy<SdfSpecHandle>
139 {
140 public:
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 
152  public Sdf_TokenChildPolicy<SdfSpecHandle>
153 {
154 public:
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 
165  public Sdf_TokenChildPolicy<SdfVariantSpecHandle>
166 {
167 public:
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 
187  public Sdf_TokenChildPolicy<SdfVariantSetSpecHandle>
188 {
189 public:
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 
204 template <class SpecType>
206 {
207 public:
210  typedef SpecType ValueType;
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 
239  public Sdf_PathChildPolicy<SdfSpecHandle>
240 {
241 public:
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 
258  public Sdf_PathChildPolicy<SdfSpecHandle> {
259 public:
260  static TfToken GetChildrenToken(const SdfPath& parentPath) {
261  return SdfChildrenKeys->ConnectionChildren;
262  }
263 };
264 
266  public Sdf_PathChildPolicy<SdfSpecHandle> {
267 
268 public:
269  static TfToken GetChildrenToken(const SdfPath& parentPath) {
270  return SdfChildrenKeys->RelationshipTargetChildren;
271  }
272 };
273 
275 
276 #endif // PXR_USD_SDF_CHILDREN_POLICIES_H
static FieldType GetFieldValue(const SdfPath &childPath)
SDF_API SdfPath AppendTarget(const SdfPath &targetPath) const
static FieldType GetFieldValue(const SdfPath &childPath)
SDF_API SdfPath AppendExpression() const
static SdfPath GetParentPath(const SdfPath &childPath)
static KeyType GetKey(const ValueType &value)
SDF_API SdfPath AppendMapper(const SdfPath &targetPath) const
static SDF_API bool IsValidPathString(const std::string &pathString, std::string *errMsg=0)
GLsizei const GLfloat * value
Definition: glcorearb.h:824
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
SDF_API const SdfPath & GetTargetPath() const
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key)
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key)
SdfPathKeyPolicy KeyPolicy
static TfToken GetChildrenToken(const SdfPath &parentPath)
std::string value_type
Definition: proxyPolicies.h:28
static TfToken GetChildrenToken(const SdfPath &parentPath)
KeyPolicy::value_type KeyType
static TfToken GetChildrenToken(const SdfPath &parentPath)
static KeyType GetKey(const ValueType &spec)
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key)
SDF_API std::pair< std::string, std::string > GetVariantSelection() const
static bool IsValidIdentifier(const std::string &name)
SDF_API SdfPath AppendRelationalAttribute(TfToken const &attrName) const
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key)
PXR_NAMESPACE_OPEN_SCOPE SDF_DECLARE_HANDLES(SdfAttributeSpec)
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key)
static SdfPath GetParentPath(const SdfPath &childPath)
Definition: token.h:70
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key)
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key)
SDF_API SdfPath AppendChild(TfToken const &childName) const
static bool IsValidIdentifier(const std::string &path)
static bool IsValidIdentifier(const std::string &name)
static TfToken GetChildrenToken(const SdfPath &parentPath)
static TfToken GetChildrenToken(const SdfPath &parentPath)
SDF_API SdfPath AppendVariantSelection(const std::string &variantSet, const std::string &variant) const
SDF_API SdfPath AppendMapperArg(TfToken const &argName) const
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key)
KeyPolicy::value_type KeyType
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key)
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: path.h:273
SDF_API const TfToken & GetNameToken() const
static TfToken GetChildrenToken(const SdfPath &parentPath)
SDF_API SdfPath AppendProperty(TfToken const &propName) const
static bool IsValidIdentifier(const std::string &name)
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key)
static SDF_API SdfAllowed IsValidIdentifier(const std::string &name)
static bool IsValidIdentifier(const FieldType &path)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
static TfToken GetChildrenToken(const SdfPath &parentPath)
SDF_API bool IsTargetPath() const
static TfToken GetChildrenToken(const SdfPath &parentPath)
static TfToken GetChildrenToken(const SdfPath &parentPath)
SDF_API SdfPath MakeAbsolutePath(const SdfPath &anchor) const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static TfToken GetChildrenToken(const SdfPath &parentPath)
SDF_API SdfPath GetParentPath() const
SdfNameKeyPolicy KeyPolicy
static TfToken GetChildrenToken(const SdfPath &parentPath)
static SdfPath GetParentPath(const SdfPath &childPath)
static bool IsValidIdentifier(const std::string &name)
static SDF_API SdfAllowed IsValidNamespacedIdentifier(const std::string &name)
static FieldType GetFieldValue(const SdfPath &childPath)
SDF_API SdfPath GetPrimPath() const