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"
16
17#include <iosfwd>
18#include <string>
19
20PXR_NAMESPACE_OPEN_SCOPE
21
22class SdfAssetPath;
23class VtDictionary;
24class VtValue;
25template<typename T> class TfSpan;
26SDF_DECLARE_HANDLES(SdfLayer);
27
42public:
43 SdfAssetPathParams& Authored(const std::string &authoredPath_) {
44 authoredPath = authoredPath_;
45 return *this;
46 }
47
48 SdfAssetPathParams& Evaluated(const std::string &evaluatedPath_) {
49 evaluatedPath = evaluatedPath_;
50 return *this;
51 }
52
53 SdfAssetPathParams& Resolved(const std::string &resolvedPath_) {
54 resolvedPath = resolvedPath_;
55 return *this;
56 }
57
58private:
59 friend class SdfAssetPath;
60
61 std::string authoredPath;
62 std::string evaluatedPath;
63 std::string resolvedPath;
64};
65
78{
79public:
83
85 SDF_API SdfAssetPath();
86
93 SDF_API explicit SdfAssetPath(const std::string &authoredPath);
94
101 SDF_API
102 SdfAssetPath(const std::string &authoredPath,
103 const std::string &resolvedPath);
104
110 SDF_API
112
114
117
119 bool operator==(const SdfAssetPath &rhs) const {
120 return _authoredPath == rhs._authoredPath &&
121 _evaluatedPath == rhs._evaluatedPath &&
122 _resolvedPath == rhs._resolvedPath;
123 }
124
127 bool operator!=(const SdfAssetPath& rhs) const {
128 return !(*this == rhs);
129 }
130
132 SDF_API bool operator<(const SdfAssetPath &rhs) const;
133
136 bool operator<=(const SdfAssetPath& rhs) const {
137 return !(rhs < *this);
138 }
139
142 bool operator>(const SdfAssetPath& rhs) const {
143 return rhs < *this;
144 }
145
148 bool operator>=(const SdfAssetPath& rhs) const {
149 return !(*this < rhs);
150 }
151
153 size_t GetHash() const {
154 return TfHash::Combine(_authoredPath, _evaluatedPath, _resolvedPath);
155 }
156
158 struct Hash
159 {
160 size_t operator()(const SdfAssetPath &ap) const {
161 return ap.GetHash();
162 }
163 };
164
165 friend size_t hash_value(const SdfAssetPath &ap) { return ap.GetHash(); }
166
168
171
174 const std::string &GetAuthoredPath() const & {
175 return _authoredPath;
176 }
177
179 std::string GetAuthoredPath() const && {
180 return std::move(_authoredPath);
181 }
182
191 const std::string &GetEvaluatedPath() const & {
192 return _evaluatedPath;
193 }
194
196 std::string GetEvaluatedPath() const && {
197 return std::move(_evaluatedPath);
198 }
199
204 const std::string &GetAssetPath() const & {
205 return _evaluatedPath.empty() ? _authoredPath : _evaluatedPath;
206 }
207
209 std::string GetAssetPath() const && {
210 return std::move(
211 _evaluatedPath.empty() ? _authoredPath : _evaluatedPath);
212 }
213
220 const std::string &GetResolvedPath() const & {
221 return _resolvedPath;
222 }
223
225 std::string GetResolvedPath() const && {
226 return std::move(_resolvedPath);
227 }
228
230
233
236 void SetAuthoredPath(const std::string &authoredPath) {
237 _authoredPath = authoredPath;
238 }
239
242 void SetEvaluatedPath(const std::string &evaluatedPath) {
243 _evaluatedPath = evaluatedPath;
244 }
245
247 void SetResolvedPath(const std::string &resolvedPath) {
248 _resolvedPath = resolvedPath;
249 }
250
252
253private:
254 friend inline void swap(SdfAssetPath &lhs, SdfAssetPath &rhs) {
255 lhs._authoredPath.swap(rhs._authoredPath);
256 lhs._evaluatedPath.swap(rhs._evaluatedPath);
257 lhs._resolvedPath.swap(rhs._resolvedPath);
258 }
259
261 std::string _authoredPath;
264 std::string _evaluatedPath;
266 std::string _resolvedPath;
267};
268
271
278SDF_API std::ostream& operator<<(std::ostream& out, const SdfAssetPath& ap);
279
281
284SDF_API
285void SdfAnchorAssetPaths(const SdfLayerHandle &anchor,
286 const VtDictionary &exprVars,
287 TfSpan<SdfAssetPath> assetPaths,
288 std::vector<std::string> *errors);
289
293SDF_API
294void SdfResolveAssetPaths(const SdfLayerHandle &anchor,
295 const VtDictionary &exprVars,
296 TfSpan<SdfAssetPath> assetPaths,
297 std::vector<std::string> *errors);
298
299PXR_NAMESPACE_CLOSE_SCOPE
300
301#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.
Contains an asset path and optional evaluated and resolved paths.
Definition: assetPath.h:78
void SetAuthoredPath(const std::string &authoredPath)
Sets the authored path.
Definition: assetPath.h:236
void SetEvaluatedPath(const std::string &evaluatedPath)
Sets the evaluated path.
Definition: assetPath.h:242
std::string GetAuthoredPath() const &&
Overload for rvalues, move out the asset path.
Definition: assetPath.h:179
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:225
bool operator<=(const SdfAssetPath &rhs) const
Less than or equal operator.
Definition: assetPath.h:136
bool operator>=(const SdfAssetPath &rhs) const
Greater than or equal operator.
Definition: assetPath.h:148
const std::string & GetEvaluatedPath() const &
Return the evaluated asset path, if any.
Definition: assetPath.h:191
const std::string & GetResolvedPath() const &
Return the resolved asset path, if any.
Definition: assetPath.h:220
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:209
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:127
const std::string & GetAssetPath() const &
Return the asset path.
Definition: assetPath.h:204
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:247
size_t GetHash() const
Hash function.
Definition: assetPath.h:153
const std::string & GetAuthoredPath() const &
Returns the asset path as it was authored in the original layer.
Definition: assetPath.h:174
bool operator==(const SdfAssetPath &rhs) const
Equality, including the evaluated and resolved paths.
Definition: assetPath.h:119
std::string GetEvaluatedPath() const &&
Overload for rvalues, move out the evaluated path.
Definition: assetPath.h:196
bool operator>(const SdfAssetPath &rhs) const
Greater than operator.
Definition: assetPath.h:142
SDF_API SdfAssetPath()
Construct an empty asset path.
Helper class for explicitly setting values when creating a SdfAssetPath.
Definition: assetPath.h:41
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:43
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:152
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].