Loading...
Searching...
No Matches
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:
67 SDF_API SdfReference(
68 const std::string &assetPath = std::string(),
69 const SdfPath &primPath = SdfPath(),
70 const SdfLayerOffset &layerOffset = SdfLayerOffset(),
71 const VtDictionary &customData = VtDictionary());
72
76 const std::string &GetAssetPath() const {
77 return _assetPath;
78 }
79
85 void SetAssetPath(const std::string &assetPath) {
86 // Go through SdfAssetPath() to raise an error if \p assetPath contains
87 // illegal characters (i.e. control characters).
88 _assetPath = SdfAssetPath(assetPath).GetAssetPath();
89 }
90
95 const SdfPath &GetPrimPath() const {
96 return _primPath;
97 }
98
103 void SetPrimPath(const SdfPath &primPath) {
104 _primPath = primPath;
105 }
106
110 return _layerOffset;
111 }
112
115 void SetLayerOffset(const SdfLayerOffset &layerOffset) {
116 _layerOffset = layerOffset;
117 }
118
122 return _customData;
123 }
124
128 void SetCustomData(const VtDictionary &customData) {
129 _customData = customData;
130 }
131
136 SDF_API void SetCustomData(const std::string &name, const VtValue &value);
137
139 void SwapCustomData(VtDictionary &customData) {
140 _customData.swap(customData);
141 }
142
147 SDF_API bool IsInternal() const;
148
149 friend inline size_t hash_value(const SdfReference &r) {
150 return TfHash::Combine(
151 r._assetPath,
152 r._primPath,
153 r._layerOffset,
154 r._customData
155 );
156 }
157
159 SDF_API bool operator==(const SdfReference &rhs) const;
160
162 bool operator!=(const SdfReference &rhs) const {
163 return !(*this == rhs);
164 }
165
168 SDF_API bool operator<(const SdfReference &rhs) const;
169
171 bool operator>(const SdfReference &rhs) const {
172 return rhs < *this;
173 }
174
176 bool operator<=(const SdfReference &rhs) const {
177 return !(rhs < *this);
178 }
179
181 bool operator>=(const SdfReference &rhs) const {
182 return !(*this < rhs);
183 }
184
189 bool operator()(const SdfReference &lhs, const SdfReference &rhs) const {
190 return lhs._assetPath == rhs._assetPath &&
191 lhs._primPath == rhs._primPath;
192 }
193 };
194
199 bool operator()(const SdfReference &lhs, const SdfReference &rhs) const {
200 return lhs._assetPath < rhs._assetPath ||
201 (lhs._assetPath == rhs._assetPath &&
202 lhs._primPath < rhs._primPath);
203 }
204 };
205
206private:
207 // The asset path to the external layer.
208 std::string _assetPath;
209
210 // The path to the referenced prim in the external layer.
211 SdfPath _primPath;
212
213 // The layer offset to transform time.
214 SdfLayerOffset _layerOffset;
215
216 // The custom data associated with the reference.
217 VtDictionary _customData;
218};
219
231 const SdfReferenceVector &references,
232 const SdfReference &referenceId);
233
235SDF_API std::ostream & operator<<( std::ostream &out,
236 const SdfReference &reference );
237
238PXR_NAMESPACE_CLOSE_SCOPE
239
240#endif // PXR_USD_SDF_REFERENCE_H
Contains an asset path and optional evaluated and resolved paths.
Definition assetPath.h:79
const std::string & GetAssetPath() const &
Return the asset path.
Definition assetPath.h:205
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:281
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:121
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:109
void SwapCustomData(VtDictionary &customData)
Swaps the custom data dictionary for this reference.
Definition reference.h:139
void SetPrimPath(const SdfPath &primPath)
Sets the path of the referenced prim.
Definition reference.h:103
void SetLayerOffset(const SdfLayerOffset &layerOffset)
Sets a new layer offset.
Definition reference.h:115
void SetAssetPath(const std::string &assetPath)
Sets the asset path for the root layer of the referenced layer stack.
Definition reference.h:85
const std::string & GetAssetPath() const
Returns the asset path to the root layer of the referenced layer stack.
Definition reference.h:76
bool operator>(const SdfReference &rhs) const
Definition reference.h:171
void SetCustomData(const VtDictionary &customData)
Sets the custom data associated with the reference.
Definition reference.h:128
bool operator!=(const SdfReference &rhs) const
Definition reference.h:162
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:95
bool operator>=(const SdfReference &rhs) const
Definition reference.h:181
SDF_API bool IsInternal() const
Returns true in the case of an internal reference.
bool operator<=(const SdfReference &rhs) const
Definition reference.h:176
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:487
A map with string keys and VtValue values.
Definition dictionary.h:52
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:90
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 std::ostream & operator<<(std::ostream &out, const SdfReference &reference)
Writes the string representation of SdfReference to out.
Struct that defines equality of SdfReferences based on their identity (the asset path and prim path).
Definition reference.h:188
Struct that defines a strict weak ordering of SdfReferences based on their identity (the asset path a...
Definition reference.h:198