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/tf/hash.h"
35 #include "pxr/base/vt/dictionary.h"
36 #include "pxr/base/vt/value.h"
37 
38 #include <boost/operators.hpp>
39 
40 #include <iosfwd>
41 #include <string>
42 #include <vector>
43 
44 PXR_NAMESPACE_OPEN_SCOPE
45 
46 class SdfReference;
47 
48 typedef std::vector<SdfReference> SdfReferenceVector;
49 
77 class SdfReference : boost::totally_ordered<SdfReference> {
78 public:
85  SDF_API SdfReference(
86  const std::string &assetPath = std::string(),
87  const SdfPath &primPath = SdfPath(),
88  const SdfLayerOffset &layerOffset = SdfLayerOffset(),
89  const VtDictionary &customData = VtDictionary());
90 
94  const std::string &GetAssetPath() const {
95  return _assetPath;
96  }
97 
103  void SetAssetPath(const std::string &assetPath) {
104  // Go through SdfAssetPath() to raise an error if \p assetPath contains
105  // illegal characters (i.e. control characters).
106  _assetPath = SdfAssetPath(assetPath).GetAssetPath();
107  }
108 
113  const SdfPath &GetPrimPath() const {
114  return _primPath;
115  }
116 
121  void SetPrimPath(const SdfPath &primPath) {
122  _primPath = primPath;
123  }
124 
128  return _layerOffset;
129  }
130 
133  void SetLayerOffset(const SdfLayerOffset &layerOffset) {
134  _layerOffset = layerOffset;
135  }
136 
139  const VtDictionary &GetCustomData() const {
140  return _customData;
141  }
142 
145  void SetCustomData(const VtDictionary &customData) {
146  _customData = customData;
147  }
148 
153  SDF_API void SetCustomData(const std::string &name, const VtValue &value);
154 
156  void SwapCustomData(VtDictionary &customData) {
157  _customData.swap(customData);
158  }
159 
164  SDF_API bool IsInternal() const;
165 
166  friend inline size_t hash_value(const SdfReference &r) {
167  return TfHash::Combine(
168  r._assetPath,
169  r._primPath,
170  r._layerOffset,
171  r._customData
172  );
173  }
174 
176  SDF_API bool operator==(const SdfReference &rhs) const;
177 
180  SDF_API bool operator<(const SdfReference &rhs) const;
181 
185  struct IdentityEqual {
186  bool operator()(const SdfReference &lhs, const SdfReference &rhs) const {
187  return lhs._assetPath == rhs._assetPath &&
188  lhs._primPath == rhs._primPath;
189  }
190  };
191 
196  bool operator()(const SdfReference &lhs, const SdfReference &rhs) const {
197  return lhs._assetPath < rhs._assetPath ||
198  (lhs._assetPath == rhs._assetPath &&
199  lhs._primPath < rhs._primPath);
200  }
201  };
202 
203 private:
204  // The asset path to the external layer.
205  std::string _assetPath;
206 
207  // The path to the referenced prim in the external layer.
208  SdfPath _primPath;
209 
210  // The layer offset to transform time.
211  SdfLayerOffset _layerOffset;
212 
213  // The custom data associated with the reference.
214  VtDictionary _customData;
215 };
216 
227 SDF_API int SdfFindReferenceByIdentity(
228  const SdfReferenceVector &references,
229  const SdfReference &referenceId);
230 
232 SDF_API std::ostream & operator<<( std::ostream &out,
233  const SdfReference &reference );
234 
235 PXR_NAMESPACE_CLOSE_SCOPE
236 
237 #endif // PXR_USD_SDF_REFERENCE_H
SDF_API bool operator<(const SdfReference &rhs) const
Returns whether this reference is less than rhs.
SDF_API bool operator==(const SdfReference &rhs) const
Returns whether this reference equals rhs.
const SdfLayerOffset & GetLayerOffset() const
Returns the layer offset associated with the reference.
Definition: reference.h:127
SDF_API std::ostream & operator<<(std::ostream &out, const SdfReference &reference)
Writes the string representation of SdfReference to out.
void SetCustomData(const VtDictionary &customData)
Sets the custom data associated with the reference.
Definition: reference.h:145
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:133
A map with string keys and VtValue values.
Definition: dictionary.h:62
void SetAssetPath(const std::string &assetPath)
Sets the asset path for the root layer of the referenced layer stack.
Definition: reference.h:103
Struct that defines equality of SdfReferences based on their identity (the asset path and prim path).
Definition: reference.h:185
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:519
const std::string & GetAssetPath() const
Returns the asset path to the root layer of the referenced layer stack.
Definition: reference.h:94
const std::string & GetAssetPath() const &
Return the asset path.
Definition: assetPath.h:108
Struct that defines a strict weak ordering of SdfReferences based on their identity (the asset path a...
Definition: reference.h:195
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
void SetPrimPath(const SdfPath &primPath)
Sets the path of the referenced prim.
Definition: reference.h:121
Represents a reference and all its meta data.
Definition: reference.h:77
void SwapCustomData(VtDictionary &customData)
Swaps the custom data dictionary for this reference.
Definition: reference.h:156
const VtDictionary & GetCustomData() const
Returns the custom data associated with the reference.
Definition: reference.h:139
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:113
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...
SDF_API bool IsInternal() const
Returns true in the case of an internal reference.
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:166
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.