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 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_PROXY_POLICIES_H
25 #define PXR_USD_SDF_PROXY_POLICIES_H
26 
27 /// \file sdf/proxyPolicies.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/sdf/api.h"
32 #include "pxr/usd/sdf/path.h"
33 #include "pxr/usd/sdf/spec.h"
34 
36 
37 class SdfReference;
38 
39 /// \class SdfNameKeyPolicy
40 ///
41 /// Key policy for \c std::string names.
42 ///
44 public:
46 
47  static const value_type& Canonicalize(const value_type& x)
48  {
49  return x;
50  }
51 
52  static const std::vector<value_type>& Canonicalize(
53  const std::vector<value_type>& x)
54  {
55  return x;
56  }
57 };
58 
59 /// \class SdfNameTokenKeyPolicy
60 ///
61 /// Key policy for \c TfToken names.
62 ///
64 public:
66 
67  static const value_type& Canonicalize(const value_type& x)
68  {
69  return x;
70  }
71 
72  static const std::vector<value_type>& Canonicalize(
73  const std::vector<value_type>& x)
74  {
75  return x;
76  }
77 };
78 
79 /// \class SdfPathKeyPolicy
80 ///
81 /// Key policy for \c SdfPath; converts all SdfPaths to absolute.
82 ///
84 public:
86 
88  explicit SdfPathKeyPolicy(const SdfSpecHandle& owner) : _owner(owner) { }
89 
90 
92  {
93  return _Canonicalize(x, _GetAnchor());
94  }
95 
96  std::vector<value_type> Canonicalize(const std::vector<value_type>& x) const
97  {
98  if (x.empty()) {
99  return x;
100  }
101 
102  const SdfPath anchor = _GetAnchor();
103 
104  std::vector<value_type> result = x;
105  TF_FOR_ALL(it, result) {
106  *it = _Canonicalize(*it, anchor);
107  }
108  return result;
109  }
110 
111 private:
112  // Get the most recent SdfPath of the owning object, for expanding
113  // relative SdfPaths to absolute
114  SdfPath _GetAnchor() const
115  {
116  return _owner ? _owner->GetPath().GetPrimPath() :
118  }
119 
120  value_type _Canonicalize(const value_type& x, const SdfPath& primPath) const
121  {
122  return x.IsEmpty() ? value_type() : x.MakeAbsolutePath(primPath);
123  }
124 
125 private:
126  SdfSpecHandle _owner;
127 };
128 
129 // Cannot get from a VtValue except as the correct type.
130 template <>
133  TF_AXIOM(false && "Failed VtValue::Get<SdfPathKeyPolicy> not allowed");
134  return Vt_DefaultValueHolder::Create((void*)0);
135  }
136 };
137 
138 /// \class SdfPayloadTypePolicy
139 ///
140 /// List editor type policy for \c SdfPayload.
141 ///
143 public:
145 
146  static const value_type& Canonicalize(const value_type& x)
147  {
148  return x;
149  }
150 
151  static const std::vector<value_type>& Canonicalize(
152  const std::vector<value_type>& x)
153  {
154  return x;
155  }
156 };
157 
158 // Cannot get from a VtValue except as the correct type.
159 template <>
162  TF_AXIOM(false && "Failed VtValue::Get<SdfPayloadTypePolicy> not allowed");
163  return Vt_DefaultValueHolder::Create((void*)0);
164  }
165 };
166 
167 /// \class SdfReferenceTypePolicy
168 ///
169 /// List editor type policy for \c SdfReference.
170 ///
172 public:
174 
175  static const value_type& Canonicalize(const value_type& x)
176  {
177  return x;
178  }
179 
180  static const std::vector<value_type>& Canonicalize(
181  const std::vector<value_type>& x)
182  {
183  return x;
184  }
185 };
186 
187 // Cannot get from a VtValue except as the correct type.
188 template <>
191  TF_AXIOM(false && "Failed VtValue::Get<SdfReferenceTypePolicy> not allowed");
192  return Vt_DefaultValueHolder::Create((void*)0);
193  }
194 };
195 
196 /// \class SdfSubLayerTypePolicy
197 ///
198 /// List editor type policy for sublayers.
199 ///
201 public:
203 
204  static const value_type& Canonicalize(const value_type& x)
205  {
206  return x;
207  }
208 
209  static const std::vector<value_type>& Canonicalize(
210  const std::vector<value_type>& x)
211  {
212  return x;
213  }
214 };
215 
216 /// \class SdfRelocatesMapProxyValuePolicy
217 ///
218 /// Map edit proxy value policy for relocates maps. This absolutizes all
219 /// paths.
220 ///
222 public:
223  typedef std::map<SdfPath, SdfPath> Type;
224  typedef Type::key_type key_type;
225  typedef Type::mapped_type mapped_type;
227 
228  SDF_API
229  static Type CanonicalizeType(const SdfSpecHandle& v, const Type& x);
230  SDF_API
231  static key_type CanonicalizeKey(const SdfSpecHandle& v,
232  const key_type& x);
233  SDF_API
234  static mapped_type CanonicalizeValue(const SdfSpecHandle& v,
235  const mapped_type& x);
236  SDF_API
237  static value_type CanonicalizePair(const SdfSpecHandle& v,
238  const value_type& x);
239 };
240 
241 /// \class SdfGenericSpecViewPredicate
242 ///
243 /// Predicate for viewing properties.
244 ///
246 public:
248 
249  template <class T>
250  bool operator()(const SdfHandle<T>& x) const
251  {
252  // XXX: x is sometimes null. why?
253  if (x) {
254  return x->GetSpecType() == _type;
255  }
256  return false;
257  }
258 
259 private:
260  SdfSpecType _type;
261 };
262 
263 /// \class SdfAttributeViewPredicate
264 ///
265 /// Predicate for viewing attributes.
266 ///
268 public:
269  SDF_API
271 };
272 
273 /// \class SdfRelationshipViewPredicate
274 ///
275 /// Predicate for viewing relationships.
276 ///
278 public:
279  SDF_API
281 };
282 
284 
285 #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:91
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
bool operator()(const SdfHandle< T > &x) const
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
Definition: path.h:424
static const value_type & Canonicalize(const value_type &x)
Definition: proxyPolicies.h:47
std::string value_type
Definition: proxyPolicies.h:45
**But if you need a result
Definition: thread.h:613
std::vector< value_type > Canonicalize(const std::vector< value_type > &x) const
Definition: proxyPolicies.h:96
uint64 value_type
Definition: GA_PrimCompat.h:29
static const std::vector< value_type > & Canonicalize(const std::vector< value_type > &x)
Definition: proxyPolicies.h:72
static const value_type & Canonicalize(const value_type &x)
static const std::vector< value_type > & Canonicalize(const std::vector< value_type > &x)
Definition: token.h:87
static Vt_DefaultValueHolder Invoke()
SDF_API SdfAttributeViewPredicate()
static Vt_DefaultValueHolder Invoke()
static const value_type & Canonicalize(const value_type &x)
Definition: proxyPolicies.h:67
static SDF_API key_type CanonicalizeKey(const SdfSpecHandle &v, const key_type &x)
Definition: path.h:291
GLint GLenum GLint x
Definition: glcorearb.h:409
SdfPathKeyPolicy(const SdfSpecHandle &owner)
Definition: proxyPolicies.h:88
static SDF_API mapped_type CanonicalizeValue(const SdfSpecHandle &v, const mapped_type &x)
#define SDF_API
Definition: api.h:40
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:1441
static const std::vector< value_type > & Canonicalize(const std::vector< value_type > &x)
Definition: proxyPolicies.h:52
SdfSpecType
Definition: types.h:90
static Vt_DefaultValueHolder Create()
Definition: value.h:76
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
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:390
type
Definition: core.h:1059
static const value_type & Canonicalize(const value_type &x)