Skip to content

Commit 7e66c10

Browse files
matthewcpppixar-oss
authored andcommitted
This change alters the behavior of SdfAssetPath in a few ways:
Renames the existing _assetPath member and meaning of first parameter to the constructor to now represent the raw authored path in the layerr. Added explicit getters for this authored path. It is important to note that when authoring scene description, this value will be used for serilization, all other fields will be ignored. Adds a new evaluatedPath field to SdfAssetPath. This field is meant to hold the original asset path as authored in the layer with any variable expressions evaluated. This field is only populated if passed in at construction time. Changes the behavior of SdfAssetPath::GetAssetPath to return the evaulated path if present, otherwise returns the raw authored path. This is to preserve compatibility with existing callers who were relying on this method to return them the unresolved asset path containing evaulated expression variables. Additionally, _MakeResolvedAssetPathsImpl in UsdStage has been augmented to provide the unresolved, evaluated path when creating SdfAssetPath objects. This function services calls to UsdAttribute::Get(). (Internal change: 2358824)
1 parent 9850fdf commit 7e66c10

File tree

10 files changed

+459
-59
lines changed

10 files changed

+459
-59
lines changed

pxr/usd/sdf/assetPath.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,34 +122,42 @@ SdfAssetPath::SdfAssetPath()
122122
{
123123
}
124124

125-
SdfAssetPath::SdfAssetPath(const std::string &path)
126-
: _assetPath(path)
127-
{
128-
if (!_ValidateAssetPathString(path.c_str())) {
125+
SdfAssetPath::SdfAssetPath(const std::string &authoredPath)
126+
: _authoredPath(authoredPath)
127+
{
128+
if (!_ValidateAssetPathString(authoredPath.c_str())) {
129129
*this = SdfAssetPath();
130130
}
131131
}
132132

133-
SdfAssetPath::SdfAssetPath(const std::string &path,
133+
SdfAssetPath::SdfAssetPath(const std::string &authoredPath,
134134
const std::string &resolvedPath)
135-
: _assetPath(path)
135+
: _authoredPath(authoredPath)
136136
, _resolvedPath(resolvedPath)
137137
{
138-
if (!_ValidateAssetPathString(path.c_str()) ||
138+
if (!_ValidateAssetPathString(authoredPath.c_str()) ||
139139
!_ValidateAssetPathString(resolvedPath.c_str())) {
140140
*this = SdfAssetPath();
141141
}
142142
}
143143

144+
SdfAssetPath::SdfAssetPath(const SdfAssetPathParams &params)
145+
: _authoredPath(params.authoredPath)
146+
, _evaluatedPath(params.evaluatedPath)
147+
, _resolvedPath(params.resolvedPath)
148+
{
149+
if (!_ValidateAssetPathString(params.authoredPath.c_str()) ||
150+
!_ValidateAssetPathString(params.evaluatedPath.c_str()) ||
151+
!_ValidateAssetPathString(params.resolvedPath.c_str())) {
152+
*this = SdfAssetPath();
153+
}
154+
}
155+
144156
bool
145157
SdfAssetPath::operator<(const SdfAssetPath &rhs) const
146158
{
147-
if (_assetPath < rhs._assetPath)
148-
return true;
149-
if (rhs._assetPath < _assetPath)
150-
return false;
151-
152-
return _resolvedPath < rhs._resolvedPath;
159+
return std::tie(_authoredPath, _resolvedPath, _evaluatedPath) <
160+
std::tie(rhs._authoredPath, rhs._resolvedPath, rhs._evaluatedPath);
153161
}
154162

155163
std::ostream&

pxr/usd/sdf/assetPath.h

Lines changed: 140 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,56 @@
1818

1919
PXR_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
///
2972
class 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 &params);
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+
138248
private:
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

pxr/usd/sdf/fileIO_Common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ _StringFromValue(const TfToken& s)
140140
static string
141141
_StringFromValue(const SdfAssetPath& assetPath)
142142
{
143-
return _StringFromAssetPath(assetPath.GetAssetPath());
143+
return _StringFromAssetPath(assetPath.GetAuthoredPath());
144144
}
145145

146146
static string

0 commit comments

Comments
 (0)