This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
reference.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_USD_SDF_REFERENCE_H
8#define PXR_USD_SDF_REFERENCE_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/usd/sdf/api.h"
16#include "pxr/usd/sdf/path.h"
17#include "pxr/base/tf/hash.h"
19#include "pxr/base/vt/value.h"
20
21#include <iosfwd>
22#include <string>
23#include <vector>
24
25PXR_NAMESPACE_OPEN_SCOPE
26
27class SdfReference;
28
29typedef std::vector<SdfReference> SdfReferenceVector;
30
59public:
66 SDF_API SdfReference(
67 const std::string &assetPath = std::string(),
68 const SdfPath &primPath = SdfPath(),
69 const SdfLayerOffset &layerOffset = SdfLayerOffset(),
70 const VtDictionary &customData = VtDictionary());
71
75 const std::string &GetAssetPath() const {
76 return _assetPath;
77 }
78
84 void SetAssetPath(const std::string &assetPath) {
85 // Go through SdfAssetPath() to raise an error if \p assetPath contains
86 // illegal characters (i.e. control characters).
87 _assetPath = SdfAssetPath(assetPath).GetAssetPath();
88 }
89
94 const SdfPath &GetPrimPath() const {
95 return _primPath;
96 }
97
102 void SetPrimPath(const SdfPath &primPath) {
103 _primPath = primPath;
104 }
105
109 return _layerOffset;
110 }
111
114 void SetLayerOffset(const SdfLayerOffset &layerOffset) {
115 _layerOffset = layerOffset;
116 }
117
121 return _customData;
122 }
123
126 void SetCustomData(const VtDictionary &customData) {
127 _customData = customData;
128 }
129
134 SDF_API void SetCustomData(const std::string &name, const VtValue &value);
135
137 void SwapCustomData(VtDictionary &customData) {
138 _customData.swap(customData);
139 }
140
145 SDF_API bool IsInternal() const;
146
147 friend inline size_t hash_value(const SdfReference &r) {
148 return TfHash::Combine(
149 r._assetPath,
150 r._primPath,
151 r._layerOffset,
152 r._customData
153 );
154 }
155
157 SDF_API bool operator==(const SdfReference &rhs) const;
158
160 bool operator!=(const SdfReference &rhs) const {
161 return !(*this == rhs);
162 }
163
166 SDF_API bool operator<(const SdfReference &rhs) const;
167
169 bool operator>(const SdfReference &rhs) const {
170 return rhs < *this;
171 }
172
174 bool operator<=(const SdfReference &rhs) const {
175 return !(rhs < *this);
176 }
177
179 bool operator>=(const SdfReference &rhs) const {
180 return !(*this < rhs);
181 }
182
187 bool operator()(const SdfReference &lhs, const SdfReference &rhs) const {
188 return lhs._assetPath == rhs._assetPath &&
189 lhs._primPath == rhs._primPath;
190 }
191 };
192
197 bool operator()(const SdfReference &lhs, const SdfReference &rhs) const {
198 return lhs._assetPath < rhs._assetPath ||
199 (lhs._assetPath == rhs._assetPath &&
200 lhs._primPath < rhs._primPath);
201 }
202 };
203
204private:
205 // The asset path to the external layer.
206 std::string _assetPath;
207
208 // The path to the referenced prim in the external layer.
209 SdfPath _primPath;
210
211 // The layer offset to transform time.
212 SdfLayerOffset _layerOffset;
213
214 // The custom data associated with the reference.
215 VtDictionary _customData;
216};
217
229 const SdfReferenceVector &references,
230 const SdfReference &referenceId);
231
233SDF_API std::ostream & operator<<( std::ostream &out,
234 const SdfReference &reference );
235
236PXR_NAMESPACE_CLOSE_SCOPE
237
238#endif // PXR_USD_SDF_REFERENCE_H
Contains an asset path and an optional resolved path.
Definition: assetPath.h:30
const std::string & GetAssetPath() const &
Return the asset path.
Definition: assetPath.h:113
Represents a time offset and scale between layers.
Definition: layerOffset.h:44
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
Represents a reference and all its meta data.
Definition: reference.h:58
const VtDictionary & GetCustomData() const
Returns the custom data associated with the reference.
Definition: reference.h:120
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.
SDF_API bool operator<(const SdfReference &rhs) const
Returns whether this reference is less than rhs.
const SdfLayerOffset & GetLayerOffset() const
Returns the layer offset associated with the reference.
Definition: reference.h:108
void SwapCustomData(VtDictionary &customData)
Swaps the custom data dictionary for this reference.
Definition: reference.h:137
void SetPrimPath(const SdfPath &primPath)
Sets the path of the referenced prim.
Definition: reference.h:102
void SetLayerOffset(const SdfLayerOffset &layerOffset)
Sets a new layer offset.
Definition: reference.h:114
void SetAssetPath(const std::string &assetPath)
Sets the asset path for the root layer of the referenced layer stack.
Definition: reference.h:84
const std::string & GetAssetPath() const
Returns the asset path to the root layer of the referenced layer stack.
Definition: reference.h:75
bool operator>(const SdfReference &rhs) const
Definition: reference.h:169
void SetCustomData(const VtDictionary &customData)
Sets the custom data associated with the reference.
Definition: reference.h:126
bool operator!=(const SdfReference &rhs) const
Definition: reference.h:160
SDF_API void SetCustomData(const std::string &name, const VtValue &value)
Sets a custom data entry for the reference.
const SdfPath & GetPrimPath() const
Returns the path of the referenced prim.
Definition: reference.h:94
bool operator>=(const SdfReference &rhs) const
Definition: reference.h:179
SDF_API bool IsInternal() const
Returns true in the case of an internal reference.
bool operator<=(const SdfReference &rhs) const
Definition: reference.h:174
SDF_API bool operator==(const SdfReference &rhs) const
Returns whether this reference equals rhs.
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:475
A map with string keys and VtValue values.
Definition: dictionary.h:43
VT_API void swap(VtDictionary &dict)
Swaps the contents of two VtDictionaries.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:147
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
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...
Struct that defines equality of SdfReferences based on their identity (the asset path and prim path).
Definition: reference.h:186
Struct that defines a strict weak ordering of SdfReferences based on their identity (the asset path a...
Definition: reference.h:196