Loading...
Searching...
No Matches
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
204public:
205 SdfGenericSpecViewPredicate(SdfSpecType type) : _type(type) { }
206
207 template <class T>
208 bool operator()(const SdfHandle<T>& x) const
209 {
210 // XXX: x is sometimes null. why?
211 if (x) {
212 return x->GetSpecType() == _type;
213 }
214 return false;
215 }
216
217private:
218 SdfSpecType _type;
219};
220
226public:
227 SDF_API
229};
230
240
241PXR_NAMESPACE_CLOSE_SCOPE
242
243#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.
Key policy for TfToken names.
A path value used to locate objects in layers or scenegraphs.
Definition path.h:281
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:405
Key policy for SdfPath; converts all SdfPaths to absolute.
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.
List editor type policy for sublayers.
Token for efficient comparison, assignment, and hashing of known strings.
Definition token.h:81
#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:194
SdfSpecType
An enum that specifies the type of an object.
Definition types.h:73