Loading...
Searching...
No Matches
resolver.h
Go to the documentation of this file.
1//
2// Copyright 2020 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 PXR_USD_AR_RESOLVER_H
25#define PXR_USD_AR_RESOLVER_H
26
28
29#include "pxr/pxr.h"
30#include "pxr/usd/ar/api.h"
31#include "pxr/usd/ar/ar.h"
35
36#include <memory>
37#include <string>
38#include <vector>
39
40PXR_NAMESPACE_OPEN_SCOPE
41
42class ArAsset;
43class ArAssetInfo;
45class ArWritableAsset;
46class TfType;
47class VtValue;
48
60{
61public:
62 AR_API
63 virtual ~ArResolver();
64
65 // Disallow copies
66 ArResolver(const ArResolver&) = delete;
67 ArResolver& operator=(const ArResolver&) = delete;
68
69 // --------------------------------------------------------------------- //
90 // --------------------------------------------------------------------- //
91
95 AR_API
96 std::string CreateIdentifier(
97 const std::string& assetPath,
98 const ArResolvedPath& anchorAssetPath = ArResolvedPath()) const;
99
103 AR_API
105 const std::string& assetPath,
106 const ArResolvedPath& anchorAssetPath = ArResolvedPath()) const;
107
109
110 // --------------------------------------------------------------------- //
115 // --------------------------------------------------------------------- //
116
120 AR_API
122 const std::string& assetPath) const;
123
130 AR_API
132 const std::string& assetPath) const;
133
135
136 // --------------------------------------------------------------------- //
141 // --------------------------------------------------------------------- //
142
149 AR_API
151 const ArResolverContext& context,
152 VtValue* bindingData);
153
160 AR_API
162 const ArResolverContext& context,
163 VtValue* bindingData);
164
170 AR_API
172
179 AR_API
181 const std::string& assetPath) const;
182
185 AR_API
187 const std::string& contextStr) const;
188
197 AR_API
199 const std::string& uriScheme, const std::string& contextStr) const;
200
225 AR_API
227 const std::vector<
228 std::pair<std::string, std::string>>& contextStrs) const;
229
243 AR_API
245 const ArResolverContext& context);
246
250 AR_API
252
262 AR_API
264 const std::string& assetPath) const;
265
267
268 // --------------------------------------------------------------------- //
273 // --------------------------------------------------------------------- //
274
277 AR_API
278 std::string GetExtension(
279 const std::string& assetPath) const;
280
284 AR_API
286 const std::string& assetPath,
287 const ArResolvedPath& resolvedPath) const;
288
293 AR_API
295 const std::string& assetPath,
296 const ArResolvedPath& resolvedPath) const;
297
303 AR_API
304 std::shared_ptr<ArAsset> OpenAsset(
305 const ArResolvedPath& resolvedPath) const;
306
308 enum class WriteMode
309 {
313 Update = 0,
314
318 Replace
319 };
320
332 AR_API
333 std::shared_ptr<ArWritableAsset> OpenAssetForWrite(
334 const ArResolvedPath& resolvedPath,
335 WriteMode writeMode) const;
336
340 AR_API
342 const ArResolvedPath& resolvedPath,
343 std::string* whyNot = nullptr) const;
344
346
347 // --------------------------------------------------------------------- //
376 // --------------------------------------------------------------------- //
377
388 AR_API
390 VtValue* cacheScopeData);
391
401 AR_API
403 VtValue* cacheScopeData);
404
406
407 // --------------------------------------------------------------------- //
416 // --------------------------------------------------------------------- //
417
420 AR_API
421 bool IsRepositoryPath(const std::string& path) const;
422
424
425protected:
426 AR_API
427 ArResolver();
428
429 // --------------------------------------------------------------------- //
434
471 virtual std::string _CreateIdentifier(
472 const std::string& assetPath,
473 const ArResolvedPath& anchorAssetPath) const = 0;
474
485 virtual std::string _CreateIdentifierForNewAsset(
486 const std::string& assetPath,
487 const ArResolvedPath& anchorAssetPath) const = 0;
488
492 const std::string& assetPath) const = 0;
493
498 const std::string& assetPath) const = 0;
499
501
502 // --------------------------------------------------------------------- //
519
541 AR_API
542 virtual void _BindContext(
543 const ArResolverContext& context,
544 VtValue* bindingData);
545
557 AR_API
558 virtual void _UnbindContext(
559 const ArResolverContext& context,
560 VtValue* bindingData);
561
580 AR_API
582
611 AR_API
613 const std::string& assetPath) const;
614
619 AR_API
621 const std::string& contextStr) const;
622
630 AR_API
631 virtual void _RefreshContext(
632 const ArResolverContext& context);
633
648 AR_API
650
665 AR_API
667 const std::string& assetPath) const;
668
670
671 // --------------------------------------------------------------------- //
676
685 AR_API
686 virtual std::string _GetExtension(
687 const std::string& assetPath) const;
688
693 AR_API
695 const std::string& assetPath,
696 const ArResolvedPath& resolvedPath) const;
697
711 AR_API
713 const std::string& assetPath,
714 const ArResolvedPath& resolvedPath) const;
715
725 AR_API
726 virtual std::shared_ptr<ArAsset> _OpenAsset(
727 const ArResolvedPath& resolvedPath) const = 0;
728
733 AR_API
735 const ArResolvedPath& resolvedPath,
736 std::string* whyNot) const;
737
747 AR_API
748 virtual std::shared_ptr<ArWritableAsset>
750 const ArResolvedPath& resolvedPath,
751 WriteMode writeMode) const = 0;
752
754
755 // --------------------------------------------------------------------- //
773
782 AR_API
783 virtual void _BeginCacheScope(
784 VtValue* cacheScopeData);
785
793 AR_API
794 virtual void _EndCacheScope(
795 VtValue* cacheScopeData);
796
798
802 AR_API
803 virtual bool _IsRepositoryPath(
804 const std::string& path) const;
805
806 // --------------------------------------------------------------------- //
813
839 template <class ContextObj>
840 const ContextObj* _GetCurrentContextObject() const
841 {
842 const ArResolverContext* ctx = _GetInternallyManagedCurrentContext();
843 return ctx ? ctx->Get<ContextObj>() : nullptr;
844 }
845
847
848private:
849 // Returns pointer to ArResolverContext that was most recently bound
850 // via BindContext. This is *not* the same as GetCurrentContext,
851 // since subclasses may return an ArResolverContext that hasn't
852 // been bound via BindContext in their implementations.
853 AR_API
854 const ArResolverContext* _GetInternallyManagedCurrentContext() const;
855
856};
857
883AR_API
885
897AR_API
898void ArSetPreferredResolver(const std::string& resolverTypeName);
899
907
916AR_API
918
935AR_API
936std::vector<TfType> ArGetAvailableResolvers();
937
955AR_API
956std::unique_ptr<ArResolver> ArCreateResolver(const TfType& resolverType);
957
959
960PXR_NAMESPACE_CLOSE_SCOPE
961
962#endif
AR_API void ArSetPreferredResolver(const std::string &resolverTypeName)
Set the preferred ArResolver subclass used by ArGetResolver.
AR_API ArResolver & ArGetUnderlyingResolver()
Returns the underlying ArResolver instance used by ArGetResolver.
AR_API std::unique_ptr< ArResolver > ArCreateResolver(const TfType &resolverType)
Construct an instance of the ArResolver subclass specified by resolverType.
AR_API std::vector< TfType > ArGetAvailableResolvers()
Returns list of TfTypes for available ArResolver subclasses.
AR_API ArResolver & ArGetResolver()
Returns the configured asset resolver.
Interface for accessing the contents of an asset.
Definition: asset.h:44
Contains information about a resolved asset.
Definition: assetInfo.h:42
Represents a resolved asset path.
Definition: resolvedPath.h:40
An asset resolver context allows clients to provide additional data to the resolver for use during re...
const ContextObj * Get() const
Returns pointer to the context object of the given type held in this resolver context.
Interface for the asset resolution system.
Definition: resolver.h:60
virtual AR_API void _BeginCacheScope(VtValue *cacheScopeData)
Mark the start of a resolution caching scope.
virtual AR_API std::shared_ptr< ArAsset > _OpenAsset(const ArResolvedPath &resolvedPath) const =0
Return an ArAsset object for the asset located at resolvedPath.
virtual AR_API void _UnbindContext(const ArResolverContext &context, VtValue *bindingData)
Unbind the given context from this resolver.
AR_API ArResolverContext CreateDefaultContextForAsset(const std::string &assetPath) const
Return an ArResolverContext that may be bound to this resolver to resolve the asset located at assetP...
virtual AR_API ArResolverContext _GetCurrentContext() const
Return the currently bound context.
AR_API ArResolverContext CreateDefaultContext() const
Return an ArResolverContext that may be bound to this resolver to resolve assets when no other contex...
AR_API ArResolvedPath Resolve(const std::string &assetPath) const
Returns the resolved path for the asset identified by the given assetPath if it exists.
AR_API void EndCacheScope(VtValue *cacheScopeData)
Mark the end of a resolution caching scope.
virtual ArResolvedPath _Resolve(const std::string &assetPath) const =0
Return the resolved path for the given assetPath or an empty ArResolvedPath if no asset exists at tha...
virtual AR_API ArTimestamp _GetModificationTimestamp(const std::string &assetPath, const ArResolvedPath &resolvedPath) const
Return an ArTimestamp representing the last time the asset at assetPath was modified.
AR_API void BeginCacheScope(VtValue *cacheScopeData)
Mark the start of a resolution caching scope.
virtual AR_API ArResolverContext _CreateDefaultContextForAsset(const std::string &assetPath) const
Return an ArResolverContext that may be bound to this resolver to resolve the asset located at assetP...
AR_API ArResolverContext CreateContextFromString(const std::string &contextStr) const
Return an ArResolverContext created from the primary ArResolver implementation using the given contex...
AR_API ArAssetInfo GetAssetInfo(const std::string &assetPath, const ArResolvedPath &resolvedPath) const
Returns an ArAssetInfo populated with additional metadata (if any) about the asset at the given asset...
virtual AR_API bool _IsContextDependentPath(const std::string &assetPath) const
Return true if the result of resolving the given assetPath may differ depending on the asset resolver...
WriteMode
Enumeration of write modes for OpenAssetForWrite.
Definition: resolver.h:309
@ Update
Open asset for in-place updates.
@ Replace
Open asset for replacement.
virtual ArResolvedPath _ResolveForNewAsset(const std::string &assetPath) const =0
Return the resolved path for the given assetPath that may be used to create a new asset or an empty A...
AR_API std::string CreateIdentifier(const std::string &assetPath, const ArResolvedPath &anchorAssetPath=ArResolvedPath()) const
Returns an identifier for the asset specified by assetPath.
AR_API void RefreshContext(const ArResolverContext &context)
Refresh any caches associated with the given context.
AR_API ArResolverContext CreateContextFromString(const std::string &uriScheme, const std::string &contextStr) const
Return an ArResolverContext created from the ArResolver registered for the given uriScheme using the ...
virtual AR_API std::string _GetExtension(const std::string &assetPath) const
Return the file extension for the given assetPath.
AR_API std::shared_ptr< ArWritableAsset > OpenAssetForWrite(const ArResolvedPath &resolvedPath, WriteMode writeMode) const
Returns an ArWritableAsset object for the asset located at resolvedPath using the specified writeMode...
AR_API bool CanWriteAssetToPath(const ArResolvedPath &resolvedPath, std::string *whyNot=nullptr) const
Returns true if an asset may be written to the given resolvedPath, false otherwise.
AR_API void BindContext(const ArResolverContext &context, VtValue *bindingData)
Binds the given context to this resolver.
AR_API void UnbindContext(const ArResolverContext &context, VtValue *bindingData)
Unbind the given context from this resolver.
virtual AR_API ArResolverContext _CreateDefaultContext() const
Return a default ArResolverContext that may be bound to this resolver to resolve assets when no other...
virtual std::string _CreateIdentifierForNewAsset(const std::string &assetPath, const ArResolvedPath &anchorAssetPath) const =0
Return an identifier for a new asset at the given assetPath.
AR_API bool IsRepositoryPath(const std::string &path) const
AR_API ArResolverContext CreateContextFromStrings(const std::vector< std::pair< std::string, std::string > > &contextStrs) const
Return an ArResolverContext created by combining the ArResolverContext objects created from the given...
virtual AR_API bool _IsRepositoryPath(const std::string &path) const
AR_API ArResolverContext GetCurrentContext() const
Returns the asset resolver context currently bound in this thread.
virtual AR_API bool _CanWriteAssetToPath(const ArResolvedPath &resolvedPath, std::string *whyNot) const
Return true if an asset may be written to the given resolvedPath, false otherwise.
AR_API std::string CreateIdentifierForNewAsset(const std::string &assetPath, const ArResolvedPath &anchorAssetPath=ArResolvedPath()) const
Returns an identifier for a new asset specified by assetPath.
const ContextObj * _GetCurrentContextObject() const
Returns a pointer to the context object of type ContextObj from the last ArResolverContext that was b...
Definition: resolver.h:840
virtual AR_API void _EndCacheScope(VtValue *cacheScopeData)
Mark the end of a resolution caching scope.
virtual AR_API ArResolverContext _CreateContextFromString(const std::string &contextStr) const
Return an ArResolverContext created from the given contextStr.
virtual std::string _CreateIdentifier(const std::string &assetPath, const ArResolvedPath &anchorAssetPath) const =0
Return an identifier for the asset at the given assetPath.
AR_API std::string GetExtension(const std::string &assetPath) const
Returns the file extension for the given assetPath.
virtual AR_API std::shared_ptr< ArWritableAsset > _OpenAssetForWrite(const ArResolvedPath &resolvedPath, WriteMode writeMode) const =0
Return an ArWritableAsset object for the asset at resolvedPath using the specified writeMode.
AR_API bool IsContextDependentPath(const std::string &assetPath) const
Returns true if assetPath is a context-dependent path, false otherwise.
virtual AR_API ArAssetInfo _GetAssetInfo(const std::string &assetPath, const ArResolvedPath &resolvedPath) const
Return an ArAssetInfo populated with additional metadata (if any) about the asset at the given assetP...
AR_API ArResolvedPath ResolveForNewAsset(const std::string &assetPath) const
Returns the resolved path for the given assetPath that may be used to create a new asset.
virtual AR_API void _BindContext(const ArResolverContext &context, VtValue *bindingData)
Bind the given context to this resolver.
AR_API std::shared_ptr< ArAsset > OpenAsset(const ArResolvedPath &resolvedPath) const
Returns an ArAsset object for the asset located at resolvedPath.
AR_API ArTimestamp GetModificationTimestamp(const std::string &assetPath, const ArResolvedPath &resolvedPath) const
Returns an ArTimestamp representing the last time the asset at assetPath was modified.
virtual AR_API void _RefreshContext(const ArResolverContext &context)
Refresh any caches associated with the given context.
Represents a timestamp for an asset.
Definition: timestamp.h:43
Interface for writing data to an asset.
Definition: writableAsset.h:44
TfType represents a dynamic runtime type.
Definition: type.h:65
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:168