Loading...
Searching...
No Matches
assetPath.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_ASSET_PATH_H
8#define PXR_USD_SDF_ASSET_PATH_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/usd/sdf/api.h"
14#include "pxr/base/tf/hash.h"
15#include "pxr/base/vt/traits.h"
17
18#include <iosfwd>
19#include <string>
20
21PXR_NAMESPACE_OPEN_SCOPE
22
23class SdfAssetPath;
24class VtDictionary;
25class VtValue;
26template<typename T> class TfSpan;
27SDF_DECLARE_HANDLES(SdfLayer);
28
43public:
44 SdfAssetPathParams& Authored(const std::string &authoredPath_) {
45 authoredPath = authoredPath_;
46 return *this;
47 }
48
49 SdfAssetPathParams& Evaluated(const std::string &evaluatedPath_) {
50 evaluatedPath = evaluatedPath_;
51 return *this;
52 }
53
54 SdfAssetPathParams& Resolved(const std::string &resolvedPath_) {
55 resolvedPath = resolvedPath_;
56 return *this;
57 }
58
59private:
60 friend class SdfAssetPath;
61
62 std::string authoredPath;
63 std::string evaluatedPath;
64 std::string resolvedPath;
65};
66
79{
80public:
84
86 SDF_API SdfAssetPath();
87
94 SDF_API explicit SdfAssetPath(const std::string &authoredPath);
95
102 SDF_API
103 SdfAssetPath(const std::string &authoredPath,
104 const std::string &resolvedPath);
105
111 SDF_API
113
115
118
120 bool operator==(const SdfAssetPath &rhs) const {
121 return _authoredPath == rhs._authoredPath &&
122 _evaluatedPath == rhs._evaluatedPath &&
123 _resolvedPath == rhs._resolvedPath;
124 }
125
128 bool operator!=(const SdfAssetPath& rhs) const {
129 return !(*this == rhs);
130 }
131
133 SDF_API bool operator<(const SdfAssetPath &rhs) const;
134
137 bool operator<=(const SdfAssetPath& rhs) const {
138 return !(rhs < *this);
139 }
140
143 bool operator>(const SdfAssetPath& rhs) const {
144 return rhs < *this;
145 }
146
149 bool operator>=(const SdfAssetPath& rhs) const {
150 return !(*this < rhs);
151 }
152
154 size_t GetHash() const {
155 return TfHash::Combine(_authoredPath, _evaluatedPath, _resolvedPath);
156 }
157
159 struct Hash
160 {
161 size_t operator()(const SdfAssetPath &ap) const {
162 return ap.GetHash();
163 }
164 };
165
166 friend size_t hash_value(const SdfAssetPath &ap) { return ap.GetHash(); }
167
169
172
175 const std::string &GetAuthoredPath() const & {
176 return _authoredPath;
177 }
178
180 std::string GetAuthoredPath() const && {
181 return std::move(_authoredPath);
182 }
183
192 const std::string &GetEvaluatedPath() const & {
193 return _evaluatedPath;
194 }
195
197 std::string GetEvaluatedPath() const && {
198 return std::move(_evaluatedPath);
199 }
200
205 const std::string &GetAssetPath() const & {
206 return _evaluatedPath.empty() ? _authoredPath : _evaluatedPath;
207 }
208
210 std::string GetAssetPath() const && {
211 return std::move(
212 _evaluatedPath.empty() ? _authoredPath : _evaluatedPath);
213 }
214
221 const std::string &GetResolvedPath() const & {
222 return _resolvedPath;
223 }
224
226 std::string GetResolvedPath() const && {
227 return std::move(_resolvedPath);
228 }
229
231
234
237 void SetAuthoredPath(const std::string &authoredPath) {
238 _authoredPath = authoredPath;
239 }
240
243 void SetEvaluatedPath(const std::string &evaluatedPath) {
244 _evaluatedPath = evaluatedPath;
245 }
246
248 void SetResolvedPath(const std::string &resolvedPath) {
249 _resolvedPath = resolvedPath;
250 }
251
253
254private:
255 friend inline void swap(SdfAssetPath &lhs, SdfAssetPath &rhs) {
256 lhs._authoredPath.swap(rhs._authoredPath);
257 lhs._evaluatedPath.swap(rhs._evaluatedPath);
258 lhs._resolvedPath.swap(rhs._resolvedPath);
259 }
260
262 std::string _authoredPath;
265 std::string _evaluatedPath;
267 std::string _resolvedPath;
268};
269
270// SdfAssetPath supports value transforms.
272
275
282SDF_API std::ostream& operator<<(std::ostream& out, const SdfAssetPath& ap);
283
285
288SDF_API
289void SdfAnchorAssetPaths(const SdfLayerHandle &anchor,
290 const VtDictionary &exprVars,
291 TfSpan<SdfAssetPath> assetPaths,
292 std::vector<std::string> *errors);
293
297SDF_API
298void SdfResolveAssetPaths(const SdfLayerHandle &anchor,
299 const VtDictionary &exprVars,
300 TfSpan<SdfAssetPath> assetPaths,
301 std::vector<std::string> *errors);
302
303PXR_NAMESPACE_CLOSE_SCOPE
304
305#endif // PXR_USD_SDF_ASSET_PATH_H
SDF_API void SdfResolveAssetPaths(const SdfLayerHandle &anchor, const VtDictionary &exprVars, TfSpan< SdfAssetPath > assetPaths, std::vector< std::string > *errors)
Anchors and resolves the given assetPaths with respect to the anchor layer.
SDF_API void SdfAnchorAssetPaths(const SdfLayerHandle &anchor, const VtDictionary &exprVars, TfSpan< SdfAssetPath > assetPaths, std::vector< std::string > *errors)
Anchors all paths in assetPaths to the anchor layer.
#define VT_VALUE_TYPE_CAN_TRANSFORM(T)
A helper for specializing the above trait.
Definition: traits.h:150
Contains an asset path and optional evaluated and resolved paths.
Definition: assetPath.h:79
void SetAuthoredPath(const std::string &authoredPath)
Sets the authored path.
Definition: assetPath.h:237
void SetEvaluatedPath(const std::string &evaluatedPath)
Sets the evaluated path.
Definition: assetPath.h:243
std::string GetAuthoredPath() const &&
Overload for rvalues, move out the asset path.
Definition: assetPath.h:180
SDF_API SdfAssetPath(const std::string &authoredPath, const std::string &resolvedPath)
Construct an asset path with authoredPath and an associated resolvedPath.
std::string GetResolvedPath() const &&
Overload for rvalues, move out the asset path.
Definition: assetPath.h:226
bool operator<=(const SdfAssetPath &rhs) const
Less than or equal operator.
Definition: assetPath.h:137
bool operator>=(const SdfAssetPath &rhs) const
Greater than or equal operator.
Definition: assetPath.h:149
const std::string & GetEvaluatedPath() const &
Return the evaluated asset path, if any.
Definition: assetPath.h:192
const std::string & GetResolvedPath() const &
Return the resolved asset path, if any.
Definition: assetPath.h:221
SDF_API SdfAssetPath(const std::string &authoredPath)
Construct an asset path with authoredPath and no associated evaluated or resolved path.
std::string GetAssetPath() const &&
Overload for rvalues, move out the asset path.
Definition: assetPath.h:210
SDF_API bool operator<(const SdfAssetPath &rhs) const
Ordering first by asset path, resolved path, then by evaluated path.
bool operator!=(const SdfAssetPath &rhs) const
Inequality operator.
Definition: assetPath.h:128
const std::string & GetAssetPath() const &
Return the asset path.
Definition: assetPath.h:205
SDF_API SdfAssetPath(const SdfAssetPathParams &params)
Construct an asset path using a SdfAssetPathParams object.
void SetResolvedPath(const std::string &resolvedPath)
Sets the resolved path. This value is the result of asset resolution.
Definition: assetPath.h:248
size_t GetHash() const
Hash function.
Definition: assetPath.h:154
const std::string & GetAuthoredPath() const &
Returns the asset path as it was authored in the original layer.
Definition: assetPath.h:175
bool operator==(const SdfAssetPath &rhs) const
Equality, including the evaluated and resolved paths.
Definition: assetPath.h:120
std::string GetEvaluatedPath() const &&
Overload for rvalues, move out the evaluated path.
Definition: assetPath.h:197
bool operator>(const SdfAssetPath &rhs) const
Greater than operator.
Definition: assetPath.h:143
SDF_API SdfAssetPath()
Construct an empty asset path.
Helper class for explicitly setting values when creating a SdfAssetPath.
Definition: assetPath.h:42
A scene description container that can combine with other such containers to form simple component as...
Definition: layer.h:84
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:487
Represents a range of contiguous elements.
Definition: span.h:71
A map with string keys and VtValue values.
Definition: dictionary.h:52
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:90
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].