forked from PixarAnimationStudios/OpenUSD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assetPathResolver.h
176 lines (147 loc) · 6.35 KB
/
assetPathResolver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_SDF_ASSET_PATH_RESOLVER_H
#define PXR_USD_SDF_ASSET_PATH_RESOLVER_H
/// \file sdf/assetPathResolver.h
#include "pxr/pxr.h"
#include "pxr/usd/sdf/declareHandles.h"
#include "pxr/usd/sdf/layer.h"
#include "pxr/usd/ar/assetInfo.h"
#include "pxr/usd/ar/resolvedPath.h"
#include "pxr/usd/ar/resolverContext.h"
#include "pxr/base/vt/value.h"
#include <string>
PXR_NAMESPACE_OPEN_SCOPE
SDF_DECLARE_HANDLES(SdfLayer);
/// \struct Sdf_AssetInfo
///
/// Container for layer asset information.
///
struct Sdf_AssetInfo
{
std::string identifier;
ArResolvedPath resolvedPath;
ArResolverContext resolverContext;
ArAssetInfo assetInfo;
};
/// Equality operator for Sdf_AssetInfo structures. Two asset info structures
/// if all fields match exactly.
bool operator==(const Sdf_AssetInfo& lhs, const Sdf_AssetInfo& rhs);
/// Returns true if \p identifier can be used to create a new layer, given
/// characteristics of the identifier itself, and the current path resolver
/// configuration.
bool Sdf_CanCreateNewLayerWithIdentifier(
const std::string& identifier,
std::string* whyNot);
/// Returns the resolved path for \p layerPath if an asset exists at that
/// path. Otherwise, returns an empty ArResolvedPath. Populates \p assetInfo
/// if it's non-nullptr.
ArResolvedPath Sdf_ResolvePath(
const std::string& layerPath,
ArAssetInfo* assetInfo = nullptr);
/// Returns the resolved path for \p layerPath. If no asset exists at that
/// path, returns a resolved path indicating where that asset should be
/// created. Otherwise, returns an empty ArResolvedPath. Populates \p assetInfo
/// if it's non-nullptr.
ArResolvedPath Sdf_ComputeFilePath(
const std::string& layerPath,
ArAssetInfo* assetInfo = nullptr);
/// Returns true if a layer can be written to \p resolvedPath.
bool Sdf_CanWriteLayerToPath(
const ArResolvedPath& resolvedPath);
/// Returns a newly allocated Sdf_AssetInfo struct with fields computed using
/// the specified \p identifier and \p filePath. If \p fileVersion is
/// specified, it is used over the discovered revision of the file. It is the
/// responsibility of the caller to delete the returned value.
Sdf_AssetInfo* Sdf_ComputeAssetInfoFromIdentifier(
const std::string& identifier,
const std::string& filePath,
const ArAssetInfo& assetInfo,
const std::string& fileVersion = std::string());
/// Returns the identifierTemplate, placeholders replaced with information
/// from the specified \p layer.
std::string Sdf_ComputeAnonLayerIdentifier(
const std::string& identifierTemplate,
const SdfLayer* layer);
/// Returns true if \p identifier is an anonymous layer identifier.
bool Sdf_IsAnonLayerIdentifier(
const std::string& identifier);
/// Returns the portion of the anonymous layer identifier to be used as the
/// display name. This is either the identifier tag, if one is present, or the
/// empty string.
std::string Sdf_GetAnonLayerDisplayName(
const std::string& identifier);
/// Returns the anonymous layer identifier template, from which
/// Sdf_ComputeAnonLayerIdentifier can compute an anonymous layer identifier.
std::string Sdf_GetAnonLayerIdentifierTemplate(
const std::string& tag);
/// Splits the given \p identifier into two portions: the layer path
/// and the arguments. For example, given the identifier foo.menva?a=b,
/// this function returns ("foo.menva", "?a=b")
bool Sdf_SplitIdentifier(
const std::string& identifier,
std::string* layerPath,
std::string* arguments);
/// Splits the given \p identifier into the layer path and the arguments.
bool Sdf_SplitIdentifier(
const std::string& identifier,
std::string* layerPath,
SdfLayer::FileFormatArguments* arguments);
/// Joins the given \p layerPath and \p arguments into an identifier.
/// These parameters are expected to be in the format returned by
/// Sdf_SplitIdentifier.
std::string Sdf_CreateIdentifier(
const std::string& layerPath,
const std::string& arguments);
/// Joins the given \p layerPath and \p arguments into an identifier.
std::string Sdf_CreateIdentifier(
const std::string& layerPath,
const SdfLayer::FileFormatArguments& arguments);
/// Returns true if the given layer \p identifier contains any file
/// format arguments.
bool Sdf_IdentifierContainsArguments(
const std::string& identifier);
/// Returns the display name for the layer with the given identifier.
/// The identifier may be an anonymous layer identifier, in which case
/// Sdf_GetAnonLayerDisplayName is called.
std::string Sdf_GetLayerDisplayName(
const std::string& identifier);
/// Returns the extension of the given identifier used to identify the
/// associated file format.
std::string Sdf_GetExtension(
const std::string& identifier);
/// Returns true if \p layer is a package layer or packaged within a package
/// layer.
bool Sdf_IsPackageOrPackagedLayer(
const SdfLayerHandle& layer);
/// Returns true if \p fileFormat is a package file format or \p identifier
/// is a package-relative path. This is just a convenience function.
bool Sdf_IsPackageOrPackagedLayer(
const SdfFileFormatConstPtr& fileFormat,
const std::string& identifier);
/// Returns the canonicalized form of the given \p realPath.
std::string Sdf_CanonicalizeRealPath(
const std::string& realPath);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_SDF_ASSET_PATH_RESOLVER_H