1818
1919PXR_NAMESPACE_OPEN_SCOPE
2020
21+ class SdfAssetPath ;
22+
23+ // / \struct SdfAssetPathParams
24+ // / Helper class for explicitly setting values when creating a SdfAssetPath
25+ // /
26+ // / Example usage:
27+ // / \code
28+ // / SdfAssetPath myAssetPath(
29+ // / SdfAssetPathParams()
30+ // / .Authored("blah_{VAR}.usda")
31+ // / .Evaluated("blah_foo.usda")
32+ // / .Resolved("/foo/bar/blah_foo.usda")
33+ // / );
34+ // / \endcode
35+ // /
36+ class SdfAssetPathParams {
37+ public:
38+ SdfAssetPathParams& Authored (const std::string &authoredPath_) {
39+ authoredPath = authoredPath_;
40+ return *this ;
41+ }
42+
43+ SdfAssetPathParams& Evaluated (const std::string &evaluatedPath_) {
44+ evaluatedPath = evaluatedPath_;
45+ return *this ;
46+ }
47+
48+ SdfAssetPathParams& Resolved (const std::string &resolvedPath_) {
49+ resolvedPath = resolvedPath_;
50+ return *this ;
51+ }
52+
53+ private:
54+ friend class SdfAssetPath ;
55+
56+ std::string authoredPath;
57+ std::string evaluatedPath;
58+ std::string resolvedPath;
59+ };
60+
2161// / \class SdfAssetPath
2262// /
23- // / Contains an asset path and an optional resolved path. Asset paths may
24- // / contain non-control UTF-8 encoded characters. Specifically, U+0000..U+001F
25- // / (C0 controls), U+007F (delete), and U+0080..U+009F (C1 controls) are
26- // / disallowed. Attempts to construct asset paths with such characters will
27- // / issue a TfError and produce the default-constructed empty asset path.
63+ // / Contains an asset path and optional evaluated and resolved paths.
64+ // / When this class is used to author scene description, the value returned
65+ // / by GetAssetPath() is serialized out, all other fields are ignored.
66+ // / Asset paths may contain non-control UTF-8 encoded characters.
67+ // / Specifically, U+0000..U+001F (C0 controls), U+007F (delete),
68+ // / and U+0080..U+009F (C1 controls) are disallowed. Attempts to construct
69+ // / asset paths with such characters will issue a TfError and produce the
70+ // / default-constructed empty asset path.
2871// /
2972class SdfAssetPath
3073{
@@ -36,29 +79,41 @@ class SdfAssetPath
3679 // / Construct an empty asset path.
3780 SDF_API SdfAssetPath ();
3881
39- // / Construct an asset path with \p path and no associated resolved path.
82+ // / Construct an asset path with \p authoredPath and no associated
83+ // / evaluated or resolved path.
4084 // /
41- // / If the passed \p path is not valid UTF-8 or contains C0 or C1 control
42- // / characters, raise a TfError and return the default-constructed empty
43- // / asset path.
44- SDF_API explicit SdfAssetPath (const std::string &path );
85+ // / If the passed \p authoredPath is not valid UTF-8 or contains C0 or C1
86+ // / control characters, raise a TfError and return the default-constructed
87+ // / empty asset path.
88+ SDF_API explicit SdfAssetPath (const std::string &authoredPath );
4589
46- // / Construct an asset path with \p path and an associated \p resolvedPath.
90+ // / Construct an asset path with \p authoredPath and an associated
91+ // / \p resolvedPath.
4792 // /
48- // / If either the passed \path or \p resolvedPath are not valid UTF-8 or
49- // / either contain C0 or C1 control characters, raise a TfError and return
93+ // / If either the passed \p authoredPath or \p resolvedPath are not valid
94+ // / UTF-8 or either contain C0 or C1 control characters, raise a TfError and
95+ // / return the default-constructed empty asset path.
96+ SDF_API
97+ SdfAssetPath (const std::string &authoredPath,
98+ const std::string &resolvedPath);
99+
100+ // / Construct an asset path using a SdfAssetPathParams object
101+ // /
102+ // / If any fields of the passed in structure are not valid UTF-8 or either
103+ // / contain C0 or C1 control, characters, raise a TfError and return
50104 // / the default-constructed empty asset path.
51105 SDF_API
52- SdfAssetPath (const std::string &path, const std::string &resolvedPath );
106+ SdfAssetPath (const SdfAssetPathParams ¶ms );
53107
54108 // / @}
55109
56110 // /\name Operators
57111 // / @{
58112
59- // / Equality, including the resolved path .
113+ // / Equality, including the evaluated and resolved paths .
60114 bool operator ==(const SdfAssetPath &rhs) const {
61- return _assetPath == rhs._assetPath &&
115+ return _authoredPath == rhs._authoredPath &&
116+ _evaluatedPath == rhs._evaluatedPath &&
62117 _resolvedPath == rhs._resolvedPath ;
63118 }
64119
@@ -68,7 +123,7 @@ class SdfAssetPath
68123 return !(*this == rhs);
69124 }
70125
71- // / Ordering first by asset path, then by resolved path.
126+ // / Ordering first by asset path, resolved path, then by evaluated path.
72127 SDF_API bool operator <(const SdfAssetPath &rhs) const ;
73128
74129 // / Less than or equal operator
@@ -91,7 +146,7 @@ class SdfAssetPath
91146
92147 // / Hash function
93148 size_t GetHash () const {
94- return TfHash::Combine (_assetPath , _resolvedPath);
149+ return TfHash::Combine (_authoredPath, _evaluatedPath , _resolvedPath);
95150 }
96151
97152 // / \class Hash
@@ -109,17 +164,50 @@ class SdfAssetPath
109164 // / \name Accessors
110165 // / @{
111166
112- // / Return the asset path.
167+ // / Returns the asset path as it was authored in the original layer. When
168+ // / authoring scene description, this value is used for serialization.
169+ const std::string &GetAuthoredPath () const & {
170+ return _authoredPath;
171+ }
172+
173+ // / Overload for rvalues, move out the asset path.
174+ std::string GetAuthoredPath () const && {
175+ return std::move (_authoredPath);
176+ }
177+
178+ // / Return the evaluated asset path, if any. The evaluated path's value
179+ // / consists of the authored path with any expression variables
180+ // / evaluated. If the authored path does not contain any expression
181+ // / variables, this field will be empty.
182+ // /
183+ // / Note that SdfAssetPath carries an evaluated path only if its creator
184+ // / passed one to the constructor. SdfAssetPath never performs variable
185+ // / expression evaluation itself.
186+ const std::string &GetEvaluatedPath () const & {
187+ return _evaluatedPath;
188+ }
189+
190+ // / Overload for rvalues, move out the evaluated path.
191+ std::string GetEvaluatedPath () const && {
192+ return std::move (_evaluatedPath);
193+ }
194+
195+ // / Return the asset path. If the the evaluated path is not empty, it will
196+ // / be returned, otherwise the raw, authored path is returned.
197+ // / The value this function returns is the exact input that is passed to
198+ // / asset resolution.
113199 const std::string &GetAssetPath () const & {
114- return _assetPath ;
200+ return _evaluatedPath. empty () ? _authoredPath : _evaluatedPath ;
115201 }
116202
117203 // / Overload for rvalues, move out the asset path.
118204 std::string GetAssetPath () const && {
119- return std::move (_assetPath);
205+ return std::move (
206+ _evaluatedPath.empty () ? _authoredPath : _evaluatedPath);
120207 }
121208
122- // / Return the resolved asset path, if any.
209+ // / Return the resolved asset path, if any. This is the resolved value of
210+ // / GetAssetPath()
123211 // /
124212 // / Note that SdfAssetPath carries a resolved path only if its creator
125213 // / passed one to the constructor. SdfAssetPath never performs resolution
@@ -135,13 +223,41 @@ class SdfAssetPath
135223
136224 // / @}
137225
226+ // / \name Setters
227+ // / @{
228+
229+ // / Sets the authored path. This value is the path exactly as it is
230+ // / authored in the layer.
231+ void SetAuthoredPath (const std::string &authoredPath) {
232+ _authoredPath = authoredPath;
233+ }
234+
235+ // / Sets the evaluated path. This value is the result of performing
236+ // / variable expression resolution on the authored path.
237+ void SetEvaluatedPath (const std::string &evaluatedPath) {
238+ _evaluatedPath = evaluatedPath;
239+ }
240+
241+ // / Sets the resolved path. This value is the result of asset resolution.
242+ void SetResolvedPath (const std::string &resolvedPath) {
243+ _resolvedPath = resolvedPath;
244+ }
245+
246+ // / @}
247+
138248private:
139249 friend inline void swap (SdfAssetPath &lhs, SdfAssetPath &rhs) {
140- lhs._assetPath .swap (rhs._assetPath );
250+ lhs._authoredPath .swap (rhs._authoredPath );
251+ lhs._evaluatedPath .swap (rhs._evaluatedPath );
141252 lhs._resolvedPath .swap (rhs._resolvedPath );
142253 }
143254
144- std::string _assetPath;
255+ // / Raw path, as authored in the layer.
256+ std::string _authoredPath;
257+ // / Contains the evaluated authored path, if variable expressions
258+ // / were present, otherwise empty.
259+ std::string _evaluatedPath;
260+ // / Fully evaluated and resolved path
145261 std::string _resolvedPath;
146262};
147263
0 commit comments