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 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 
40 
47 
48 //
49 // Token Child Policies
50 //
51 
52 template <class SpecType>
54 public:
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 
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 
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) {
111  }
112 };
113 
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) {
133  }
134 };
135 
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) {
151  }
152 };
153 
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 
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 
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 
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>
223 {
224 public:
227  typedef SpecType ValueType;
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 
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 
275  public Sdf_PathChildPolicy<SdfSpecHandle> {
276 public:
277  static TfToken GetChildrenToken(const SdfPath& parentPath) {
278  return SdfChildrenKeys->ConnectionChildren;
279  }
280 };
281 
283  public Sdf_PathChildPolicy<SdfSpecHandle> {
284 
285 public:
286  static TfToken GetChildrenToken(const SdfPath& parentPath) {
287  return SdfChildrenKeys->RelationshipTargetChildren;
288  }
289 };
290 
292 
293 #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 GLchar *const * string
Definition: glcorearb.h:814
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:45
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:87
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:290
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:1432
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:91
static TfToken GetChildrenToken(const SdfPath &parentPath)
SDF_API SdfPath GetParentPath() const
SdfNameKeyPolicy KeyPolicy
Definition: core.h:1131
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