HDK
|
#include <resolver.h>
Public Member Functions | |
virtual AR_API | ~ArResolver () |
ArResolver (const ArResolver &)=delete | |
ArResolver & | operator= (const ArResolver &)=delete |
Identifiers | |
Identifiers are canonicalized asset paths that may be assigned to a logical asset to facilitate comparisons and lookups. They may be used to determine if different asset paths might refer to the same asset without performing resolution. Since identifiers are just a form of asset path, they may be used with other functions on ArResolver that require an asset path, like Resolve. If two asset paths produce the same identifier, those asset paths must refer to the same asset. However, in some cases comparing identifiers may not be sufficient to determine if assets are equal. For example, there could be two assets with the same identifier but whose contents were read from different resolved paths because different resolver contexts were bound when those assets were loaded. | |
AR_API std::string | CreateIdentifier (const std::string &assetPath, const ArResolvedPath &anchorAssetPath=ArResolvedPath()) const |
AR_API std::string | CreateIdentifierForNewAsset (const std::string &assetPath, const ArResolvedPath &anchorAssetPath=ArResolvedPath()) const |
Path Resolution Operations | |
AR_API ArResolvedPath | Resolve (const std::string &assetPath) const |
AR_API ArResolvedPath | ResolveForNewAsset (const std::string &assetPath) const |
Asset Resolver Context Operations | |
AR_API void | BindContext (const ArResolverContext &context, VtValue *bindingData) |
AR_API void | UnbindContext (const ArResolverContext &context, VtValue *bindingData) |
AR_API ArResolverContext | CreateDefaultContext () const |
AR_API ArResolverContext | CreateDefaultContextForAsset (const std::string &assetPath) const |
AR_API ArResolverContext | CreateContextFromString (const std::string &contextStr) const |
AR_API ArResolverContext | CreateContextFromString (const std::string &uriScheme, const std::string &contextStr) const |
AR_API ArResolverContext | CreateContextFromStrings (const std::vector< std::pair< std::string, std::string >> &contextStrs) const |
AR_API void | RefreshContext (const ArResolverContext &context) |
AR_API ArResolverContext | GetCurrentContext () const |
AR_API bool | IsContextDependentPath (const std::string &assetPath) const |
Scoped Resolution Cache | |
A scoped resolution cache indicates to the resolver that results of calls to Resolve should be cached for a certain scope. This is important for performance and also for consistency – it ensures that repeated calls to Resolve with the same parameters will return the same result. A resolution cache scope is opened by a call to BeginCacheScope and must be closed with a matching call to EndCacheScope. The resolver must cache the results of Resolve until the scope is closed. Note that these calls may be nested. Cache scopes are thread-specific: if multiple threads are running and a cache scope is opened in one of those threads, caching should be enabled in that thread only. When opening a scope, a resolver may return additional data for implementation-specific purposes. This data may be shared across threads, so long as it is safe to access this data concurrently. ArResolverScopedCache is an RAII object for managing cache scope lifetimes and data. Clients should generally use that class rather than calling the BeginCacheScope and EndCacheScope functions manually.
| |
AR_API void | BeginCacheScope (VtValue *cacheScopeData) |
AR_API void | EndCacheScope (VtValue *cacheScopeData) |
Deprecated APIs | |
AR_API bool | IsRepositoryPath (const std::string &path) const |
Protected Member Functions | |
AR_API | ArResolver () |
virtual AR_API bool | _IsRepositoryPath (const std::string &path) const |
Context Operations Implementation | |
If any of these functions are implemented in a subclass, the plugin metadata for that subclass in the plugin library's plugInfo.json must specify: "implementsContexts" : true.
If a subclass indicates that it implements any of these functions, its plugin library will be loaded and these functions will be called when the corresponding public ArResolver API is called. Otherwise, these functions will not be called. | |
virtual AR_API void | _BindContext (const ArResolverContext &context, VtValue *bindingData) |
virtual AR_API void | _UnbindContext (const ArResolverContext &context, VtValue *bindingData) |
virtual AR_API ArResolverContext | _CreateDefaultContext () const |
virtual AR_API ArResolverContext | _CreateDefaultContextForAsset (const std::string &assetPath) const |
virtual AR_API ArResolverContext | _CreateContextFromString (const std::string &contextStr) const |
virtual AR_API void | _RefreshContext (const ArResolverContext &context) |
virtual AR_API ArResolverContext | _GetCurrentContext () const |
virtual AR_API bool | _IsContextDependentPath (const std::string &assetPath) const |
Asset Operations Implementation | |
virtual AR_API std::string | _GetExtension (const std::string &assetPath) const |
virtual AR_API ArAssetInfo | _GetAssetInfo (const std::string &assetPath, const ArResolvedPath &resolvedPath) const |
virtual AR_API ArTimestamp | _GetModificationTimestamp (const std::string &assetPath, const ArResolvedPath &resolvedPath) const |
virtual AR_API std::shared_ptr < ArAsset > | _OpenAsset (const ArResolvedPath &resolvedPath) const =0 |
virtual AR_API bool | _CanWriteAssetToPath (const ArResolvedPath &resolvedPath, std::string *whyNot) const |
virtual AR_API std::shared_ptr < ArWritableAsset > | _OpenAssetForWrite (const ArResolvedPath &resolvedPath, WriteMode writeMode) const =0 |
Scoped Resolution Cache Implementation | |
If any of these functions are implemented in a subclass, the plugin metadata for that subclass in the plugin library's plugInfo.json must specify: "implementsScopedCaches" : true.
If a subclass indicates that it implements these functions, ArResolver will assume the subclass is handling all caching of resolved paths and will call these functions when a caching scope is opened and closed. Otherwise, these functions will not be called. Instead, ArResolver itself will handle caching and returning resolved paths as needed. | |
virtual AR_API void | _BeginCacheScope (VtValue *cacheScopeData) |
virtual AR_API void | _EndCacheScope (VtValue *cacheScopeData) |
Implementation Utilities | |
template<class ContextObj > | |
const ContextObj * | _GetCurrentContextObject () const |
File/asset-specific Operations | |
enum | WriteMode { WriteMode::Update = 0, WriteMode::Replace } |
Enumeration of write modes for OpenAssetForWrite. More... | |
AR_API std::string | GetExtension (const std::string &assetPath) const |
AR_API ArAssetInfo | GetAssetInfo (const std::string &assetPath, const ArResolvedPath &resolvedPath) const |
AR_API ArTimestamp | GetModificationTimestamp (const std::string &assetPath, const ArResolvedPath &resolvedPath) const |
AR_API std::shared_ptr< ArAsset > | OpenAsset (const ArResolvedPath &resolvedPath) const |
AR_API std::shared_ptr < ArWritableAsset > | OpenAssetForWrite (const ArResolvedPath &resolvedPath, WriteMode writeMode) const |
AR_API bool | CanWriteAssetToPath (const ArResolvedPath &resolvedPath, std::string *whyNot=nullptr) const |
Implementation | |
abs path to model | usd |
abs path to model * | ArResolvedPath ("/abs/path/to/shot.usd"))* |
virtual std::string | _CreateIdentifierForNewAsset (const std::string &assetPath, const ArResolvedPath &anchorAssetPath) const =0 |
virtual ArResolvedPath | _Resolve (const std::string &assetPath) const =0 |
virtual ArResolvedPath | _ResolveForNewAsset (const std::string &assetPath) const =0 |
Interface for the asset resolution system. An asset resolver is responsible for resolving asset information (including the asset's physical path) from a logical path.
See ar_implementing_resolver for information on how to customize asset resolution behavior by implementing a subclass of ArResolver. Clients may use ArGetResolver to access the configured asset resolver.
Definition at line 59 of file resolver.h.
|
strong |
Enumeration of write modes for OpenAssetForWrite.
Enumerator | |
---|---|
Update |
Open asset for in-place updates. If the asset exists, its contents will not be discarded and writes may overwrite existing data. Otherwise, the asset will be created. |
Replace |
Open asset for replacement. If the asset exists, its contents will be discarded by the time the ArWritableAsset is destroyed. Otherwise, the asset will be created. |
Definition at line 311 of file resolver.h.
|
virtual |
|
delete |
|
protected |
Mark the start of a resolution caching scope.
Resolvers may fill cacheScopeData
with arbitrary data. Clients may also pass in a cacheScopeData
populated by an earlier call to BeginCacheScope to allow the resolver access to that information.
See Scoped Resolution Cache Implementation for more implementation details.
|
protectedvirtual |
Bind the given context
to this resolver. bindingData
may be populated with additional information that will be kept alive while context
is bound. Both context
and bindingData
will be passed to UnbindContext when the context is being unbound.
Contexts may be nested; if multiple contexts are bound, the context that was most recently bound must take precedence and block all previously bound contexts.
Context binding is thread-specific; contexts bound in a thread must only affect other resolver calls in the same thread.
ArResolver itself manages thread-local stacks of bound contexts. Subclasses can retrieve the most recent context object which was passed to BindContext using _GetCurrentContextObject. Because of this, subclasses typically do not need to implement this function unless they need to be informed when a context object is bound. For example, this may be needed if the context needs to be passed on to another subsystem that manages these bindings itself.
The default implementation does nothing.
|
protectedvirtual |
Return true if an asset may be written to the given resolvedPath
, false otherwise. If this function returns false and whyNot
is not nullptr
, it may be filled with an explanation. The default implementation returns true.
|
protectedvirtual |
Return an ArResolverContext created from the given contextStr
.
The default implementation returns a default-constructed ArResolverContext.
Reimplemented in ArDefaultResolver.
|
protectedvirtual |
Return a default ArResolverContext that may be bound to this resolver to resolve assets when no other context is explicitly specified.
When CreateDefaultContext is called on the configured asset resolver, Ar will call this method on the primary resolver and all URI/IRI resolvers and merge the results into a single ArResolverContext that will be returned to the consumer.
This function should not automatically bind this context, but should create one that may be used later.
The default implementation returns a default-constructed ArResolverContext.
Example uses:
Reimplemented in ArDefaultResolver.
|
protectedvirtual |
Return an ArResolverContext that may be bound to this resolver to resolve the asset located at assetPath
or referenced by that asset when no other context is explicitly specified.
When CreateDefaultContextForAsset is called on the configured asset resolver, Ar will call this method on the primary resolver and all URI/IRI resolvers and merge the results into a single ArResolverContext that will be returned to the consumer.
Note that this means this method may be called with asset paths that are not associated with this resolver. For example, this method may be called on a URI/IRI resolver with a non-URI/IRI asset path. This is to support cases where the asset at assetPath
references other assets with URI/IRI schemes that differ from the URI/IRI scheme (if any) in assetPath
.
This function should not automatically bind this context, but should create one that may be used later.
The default implementation returns a default-constructed ArResolverContext.
Example uses:
assetPath
. The returned context will be bound when resolving asset paths on that stage. Reimplemented in ArDefaultResolver.
|
protectedpure virtual |
Return an identifier for a new asset at the given assetPath
.
This is similar to _CreateIdentifier but is used to create identifiers for assets that may not exist yet and are being created.
Example uses:
Implemented in ArDefaultResolver.
Mark the end of a resolution caching scope.
cacheScopeData
should contain the data that was populated by the previous corresponding call to BeginCacheScope.
See Scoped Resolution Cache Implementation for more implementation details.
|
protectedvirtual |
Return an ArAssetInfo populated with additional metadata (if any) about the asset at the given assetPath
. resolvedPath
is the resolved path computed for the given assetPath
. The default implementation returns a default-constructed ArAssetInfo.
|
protectedvirtual |
Return the currently bound context. Since context binding is thread-specific, this should return the context that was most recently bound in this thread.
Subclasses typically do not need to implement this function since ArResolver itself keeps track of the contexts that are bound via calls to BindContext. However, if a subclass is managing bound contexts itself and allows clients to bind context objects via other API outside of BindContext, this function should return the context object as described above. This typically happens with subclasses that are wrappers around other resolution subsystems.
The default implementation returns a default-constructed ArResolverContext.
|
inlineprotected |
Returns a pointer to the context object of type ContextObj
from the last ArResolverContext that was bound via a call to BindContext, or NULL
if no context object of that type exists.
Typically, a subclass might use this in their _Resolve function to get the currently bound context to drive their resolution behavior.
This is the same as GetCurrentContext().Get<ContextObj>() but more efficient, since it does not make a copy of the ArResolverContext. However, it is not the same as _GetCurrentContext().Get<ContextObj>(). Subclasses that manage context binding themselves may have overridden _GetCurrentContext to return a context that was bound without calling BindContext. These subclasses should not use this function and should retrieve the current context from their own internal data structures.
Definition at line 843 of file resolver.h.
|
protectedvirtual |
Return the file extension for the given assetPath
. This extension should not include a "." at the beginning of the string.
The default implementation returns the string after the last "." in assetPath
. If assetPath
begins with a ".", the extension will be empty unless there is another "." in the path. If assetPath
has components separated by '/' (or '\' on Windows), only the last component will be considered.
|
protectedvirtual |
Return an ArTimestamp representing the last time the asset at assetPath
was modified. resolvedPath
is the resolved path computed for the given assetPath
. If a timestamp cannot be retrieved, return an invalid ArTimestamp.
The default implementation returns an invalid ArTimestamp.
Example uses:
Reimplemented in ArDefaultResolver.
|
protectedvirtual |
Return true if the result of resolving the given assetPath
may differ depending on the asset resolver context that is bound when Resolve is called, false otherwise.
The default implementation returns false.
Example uses:
Reimplemented in ArDefaultResolver.
|
protectedvirtual |
|
protectedpure virtual |
Return an ArAsset object for the asset located at resolvedPath
. Return an invalid std::shared_ptr if object could not be created (for example, if the asset at the given path could not be opened).
Note that clients may still be using the data associated with this object even after the last shared_ptr has been destroyed. For example, a client may have created a memory mapping using the FILE* presented in the ArAsset object; this would preclude truncating or overwriting any of the contents of that file.
Implemented in ArDefaultResolver.
|
protectedpure virtual |
Return an ArWritableAsset object for the asset at resolvedPath
using the specified writeMode
. Return an invalid std::shared_ptr if object could not be created (for example, if writing to the given path is not allowed).
Implementations should create any parent paths that are necessary to write this asset. The returned ArWritableAsset must obey the behaviors for the given writeMode
, see the documentation for the WriteMode enum for more details.
Implemented in ArDefaultResolver.
|
protectedvirtual |
Refresh any caches associated with the given context. If doing so would invalidate asset paths that had previously been resolved, this function should send an ArNotice::ResolverChanged notice to inform clients of this. See documentation on that class for more details.
The default implementation does nothing.
|
protectedpure virtual |
Return the resolved path for the given assetPath
or an empty ArResolvedPath if no asset exists at that path.
Implemented in ArDefaultResolver.
|
protectedpure virtual |
Return the resolved path for the given assetPath
that may be used to create a new asset or an empty ArResolvedPath if such a path cannot be computed.
Implemented in ArDefaultResolver.
|
protectedvirtual |
Unbind the given context
from this resolver.
It is an error if the context being unbound is not the currently bound context.
Subclasses typically do not need to implement this function since ArResolver itself keeps track of the contexts that are bound via calls to BindContext. However, subclasses may need to implement this function if they are managing these bindings itself.
The default implementation does nothing.
Return an identifier for the asset at the given assetPath
. See Identifiers for more information.
If anchorAssetPath
is non-empty, it should be used as the anchoring asset if assetPath
is relative. For example, for a filesystem-based implementation _CreateIdentifier might return:
_CreateIdentifier( /* assetPath =
Mark the start of a resolution caching scope.
Clients should generally use ArResolverScopedCache instead of calling this function directly.
Resolvers may fill cacheScopeData
with arbitrary data. Clients may also pass in a cacheScopeData
populated by an earlier call to BeginCacheScope to allow the resolver access to that information.
AR_API void ArResolver::BindContext | ( | const ArResolverContext & | context, |
VtValue * | bindingData | ||
) |
Binds the given context to this resolver.
Clients should generally use ArResolverContextBinder instead of calling this function directly.
AR_API bool ArResolver::CanWriteAssetToPath | ( | const ArResolvedPath & | resolvedPath, |
std::string * | whyNot = nullptr |
||
) | const |
Returns true if an asset may be written to the given resolvedPath
, false otherwise. If this function returns false and whyNot
is not nullptr
, it may be filled with an explanation.
AR_API ArResolverContext ArResolver::CreateContextFromString | ( | const std::string & | contextStr | ) | const |
Return an ArResolverContext created from the primary ArResolver implementation using the given contextStr
.
AR_API ArResolverContext ArResolver::CreateContextFromString | ( | const std::string & | uriScheme, |
const std::string & | contextStr | ||
) | const |
Return an ArResolverContext created from the ArResolver registered for the given uriScheme
using the given contextStr
.
An empty uriScheme
indicates the primary resolver and is equivalent to CreateContextFromString(string).
If no resolver is registered for uriScheme
, returns an empty ArResolverContext.
AR_API ArResolverContext ArResolver::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 contextStrs
.
contextStrs
is a list of pairs of strings. The first element in the pair is the URI/IRI scheme for the ArResolver that will be used to create the ArResolverContext from the second element in the pair. An empty resource identifier scheme indicates the primary resolver.
For example:
This will use the primary resolver to create an ArResolverContext using the string "context str 1" and use the resolver registered for the "my-scheme" URI/IRI scheme to create an ArResolverContext using "context str 2". These contexts will be combined into a single ArResolverContext and returned.
If no resolver is registered for a URI/IRI scheme in an entry in contextStrs
, that entry will be ignored.
AR_API ArResolverContext ArResolver::CreateDefaultContext | ( | ) | const |
Return an ArResolverContext that may be bound to this resolver to resolve assets when no other context is explicitly specified.
The returned ArResolverContext will contain the default context returned by the primary resolver and all URI/IRI resolvers.
AR_API ArResolverContext ArResolver::CreateDefaultContextForAsset | ( | const std::string & | assetPath | ) | const |
Return an ArResolverContext that may be bound to this resolver to resolve the asset located at assetPath
or referenced by that asset when no other context is explicitly specified.
The returned ArResolverContext will contain the default context for assetPath
returned by the primary resolver and all URI/IRI resolvers.
AR_API std::string ArResolver::CreateIdentifier | ( | const std::string & | assetPath, |
const ArResolvedPath & | anchorAssetPath = ArResolvedPath() |
||
) | const |
Returns an identifier for the asset specified by assetPath
. If anchorAssetPath
is not empty, it is the resolved asset path that assetPath
should be anchored to if it is a relative path.
AR_API std::string ArResolver::CreateIdentifierForNewAsset | ( | const std::string & | assetPath, |
const ArResolvedPath & | anchorAssetPath = ArResolvedPath() |
||
) | const |
Returns an identifier for a new asset specified by assetPath
. If anchorAssetPath
is not empty, it is the resolved asset path that assetPath
should be anchored to if it is a relative path.
Mark the end of a resolution caching scope.
Clients should generally use ArResolverScopedCache instead of calling this function directly.
cacheScopeData
should contain the data that was populated by the previous corresponding call to BeginCacheScope.
AR_API ArAssetInfo ArResolver::GetAssetInfo | ( | const std::string & | assetPath, |
const ArResolvedPath & | resolvedPath | ||
) | const |
Returns an ArAssetInfo populated with additional metadata (if any) about the asset at the given assetPath
. resolvedPath
is the resolved path computed for the given assetPath
.
AR_API ArResolverContext ArResolver::GetCurrentContext | ( | ) | const |
Returns the asset resolver context currently bound in this thread.
AR_API std::string ArResolver::GetExtension | ( | const std::string & | assetPath | ) | const |
Returns the file extension for the given assetPath
. The returned extension does not include a "." at the beginning.
AR_API ArTimestamp ArResolver::GetModificationTimestamp | ( | const std::string & | assetPath, |
const ArResolvedPath & | resolvedPath | ||
) | const |
Returns an ArTimestamp representing the last time the asset at assetPath
was modified. resolvedPath
is the resolved path computed for the given assetPath
. If a timestamp cannot be retrieved, return an invalid ArTimestamp.
AR_API bool ArResolver::IsContextDependentPath | ( | const std::string & | assetPath | ) | const |
Returns true if assetPath
is a context-dependent path, false otherwise.
A context-dependent path may result in different resolved paths depending on what asset resolver context is bound when Resolve is called. Assets located at the same context-dependent path may not be the same since those assets may have been loaded from different resolved paths. In this case, the assets' resolved paths must be consulted to determine if they are the same.
AR_API bool ArResolver::IsRepositoryPath | ( | const std::string & | path | ) | const |
AR_API std::shared_ptr<ArAsset> ArResolver::OpenAsset | ( | const ArResolvedPath & | resolvedPath | ) | const |
AR_API std::shared_ptr<ArWritableAsset> ArResolver::OpenAssetForWrite | ( | const ArResolvedPath & | resolvedPath, |
WriteMode | writeMode | ||
) | const |
Returns an ArWritableAsset object for the asset located at resolvedPath
using the specified writeMode
. Returns an invalid std::shared_ptr if object could not be created.
The returned ArWritableAsset object provides functions for writing data to the specified asset.
Note that support for reading an asset through other APIs while it is open for write is implementation-specific. For example, writes to an asset may or may not be immediately visible to other threads or processes depending on the implementation.
|
delete |
AR_API void ArResolver::RefreshContext | ( | const ArResolverContext & | context | ) |
Refresh any caches associated with the given context. If doing so would invalidate asset paths that had previously been resolved, an ArNotice::ResolverChanged notice will be sent to inform clients of this.
Avoid calling RefreshContext() on the same context from more than one thread concurrently as ArNotice::ResolverChanged notice listeners may mutate their state in response to receiving the notice.
Avoid calling RefreshContext() with a context that is active (bound to a resolver). Unbind the context before refreshing it.
AR_API ArResolvedPath ArResolver::Resolve | ( | const std::string & | assetPath | ) | const |
Returns the resolved path for the asset identified by the given assetPath
if it exists. If the asset does not exist, returns an empty ArResolvedPath.
AR_API ArResolvedPath ArResolver::ResolveForNewAsset | ( | const std::string & | assetPath | ) | const |
Returns the resolved path for the given assetPath
that may be used to create a new asset. If such a path cannot be computed for assetPath
, returns an empty ArResolvedPath.
Note that an asset might or might not already exist at the returned resolved path.
AR_API void ArResolver::UnbindContext | ( | const ArResolverContext & | context, |
VtValue * | bindingData | ||
) |
Unbind the given context from this resolver.
Clients should generally use ArResolverContextBinder instead of calling this function directly.
Return an identifier for the asset at the given assetPath
. See Identifiers for more information.
If anchorAssetPath
is non-empty, it should be used as the anchoring asset if assetPath
is relative. For example, for a filesystem-based implementation _CreateIdentifier might return:
_CreateIdentifier( /* assetPath =
Definition at line 446 of file resolver.h.