This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
proxyPolicies.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_PROXY_POLICIES_H
8#define PXR_USD_SDF_PROXY_POLICIES_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/usd/sdf/api.h"
15#include "pxr/usd/sdf/path.h"
16#include "pxr/usd/sdf/spec.h"
17
18PXR_NAMESPACE_OPEN_SCOPE
19
20class SdfReference;
21
27public:
28 typedef std::string value_type;
29
30 static const value_type& Canonicalize(const value_type& x)
31 {
32 return x;
33 }
34
35 static const std::vector<value_type>& Canonicalize(
36 const std::vector<value_type>& x)
37 {
38 return x;
39 }
40};
41
47public:
48 typedef TfToken value_type;
49
50 static const value_type& Canonicalize(const value_type& x)
51 {
52 return x;
53 }
54
55 static const std::vector<value_type>& Canonicalize(
56 const std::vector<value_type>& x)
57 {
58 return x;
59 }
60};
61
67public:
68 typedef SdfPath value_type;
69
71 explicit SdfPathKeyPolicy(const SdfSpecHandle& owner) : _owner(owner) { }
72
73
74 value_type Canonicalize(const value_type& x) const
75 {
76 return _Canonicalize(x, _GetAnchor());
77 }
78
79 std::vector<value_type> Canonicalize(const std::vector<value_type>& x) const
80 {
81 if (x.empty()) {
82 return x;
83 }
84
85 const SdfPath anchor = _GetAnchor();
86
87 std::vector<value_type> result = x;
88 TF_FOR_ALL(it, result) {
89 *it = _Canonicalize(*it, anchor);
90 }
91 return result;
92 }
93
94private:
95 // Get the most recent SdfPath of the owning object, for expanding
96 // relative SdfPaths to absolute
97 SdfPath _GetAnchor() const
98 {
99 return _owner ? _owner->GetPath().GetPrimPath() :
101 }
102
103 value_type _Canonicalize(const value_type& x, const SdfPath& primPath) const
104 {
105 return x.IsEmpty() ? value_type() : x.MakeAbsolutePath(primPath);
106 }
107
108private:
109 SdfSpecHandle _owner;
110};
111
112// Cannot get from a VtValue except as the correct type.
113template <>
114struct Vt_DefaultValueFactory<SdfPathKeyPolicy> {
115 static Vt_DefaultValueHolder Invoke() {
116 TF_AXIOM(false && "Failed VtValue::Get<SdfPathKeyPolicy> not allowed");
117 return Vt_DefaultValueHolder::Create((void*)0);
118 }
119};
120
126public:
127 typedef SdfPayload value_type;
128
129 static const value_type& Canonicalize(const value_type& x)
130 {
131 return x;
132 }
133
134 static const std::vector<value_type>& Canonicalize(
135 const std::vector<value_type>& x)
136 {
137 return x;
138 }
139};
140
141// Cannot get from a VtValue except as the correct type.
142template <>
143struct Vt_DefaultValueFactory<SdfPayloadTypePolicy> {
144 static Vt_DefaultValueHolder Invoke() {
145 TF_AXIOM(false && "Failed VtValue::Get<SdfPayloadTypePolicy> not allowed");
146 return Vt_DefaultValueHolder::Create((void*)0);
147 }
148};
149
155public:
156 typedef SdfReference value_type;
157
158 static const value_type& Canonicalize(const value_type& x)
159 {
160 return x;
161 }
162
163 static const std::vector<value_type>& Canonicalize(
164 const std::vector<value_type>& x)
165 {
166 return x;
167 }
168};
169
170// Cannot get from a VtValue except as the correct type.
171template <>
172struct Vt_DefaultValueFactory<SdfReferenceTypePolicy> {
173 static Vt_DefaultValueHolder Invoke() {
174 TF_AXIOM(false && "Failed VtValue::Get<SdfReferenceTypePolicy> not allowed");
175 return Vt_DefaultValueHolder::Create((void*)0);
176 }
177};
178
184public:
185 typedef std::string value_type;
186
187 static const value_type& Canonicalize(const value_type& x)
188 {
189 return x;
190 }
191
192 static const std::vector<value_type>& Canonicalize(
193 const std::vector<value_type>& x)
194 {
195 return x;
196 }
197};
198
205public:
206 typedef std::map<SdfPath, SdfPath> Type;
207 typedef Type::key_type key_type;
208 typedef Type::mapped_type mapped_type;
209 typedef Type::value_type value_type;
210
211 SDF_API
212 static Type CanonicalizeType(const SdfSpecHandle& v, const Type& x);
213 SDF_API
214 static key_type CanonicalizeKey(const SdfSpecHandle& v,
215 const key_type& x);
216 SDF_API
217 static mapped_type CanonicalizeValue(const SdfSpecHandle& v,
218 const mapped_type& x);
219 SDF_API
220 static value_type CanonicalizePair(const SdfSpecHandle& v,
221 const value_type& x);
222};
223
229public:
230 SdfGenericSpecViewPredicate(SdfSpecType type) : _type(type) { }
231
232 template <class T>
233 bool operator()(const SdfHandle<T>& x) const
234 {
235 // XXX: x is sometimes null. why?
236 if (x) {
237 return x->GetSpecType() == _type;
238 }
239 return false;
240 }
241
242private:
243 SdfSpecType _type;
244};
245
251public:
252 SDF_API
254};
255
261public:
262 SDF_API
264};
265
266PXR_NAMESPACE_CLOSE_SCOPE
267
268#endif // PXR_USD_SDF_PROXY_POLICIES_H
Predicate for viewing attributes.
Predicate for viewing properties.
SdfHandle is a smart ptr that calls IsDormant() on the pointed-to object as an extra expiration check...
Key policy for std::string names.
Definition: proxyPolicies.h:26
Key policy for TfToken names.
Definition: proxyPolicies.h:46
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.
static SDF_API const SdfPath & AbsoluteRootPath()
The absolute path representing the top of the namespace hierarchy.
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
Definition: path.h:398
Key policy for SdfPath; converts all SdfPaths to absolute.
Definition: proxyPolicies.h:66
Represents a payload and all its meta data.
Definition: payload.h:41
List editor type policy for SdfPayload.
Represents a reference and all its meta data.
Definition: reference.h:58
List editor type policy for SdfReference.
Predicate for viewing relationships.
Map edit proxy value policy for relocates maps.
List editor type policy for sublayers.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
#define TF_FOR_ALL(iter, c)
Macro for iterating over a container.
Definition: iterator.h:373
#define TF_AXIOM(cond)
Aborts if the condition cond is not met.
Definition: diagnostic.h:193
SdfSpecType
An enum that specifies the type of an object.
Definition: types.h:68