HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 
10 /// \file sdf/proxyPolicies.h
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 
19 
20 class SdfReference;
21 
22 /// \class SdfNameKeyPolicy
23 ///
24 /// Key policy for \c std::string names.
25 ///
27 public:
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 
42 /// \class SdfNameTokenKeyPolicy
43 ///
44 /// Key policy for \c TfToken names.
45 ///
47 public:
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 
62 /// \class SdfPathKeyPolicy
63 ///
64 /// Key policy for \c SdfPath; converts all SdfPaths to absolute.
65 ///
67 public:
69 
71  explicit SdfPathKeyPolicy(const SdfSpecHandle& owner) : _owner(owner) { }
72 
73 
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 
94 private:
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 
108 private:
109  SdfSpecHandle _owner;
110 };
111 
112 // Cannot get from a VtValue except as the correct type.
113 template <>
116  TF_AXIOM(false && "Failed VtValue::Get<SdfPathKeyPolicy> not allowed");
117  return Vt_DefaultValueHolder::Create((void*)0);
118  }
119 };
120 
121 /// \class SdfPayloadTypePolicy
122 ///
123 /// List editor type policy for \c SdfPayload.
124 ///
126 public:
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.
142 template <>
145  TF_AXIOM(false && "Failed VtValue::Get<SdfPayloadTypePolicy> not allowed");
146  return Vt_DefaultValueHolder::Create((void*)0);
147  }
148 };
149 
150 /// \class SdfReferenceTypePolicy
151 ///
152 /// List editor type policy for \c SdfReference.
153 ///
155 public:
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.
171 template <>
174  TF_AXIOM(false && "Failed VtValue::Get<SdfReferenceTypePolicy> not allowed");
175  return Vt_DefaultValueHolder::Create((void*)0);
176  }
177 };
178 
179 /// \class SdfSubLayerTypePolicy
180 ///
181 /// List editor type policy for sublayers.
182 ///
184 public:
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 
199 /// \class SdfRelocatesMapProxyValuePolicy
200 ///
201 /// Map edit proxy value policy for relocates maps. This absolutizes all
202 /// paths.
203 ///
205 public:
206  typedef std::map<SdfPath, SdfPath> Type;
207  typedef Type::key_type key_type;
208  typedef Type::mapped_type mapped_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 
224 /// \class SdfGenericSpecViewPredicate
225 ///
226 /// Predicate for viewing properties.
227 ///
229 public:
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 
242 private:
243  SdfSpecType _type;
244 };
245 
246 /// \class SdfAttributeViewPredicate
247 ///
248 /// Predicate for viewing attributes.
249 ///
251 public:
252  SDF_API
254 };
255 
256 /// \class SdfRelationshipViewPredicate
257 ///
258 /// Predicate for viewing relationships.
259 ///
261 public:
262  SDF_API
264 };
265 
267 
268 #endif // PXR_USD_SDF_PROXY_POLICIES_H
std::map< SdfPath, SdfPath > Type
static SDF_API const SdfPath & AbsoluteRootPath()
static const value_type & Canonicalize(const value_type &x)
const GLdouble * v
Definition: glcorearb.h:837
value_type Canonicalize(const value_type &x) const
Definition: proxyPolicies.h:74
bool operator()(const SdfHandle< T > &x) const
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
Definition: path.h:398
static const value_type & Canonicalize(const value_type &x)
Definition: proxyPolicies.h:30
std::string value_type
Definition: proxyPolicies.h:28
**But if you need a result
Definition: thread.h:622
std::vector< value_type > Canonicalize(const std::vector< value_type > &x) const
Definition: proxyPolicies.h:79
uint64 value_type
Definition: GA_PrimCompat.h:29
static const std::vector< value_type > & Canonicalize(const std::vector< value_type > &x)
Definition: proxyPolicies.h:55
static const value_type & Canonicalize(const value_type &x)
static const std::vector< value_type > & Canonicalize(const std::vector< value_type > &x)
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
Definition: token.h:70
static Vt_DefaultValueHolder Invoke()
SDF_API SdfAttributeViewPredicate()
static Vt_DefaultValueHolder Invoke()
static const value_type & Canonicalize(const value_type &x)
Definition: proxyPolicies.h:50
static SDF_API key_type CanonicalizeKey(const SdfSpecHandle &v, const key_type &x)
Definition: path.h:273
GLint GLenum GLint x
Definition: glcorearb.h:409
SdfPathKeyPolicy(const SdfSpecHandle &owner)
Definition: proxyPolicies.h:71
static SDF_API mapped_type CanonicalizeValue(const SdfSpecHandle &v, const mapped_type &x)
#define SDF_API
Definition: api.h:23
static SDF_API Type CanonicalizeType(const SdfSpecHandle &v, const Type &x)
#define TF_AXIOM(cond)
static const std::vector< value_type > & Canonicalize(const std::vector< value_type > &x)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
static const std::vector< value_type > & Canonicalize(const std::vector< value_type > &x)
Definition: proxyPolicies.h:35
SdfSpecType
Definition: types.h:68
static Vt_DefaultValueHolder Create()
Definition: value.h:55
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static SDF_API value_type CanonicalizePair(const SdfSpecHandle &v, const value_type &x)
SdfGenericSpecViewPredicate(SdfSpecType type)
static const std::vector< value_type > & Canonicalize(const std::vector< value_type > &x)
#define TF_FOR_ALL(iter, c)
Definition: iterator.h:373
static const value_type & Canonicalize(const value_type &x)