Loading...
Searching...
No Matches
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"
33#include "pxr/usd/sdf/path.h"
34#include "pxr/base/tf/hash.h"
36#include "pxr/base/vt/value.h"
37
38#include <iosfwd>
39#include <string>
40#include <vector>
41
42PXR_NAMESPACE_OPEN_SCOPE
43
44class SdfReference;
45
46typedef std::vector<SdfReference> SdfReferenceVector;
47
76public:
83 SDF_API SdfReference(
84 const std::string &assetPath = std::string(),
85 const SdfPath &primPath = SdfPath(),
86 const SdfLayerOffset &layerOffset = SdfLayerOffset(),
87 const VtDictionary &customData = VtDictionary());
88
92 const std::string &GetAssetPath() const {
93 return _assetPath;
94 }
95
101 void SetAssetPath(const std::string &assetPath) {
102 // Go through SdfAssetPath() to raise an error if \p assetPath contains
103 // illegal characters (i.e. control characters).
104 _assetPath = SdfAssetPath(assetPath).GetAssetPath();
105 }
106
111 const SdfPath &GetPrimPath() const {
112 return _primPath;
113 }
114
119 void SetPrimPath(const SdfPath &primPath) {
120 _primPath = primPath;
121 }
122
126 return _layerOffset;
127 }
128
131 void SetLayerOffset(const SdfLayerOffset &layerOffset) {
132 _layerOffset = layerOffset;
133 }
134
138 return _customData;
139 }
140
143 void SetCustomData(const VtDictionary &customData) {
144 _customData = customData;
145 }
146
151 SDF_API void SetCustomData(const std::string &name, const VtValue &value);
152
154 void SwapCustomData(VtDictionary &customData) {
155 _customData.swap(customData);
156 }
157
162 SDF_API bool IsInternal() const;
163
164 friend inline size_t hash_value(const SdfReference &r) {
165 return TfHash::Combine(
166 r._assetPath,
167 r._primPath,
168 r._layerOffset,
169 r._customData
170 );
171 }
172
174 SDF_API bool operator==(const SdfReference &rhs) const;
175
177 bool operator!=(const SdfReference &rhs) const {
178 return !(*this == rhs);
179 }
180
183 SDF_API bool operator<(const SdfReference &rhs) const;
184
186 bool operator>(const SdfReference &rhs) const {
187 return rhs < *this;
188 }
189
191 bool operator<=(const SdfReference &rhs) const {
192 return !(rhs < *this);
193 }
194
196 bool operator>=(const SdfReference &rhs) const {
197 return !(*this < rhs);
198 }
199
204 bool operator()(const SdfReference &lhs, const SdfReference &rhs) const {
205 return lhs._assetPath == rhs._assetPath &&
206 lhs._primPath == rhs._primPath;
207 }
208 };
209
214 bool operator()(const SdfReference &lhs, const SdfReference &rhs) const {
215 return lhs._assetPath < rhs._assetPath ||
216 (lhs._assetPath == rhs._assetPath &&
217 lhs._primPath < rhs._primPath);
218 }
219 };
220
221private:
222 // The asset path to the external layer.
223 std::string _assetPath;
224
225 // The path to the referenced prim in the external layer.
226 SdfPath _primPath;
227
228 // The layer offset to transform time.
229 SdfLayerOffset _layerOffset;
230
231 // The custom data associated with the reference.
232 VtDictionary _customData;
233};
234
246 const SdfReferenceVector &references,
247 const SdfReference &referenceId);
248
250SDF_API std::ostream & operator<<( std::ostream &out,
251 const SdfReference &reference );
252
253PXR_NAMESPACE_CLOSE_SCOPE
254
255#endif // PXR_USD_SDF_REFERENCE_H
Contains an asset path and an optional resolved path.
Definition: assetPath.h:47
const std::string & GetAssetPath() const &
Return the asset path.
Definition: assetPath.h:130
Represents a time offset and scale between layers.
Definition: layerOffset.h:61
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
Represents a reference and all its meta data.
Definition: reference.h:75
const VtDictionary & GetCustomData() const
Returns the custom data associated with the reference.
Definition: reference.h:137
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:125
void SwapCustomData(VtDictionary &customData)
Swaps the custom data dictionary for this reference.
Definition: reference.h:154
void SetPrimPath(const SdfPath &primPath)
Sets the path of the referenced prim.
Definition: reference.h:119
void SetLayerOffset(const SdfLayerOffset &layerOffset)
Sets a new layer offset.
Definition: reference.h:131
void SetAssetPath(const std::string &assetPath)
Sets the asset path for the root layer of the referenced layer stack.
Definition: reference.h:101
const std::string & GetAssetPath() const
Returns the asset path to the root layer of the referenced layer stack.
Definition: reference.h:92
bool operator>(const SdfReference &rhs) const
Definition: reference.h:186
void SetCustomData(const VtDictionary &customData)
Sets the custom data associated with the reference.
Definition: reference.h:143
bool operator!=(const SdfReference &rhs) const
Definition: reference.h:177
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:111
bool operator>=(const SdfReference &rhs) const
Definition: reference.h:196
SDF_API bool IsInternal() const
Returns true in the case of an internal reference.
bool operator<=(const SdfReference &rhs) const
Definition: reference.h:191
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:492
A map with string keys and VtValue values.
Definition: dictionary.h:60
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:164
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:203
Struct that defines a strict weak ordering of SdfReferences based on their identity (the asset path a...
Definition: reference.h:213