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
180 AR_API
182 const std::string& assetPath) const;
183
186 AR_API
188 const std::string& contextStr) const;
189
200 AR_API
202 const std::string& uriScheme, const std::string& contextStr) const;
203
228 AR_API
230 const std::vector<
231 std::pair<std::string, std::string>>& contextStrs) const;
232
246 AR_API
248 const ArResolverContext& context);
249
253 AR_API
255
265 AR_API
267 const std::string& assetPath) const;
268
270
271 // --------------------------------------------------------------------- //
276 // --------------------------------------------------------------------- //
277
280 AR_API
281 std::string GetExtension(
282 const std::string& assetPath) const;
283
287 AR_API
289 const std::string& assetPath,
290 const ArResolvedPath& resolvedPath) const;
291
296 AR_API
298 const std::string& assetPath,
299 const ArResolvedPath& resolvedPath) const;
300
306 AR_API
307 std::shared_ptr<ArAsset> OpenAsset(
308 const ArResolvedPath& resolvedPath) const;
309
311 enum class WriteMode
312 {
316 Update = 0,
317
321 Replace
322 };
323
335 AR_API
336 std::shared_ptr<ArWritableAsset> OpenAssetForWrite(
337 const ArResolvedPath& resolvedPath,
338 WriteMode writeMode) const;
339
343 AR_API
345 const ArResolvedPath& resolvedPath,
346 std::string* whyNot = nullptr) const;
347
349
350 // --------------------------------------------------------------------- //
379 // --------------------------------------------------------------------- //
380
391 AR_API
393 VtValue* cacheScopeData);
394
404 AR_API
406 VtValue* cacheScopeData);
407
409
410 // --------------------------------------------------------------------- //
419 // --------------------------------------------------------------------- //
420
423 AR_API
424 bool IsRepositoryPath(const std::string& path) const;
425
427
428protected:
429 AR_API
430 ArResolver();
431
432 // --------------------------------------------------------------------- //
437
474 virtual std::string _CreateIdentifier(
475 const std::string& assetPath,
476 const ArResolvedPath& anchorAssetPath) const = 0;
477
488 virtual std::string _CreateIdentifierForNewAsset(
489 const std::string& assetPath,
490 const ArResolvedPath& anchorAssetPath) const = 0;
491
495 const std::string& assetPath) const = 0;
496
501 const std::string& assetPath) const = 0;
502
504
505 // --------------------------------------------------------------------- //
522
544 AR_API
545 virtual void _BindContext(
546 const ArResolverContext& context,
547 VtValue* bindingData);
548
560 AR_API
561 virtual void _UnbindContext(
562 const ArResolverContext& context,
563 VtValue* bindingData);
564
583 AR_API
585
614 AR_API
616 const std::string& assetPath) const;
617
622 AR_API
624 const std::string& contextStr) const;
625
633 AR_API
634 virtual void _RefreshContext(
635 const ArResolverContext& context);
636
651 AR_API
653
668 AR_API
670 const std::string& assetPath) const;
671
673
674 // --------------------------------------------------------------------- //
679
688 AR_API
689 virtual std::string _GetExtension(
690 const std::string& assetPath) const;
691
696 AR_API
698 const std::string& assetPath,
699 const ArResolvedPath& resolvedPath) const;
700
714 AR_API
716 const std::string& assetPath,
717 const ArResolvedPath& resolvedPath) const;
718
728 AR_API
729 virtual std::shared_ptr<ArAsset> _OpenAsset(
730 const ArResolvedPath& resolvedPath) const = 0;
731
736 AR_API
738 const ArResolvedPath& resolvedPath,
739 std::string* whyNot) const;
740
750 AR_API
751 virtual std::shared_ptr<ArWritableAsset>
753 const ArResolvedPath& resolvedPath,
754 WriteMode writeMode) const = 0;
755
757
758 // --------------------------------------------------------------------- //
776
785 AR_API
786 virtual void _BeginCacheScope(
787 VtValue* cacheScopeData);
788
796 AR_API
797 virtual void _EndCacheScope(
798 VtValue* cacheScopeData);
799
801
805 AR_API
806 virtual bool _IsRepositoryPath(
807 const std::string& path) const;
808
809 // --------------------------------------------------------------------- //
816
842 template <class ContextObj>
843 const ContextObj* _GetCurrentContextObject() const
844 {
845 const ArResolverContext* ctx = _GetInternallyManagedCurrentContext();
846 return ctx ? ctx->Get<ContextObj>() : nullptr;
847 }
848
850
851private:
852 // Returns pointer to ArResolverContext that was most recently bound
853 // via BindContext. This is *not* the same as GetCurrentContext,
854 // since subclasses may return an ArResolverContext that hasn't
855 // been bound via BindContext in their implementations.
856 AR_API
857 const ArResolverContext* _GetInternallyManagedCurrentContext() const;
858
859};
860
886AR_API
888
900AR_API
901void ArSetPreferredResolver(const std::string& resolverTypeName);
902
910
919AR_API
921
938AR_API
939std::vector<TfType> ArGetAvailableResolvers();
940
958AR_API
959std::unique_ptr<ArResolver> ArCreateResolver(const TfType& resolverType);
960
962
963PXR_NAMESPACE_CLOSE_SCOPE
964
965#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:312
@ 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:843
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:165