-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
childrenPolicies.h
276 lines (224 loc) · 7.43 KB
/
childrenPolicies.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
//
// Copyright 2016 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://openusd.org/license.
//
#ifndef PXR_USD_SDF_CHILDREN_POLICIES_H
#define PXR_USD_SDF_CHILDREN_POLICIES_H
// These policies are used as template arguments to SdfChildrenView to
// determine how the view maps between keys (the child's name or path) and
// values (the child's SpecHandle).
#include "pxr/pxr.h"
#include "pxr/usd/sdf/api.h"
#include "pxr/usd/sdf/path.h"
#include "pxr/usd/sdf/types.h"
#include "pxr/usd/sdf/declareHandles.h"
#include "pxr/usd/sdf/proxyPolicies.h"
#include "pxr/usd/sdf/schema.h"
PXR_NAMESPACE_OPEN_SCOPE
SDF_DECLARE_HANDLES(SdfAttributeSpec);
SDF_DECLARE_HANDLES(SdfPrimSpec);
SDF_DECLARE_HANDLES(SdfPropertySpec);
SDF_DECLARE_HANDLES(SdfRelationshipSpec);
SDF_DECLARE_HANDLES(SdfVariantSpec);
SDF_DECLARE_HANDLES(SdfVariantSetSpec);
//
// Token Child Policies
//
template <class SpecType>
class Sdf_TokenChildPolicy {
public:
typedef SdfNameKeyPolicy KeyPolicy;
typedef KeyPolicy::value_type KeyType;
typedef TfToken FieldType;
typedef SpecType ValueType;
static KeyType GetKey(const ValueType &spec) {
return spec->GetPath().GetName();
}
static SdfPath GetParentPath(const SdfPath &childPath) {
return childPath.GetParentPath();
}
static FieldType GetFieldValue(const SdfPath &childPath) {
return childPath.GetNameToken();
}
static bool IsValidIdentifier(const std::string &name) {
return SdfSchema::IsValidIdentifier(name);
}
};
class Sdf_PrimChildPolicy :
public Sdf_TokenChildPolicy<SdfPrimSpecHandle>
{
public:
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
return parentPath.AppendChild(key);
}
static TfToken GetChildrenToken(const SdfPath& parentPath) {
return SdfChildrenKeys->PrimChildren;
}
};
class Sdf_PropertyChildPolicy :
public Sdf_TokenChildPolicy<SdfPropertySpecHandle>
{
public:
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
if (parentPath.IsTargetPath()) {
return parentPath.AppendRelationalAttribute(key);
}
else {
return parentPath.AppendProperty(key);
}
}
static TfToken GetChildrenToken(const SdfPath& parentPath) {
return SdfChildrenKeys->PropertyChildren;
}
static bool IsValidIdentifier(const std::string &name) {
return SdfSchema::IsValidNamespacedIdentifier(name);
}
};
class Sdf_AttributeChildPolicy :
public Sdf_TokenChildPolicy<SdfAttributeSpecHandle>
{
public:
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
if (parentPath.IsTargetPath()) {
return parentPath.AppendRelationalAttribute(key);
}
else {
return parentPath.AppendProperty(key);
}
}
static TfToken GetChildrenToken(const SdfPath& parentPath) {
return SdfChildrenKeys->PropertyChildren;
}
static bool IsValidIdentifier(const std::string &name) {
return SdfSchema::IsValidNamespacedIdentifier(name);
}
};
class Sdf_RelationshipChildPolicy :
public Sdf_TokenChildPolicy<SdfRelationshipSpecHandle>
{
public:
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
return parentPath.AppendProperty(key);
}
static TfToken GetChildrenToken(const SdfPath& parentPath) {
return SdfChildrenKeys->PropertyChildren;
}
static bool IsValidIdentifier(const std::string &name) {
return SdfSchema::IsValidNamespacedIdentifier(name);
}
};
class Sdf_MapperArgChildPolicy :
public Sdf_TokenChildPolicy<SdfSpecHandle>
{
public:
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
return parentPath.AppendMapperArg(key);
}
static TfToken GetChildrenToken(const SdfPath& parentPath) {
return SdfChildrenKeys->MapperArgChildren;
}
};
class Sdf_ExpressionChildPolicy :
public Sdf_TokenChildPolicy<SdfSpecHandle>
{
public:
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
return parentPath.AppendExpression();
}
static TfToken GetChildrenToken(const SdfPath& parentPath) {
return SdfChildrenKeys->ExpressionChildren;
}
};
class Sdf_VariantChildPolicy :
public Sdf_TokenChildPolicy<SdfVariantSpecHandle>
{
public:
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
std::string variantSet = parentPath.GetVariantSelection().first;
return parentPath.GetParentPath().AppendVariantSelection(
TfToken(variantSet), key);
}
static SdfPath GetParentPath(const SdfPath &childPath) {
// Construct a path with the same variant set but an empty variant
std::string variantSet = childPath.GetVariantSelection().first;
return childPath.GetParentPath().AppendVariantSelection(variantSet, "");
}
static TfToken GetChildrenToken(const SdfPath& parentPath) {
return SdfChildrenKeys->VariantChildren;
}
};
class Sdf_VariantSetChildPolicy :
public Sdf_TokenChildPolicy<SdfVariantSetSpecHandle>
{
public:
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
return parentPath.AppendVariantSelection(key, "");
}
static TfToken GetChildrenToken(const SdfPath& parentPath) {
return SdfChildrenKeys->VariantSetChildren;
}
};
//
// Path Child Policies
//
template <class SpecType>
class Sdf_PathChildPolicy
{
public:
typedef SdfPathKeyPolicy KeyPolicy;
typedef KeyPolicy::value_type KeyType;
typedef SpecType ValueType;
typedef SdfPath FieldType;
static SdfPath GetParentPath(const SdfPath &childPath) {
return childPath.GetParentPath();
}
static KeyType GetKey(const ValueType &value) {
return value->GetPath().GetTargetPath();
}
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
return parentPath.AppendTarget(key);
}
static FieldType GetFieldValue(const SdfPath &childPath) {
return childPath.GetTargetPath();
}
static bool IsValidIdentifier(const FieldType &path) {
return true;
}
static bool IsValidIdentifier(const std::string &path) {
return SdfPath::IsValidPathString(path);
}
};
class Sdf_MapperChildPolicy :
public Sdf_PathChildPolicy<SdfSpecHandle>
{
public:
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
SdfPath targetPath = key.MakeAbsolutePath(parentPath.GetPrimPath());
return parentPath.AppendMapper(targetPath);
}
static FieldType GetFieldValue(const SdfPath &childPath) {
SdfPath targetPath = childPath.GetTargetPath();
return targetPath.MakeAbsolutePath(childPath.GetPrimPath());
}
static TfToken GetChildrenToken(const SdfPath& parentPath) {
return SdfChildrenKeys->MapperChildren;
}
};
class Sdf_AttributeConnectionChildPolicy :
public Sdf_PathChildPolicy<SdfSpecHandle> {
public:
static TfToken GetChildrenToken(const SdfPath& parentPath) {
return SdfChildrenKeys->ConnectionChildren;
}
};
class Sdf_RelationshipTargetChildPolicy :
public Sdf_PathChildPolicy<SdfSpecHandle> {
public:
static TfToken GetChildrenToken(const SdfPath& parentPath) {
return SdfChildrenKeys->RelationshipTargetChildren;
}
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_SDF_CHILDREN_POLICIES_H