All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
reference.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_REFERENCE_H
25 #define PXR_USD_SDF_REFERENCE_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/sdf/api.h"
31 #include "pxr/usd/sdf/assetPath.h"
33 #include "pxr/usd/sdf/path.h"
34 #include "pxr/base/vt/dictionary.h"
35 #include "pxr/base/vt/value.h"
36 
37 #include <boost/operators.hpp>
38 
39 #include <iosfwd>
40 #include <string>
41 #include <vector>
42 
43 PXR_NAMESPACE_OPEN_SCOPE
44 
45 class SdfReference;
46 
47 typedef std::vector<SdfReference> SdfReferenceVector;
48 
76 class SdfReference : boost::totally_ordered<SdfReference> {
77 public:
84  SDF_API SdfReference(
85  const std::string &assetPath = std::string(),
86  const SdfPath &primPath = SdfPath(),
87  const SdfLayerOffset &layerOffset = SdfLayerOffset(),
88  const VtDictionary &customData = VtDictionary());
89 
93  const std::string &GetAssetPath() const {
94  return _assetPath;
95  }
96 
102  void SetAssetPath(const std::string &assetPath) {
103  // Go through SdfAssetPath() to raise an error if \p assetPath contains
104  // illegal characters (i.e. control characters).
105  _assetPath = SdfAssetPath(assetPath).GetAssetPath();
106  }
107 
112  const SdfPath &GetPrimPath() const {
113  return _primPath;
114  }
115 
120  void SetPrimPath(const SdfPath &primPath) {
121  _primPath = primPath;
122  }
123 
127  return _layerOffset;
128  }
129 
132  void SetLayerOffset(const SdfLayerOffset &layerOffset) {
133  _layerOffset = layerOffset;
134  }
135 
138  const VtDictionary &GetCustomData() const {
139  return _customData;
140  }
141 
144  void SetCustomData(const VtDictionary &customData) {
145  _customData = customData;
146  }
147 
152  SDF_API void SetCustomData(const std::string &name, const VtValue &value);
153 
155  void SwapCustomData(VtDictionary &customData) {
156  _customData.swap(customData);
157  }
158 
163  SDF_API bool IsInternal() const;
164 
165  friend inline size_t hash_value(const SdfReference &r) {
166  size_t h = 0;
167  boost::hash_combine(h, r._assetPath);
168  boost::hash_combine(h, r._primPath);
169  boost::hash_combine(h, r._layerOffset);
170  boost::hash_combine(h, r._customData);
171  return h;
172  }
173 
175  SDF_API bool operator==(const SdfReference &rhs) const;
176 
179  SDF_API bool operator<(const SdfReference &rhs) const;
180 
184  struct IdentityEqual {
185  bool operator()(const SdfReference &lhs, const SdfReference &rhs) const {
186  return lhs._assetPath == rhs._assetPath &&
187  lhs._primPath == rhs._primPath;
188  }
189  };
190 
195  bool operator()(const SdfReference &lhs, const SdfReference &rhs) const {
196  return lhs._assetPath < rhs._assetPath ||
197  (lhs._assetPath == rhs._assetPath &&
198  lhs._primPath < rhs._primPath);
199  }
200  };
201 
202 private:
203  // The asset path to the external layer.
204  std::string _assetPath;
205 
206  // The path to the referenced prim in the external layer.
207  SdfPath _primPath;
208 
209  // The layer offset to transform time.
210  SdfLayerOffset _layerOffset;
211 
212  // The custom data associated with the reference.
213  VtDictionary _customData;
214 };
215 
226 SDF_API int SdfFindReferenceByIdentity(
227  const SdfReferenceVector &references,
228  const SdfReference &referenceId);
229 
231 SDF_API std::ostream & operator<<( std::ostream &out,
232  const SdfReference &reference );
233 
234 PXR_NAMESPACE_CLOSE_SCOPE
235 
236 #endif // PXR_USD_SDF_REFERENCE_H
const VtDictionary & GetCustomData() const
Returns the custom data associated with the reference.
Definition: reference.h:138
void SetCustomData(const VtDictionary &customData)
Sets the custom data associated with the reference.
Definition: reference.h:144
SDF_API bool operator<(const SdfReference &rhs) const
Returns whether this reference is less than rhs.
VT_API void swap(VtDictionary &dict)
Swaps the contents of two VtDictionaries.
void SetLayerOffset(const SdfLayerOffset &layerOffset)
Sets a new layer offset.
Definition: reference.h:132
A map with string keys and VtValue values.
Definition: dictionary.h:63
const std::string & GetAssetPath() const
Return the asset path.
Definition: assetPath.h:111
void SetAssetPath(const std::string &assetPath)
Sets the asset path for the root layer of the referenced layer stack.
Definition: reference.h:102
Struct that defines equality of SdfReferences based on their identity (the asset path and prim path)...
Definition: reference.h:184
const std::string & GetAssetPath() const
Returns the asset path to the root layer of the referenced layer stack.
Definition: reference.h:93
SDF_API bool IsInternal() const
Returns true in the case of an internal reference.
const SdfLayerOffset & GetLayerOffset() const
Returns the layer offset associated with the reference.
Definition: reference.h:126
Struct that defines a strict weak ordering of SdfReferences based on their identity (the asset path a...
Definition: reference.h:194
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:288
SDF_API bool operator==(const SdfReference &rhs) const
Returns whether this reference equals rhs.
void SetPrimPath(const SdfPath &primPath)
Sets the path of the referenced prim.
Definition: reference.h:120
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
Represents a reference and all its meta data.
Definition: reference.h:76
void SwapCustomData(VtDictionary &customData)
Swaps the custom data dictionary for this reference.
Definition: reference.h:155
Contains an asset path and an optional resolved path.
Definition: assetPath.h:47
const SdfPath & GetPrimPath() const
Returns the path of the referenced prim.
Definition: reference.h:112
SDF_API int SdfFindReferenceByIdentity(const SdfReferenceVector &references, const SdfReference &referenceId)
Convenience function to find the index of the reference in references that has the same identity as t...
Represents a time offset and scale between layers.
Definition: layerOffset.h:61
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:168
SDF_API SdfReference(const std::string &assetPath=std::string(), const SdfPath &primPath=SdfPath(), const SdfLayerOffset &layerOffset=SdfLayerOffset(), const VtDictionary &customData=VtDictionary())
Creates a reference with all its meta data.