All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
defaultResolver.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef AR_DEFAULT_RESOLVER_H
25 #define AR_DEFAULT_RESOLVER_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/ar/api.h"
31 #include "pxr/usd/ar/defaultResolverContext.h"
32 #include "pxr/usd/ar/resolver.h"
33 #include "pxr/usd/ar/threadLocalScopedCache.h"
34 
35 #include <tbb/enumerable_thread_specific.h>
36 
37 #include <memory>
38 #include <string>
39 #include <vector>
40 
41 PXR_NAMESPACE_OPEN_SCOPE
42 
64  : public ArResolver
65 {
66 public:
67  AR_API
69 
70  AR_API
71  virtual ~ArDefaultResolver();
72 
78  AR_API
79  static void SetDefaultSearchPath(
80  const std::vector<std::string>& searchPath);
81 
82  // ArResolver overrides
83 
88  AR_API
89  virtual void ConfigureResolverForAsset(const std::string& path) override;
90 
91  AR_API
92  virtual std::string AnchorRelativePath(
93  const std::string& anchorPath,
94  const std::string& path) override;
95 
96  AR_API
97  virtual bool IsRelativePath(const std::string& path) override;
98 
99  AR_API
100  virtual bool IsRepositoryPath(const std::string& path) override;
101 
102  AR_API
103  virtual bool IsSearchPath(const std::string& path) override;
104 
105  AR_API
106  virtual std::string GetExtension(const std::string& path) override;
107 
108  AR_API
109  virtual std::string ComputeNormalizedPath(const std::string& path) override;
110 
111  AR_API
112  virtual std::string ComputeRepositoryPath(const std::string& path) override;
113 
114  AR_API
115  virtual std::string ComputeLocalPath(const std::string& path) override;
116 
117  AR_API
118  virtual std::string Resolve(const std::string& path) override;
119 
120  AR_API
121  virtual std::string ResolveWithAssetInfo(
122  const std::string& path,
123  ArAssetInfo* assetInfo) override;
124 
125  AR_API
126  virtual void UpdateAssetInfo(
127  const std::string& identifier,
128  const std::string& filePath,
129  const std::string& fileVersion,
130  ArAssetInfo* assetInfo) override;
131 
132  AR_API
134  const std::string& path,
135  const std::string& resolvedPath) override;
136 
137  AR_API
138  virtual bool FetchToLocalResolvedPath(
139  const std::string& path,
140  const std::string& resolvedPath) override;
141 
142  AR_API
143  virtual std::shared_ptr<ArAsset> OpenAsset(
144  const std::string& resolvedPath) override;
145 
146  AR_API
147  virtual bool CanWriteLayerToPath(
148  const std::string& path,
149  std::string* whyNot) override;
150 
151  AR_API
152  virtual bool CanCreateNewLayerWithIdentifier(
153  const std::string& identifier,
154  std::string* whyNot) override;
155 
156  AR_API
157  virtual ArResolverContext CreateDefaultContext() override;
158 
166  AR_API
168  const std::string& filePath) override;
169 
170  AR_API
171  virtual void RefreshContext(const ArResolverContext& context) override;
172 
173  AR_API
174  virtual ArResolverContext GetCurrentContext() override;
175 
176  AR_API
177  virtual void BeginCacheScope(
178  VtValue* cacheScopeData) override;
179 
180  AR_API
181  virtual void EndCacheScope(
182  VtValue* cacheScopeData) override;
183 
184  AR_API
185  virtual void BindContext(
186  const ArResolverContext& context,
187  VtValue* bindingData) override;
188 
189  AR_API
190  virtual void UnbindContext(
191  const ArResolverContext& context,
192  VtValue* bindingData) override;
193 
194 private:
195  struct _Cache;
197  using _CachePtr = _PerThreadCache::CachePtr;
198  _CachePtr _GetCurrentCache();
199 
200  const ArDefaultResolverContext* _GetCurrentContext();
201 
202  std::string _ResolveNoCache(const std::string& path);
203 
204 private:
205  ArDefaultResolverContext _fallbackContext;
206  ArResolverContext _defaultContext;
207 
208  _PerThreadCache _threadCache;
209 
210  using _ContextStack = std::vector<const ArDefaultResolverContext*>;
211  using _PerThreadContextStack =
212  tbb::enumerable_thread_specific<_ContextStack>;
213  _PerThreadContextStack _threadContextStack;
214 
215 };
216 
217 PXR_NAMESPACE_CLOSE_SCOPE
218 
219 #endif // AR_DEFAULT_RESOLVER_H
static AR_API void SetDefaultSearchPath(const std::vector< std::string > &searchPath)
Set the default search path that will be used during asset resolution.
virtual AR_API std::string AnchorRelativePath(const std::string &anchorPath, const std::string &path) override
Returns the path formed by anchoring path to anchorPath.
Default asset resolution implementation used when no plugin implementation is provided.
virtual AR_API VtValue GetModificationTimestamp(const std::string &path, const std::string &resolvedPath) override
Returns a value representing the last time the asset identified by path was modified.
virtual AR_API ArResolverContext CreateDefaultContext() override
Return a default ArResolverContext that may be bound to this resolver to resolve assets when no other...
virtual AR_API bool IsRepositoryPath(const std::string &path) override
Returns true if the given path is a repository path.
virtual AR_API void RefreshContext(const ArResolverContext &context) override
Refresh any caches associated with the given context.
virtual AR_API ArResolverContext GetCurrentContext() override
Returns the currently-bound asset resolver context.
Resolver context object that specifies a search path to use during asset resolution.
virtual AR_API std::string ComputeLocalPath(const std::string &path) override
Returns the local path for the given path.
virtual AR_API bool IsSearchPath(const std::string &path) override
Returns whether this path is a search path.
virtual AR_API void EndCacheScope(VtValue *cacheScopeData) override
Mark the end of a resolution caching scope.
virtual AR_API bool CanWriteLayerToPath(const std::string &path, std::string *whyNot) override
Returns true if a file may be written to the given path, false otherwise.
virtual AR_API std::shared_ptr< ArAsset > OpenAsset(const std::string &resolvedPath) override
Returns an ArAsset object for the asset located at resolvedPath.
virtual AR_API void ConfigureResolverForAsset(const std::string &path) override
Sets the resolver&#39;s default context (returned by CreateDefaultContext()) to the same context you woul...
virtual AR_API bool FetchToLocalResolvedPath(const std::string &path, const std::string &resolvedPath) override
Fetch the asset identified by path to the filesystem location specified by resolvedPath.
virtual AR_API void BindContext(const ArResolverContext &context, VtValue *bindingData) override
Binds the given context to this resolver.
virtual AR_API bool IsRelativePath(const std::string &path) override
Returns true if the given path is a relative path.
virtual AR_API void BeginCacheScope(VtValue *cacheScopeData) override
Mark the start of a resolution caching scope.
virtual AR_API std::string ResolveWithAssetInfo(const std::string &path, ArAssetInfo *assetInfo) override
Returns the resolved filesystem path for the file identified by path following the same path resoluti...
virtual AR_API std::string Resolve(const std::string &path) override
Returns the resolved filesystem path for the file identified by the given path if it exists...
virtual AR_API ArResolverContext CreateDefaultContextForAsset(const std::string &filePath) override
Creates a context that adds the directory containing filePath as a first directory to be searched...
virtual AR_API std::string ComputeNormalizedPath(const std::string &path) override
Returns a normalized version of the given path.
An asset resolver context allows clients to provide additional data to the resolver for use during re...
virtual AR_API bool CanCreateNewLayerWithIdentifier(const std::string &identifier, std::string *whyNot) override
Returns true if a new file may be created using the given identifier, false otherwise.
virtual AR_API void UnbindContext(const ArResolverContext &context, VtValue *bindingData) override
Unbind the given context from this resolver.
virtual AR_API void UpdateAssetInfo(const std::string &identifier, const std::string &filePath, const std::string &fileVersion, ArAssetInfo *assetInfo) override
Update assetInfo with respect to the given fileVersion .
virtual AR_API std::string ComputeRepositoryPath(const std::string &path) override
Returns the computed repository path using the current resolver.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:182
virtual AR_API std::string GetExtension(const std::string &path) override
Returns the normalized extension for the given path.
Interface for the asset resolution system.
Definition: resolver.h:53
Contains information about a resolved asset.
Definition: assetInfo.h:40