Skip to content

Commit

Permalink
Expose Ar_DefaultResolver (now ArDefaultResolver)
Browse files Browse the repository at this point in the history
Also mark virtual methods on this class as overrides.

This provides a starting point for clients that want to
extend the default resolution behavior with their own
logic.

Fixes #68

(Internal change: 1669112)
  • Loading branch information
sunyab authored and pixar-oss committed Oct 28, 2016
1 parent 3f759ef commit 8d44cf8
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 59 deletions.
2 changes: 1 addition & 1 deletion pxr/usd/lib/ar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pxr_shared_library(ar
PUBLIC_HEADERS
api.h
assetInfo.h
defaultResolver.h
pyResolverContext.h
resolver.h
resolverContext.h
Expand All @@ -25,7 +26,6 @@ pxr_shared_library(ar

PRIVATE_HEADERS
debugCodes.h
defaultResolver.h

CPPFILES
assetInfo.cpp
Expand Down
58 changes: 29 additions & 29 deletions pxr/usd/lib/ar/defaultResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ _IsFileRelative(const std::string& path) {
}


struct Ar_DefaultResolver::_Cache
struct ArDefaultResolver::_Cache
{
using _PathToResolvedPathMap =
tbb::concurrent_hash_map<std::string, std::string>;
_PathToResolvedPathMap _pathToResolvedPathMap;
};

Ar_DefaultResolver::Ar_DefaultResolver()
ArDefaultResolver::ArDefaultResolver()
{
_searchPath.push_back(ArchGetCwd());

Expand All @@ -60,30 +60,30 @@ Ar_DefaultResolver::Ar_DefaultResolver()
}
}

Ar_DefaultResolver::~Ar_DefaultResolver()
ArDefaultResolver::~ArDefaultResolver()
{
}

void
Ar_DefaultResolver::ConfigureResolverForAsset(const std::string& path)
ArDefaultResolver::ConfigureResolverForAsset(const std::string& path)
{
// no configuration takes place in search path resolver
}

bool
Ar_DefaultResolver::IsRelativePath(const std::string& path)
ArDefaultResolver::IsRelativePath(const std::string& path)
{
return (not path.empty() and path[0] != '/');
}

bool
Ar_DefaultResolver::IsRepositoryPath(const std::string& path)
ArDefaultResolver::IsRepositoryPath(const std::string& path)
{
return false;
}

std::string
Ar_DefaultResolver::AnchorRelativePath(
ArDefaultResolver::AnchorRelativePath(
const std::string& anchorPath,
const std::string& path)
{
Expand All @@ -100,25 +100,25 @@ Ar_DefaultResolver::AnchorRelativePath(
}

bool
Ar_DefaultResolver::IsSearchPath(const std::string& path)
ArDefaultResolver::IsSearchPath(const std::string& path)
{
return IsRelativePath(path) and not _IsFileRelative(path);
}

std::string
Ar_DefaultResolver::GetExtension(const std::string& path)
ArDefaultResolver::GetExtension(const std::string& path)
{
return TfGetExtension(path);
}

std::string
Ar_DefaultResolver::ComputeNormalizedPath(const std::string& path)
ArDefaultResolver::ComputeNormalizedPath(const std::string& path)
{
return TfNormPath(path);
}

std::string
Ar_DefaultResolver::ComputeRepositoryPath(const std::string& path)
ArDefaultResolver::ComputeRepositoryPath(const std::string& path)
{
return std::string();
}
Expand All @@ -144,7 +144,7 @@ _Resolve(
}

std::string
Ar_DefaultResolver::_ResolveNoCache(const std::string& path)
ArDefaultResolver::_ResolveNoCache(const std::string& path)
{
if (path.empty()) {
return path;
Expand Down Expand Up @@ -176,13 +176,13 @@ Ar_DefaultResolver::_ResolveNoCache(const std::string& path)
}

std::string
Ar_DefaultResolver::Resolve(const std::string& path)
ArDefaultResolver::Resolve(const std::string& path)
{
return ResolveWithAssetInfo(path, /* assetInfo = */ nullptr);
}

std::string
Ar_DefaultResolver::ResolveWithAssetInfo(
ArDefaultResolver::ResolveWithAssetInfo(
const std::string& path,
ArAssetInfo* assetInfo)
{
Expand All @@ -203,13 +203,13 @@ Ar_DefaultResolver::ResolveWithAssetInfo(
}

std::string
Ar_DefaultResolver::ComputeLocalPath(const std::string& path)
ArDefaultResolver::ComputeLocalPath(const std::string& path)
{
return path.empty() ? path : TfAbsPath(path);
}

void
Ar_DefaultResolver::UpdateAssetInfo(
ArDefaultResolver::UpdateAssetInfo(
const std::string& identifier,
const std::string& filePath,
const std::string& fileVersion,
Expand All @@ -223,54 +223,54 @@ Ar_DefaultResolver::UpdateAssetInfo(
}

bool
Ar_DefaultResolver::CanWriteLayerToPath(
ArDefaultResolver::CanWriteLayerToPath(
const std::string& path,
std::string* whyNot)
{
return true;
}

bool
Ar_DefaultResolver::CanCreateNewLayerWithIdentifier(
ArDefaultResolver::CanCreateNewLayerWithIdentifier(
const std::string& identifier,
std::string* whyNot)
{
return true;
}

ArResolverContext
Ar_DefaultResolver::CreateDefaultContext()
ArDefaultResolver::CreateDefaultContext()
{
return ArResolverContext();
}

ArResolverContext
Ar_DefaultResolver::CreateDefaultContextForAsset(
ArDefaultResolver::CreateDefaultContextForAsset(
const std::string& filePath)
{
return ArResolverContext();
}

ArResolverContext
Ar_DefaultResolver::CreateDefaultContextForDirectory(
ArDefaultResolver::CreateDefaultContextForDirectory(
const std::string& fileDirectory)
{
return ArResolverContext();
}

void
Ar_DefaultResolver::RefreshContext(const ArResolverContext& context)
ArDefaultResolver::RefreshContext(const ArResolverContext& context)
{
}

ArResolverContext
Ar_DefaultResolver::GetCurrentContext()
ArDefaultResolver::GetCurrentContext()
{
return ArResolverContext();
}

void
Ar_DefaultResolver::_BeginCacheScope(
ArDefaultResolver::_BeginCacheScope(
VtValue* cacheScopeData)
{
// cacheScopeData is held by ArResolverScopedCache instances
Expand Down Expand Up @@ -300,7 +300,7 @@ Ar_DefaultResolver::_BeginCacheScope(
}

void
Ar_DefaultResolver::_EndCacheScope(
ArDefaultResolver::_EndCacheScope(
VtValue* cacheScopeData)
{
_CachePtrStack& cacheStack = _threadCacheStack.local();
Expand All @@ -309,22 +309,22 @@ Ar_DefaultResolver::_EndCacheScope(
}
}

Ar_DefaultResolver::_CachePtr
Ar_DefaultResolver::_GetCurrentCache()
ArDefaultResolver::_CachePtr
ArDefaultResolver::_GetCurrentCache()
{
_CachePtrStack& cacheStack = _threadCacheStack.local();
return (cacheStack.empty() ? _CachePtr() : cacheStack.back());
}

void
Ar_DefaultResolver::_BindContext(
ArDefaultResolver::_BindContext(
const ArResolverContext& context,
VtValue* bindingData)
{
}

void
Ar_DefaultResolver::_UnbindContext(
ArDefaultResolver::_UnbindContext(
const ArResolverContext& context,
VtValue* bindingData)
{
Expand Down
54 changes: 27 additions & 27 deletions pxr/usd/lib/ar/defaultResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <string>
#include <vector>

/// \class Ar_DefaultResolver
/// \class ArDefaultResolver
///
/// Default asset resolution implementation used when no plugin
/// implementation is provided.
Expand All @@ -47,78 +47,78 @@
/// PXR_AR_DEFAULT_SEARCH_PATH environment variable to a list of
/// directories delimited by ':'.
///
class Ar_DefaultResolver
class ArDefaultResolver
: public ArResolver
{
public:
Ar_DefaultResolver();
virtual ~Ar_DefaultResolver();
ArDefaultResolver();
virtual ~ArDefaultResolver();

// ArResolver overrides
virtual void ConfigureResolverForAsset(const std::string& path);
virtual void ConfigureResolverForAsset(const std::string& path) override;

virtual std::string AnchorRelativePath(
const std::string& anchorPath,
const std::string& path);
const std::string& path) override;

virtual bool IsRelativePath(const std::string& path);
virtual bool IsRepositoryPath(const std::string& path);
virtual bool IsSearchPath(const std::string& path);
virtual bool IsRelativePath(const std::string& path) override;
virtual bool IsRepositoryPath(const std::string& path) override;
virtual bool IsSearchPath(const std::string& path) override;

virtual std::string GetExtension(const std::string& path);
virtual std::string GetExtension(const std::string& path) override;

virtual std::string ComputeNormalizedPath(const std::string& path);
virtual std::string ComputeNormalizedPath(const std::string& path) override;

virtual std::string ComputeRepositoryPath(const std::string& path);
virtual std::string ComputeRepositoryPath(const std::string& path) override;

virtual std::string ComputeLocalPath(const std::string& path);
virtual std::string ComputeLocalPath(const std::string& path) override;

virtual std::string Resolve(const std::string& path);
virtual std::string Resolve(const std::string& path) override;

virtual std::string ResolveWithAssetInfo(
const std::string& path,
ArAssetInfo* assetInfo);
ArAssetInfo* assetInfo) override;

virtual void UpdateAssetInfo(
const std::string& identifier,
const std::string& filePath,
const std::string& fileVersion,
ArAssetInfo* assetInfo);
ArAssetInfo* assetInfo) override;

virtual bool CanWriteLayerToPath(
const std::string& path,
std::string* whyNot);
std::string* whyNot) override;

virtual bool CanCreateNewLayerWithIdentifier(
const std::string& identifier,
std::string* whyNot);
std::string* whyNot) override;

virtual ArResolverContext CreateDefaultContext();
virtual ArResolverContext CreateDefaultContext() override;

virtual ArResolverContext CreateDefaultContextForAsset(
const std::string& filePath);
const std::string& filePath) override;

virtual ArResolverContext CreateDefaultContextForDirectory(
const std::string& fileDirectory);
const std::string& fileDirectory) override;

virtual void RefreshContext(const ArResolverContext& context);
virtual void RefreshContext(const ArResolverContext& context) override;

virtual ArResolverContext GetCurrentContext();
virtual ArResolverContext GetCurrentContext() override;

protected:
virtual void _BeginCacheScope(
VtValue* cacheScopeData);
VtValue* cacheScopeData) override;

virtual void _EndCacheScope(
VtValue* cacheScopeData);
VtValue* cacheScopeData) override;

virtual void _BindContext(
const ArResolverContext& context,
VtValue* bindingData);
VtValue* bindingData) override;

virtual void _UnbindContext(
const ArResolverContext& context,
VtValue* bindingData);
VtValue* bindingData) override;

private:
struct _Cache;
Expand Down
2 changes: 1 addition & 1 deletion pxr/usd/lib/ar/overview.dox
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ and over again, we also provide an RAII ArResolverScopedCache that can
greatly speed up asset resolution by caching results.

Finally, if no custom implementation of ArResolver is found, we will fall back
to a Ar_DefaultResolver, which performs simple searchpath-based
to a ArDefaultResolver, which performs simple searchpath-based
resolution, based on an environment variable <tt>PXR_AR_DEFAULT_SEARCH_PATH</tt>
that is expected to hold a colon-separated list of filesystem paths to search.

Expand Down
2 changes: 1 addition & 1 deletion pxr/usd/lib/ar/resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace
struct _ResolverHolder
{
_ResolverHolder()
: resolver(new Ar_DefaultResolver)
: resolver(new ArDefaultResolver)
{
if (TfGetEnvSetting(PXR_AR_DISABLE_PLUGIN_RESOLVER)) {
TF_DEBUG(AR_RESOLVER_INIT).Msg(
Expand Down

0 comments on commit 8d44cf8

Please sign in to comment.