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 SDF_PROXYPOLICIES_H
25 #define SDF_PROXYPOLICIES_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/sdf/api.h"
31 #include "pxr/usd/sdf/declareHandles.h"
32 #include "pxr/usd/sdf/path.h"
33 #include "pxr/usd/sdf/spec.h"
34 
35 PXR_NAMESPACE_OPEN_SCOPE
36 
37 class SdfReference;
38 
44 public:
45  typedef std::string value_type;
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 
64 public:
65  typedef TfToken value_type;
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 
84 public:
85  typedef SdfPath value_type;
86 
87  SdfPathKeyPolicy() { }
88  explicit SdfPathKeyPolicy(const SdfSpecHandle& owner) : _owner(owner) { }
89 
90 
91  value_type Canonicalize(const value_type& x) const
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 <>
131 struct Vt_DefaultValueFactory<SdfPathKeyPolicy> {
132  static Vt_DefaultValueHolder Invoke() {
133  TF_AXIOM(false && "Failed VtValue::Get<SdfPathKeyPolicy> not allowed");
134  return Vt_DefaultValueHolder::Create((void*)0);
135  }
136 };
137 
143 public:
144  typedef SdfPayload value_type;
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 <>
160 struct Vt_DefaultValueFactory<SdfPayloadTypePolicy> {
161  static Vt_DefaultValueHolder Invoke() {
162  TF_AXIOM(false && "Failed VtValue::Get<SdfPayloadTypePolicy> not allowed");
163  return Vt_DefaultValueHolder::Create((void*)0);
164  }
165 };
166 
172 public:
173  typedef SdfReference value_type;
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 <>
189 struct Vt_DefaultValueFactory<SdfReferenceTypePolicy> {
190  static Vt_DefaultValueHolder Invoke() {
191  TF_AXIOM(false && "Failed VtValue::Get<SdfReferenceTypePolicy> not allowed");
192  return Vt_DefaultValueHolder::Create((void*)0);
193  }
194 };
195 
201 public:
202  typedef std::string value_type;
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 
222 public:
223  typedef std::map<SdfPath, SdfPath> Type;
224  typedef Type::key_type key_type;
225  typedef Type::mapped_type mapped_type;
226  typedef Type::value_type value_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 
246 public:
247  SdfGenericSpecViewPredicate(SdfSpecType type) : _type(type) { }
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 
268 public:
269  SDF_API
271 };
272 
278 public:
279  SDF_API
281 };
282 
283 PXR_NAMESPACE_CLOSE_SCOPE
284 
285 #endif // SDF_PROXYPOLICIES_H
Predicate for viewing properties.
Key policy for TfToken names.
Definition: proxyPolicies.h:63
Key policy for std::string names.
Definition: proxyPolicies.h:43
SdfSpecType
An enum that specifies the type of an object.
Definition: types.h:91
SdfHandle is a smart ptr that calls IsDormant() on the pointed-to object as an extra expiration check...
Predicate for viewing relationships.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
Predicate for viewing attributes.
Map edit proxy value policy for relocates maps.
#define TF_FOR_ALL(iter, c)
Macro for iterating over a container.
Definition: iterator.h:390
Represents a payload and all its meta data.
Definition: payload.h:59
List editor type policy for SdfPayload.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
List editor type policy for sublayers.
Represents a reference and all its meta data.
Definition: reference.h:75
static SDF_API const SdfPath & AbsoluteRootPath()
The absolute path representing the top of the namespace hierarchy.
#define TF_AXIOM(cond)
Aborts if the condition cond is not met.
Definition: diagnostic.h:215
SDF_API SdfPath MakeAbsolutePath(const SdfPath &anchor) const
Returns the absolute form of this path using anchor as the relative basis.
List editor type policy for SdfReference.
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
Definition: path.h:409
Key policy for SdfPath; converts all SdfPaths to absolute.
Definition: proxyPolicies.h:83