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 SDF_REFERENCE_H
25 #define SDF_REFERENCE_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/sdf/api.h"
31 #include "pxr/usd/sdf/layerOffset.h"
32 #include "pxr/usd/sdf/path.h"
33 #include "pxr/base/vt/dictionary.h"
34 #include "pxr/base/vt/value.h"
35 
36 #include <boost/operators.hpp>
37 
38 #include <iosfwd>
39 #include <string>
40 #include <vector>
41 
42 PXR_NAMESPACE_OPEN_SCOPE
43 
44 class SdfReference;
45 
46 typedef std::vector<SdfReference> SdfReferenceVector;
47 
75 class SdfReference : boost::totally_ordered<SdfReference> {
76 public:
80  SDF_API SdfReference(
81  const std::string &assetPath = std::string(),
82  const SdfPath &primPath = SdfPath(),
83  const SdfLayerOffset &layerOffset = SdfLayerOffset(),
84  const VtDictionary &customData = VtDictionary());
85 
89  const std::string &GetAssetPath() const {
90  return _assetPath;
91  }
92 
96  void SetAssetPath(const std::string &assetPath) {
97  _assetPath = assetPath;
98  }
99 
104  const SdfPath &GetPrimPath() const {
105  return _primPath;
106  }
107 
112  void SetPrimPath(const SdfPath &primPath) {
113  _primPath = primPath;
114  }
115 
119  return _layerOffset;
120  }
121 
124  void SetLayerOffset(const SdfLayerOffset &layerOffset) {
125  _layerOffset = layerOffset;
126  }
127 
130  const VtDictionary &GetCustomData() const {
131  return _customData;
132  }
133 
136  void SetCustomData(const VtDictionary &customData) {
137  _customData = customData;
138  }
139 
144  SDF_API void SetCustomData(const std::string &name, const VtValue &value);
145 
147  void SwapCustomData(VtDictionary &customData) {
148  _customData.swap(customData);
149  }
150 
151  friend inline size_t hash_value(const SdfReference &r) {
152  size_t h = 0;
153  boost::hash_combine(h, r._assetPath);
154  boost::hash_combine(h, r._primPath);
155  boost::hash_combine(h, r._layerOffset);
156  boost::hash_combine(h, r._customData);
157  return h;
158  }
159 
161  SDF_API bool operator==(const SdfReference &rhs) const;
162 
165  SDF_API bool operator<(const SdfReference &rhs) const;
166 
170  struct IdentityEqual {
171  bool operator()(const SdfReference &lhs, const SdfReference &rhs) const {
172  return lhs._assetPath == rhs._assetPath &&
173  lhs._primPath == rhs._primPath;
174  }
175  };
176 
181  bool operator()(const SdfReference &lhs, const SdfReference &rhs) const {
182  return lhs._assetPath < rhs._assetPath ||
183  (lhs._assetPath == rhs._assetPath &&
184  lhs._primPath < rhs._primPath);
185  }
186  };
187 
188 private:
189  // The asset path to the external layer.
190  std::string _assetPath;
191 
192  // The path to the referenced prim in the external layer.
193  SdfPath _primPath;
194 
195  // The layer offset to transform time.
196  SdfLayerOffset _layerOffset;
197 
198  // The custom data associated with the reference.
199  VtDictionary _customData;
200 };
201 
212 SDF_API int SdfFindReferenceByIdentity(
213  const SdfReferenceVector &references,
214  const SdfReference &referenceId);
215 
217 SDF_API std::ostream & operator<<( std::ostream &out,
218  const SdfReference &reference );
219 
220 PXR_NAMESPACE_CLOSE_SCOPE
221 
222 #endif // SDF_REFERENCE_H
const VtDictionary & GetCustomData() const
Returns the custom data associated with the reference.
Definition: reference.h:130
void SetCustomData(const VtDictionary &customData)
Sets the custom data associated with the reference.
Definition: reference.h:136
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:124
A map with string keys and VtValue values.
Definition: dictionary.h:61
void SetAssetPath(const std::string &assetPath)
Sets the asset path for the root layer of the referenced layer stack.
Definition: reference.h:96
Struct that defines equality of SdfReferences based on their identity (the asset path and prim path)...
Definition: reference.h:170
const std::string & GetAssetPath() const
Returns the asset path to the root layer of the referenced layer stack.
Definition: reference.h:89
const SdfLayerOffset & GetLayerOffset() const
Returns the layer offset associated with the reference.
Definition: reference.h:118
Struct that defines a strict weak ordering of SdfReferences based on their identity (the asset path a...
Definition: reference.h:180
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
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:112
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:75
void SwapCustomData(VtDictionary &customData)
Swaps the custom data dictionary for this reference.
Definition: reference.h:147
const SdfPath & GetPrimPath() const
Returns the path of the referenced prim.
Definition: reference.h:104
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:182
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.