add usd-21-05-win64_py37

This commit is contained in:
Sébastien Albert committed 2021-12-07 17:16:25 +01:00
1 parent 41d23e71ba
commit 66bc054336
15675 files changed
+3061008

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
//
// Copyright 2017 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_AR_API_H
#define PXR_USD_AR_API_H
#include "pxr/base/arch/export.h"
#if defined(PXR_STATIC)
# define AR_API
# define AR_API_TEMPLATE_CLASS(...)
# define AR_API_TEMPLATE_STRUCT(...)
# define AR_LOCAL
#else
# if defined(AR_EXPORTS)
# define AR_API ARCH_EXPORT
# define AR_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__)
# define AR_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__)
# else
# define AR_API ARCH_IMPORT
# define AR_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__)
# define AR_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__)
# endif
# define AR_LOCAL ARCH_HIDDEN
#endif
#endif
+29
View File
@@ -0,0 +1,29 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_AR_AR_H
#define PXR_USD_AR_AR_H
#define AR_VERSION 1
#endif
+102
View File
@@ -0,0 +1,102 @@
//
// Copyright 2018 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_AR_ASSET_H
#define PXR_USD_AR_ASSET_H
/// \file ar/asset.h
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include <cstdio>
#include <memory>
#include <utility>
PXR_NAMESPACE_OPEN_SCOPE
/// \class ArAsset
///
/// Interface for accessing the contents of an asset.
///
/// \see ArResolver::OpenAsset for how to retrieve instances of this object.
class ArAsset {
public:
AR_API
virtual ~ArAsset();
ArAsset(const ArAsset&) = delete;
ArAsset& operator=(const ArAsset&) = delete;
/// Returns size of the asset.
AR_API
virtual size_t GetSize() = 0;
/// Returns a pointer to a buffer with the contents of the asset,
/// with size given by GetSize(). Returns an invalid std::shared_ptr
/// if the contents could not be retrieved.
///
/// The data in the returned buffer must remain valid while there are
/// outstanding copies of the returned std::shared_ptr. Note that the
/// deleter stored in the std::shared_ptr may contain additional data
/// needed to maintain the buffer's validity.
AR_API
virtual std::shared_ptr<const char> GetBuffer() = 0;
/// Read \p count bytes at \p offset from the beginning of the asset
/// into \p buffer. Returns number of bytes read, or 0 on error.
///
/// Implementers should range-check calls and return zero for out-of-bounds
/// reads.
AR_API
virtual size_t Read(void* buffer, size_t count, size_t offset) = 0;
/// Returns a read-only FILE* handle and offset for this asset if
/// available, or (nullptr, 0) otherwise.
///
/// The returned handle must remain valid for the lifetime of this
/// ArAsset object. The returned offset is the offset from the beginning
/// of the FILE* where the asset's contents begins.
///
/// This function is marked unsafe because the handle may wind up
/// being used in multiple threads depending on the underlying
/// resolver implementation. For instance, a resolver may cache
/// and return ArAsset objects with the same FILE* to multiple
/// threads.
///
/// Clients MUST NOT use this handle with functions that cannot be
/// called concurrently on the same file descriptor, e.g. read,
/// fread, fseek, etc. See ArchPRead for a function that can be used
/// to read data from this handle safely.
AR_API
virtual std::pair<FILE*, size_t> GetFileUnsafe() = 0;
protected:
AR_API
ArAsset();
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_AR_ASSET_H
+81
View File
@@ -0,0 +1,81 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_AR_ASSET_INFO_H
#define PXR_USD_AR_ASSET_INFO_H
/// \file ar/assetInfo.h
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include "pxr/base/vt/value.h"
#include <string>
PXR_NAMESPACE_OPEN_SCOPE
/// \class ArAssetInfo
///
/// Contains information about a resolved asset.
///
class ArAssetInfo
{
public:
/// Version of the resolved asset, if any.
std::string version;
/// The name of the asset represented by the resolved
/// asset, if any.
std::string assetName;
/// \deprecated
/// The repository path corresponding to the resolved asset.
std::string repoPath;
/// Additional information specific to the active plugin
/// asset resolver implementation.
VtValue resolverInfo;
};
/// \relates ArAssetInfo
inline
void swap(ArAssetInfo& lhs, ArAssetInfo& rhs)
{
lhs.version.swap(rhs.version);
lhs.assetName.swap(rhs.assetName);
lhs.repoPath.swap(rhs.repoPath);
lhs.resolverInfo.Swap(rhs.resolverInfo);
}
/// \relates ArAssetInfo
AR_API
bool
operator==(const ArAssetInfo& lhs, const ArAssetInfo& rhs);
/// \relates ArAssetInfo
AR_API
bool
operator!=(const ArAssetInfo& lhs, const ArAssetInfo& rhs);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_AR_ASSET_INFO_H
+44
View File
@@ -0,0 +1,44 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_AR_DEFAULT_RESOLVER_H
#define PXR_USD_AR_DEFAULT_RESOLVER_H
/// \file ar/defaultResolver.h
#include "pxr/pxr.h"
#include "pxr/usd/ar/ar.h"
#define PXR_INCLUDED_FROM_AR_DEFAULT_RESOLVER_H
#if AR_VERSION == 1
#include "pxr/usd/ar/defaultResolver_v1.h"
#elif AR_VERSION == 2
#include "pxr/usd/ar/defaultResolver_v2.h"
#else
#error Unhandled AR_VERSION
#endif
#undef PXR_INCLUDED_FROM_AR_DEFAULT_RESOLVER_H
#endif
+104
View File
@@ -0,0 +1,104 @@
//
// Copyright 2018 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_AR_DEFAULT_RESOLVER_CONTEXT_H
#define PXR_USD_AR_DEFAULT_RESOLVER_CONTEXT_H
/// \file ar/defaultResolverContext.h
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include "pxr/usd/ar/defineResolverContext.h"
#include <string>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
/// \class ArDefaultResolverContext
///
/// Resolver context object that specifies a search path to use during
/// asset resolution. This object is intended for use with the default
/// ArDefaultResolver asset resolution implementation; see documentation for
/// that class for more details on the search path resolution algorithm.
///
/// Example usage:
/// \code
/// ArDefaultResolverContext ctx({"/Local/Models", "/Installed/Models"});
/// {
/// // Bind the context object:
/// ArResolverContextBinder binder(ctx);
///
/// // While the context is bound, all calls to ArResolver::Resolve
/// // (assuming ArDefaultResolver is the underlying implementation being
/// // used) will include the specified paths during resolution.
/// std::string resolvedPath = resolver.Resolve("ModelName/File.txt")
/// }
///
/// // Once the context is no longer bound (due to the ArResolverContextBinder
/// // going out of scope), its search path no longer factors into asset
/// // resolution.
/// \endcode
///
class ArDefaultResolverContext
{
public:
/// Default construct a context with no search path.
ArDefaultResolverContext() = default;
/// Construct a context with the given \p searchPath.
/// Elements in \p searchPath should be absolute paths. If they are not,
/// they will be anchored to the current working directory.
AR_API ArDefaultResolverContext(const std::vector<std::string>& searchPath);
AR_API bool operator<(const ArDefaultResolverContext& rhs) const;
AR_API bool operator==(const ArDefaultResolverContext& rhs) const;
AR_API bool operator!=(const ArDefaultResolverContext& rhs) const;
/// Return this context's search path.
const std::vector<std::string>& GetSearchPath() const
{
return _searchPath;
}
/// Return a string representation of this context for debugging.
AR_API std::string GetAsString() const;
private:
std::vector<std::string> _searchPath;
};
AR_API size_t
hash_value(const ArDefaultResolverContext& context);
inline std::string
ArGetDebugString(const ArDefaultResolverContext& context)
{
return context.GetAsString();
}
AR_DECLARE_RESOLVER_CONTEXT(ArDefaultResolverContext);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_AR_DEFAULT_RESOLVER_CONTEXT_H
+227
View File
@@ -0,0 +1,227 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_INCLUDED_FROM_AR_DEFAULT_RESOLVER_H
#error This file should not be included directly. Include resolverContext.h instead
#endif
#ifndef PXR_USD_AR_DEFAULT_RESOLVER_V1_H
#define PXR_USD_AR_DEFAULT_RESOLVER_V1_H
/// \file ar/defaultResolver_v1.h
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include "pxr/usd/ar/defaultResolverContext.h"
#include "pxr/usd/ar/resolver.h"
#include "pxr/usd/ar/threadLocalScopedCache.h"
#include <tbb/enumerable_thread_specific.h>
#include <memory>
#include <string>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
/// \class ArDefaultResolver
///
/// Default asset resolution implementation used when no plugin
/// implementation is provided.
///
/// In order to resolve assets specified by relative paths, this resolver
/// implements a simple "search path" scheme. The resolver will anchor the
/// relative path to a series of directories and return the first absolute
/// path where the asset exists.
///
/// The first directory will always be the current working directory. The
/// resolver will then examine the directories specified via the following
/// mechanisms (in order):
///
/// - The currently-bound ArDefaultResolverContext for the calling thread
/// - ArDefaultResolver::SetDefaultSearchPath
/// - The environment variable PXR_AR_DEFAULT_SEARCH_PATH. This is
/// expected to be a list of directories delimited by the platform's
/// standard path separator.
///
class ArDefaultResolver
: public ArResolver
{
public:
AR_API
ArDefaultResolver();
AR_API
virtual ~ArDefaultResolver();
/// Set the default search path that will be used during asset
/// resolution. This must be called before the first call
/// to \ref ArGetResolver.
/// The specified paths will be searched *in addition to, and before*
/// paths specified via the environment variable PXR_AR_DEFAULT_SEARCH_PATH
AR_API
static void SetDefaultSearchPath(
const std::vector<std::string>& searchPath);
// ArResolver overrides
/// Sets the resolver's default context (returned by CreateDefaultContext())
/// to the same context you would get by calling
/// CreateDefaultContextForAsset(). Has no other effect on the resolver's
/// configuration.
AR_API
virtual void ConfigureResolverForAsset(const std::string& path) override;
AR_API
virtual std::string AnchorRelativePath(
const std::string& anchorPath,
const std::string& path) override;
AR_API
virtual bool IsRelativePath(const std::string& path) override;
AR_API
virtual bool IsRepositoryPath(const std::string& path) override;
AR_API
virtual bool IsSearchPath(const std::string& path) override;
AR_API
virtual std::string GetExtension(const std::string& path) override;
AR_API
virtual std::string ComputeNormalizedPath(const std::string& path) override;
AR_API
virtual std::string ComputeRepositoryPath(const std::string& path) override;
AR_API
virtual std::string ComputeLocalPath(const std::string& path) override;
AR_API
virtual std::string Resolve(const std::string& path) override;
AR_API
virtual std::string ResolveWithAssetInfo(
const std::string& path,
ArAssetInfo* assetInfo) override;
AR_API
virtual void UpdateAssetInfo(
const std::string& identifier,
const std::string& filePath,
const std::string& fileVersion,
ArAssetInfo* assetInfo) override;
AR_API
virtual VtValue GetModificationTimestamp(
const std::string& path,
const std::string& resolvedPath) override;
AR_API
virtual bool FetchToLocalResolvedPath(
const std::string& path,
const std::string& resolvedPath) override;
AR_API
virtual std::shared_ptr<ArAsset> OpenAsset(
const std::string& resolvedPath) override;
AR_API
virtual bool CreatePathForLayer(
const std::string& path) override;
AR_API
virtual bool CanWriteLayerToPath(
const std::string& path,
std::string* whyNot) override;
AR_API
virtual bool CanCreateNewLayerWithIdentifier(
const std::string& identifier,
std::string* whyNot) override;
AR_API
virtual ArResolverContext CreateDefaultContext() override;
/// Creates a context that adds the directory containing \p filePath
/// as a first directory to be searched, when the resulting context is
/// bound (\see ArResolverContextBinder).
///
/// If \p filePath is empty, returns an empty context; otherwise, if
/// \p filePath is not an absolute filesystem path, it will first be
/// anchored to the process's current working directory.
AR_API
virtual ArResolverContext CreateDefaultContextForAsset(
const std::string& filePath) override;
AR_API
virtual void RefreshContext(const ArResolverContext& context) override;
AR_API
virtual ArResolverContext GetCurrentContext() override;
AR_API
virtual void BeginCacheScope(
VtValue* cacheScopeData) override;
AR_API
virtual void EndCacheScope(
VtValue* cacheScopeData) override;
AR_API
virtual void BindContext(
const ArResolverContext& context,
VtValue* bindingData) override;
AR_API
virtual void UnbindContext(
const ArResolverContext& context,
VtValue* bindingData) override;
private:
struct _Cache;
using _PerThreadCache = ArThreadLocalScopedCache<_Cache>;
using _CachePtr = _PerThreadCache::CachePtr;
_CachePtr _GetCurrentCache();
const ArDefaultResolverContext* _GetCurrentContext();
std::string _ResolveNoCache(const std::string& path);
private:
ArDefaultResolverContext _fallbackContext;
ArResolverContext _defaultContext;
_PerThreadCache _threadCache;
using _ContextStack = std::vector<const ArDefaultResolverContext*>;
using _PerThreadContextStack =
tbb::enumerable_thread_specific<_ContextStack>;
_PerThreadContextStack _threadContextStack;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -0,0 +1,88 @@
//
// Copyright 2018 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_AR_DEFINE_PACKAGE_RESOLVER_H
#define PXR_USD_AR_DEFINE_PACKAGE_RESOLVER_H
/// \file ar/definePackageResolver.h
/// Macros for defining a package resolver implementation.
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include "pxr/usd/ar/packageResolver.h"
#include "pxr/base/tf/registryManager.h"
#include "pxr/base/tf/type.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \def AR_DEFINE_PACKAGE_RESOLVER
///
/// Performs registrations required for the specified package resolver
/// class to be discovered by Ar's plugin mechanism. This typically would be
/// invoked in the source file defining the resolver class. For example:
///
/// \code
/// // in .cpp file
/// AR_DEFINE_PACKAGE_RESOLVER(CustomPackageResolverClass, ArPackageResolver);
/// \endcode
#ifdef doxygen
#define AR_DEFINE_PACKAGE_RESOLVER(PackageResolverClass, BaseClass1, ...)
#else
#define AR_DEFINE_PACKAGE_RESOLVER(...) \
TF_REGISTRY_FUNCTION(TfType) { \
Ar_DefinePackageResolver<__VA_ARGS__>(); \
}
class Ar_PackageResolverFactoryBase
: public TfType::FactoryBase
{
public:
AR_API
virtual ArPackageResolver* New() const = 0;
};
template <class T>
class Ar_PackageResolverFactory
: public Ar_PackageResolverFactoryBase
{
public:
virtual ArPackageResolver* New() const override
{
return new T;
}
};
template <class PackageResolver, class ...Bases>
void Ar_DefinePackageResolver()
{
TfType::Define<PackageResolver, TfType::Bases<Bases...>>()
.template SetFactory<Ar_PackageResolverFactory<PackageResolver>>();
}
#endif // doxygen
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_AR_DEFINE_PACKAGE_RESOLVER_H
+86
View File
@@ -0,0 +1,86 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_AR_DEFINE_RESOLVER_H
#define PXR_USD_AR_DEFINE_RESOLVER_H
/// \file ar/defineResolver.h
/// Macros for defining a custom resolver implementation.
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include "pxr/usd/ar/resolver.h"
#include "pxr/base/tf/registryManager.h"
#include "pxr/base/tf/type.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \def AR_DEFINE_RESOLVER
///
/// Performs registrations required for the specified resolver class
/// to be discovered by Ar's plugin mechanism. This typically would be
/// invoked in the source file defining the resolver class. For example:
///
/// \code
/// // in .cpp file
/// AR_DEFINE_RESOLVER(CustomResolverClass, ArResolver);
/// \endcode
#ifdef doxygen
#define AR_DEFINE_RESOLVER(ResolverClass, BaseClass1, ...)
#else
#define AR_DEFINE_RESOLVER(...) \
TF_REGISTRY_FUNCTION(TfType) { \
Ar_DefineResolver<__VA_ARGS__>(); \
}
#endif // doxygen
class Ar_ResolverFactoryBase
: public TfType::FactoryBase
{
public:
AR_API
virtual ArResolver* New() const = 0;
};
template <class T>
class Ar_ResolverFactory
: public Ar_ResolverFactoryBase
{
public:
virtual ArResolver* New() const override
{
return new T;
}
};
template <class Resolver, class ...Bases>
void Ar_DefineResolver()
{
TfType::Define<Resolver, TfType::Bases<Bases...>>()
.template SetFactory<Ar_ResolverFactory<Resolver> >();
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_AR_DEFINE_RESOLVER_H
@@ -0,0 +1,56 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_AR_DEFINE_RESOLVER_CONTEXT_H
#define PXR_USD_AR_DEFINE_RESOLVER_CONTEXT_H
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include "pxr/usd/ar/resolverContext.h"
/// \file ar/defineResolverContext.h
/// Macros for defining an object for use with ArResolverContext
PXR_NAMESPACE_OPEN_SCOPE
/// \def AR_DECLARE_RESOLVER_CONTEXT
///
/// Declare that the specified ContextObject type may be used as an asset
/// resolver context object for ArResolverContext. This typically
/// would be invoked in the header where the ContextObject is
/// declared.
///
#ifdef doxygen
#define AR_DECLARE_RESOLVER_CONTEXT(ContextObject)
#else
#define AR_DECLARE_RESOLVER_CONTEXT(context) \
template <> \
struct ArIsContextObject<context> \
{ \
static const bool value = true; \
}
#endif
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_AR_DEFINE_RESOLVER_CONTEXT_H
+81
View File
@@ -0,0 +1,81 @@
//
// Copyright 2018 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
#ifndef PXR_USD_AR_FILESYSTEM_ASSET_H
#define PXR_USD_AR_FILESYSTEM_ASSET_H
/// \file ar/filesystemAsset.h
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include "pxr/usd/ar/asset.h"
#include <cstdio>
#include <memory>
#include <utility>
PXR_NAMESPACE_OPEN_SCOPE
/// \class ArFilesystemAsset
///
/// ArAsset implementation for asset represented by a file on a filesystem.
class ArFilesystemAsset
: public ArAsset
{
public:
/// Constructs an ArFilesystemAsset for the given \p file.
/// The ArFilesystemAsset object takes ownership of \p file and will
/// close the file handle on destruction.
AR_API
explicit ArFilesystemAsset(FILE* file);
/// Closes the file owned by this object.
AR_API
~ArFilesystemAsset();
/// Returns the size of the file held by this object.
AR_API
virtual size_t GetSize() override;
/// Creates a read-only memory map for the file held by this object
/// and returns a pointer to the start of the mapped contents.
AR_API
virtual std::shared_ptr<const char> GetBuffer() override;
/// Reads \p count bytes from the file held by this object at the
/// given \p offset into \p buffer.
AR_API
virtual size_t Read(void* buffer, size_t count, size_t offset) override;
/// Returns the FILE* handle this object was created with and an offset
/// of 0, since the asset's contents are located at the beginning of the
/// file.
AR_API
virtual std::pair<FILE*, size_t> GetFileUnsafe() override;
private:
FILE* _file;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_AR_FILESYSTEM_ASSET_H
+178
View File
@@ -0,0 +1,178 @@
//
// Copyright 2018 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_AR_PACKAGE_RESOLVER_H
#define PXR_USD_AR_PACKAGE_RESOLVER_H
/// \file ar/packageResolver.h
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include <memory>
#include <string>
PXR_NAMESPACE_OPEN_SCOPE
class ArAsset;
class VtValue;
/// \class ArPackageResolver
///
/// Interface for resolving assets within package assets. A package resolver
/// is responsible for processing particular package asset formats and
/// resolving information about assets stored within that package.
///
/// Each package resolver is associated with particular file formats and is
/// invoked by asset resolution when handling package-relative paths involving
/// those formats. ArPackageResolver instances are only used internally by Ar
/// and are not directly exposed to clients.
///
/// \section ar_implementing_package_resolver Implementing a Package Resolver
///
/// To implement a package resolver, users must create a plugin containing a
/// subclass of ArPackageResolver and register it with the plugin system
/// so that it can be discovered and instantiated at runtime.
///
/// - Implement an ArPackageResolver subclass
/// \code{.cpp}
/// class CustomPackageResolver : public ArPackageResolver {
/// // ...
/// }
/// \endcode
///
/// - In its implementation, register the ArPackageResolver subclass using
/// #AR_DEFINE_PACKAGE_RESOLVER
/// \code{.cpp}
/// # custom resolver's .cpp file
/// AR_DEFINE_PACKAGE_RESOLVER(CustomPackageResolver, ArPackageResolver);
/// \endcode
///
/// - Declare the ArPackageResolver subclass in the plugin's plugInfo.json file.
/// Note that the entry for the subclass must declare the file format it
/// handles in the 'extensions' metadata.
/// \code{.json}
/// # plugInfo.json
/// {
/// "Plugins": [
/// {
/// "Info": {
/// "Types" : {
/// "CustomPackageResolver" : {
/// "bases": [ "ArPackageResolver" ],
/// "extensions": [ "pack" ]
/// }
/// }
/// },
/// ...
/// },
/// ...
/// ]
///
/// }
/// \endcode
///
class ArPackageResolver
{
public:
ArPackageResolver(const ArPackageResolver&) = delete;
ArPackageResolver& operator=(const ArPackageResolver&) = delete;
AR_API
virtual ~ArPackageResolver();
// --------------------------------------------------------------------- //
/// \name Packaged Path Resolution Operations
///
/// @{
// --------------------------------------------------------------------- //
/// Returns the resolved path for the asset located at \p packagedPath
/// in the package specified by \p resolvedPackagePath if it exists.
/// If the asset does not exist in the package, returns an empty string.
///
/// When ArResolver::Resolve is invoked on a package-relative path, the
/// path will be parsed into the outermost package path, and the inner
/// packaged path. The outermost package path will be resolved by the
/// primary resolver. ArPackageResolver::Resolve will then be called on
/// the corresponding package resolver with that resolved path and the
/// inner packaged path. If the inner packaged path is itself a
/// package-relative path, this process recurses until all paths have been
/// resolved.
///
/// \see ArResolver::Resolve
AR_API
virtual std::string Resolve(
const std::string& resolvedPackagePath,
const std::string& packagedPath) = 0;
/// @}
// --------------------------------------------------------------------- //
/// \name Asset-specific Operations
///
/// @{
// --------------------------------------------------------------------- //
/// Returns an ArAsset object for the asset at \p resolvedPackagedPath
/// located in the package asset at \p resolvedPackagePath.
/// Returns an invalid std::shared_ptr if object could not be created.
///
/// \see ArResolver::OpenAsset
AR_API
virtual std::shared_ptr<ArAsset> OpenAsset(
const std::string& resolvedPackagePath,
const std::string& resolvedPackagedPath) = 0;
// --------------------------------------------------------------------- //
/// \name Scoped Resolution Cache
///
/// These functions are called when scoped resolution caches are enabled
/// via ArResolver.
///
/// \see \ref ArResolver_scopedCache "Scoped Resolution Cache"
/// @{
// --------------------------------------------------------------------- //
/// Mark the start of a resolution caching scope.
///
/// \see ArResolver::BeginCacheScope
AR_API
virtual void BeginCacheScope(
VtValue* cacheScopeData) = 0;
/// Mark the end of a resolution caching scope.
///
/// \see ArResolver::EndCacheScope
AR_API
virtual void EndCacheScope(
VtValue* cacheScopeData) = 0;
protected:
AR_API
ArPackageResolver();
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_AR_PACKAGE_RESOLVER_H
+134
View File
@@ -0,0 +1,134 @@
//
// Copyright 2018 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_AR_PACKAGE_UTILS_H
#define PXR_USD_AR_PACKAGE_UTILS_H
/// \file ar/packageUtils.h
/// Utility functions for working with package assets
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include <string>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
// --------------------------------------------------------------------- //
/// \anchor Ar_packagePaths
/// \name Package Relative Paths
///
/// Assets within package assets can be addressed via "package-relative"
/// paths. For example, given a hypothetical package <tt>"Model.package"</tt>,
/// the asset <tt>"Geom.file"</tt>, can be referred to using the path
/// <tt>"Model.package[Geom.file]"</tt>.
///
/// A package-relative path consists of two parts:
///
/// - The outer "package" path is the path to the containing package asset.
/// This path can be whatever is appropriate to the client's asset system.
///
/// - The inner "packaged" path is the path to an asset contained within the
/// package asset. This path must be a relative path delimited by forward
/// slashes '/', with no leading slashes or drive or device letters. Note
/// that packaged paths may themselves be package-relative paths, since
/// package assets may be nested.
///
/// Examples:
/// - <tt>/path/to/Model.package[a/b/Geom.file]</tt>
/// - <tt>/path/to/Model.package[a/b/Sub.package[c/d/Geom.file]]</tt>
///
/// @{
// --------------------------------------------------------------------- //
/// Return true if \p path is a package-relative path, false otherwise.
AR_API
bool
ArIsPackageRelativePath(const std::string& path);
/// Combines the given \p paths into a single package-relative path, nesting
/// paths as necessary.
///
/// \code
/// ArJoinPackageRelativePath(["a.pack", "b.pack"])
/// => "a.pack[b.pack]"
///
/// ArJoinPackageRelativePath(["a.pack", "b.pack", "c.pack"])
/// => "a.pack[b.pack[c.pack]]"
///
/// ArJoinPackageRelativePath(["a.pack[b.pack]", "c.pack"])
/// => "a.pack[b.pack[c.pack]]"
/// \endcode
AR_API
std::string
ArJoinPackageRelativePath(const std::vector<std::string>& paths);
/// \overload
AR_API
std::string
ArJoinPackageRelativePath(const std::pair<std::string, std::string>& paths);
/// \overload
AR_API
std::string
ArJoinPackageRelativePath(
const std::string& packagePath, const std::string& packagedPath);
/// Split package-relative path \p path into a (package path, packaged path)
/// pair. If \p packageRelativePath contains nested package-relative paths
/// the package path will be the outermost package path, and the packaged path
/// will be the inner package-relative path.
///
/// \code
/// ArSplitPackageRelativePathOuter("a.pack[b.pack]")
/// => ("a.pack", "b.pack")
///
/// ArSplitPackageRelativePathOuter("a.pack[b.pack[c.pack]]")
/// => ("a.pack", "b.pack[c.pack]")
/// \endcode
AR_API
std::pair<std::string, std::string>
ArSplitPackageRelativePathOuter(const std::string& path);
/// Split package-relative path \p path into a (package path, packaged path)
/// pair. If \p packageRelativePath contains nested package-relative paths
/// the package path will be the outermost package-relative path, and the
/// packaged path will be the innermost packaged path.
///
/// \code
/// ArSplitPackageRelativePathInner("a.pack[b.pack]")
/// => ("a.pack", "b.pack")
///
/// ArSplitPackageRelativePathInner("a.pack[b.pack[c.pack]]")
/// => ("a.pack[b.pack]", "c.pack")
/// \endcode
AR_API
std::pair<std::string, std::string>
ArSplitPackageRelativePathInner(const std::string& path);
/// @}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_AR_PACKAGE_UTILS_H
+44
View File
@@ -0,0 +1,44 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_AR_PY_RESOLVER_CONTEXT_H
#define PXR_USD_AR_PY_RESOLVER_CONTEXT_H
/// \file ar/pyResolverContext.h
#include "pxr/pxr.h"
#include "pxr/usd/ar/ar.h"
#define INCLUDE_AR_PY_RESOLVER_CONTEXT
#if AR_VERSION == 1
#include "pxr/usd/ar/pyResolverContext_v1.h"
#elif AR_VERSION == 2
#include "pxr/usd/ar/pyResolverContext_v2.h"
#else
#error Unhandled AR_VERSION
#endif
#undef INCLUDE_AR_PY_RESOLVER_CONTEXT
#endif // PXR_USD_AR_PY_RESOLVER_CONTEXT_H
+132
View File
@@ -0,0 +1,132 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef INCLUDE_AR_PY_RESOLVER_CONTEXT
#error This file should not be included directly. Include pyResolverContext.h instead
#endif
#ifndef PXR_USD_AR_PY_RESOLVER_CONTEXT_V1_H
#define PXR_USD_AR_PY_RESOLVER_CONTEXT_V1_H
/// \file ar/pyResolverContext_v1.h
/// Macros for creating Python bindings for objects used with
/// ArResolverContext.
#include "pxr/base/tf/pySafePython.h"
#include <boost/python/extract.hpp>
#include <boost/python/object.hpp>
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include "pxr/usd/ar/resolverContext.h"
#include "pxr/base/tf/pyLock.h"
#include "pxr/base/tf/pyObjWrapper.h"
#include <functional>
PXR_NAMESPACE_OPEN_SCOPE
/// Register the specified type as a context object that may be
/// converted from a Python into a ArResolverContext object
/// in C++ and vice versa. This typically would be called in the
/// source file where the Python wrapping for the context object
/// is defined.
template <class Context>
void
ArWrapResolverContextForPython();
#ifndef doxygen
// Private helper functions for converting ArResolverContext
// objects to and from Python.
template <class Context>
bool
Ar_ConvertResolverContextFromPython(
PyObject* obj,
ArResolverContext* context)
{
boost::python::extract<const Context&> x(obj);
if (x.check()) {
if (context) {
*context = ArResolverContext(x());
}
return true;
}
return false;
}
template <class Context>
bool
Ar_ConvertResolverContextToPython(
const ArResolverContext& context,
TfPyObjWrapper* obj)
{
if (const Context* contextObj = context.Get<Context>()) {
if (obj) {
TfPyLock lock;
*obj = boost::python::object(*contextObj);
}
return true;
}
return false;
}
typedef std::function<bool(PyObject*, ArResolverContext*)>
Ar_MakeResolverContextFromPythonFn;
typedef std::function<bool(const ArResolverContext&, TfPyObjWrapper*)>
Ar_ResolverContextToPythonFn;
AR_API
void
Ar_RegisterResolverContextPythonConversion(
const Ar_MakeResolverContextFromPythonFn& convertFunc,
const Ar_ResolverContextToPythonFn& getObjectFunc);
AR_API
bool
Ar_CanConvertResolverContextFromPython(PyObject* pyObj);
AR_API
ArResolverContext
Ar_ConvertResolverContextFromPython(PyObject* pyObj);
AR_API
TfPyObjWrapper
Ar_ConvertResolverContextToPython(const ArResolverContext& context);
template <class Context>
void
ArWrapResolverContextForPython()
{
Ar_RegisterResolverContextPythonConversion(
Ar_ConvertResolverContextFromPython<Context>,
Ar_ConvertResolverContextToPython<Context>);
};
#endif //doxygen
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+132
View File
@@ -0,0 +1,132 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_AR_RESOLVED_PATH_H
#define PXR_USD_AR_RESOLVED_PATH_H
/// \file ar/resolvedPath.h
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include "pxr/base/tf/hash.h"
#include <string>
PXR_NAMESPACE_OPEN_SCOPE
/// \class ArResolvedPath
/// Represents a resolved asset path.
class ArResolvedPath
{
public:
/// Construct an ArResolvedPath holding the given \p resolvedPath.
explicit ArResolvedPath(const std::string& resolvedPath)
: _resolvedPath(resolvedPath)
{
}
/// \overload
explicit ArResolvedPath(std::string&& resolvedPath)
: _resolvedPath(std::move(resolvedPath))
{
}
ArResolvedPath() = default;
ArResolvedPath(const ArResolvedPath& rhs) = default;
ArResolvedPath(ArResolvedPath&& rhs) = default;
ArResolvedPath& operator=(const ArResolvedPath& rhs) = default;
ArResolvedPath& operator=(ArResolvedPath&& rhs) = default;
bool operator==(const ArResolvedPath& rhs) const
{ return _resolvedPath == rhs._resolvedPath; }
bool operator!=(const ArResolvedPath& rhs) const
{ return _resolvedPath != rhs._resolvedPath; }
bool operator<(const ArResolvedPath& rhs) const
{ return _resolvedPath < rhs._resolvedPath; }
bool operator>(const ArResolvedPath& rhs) const
{ return _resolvedPath > rhs._resolvedPath; }
bool operator<=(const ArResolvedPath& rhs) const
{ return _resolvedPath <= rhs._resolvedPath; }
bool operator>=(const ArResolvedPath& rhs) const
{ return _resolvedPath >= rhs._resolvedPath; }
bool operator==(const std::string& rhs) const
{ return _resolvedPath == rhs; }
bool operator!=(const std::string& rhs) const
{ return _resolvedPath != rhs; }
bool operator<(const std::string& rhs) const
{ return _resolvedPath < rhs; }
bool operator>(const std::string& rhs) const
{ return _resolvedPath > rhs; }
bool operator<=(const std::string& rhs) const
{ return _resolvedPath <= rhs; }
bool operator>=(const std::string& rhs) const
{ return _resolvedPath >= rhs; }
/// Return hash value for this object.
size_t GetHash() const { return TfHash()(*this); }
/// Return true if this object is holding a non-empty resolved path,
/// false otherwise.
explicit operator bool() const { return !IsEmpty(); }
/// Return true if this object is holding an empty resolved path,
/// false otherwise.
bool IsEmpty() const { return _resolvedPath.empty(); }
/// Equivalent to IsEmpty. This exists primarily for backwards
/// compatibility.
bool empty() const { return IsEmpty(); }
/// Return the resolved path held by this object as a string.
operator const std::string&() const { return GetPathString(); }
/// Return the resolved path held by this object as a string.
const std::string& GetPathString() const { return _resolvedPath; }
private:
std::string _resolvedPath;
};
template <class HashState>
void
TfHashAppend(HashState& h, const ArResolvedPath& p)
{
h.Append(p.GetPathString());
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+42
View File
@@ -0,0 +1,42 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_AR_RESOLVER_H
#define PXR_USD_AR_RESOLVER_H
#include "pxr/pxr.h"
#include "pxr/usd/ar/ar.h"
#define INCLUDE_AR_RESOLVER
#if AR_VERSION == 1
#include "pxr/usd/ar/resolver_v1.h"
#elif AR_VERSION == 2
#include "pxr/usd/ar/resolver_v2.h"
#else
#error Unhandled AR_VERSION
#endif
#undef INCLUDE_AR_RESOLVER
#endif // PXR_USD_AR_RESOLVER_H
+44
View File
@@ -0,0 +1,44 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_AR_RESOLVER_CONTEXT_H
#define PXR_USD_AR_RESOLVER_CONTEXT_H
/// \file ar/resolverContext.h
#include "pxr/pxr.h"
#include "pxr/usd/ar/ar.h"
#define INCLUDE_AR_RESOLVER_CONTEXT
#if AR_VERSION == 1
#include "pxr/usd/ar/resolverContext_v1.h"
#elif AR_VERSION == 2
#include "pxr/usd/ar/resolverContext_v2.h"
#else
#error Unhandled AR_VERSION
#endif
#undef INCLUDE_AR_RESOLVER_CONTEXT
#endif // PXR_USD_AR_RESOLVER_CONTEXT_H
@@ -0,0 +1,80 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_AR_RESOLVER_CONTEXT_BINDER_H
#define PXR_USD_AR_RESOLVER_CONTEXT_BINDER_H
/// \file ar/resolverContextBinder.h
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include "pxr/usd/ar/resolverContext.h"
#include "pxr/base/vt/value.h"
PXR_NAMESPACE_OPEN_SCOPE
class ArResolver;
/// \class ArResolverContextBinder
///
/// Helper object for managing the binding and unbinding of
/// ArResolverContext objects with the asset resolver.
///
/// \see \ref ArResolver_context "Asset Resolver Context Operations"
class ArResolverContextBinder
{
public:
/// Bind the given \p context with the asset resolver.
///
/// Calls ArResolver::BindContext on the configured asset resolver
/// and saves the bindingData populated by that function.
AR_API
ArResolverContextBinder(
const ArResolverContext& context);
/// Bind the given \p context to the given \p assetResolver.
///
/// Calls ArResolver::BindContext on the given \p assetResolver
/// and saves the bindingData populated by that function.
AR_API
ArResolverContextBinder(
ArResolver* assetResolver,
const ArResolverContext& context);
/// Unbinds the context specified in the constructor of this
/// object from the asset resolver.
///
/// Calls ArResolver::UnbindContext on the asset resolver that was
/// bound to originally, passing the saved bindingData to that function.
AR_API
~ArResolverContextBinder();
private:
ArResolver* _resolver;
ArResolverContext _context;
VtValue _bindingData;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_AR_RESOLVER_CONTEXT_BINDER_H
+256
View File
@@ -0,0 +1,256 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef INCLUDE_AR_RESOLVER_CONTEXT
#error This file should not be included directly. Include resolverContext.h instead
#endif
#ifndef PXR_USD_AR_RESOLVER_CONTEXT_V1_H
#define PXR_USD_AR_RESOLVER_CONTEXT_V1_H
/// \file ar/resolverContext_v1.h
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include "pxr/base/tf/safeTypeCompare.h"
#include <memory>
#include <string>
#include <type_traits>
#include <typeinfo>
PXR_NAMESPACE_OPEN_SCOPE
/// \class ArIsContextObject
///
/// Metafunction to determine whether the templated object type is a
/// valid context object.
///
template <class T>
struct ArIsContextObject
{
static const bool value = false;
};
/// Default implementation for providing debug info on the contained context.
template <class Context>
std::string ArGetDebugString(const Context& context);
/// \class ArResolverContext
///
/// An asset resolver context allows clients to provide additional data
/// to the resolver for use during resolution. Clients may provide this
/// data via a context object of their own (subject to restrictions below).
/// An ArResolverContext is simply a wrapper around this object that
/// allows it to be treated as a single type.
///
/// A client-defined context object must provide the following:
/// - Default and copy constructors
/// - operator<
/// - operator==
/// - An overload for size_t hash_value(const T&)
///
/// Note that the user may define a free function:
///
/// std::string ArGetDebugString(const Context& ctx);
/// (Where Context is the type of the user's path resolver context.)
///
/// This is optional; a default generic implementation has been predefined.
/// This function should return a string representation of the context
/// to be utilized for debugging purposes(such as in TF_DEBUG statements).
///
/// The ArIsContextObject template must also be specialized for this
/// object to declare that it can be used as a context object. This is to
/// avoid accidental use of an unexpected object as a context object.
/// The AR_DECLARE_RESOLVER_CONTEXT macro can be used to do this
/// as a convenience.
///
/// \sa AR_DECLARE_RESOLVER_CONTEXT
/// \sa ArResolver::BindContext
/// \sa ArResolver::UnbindContext
/// \sa ArResolverContextBinder
class ArResolverContext
{
public:
/// Construct an empty asset resolver context.
ArResolverContext()
{
}
/// Construct a resolver context using the context object \p context.
/// See class documentation for requirements.
template <class Context,
typename std::enable_if<ArIsContextObject<Context>::value>
::type* = nullptr>
ArResolverContext(const Context& context)
: _context(new _Typed<Context>(context))
{
}
/// Returns whether this context object is empty.
bool IsEmpty() const
{
return !_context;
}
/// Return pointer to the context object held in this asset resolver
/// context if the context is holding an object of the requested type,
/// NULL otherwise.
template <class Context>
const Context* Get() const
{
return _context && _context->IsHolding(typeid(Context)) ?
&_GetTyped<Context>(*_context)._context : NULL;
}
/// Returns a debug string representing the contained context
std::string GetDebugString() const
{
return _context ? _context->GetDebugString() : std::string();
}
/// \name Operators
/// @{
bool operator==(const ArResolverContext& rhs) const
{
if (_context && rhs._context) {
return (_context->IsHolding(rhs._context->GetTypeid())
&& _context->Equals(*rhs._context));
}
return (!_context && !rhs._context);
}
bool operator!=(const ArResolverContext& rhs) const
{
return !(*this == rhs);
}
bool operator<(const ArResolverContext& rhs) const
{
if (_context && rhs._context) {
if (_context->IsHolding(rhs._context->GetTypeid())) {
return _context->LessThan(*rhs._context);
}
return (std::string(_context->GetTypeid().name()) <
std::string(rhs._context->GetTypeid().name()));
}
else if (_context && !rhs._context) {
return false;
}
else if (!_context && rhs._context) {
return true;
}
return false;
}
/// @}
/// Returns hash value for this asset resolver context.
friend size_t hash_value(const ArResolverContext& context)
{
return context._context ? context._context->Hash() : 0;
}
private:
// Type-erased storage for context objects.
struct _Untyped;
template <class Context> struct _Typed;
template <class Context>
static const _Typed<Context>& _GetTyped(const _Untyped& untyped)
{
return static_cast<const _Typed<Context>&>(untyped);
}
struct _Untyped
{
AR_API
virtual ~_Untyped();
bool IsHolding(const std::type_info& ti) const
{
return TfSafeTypeCompare(ti, GetTypeid());
}
virtual const std::type_info& GetTypeid() const = 0;
virtual bool LessThan(const _Untyped& rhs) const = 0;
virtual bool Equals(const _Untyped& rhs) const = 0;
virtual size_t Hash() const = 0;
virtual std::string GetDebugString() const = 0;
};
template <class Context>
struct _Typed : public _Untyped
{
virtual ~_Typed() { }
_Typed(const Context& context) : _context(context)
{
}
virtual const std::type_info& GetTypeid() const
{
return typeid(Context);
}
virtual bool LessThan(const _Untyped& rhs) const
{
return _context < _GetTyped<Context>(rhs)._context;
}
virtual bool Equals(const _Untyped& rhs) const
{
return _context == _GetTyped<Context>(rhs)._context;
}
virtual size_t Hash() const
{
return hash_value(_context);
}
virtual std::string GetDebugString() const
{
return ArGetDebugString(_context);
}
Context _context;
};
std::shared_ptr<_Untyped> _context;
};
// Default implementation for streaming out held contexts.
AR_API
std::string Ar_GetDebugString(const std::type_info&, void const*);
template <class Context>
std::string ArGetDebugString(const Context& context)
{
return Ar_GetDebugString(typeid(Context),
static_cast<void const*>(&context));
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+83
View File
@@ -0,0 +1,83 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_AR_RESOLVER_SCOPED_CACHE_H
#define PXR_USD_AR_RESOLVER_SCOPED_CACHE_H
/// \file ar/resolverScopedCache.h
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include "pxr/base/vt/value.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \class ArResolverScopedCache
///
/// Helper object for managing asset resolver cache scopes.
///
/// 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.
///
/// \see \ref ArResolver_scopedCache "Scoped Resolution Cache"
class ArResolverScopedCache
{
public:
// Disallow copies
ArResolverScopedCache(const ArResolverScopedCache&) = delete;
ArResolverScopedCache& operator=(const ArResolverScopedCache&) = delete;
/// Begin an asset resolver cache scope.
///
/// Calls ArResolver::BeginCacheScope on the configured asset resolver
/// and saves the cacheScopeData populated by that function.
AR_API
ArResolverScopedCache();
/// Begin an asset resolver cache scope that shares data
/// with the given \p parent scope.
///
/// Calls ArResolver::BeginCacheScope on the configured asset resolver,
/// saves the cacheScopeData stored in \p parent and passes that to that
/// function.
AR_API
explicit ArResolverScopedCache(const ArResolverScopedCache* parent);
/// End an asset resolver cache scope.
///
/// Calls ArResolver::EndCacheScope on the configured asset resolver,
/// passing the saved cacheScopeData to that function.
AR_API
~ArResolverScopedCache();
private:
VtValue _cacheScopeData;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_AR_RESOLVER_SCOPED_CACHE_H
+483
View File
@@ -0,0 +1,483 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef INCLUDE_AR_RESOLVER
#error This file should not be included directly. Include resolver.h instead.
#endif
#ifndef PXR_USD_AR_RESOLVER_V1_H
#define PXR_USD_AR_RESOLVER_V1_H
/// \file ar/resolver_v1.h
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include <memory>
#include <string>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
class ArAsset;
class ArAssetInfo;
class ArResolverContext;
class TfType;
class VtValue;
/// \class ArResolver
///
/// 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 \ref 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.
///
class ArResolver
{
public:
AR_API
virtual ~ArResolver();
// Disallow copies
ArResolver(const ArResolver&) = delete;
ArResolver& operator=(const ArResolver&) = delete;
// --------------------------------------------------------------------- //
/// \anchor ArResolver_resolution
/// \name Path Resolution Operations
///
/// @{
// --------------------------------------------------------------------- //
/// Configures the resolver for a given asset path
AR_API
virtual void ConfigureResolverForAsset(const std::string& path) = 0;
/// Returns the path formed by anchoring \p path to \p anchorPath.
///
/// If \p anchorPath ends with a trailing '/', it is treated as
/// a directory to which \p path will be anchored. Otherwise, it
/// is treated as a file and \p path will be anchored to its
/// containing directory.
///
/// If \p anchorPath is empty, \p path will be returned as-is.
///
/// If \p path is empty or not a relative path, it will be
/// returned as-is.
AR_API
virtual std::string AnchorRelativePath(
const std::string& anchorPath,
const std::string& path) = 0;
/// Returns true if the given path is a relative path.
AR_API
virtual bool IsRelativePath(const std::string& path) = 0;
/// Returns true if the given path is a repository path.
AR_API
virtual bool IsRepositoryPath(const std::string& path) = 0;
/// Returns whether this path is a search path.
AR_API
virtual bool IsSearchPath(const std::string& path) = 0;
/// Returns the normalized extension for the given \p path.
AR_API
virtual std::string GetExtension(const std::string& path) = 0;
/// Returns a normalized version of the given \p path
AR_API
virtual std::string ComputeNormalizedPath(const std::string& path) = 0;
/// Returns the computed repository path using the current resolver
AR_API
virtual std::string ComputeRepositoryPath(const std::string& path) = 0;
/// Returns the local path for the given \p path.
AR_API
virtual std::string ComputeLocalPath(const std::string& path) = 0;
/// Returns the resolved filesystem path for the file identified by
/// the given \p path if it exists. If the file does not exist,
/// returns an empty string.
AR_API
virtual std::string Resolve(const std::string& path) = 0;
/// @}
// --------------------------------------------------------------------- //
/// \anchor ArResolver_context
/// \name Asset Resolver Context Operations
///
/// @{
// --------------------------------------------------------------------- //
/// Binds the given context to this resolver.
///
/// Clients should generally use ArResolverContextBinder instead of calling
/// this function directly.
///
/// \see ArResolverContextBinder
AR_API
virtual void BindContext(
const ArResolverContext& context,
VtValue* bindingData) = 0;
/// Unbind the given context from this resolver.
///
/// Clients should generally use ArResolverContextBinder instead of calling
/// this function directly.
///
/// \see ArResolverContextBinder
AR_API
virtual void UnbindContext(
const ArResolverContext& context,
VtValue* bindingData) = 0;
/// Return a default ArResolverContext that may be bound to this resolver
/// to resolve assets when no other context is explicitly specified.
///
/// This function should not automatically bind this context, but should
/// create one that may be used later.
AR_API
virtual ArResolverContext CreateDefaultContext() = 0;
/// Return a default ArResolverContext that may be bound to this resolver
/// to resolve the asset located at \p filePath when no other context is
/// explicitly specified.
///
/// This function should not automatically bind this context, but should
/// create one that may be used later.
AR_API
virtual ArResolverContext CreateDefaultContextForAsset(
const std::string& filePath) = 0;
/// Refresh any caches associated with the given context.
AR_API
virtual void RefreshContext(const ArResolverContext& context) = 0;
/// Returns the currently-bound asset resolver context.
///
/// \see ArResolver::BindContext, ArResolver::UnbindContext
AR_API
virtual ArResolverContext GetCurrentContext() = 0;
/// @}
// --------------------------------------------------------------------- //
/// \anchor ArResolver_files
/// \name File/asset-specific Operations
///
/// @{
// --------------------------------------------------------------------- //
/// Returns the resolved filesystem path for the file identified
/// by \p path following the same path resolution behavior as in
/// \ref Resolve(const std::string&).
///
/// If the file identified by \p path represents an asset and
/// \p assetInfo is not \c nullptr, the resolver should populate
/// \p assetInfo with whatever additional metadata it knows or can
/// reasonably compute about the asset without actually opening it.
///
/// \see Resolve(const std::string&).
AR_API
virtual std::string ResolveWithAssetInfo(
const std::string& path,
ArAssetInfo* assetInfo) = 0;
/// Update \p assetInfo with respect to the given \p fileVersion .
/// \note This API is currently in flux. In general, you should prefer
/// to call ResolveWithAssetInfo()
AR_API
virtual void UpdateAssetInfo(
const std::string& identifier,
const std::string& filePath,
const std::string& fileVersion,
ArAssetInfo* assetInfo) = 0;
/// Returns a value representing the last time the asset identified
/// by \p path was modified. \p resolvedPath is the resolved path
/// of the asset.
///
/// Implementations may use whatever value is most appropriate
/// for this timestamp. The value must be equality comparable,
/// and this function must return a different timestamp whenever
/// an asset has been modified. For instance, if an asset is stored
/// as a file on disk, the timestamp may simply be that file's mtime.
///
/// If a timestamp cannot be retrieved, returns an empty VtValue.
AR_API
virtual VtValue GetModificationTimestamp(
const std::string& path,
const std::string& resolvedPath) = 0;
/// Fetch the asset identified by \p path to the filesystem location
/// specified by \p resolvedPath. \p resolvedPath is the resolved path
/// that results from calling Resolve or ResolveWithAssetInfo on
/// \p path.
///
/// This method provides a way for consumers that expect assets
/// to exist as physical files on disk to retrieve data from
/// systems that store data in external data stores, e.g. databases,
/// etc.
///
/// Returns true if the asset was successfully fetched to the specified
/// \p resolvedPath or if no fetching was required. If \p resolvedPath
/// is not a local path or the asset could not be fetched to that path,
/// returns false.
AR_API
virtual bool FetchToLocalResolvedPath(
const std::string& path,
const std::string& resolvedPath) = 0;
/// Returns an ArAsset object for the asset located at \p resolvedPath.
/// Returns an invalid std::shared_ptr if object could not be created.
///
/// The returned ArAsset object provides functions for accessing the
/// contents of the specified asset.
///
/// 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.
AR_API
virtual std::shared_ptr<ArAsset> OpenAsset(
const std::string& resolvedPath) = 0;
/// Create path needed to write a file to the given \p path.
///
/// For example:
/// - A filesystem-based resolver might create the directories specified
/// in \p path.
/// - A database-based resolver might create a new table, or it might
/// ignore this altogether.
///
/// In practice, when writing a layer, CanWriteLayerToPath will be called
/// first to check if writing is permitted. If this returns true, then
/// CreatePathForLayer will be called before writing the layer out.
///
/// Returns true on success, false otherwise.
AR_API
virtual bool CreatePathForLayer(
const std::string& path) = 0;
/// Returns true if a file may be written to the given \p path, false
/// otherwise.
///
/// In practice, when writing a layer, CanWriteLayerToPath will be called
/// first to check if writing is permitted. If this returns true, then
/// CreatePathForLayer will be called before writing the layer out.
///
/// If this function returns false and \p whyNot is not \c nullptr,
/// it will be filled in with an explanation.
AR_API
virtual bool CanWriteLayerToPath(
const std::string& path,
std::string* whyNot) = 0;
/// Returns true if a new file may be created using the given
/// \p identifier, false otherwise.
///
/// If this function returns false and \p whyNot is not \c nullptr,
/// it will be filled in with an explanation.
AR_API
virtual bool CanCreateNewLayerWithIdentifier(
const std::string& identifier,
std::string* whyNot) = 0;
/// @}
// --------------------------------------------------------------------- //
/// \anchor ArResolver_scopedCache
/// \name 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.
///
/// \see ArResolverScopedCache
/// @{
// --------------------------------------------------------------------- //
/// Mark the start of a resolution caching scope.
///
/// Clients should generally use ArResolverScopedCache instead of calling
/// this function directly.
///
/// Resolvers may fill \p cacheScopeData with arbitrary data. Clients may
/// also pass in a \p cacheScopeData populated by an earlier call to
/// BeginCacheScope to allow the resolver access to that information.
///
/// \see ArResolverScopedCache
AR_API
virtual void BeginCacheScope(
VtValue* cacheScopeData) = 0;
/// Mark the end of a resolution caching scope.
///
/// Clients should generally use ArResolverScopedCache instead of calling
/// this function directly.
///
/// \p cacheScopeData should contain the data that was populated by the
/// previous corresponding call to BeginCacheScope.
///
/// \see ArResolverScopedCache
AR_API
virtual void EndCacheScope(
VtValue* cacheScopeData) = 0;
/// @}
protected:
AR_API
ArResolver();
};
/// Returns the configured asset resolver.
///
/// When first called, this function will determine the ArResolver subclass
/// to use for asset resolution via the following process:
///
/// - If a preferred resolver has been set via \ref ArSetPreferredResolver,
/// it will be selected.
///
/// - Otherwise, a list of available ArResolver subclasses in plugins will
/// be generated. If multiple ArResolver subclasses are found, the list
/// will be sorted by typename. ArDefaultResolver will be added as the last
/// element of this list, and the first resolver in the list will be
/// selected.
///
/// - The plugin for the selected subclass will be loaded and an instance
/// of the subclass will be constructed.
///
/// - If an error occurs, an ArDefaultResolver will be constructed.
///
/// The constructed ArResolver subclass will be cached and used to service
/// function calls made on the returned resolver.
///
/// Note that this function may not return the constructed subclass itself,
/// meaning that dynamic casts to the subclass type may fail. See
/// ArGetUnderlyingResolver if access to this object is needed.
AR_API
ArResolver& ArGetResolver();
/// Set the preferred ArResolver subclass used by ArGetResolver.
///
/// Consumers may override ArGetResolver's plugin resolver discovery and
/// force the use of a specific resolver subclass by calling this
/// function with the typename of the implementation to use.
///
/// If the subclass specified by \p resolverTypeName cannot be found,
/// ArGetResolver will issue a warning and fall back to using
/// ArDefaultResolver.
///
/// This must be called before the first call to ArGetResolver.
AR_API
void ArSetPreferredResolver(const std::string& resolverTypeName);
/// \name Advanced API
///
/// \warning These functions should typically not be used by consumers except
/// in very specific cases. Consumers who want to retrieve an ArResolver to
/// perform asset resolution should use \ref ArGetResolver.
///
/// @{
/// Returns the underlying ArResolver instance used by ArGetResolver.
///
/// This function returns the instance of the ArResolver subclass used by
/// ArGetResolver and can be dynamic_cast to that type.
///
/// \warning This functions should typically not be used by consumers except
/// in very specific cases. Consumers who want to retrieve an ArResolver to
/// perform asset resolution should use \ref ArGetResolver.
AR_API
ArResolver& ArGetUnderlyingResolver();
/// Returns list of TfTypes for available ArResolver subclasses.
///
/// This function returns the list of ArResolver subclasses used to determine
/// the resolver implementation returned by \ref ArGetResolver. See
/// documentation on that function for more details.
///
/// If this function is called from within a call (or calls) to
/// \ref ArCreateResolver, the ArResolver subclass(es) being created will
/// be removed from the returned list.
///
/// This function is not safe to call concurrently with itself or
/// \ref ArCreateResolver.
///
/// \warning This functions should typically not be used by consumers except
/// in very specific cases. Consumers who want to retrieve an ArResolver to
/// perform asset resolution should use \ref ArGetResolver.
AR_API
std::vector<TfType> ArGetAvailableResolvers();
/// Construct an instance of the ArResolver subclass specified by
/// \p resolverType.
///
/// This function will load the plugin for the given \p resolverType and
/// construct and return a new instance of the specified ArResolver subclass.
/// If an error occurs, coding errors will be emitted and this function
/// will return an ArDefaultResolver instance.
///
/// Note that this function *does not* change the resolver used by
/// \ref ArGetResolver to an instance of \p resolverType.
///
/// This function is not safe to call concurrently with itself or
/// \ref ArGetAvailableResolvers.
///
/// \warning This functions should typically not be used by consumers except
/// in very specific cases. Consumers who want to retrieve an ArResolver to
/// perform asset resolution should use \ref ArGetResolver.
AR_API
std::unique_ptr<ArResolver> ArCreateResolver(const TfType& resolverType);
/// @}
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+121
View File
@@ -0,0 +1,121 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_AR_THREAD_LOCAL_SCOPED_CACHE_H
#define PXR_USD_AR_THREAD_LOCAL_SCOPED_CACHE_H
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include "pxr/base/vt/value.h"
#include "pxr/base/tf/diagnostic.h"
#include <tbb/enumerable_thread_specific.h>
#include <memory>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
/// \class ArThreadLocalScopedCache
///
/// Utility class for custom resolver implementations. This class wraps up
/// a common pattern for implementing thread-local scoped caches for
/// ArResolver::BeginCacheScope and ArResolver::EndCacheScope.
///
/// \code{.cpp}
/// class MyResolver : public ArResolver {
/// using ResolveCache = ArThreadLocalScopedCache<...>;
/// ResolveCache _cache;
///
/// void BeginCacheScope(VtValue* data) { _cache.BeginCacheScope(data); }
/// void EndCacheScope(VtValue* data) { _cache.EndCacheScope(data); }
/// void Resolve(...) {
/// // If caching is active in this thread, retrieve the current
/// // cache and use it to lookup/store values.
/// if (ResolveCache::CachePtr cache = _cache.GetCurrentCache()) {
/// // ...
/// }
/// // Otherwise, caching is not active
/// // ...
/// }
/// };
/// \endcode
///
/// \see \ref ArResolver_scopedCache "Scoped Resolution Cache"
template <class CachedType>
class ArThreadLocalScopedCache
{
public:
using CachePtr = std::shared_ptr<CachedType>;
void BeginCacheScope(VtValue* cacheScopeData)
{
// Since this is intended to be used by ArResolver implementations,
// we expect cacheScopeData to never be NULL and to either be empty
// or holding a cache pointer that we've filled in previously.
if (!cacheScopeData ||
(!cacheScopeData->IsEmpty() &&
!cacheScopeData->IsHolding<CachePtr>())) {
TF_CODING_ERROR("Unexpected cache scope data");
return;
}
_CachePtrStack& cacheStack = _threadCacheStack.local();
if (cacheScopeData->IsHolding<CachePtr>()) {
cacheStack.push_back(cacheScopeData->UncheckedGet<CachePtr>());
}
else {
if (cacheStack.empty()) {
cacheStack.push_back(std::make_shared<CachedType>());
}
else {
cacheStack.push_back(cacheStack.back());
}
}
*cacheScopeData = cacheStack.back();
}
void EndCacheScope(VtValue* cacheScopeData)
{
_CachePtrStack& cacheStack = _threadCacheStack.local();
if (TF_VERIFY(!cacheStack.empty())) {
cacheStack.pop_back();
}
}
CachePtr GetCurrentCache()
{
_CachePtrStack& cacheStack = _threadCacheStack.local();
return (cacheStack.empty() ? CachePtr() : cacheStack.back());
}
private:
using _CachePtrStack = std::vector<CachePtr>;
using _ThreadLocalCachePtrStack =
tbb::enumerable_thread_specific<_CachePtrStack>;
_ThreadLocalCachePtrStack _threadCacheStack;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_AR_THREAD_LOCAL_SCOPED_CACHE_H