add usd-21-11-win64_py39

This commit is contained in:
Sébastien Albert committed 2021-12-07 17:43:55 +01:00
1 parent 41d23e71ba
commit ba5e1f7e67
15684 files changed
+3069957

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 2
#endif
+44
View File
@@ -0,0 +1,44 @@
//
// 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/ar.h"
#define INCLUDE_AR_ASSET
#if AR_VERSION == 1
#include "pxr/usd/ar/asset_v1.h"
#elif AR_VERSION == 2
#include "pxr/usd/ar/asset_v2.h"
#else
#error Unhandled AR_VERSION
#endif
#undef INCLUDE_AR_ASSET
#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
+105
View File
@@ -0,0 +1,105 @@
//
// 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 INCLUDE_AR_ASSET
#error This file should not be included directly. Include asset.h instead.
#endif
#ifndef PXR_USD_AR_ASSET_V2_H
#define PXR_USD_AR_ASSET_V2_H
/// \file ar/asset_v2.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() const = 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() const = 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) const = 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() const = 0;
protected:
AR_API
ArAsset();
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_AR_ASSET_V2_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
+156
View File
@@ -0,0 +1,156 @@
//
// 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_V2_H
#define PXR_USD_AR_DEFAULT_RESOLVER_V2_H
/// \file ar/defaultResolver_v2.h
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include "pxr/usd/ar/defaultResolverContext.h"
#include "pxr/usd/ar/resolvedPath.h"
#include "pxr/usd/ar/resolver.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.
///
/// ArDefaultResolver supports creating an ArDefaultResolverContext via
/// ArResolver::CreateContextFromString by passing 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);
protected:
AR_API
std::string _CreateIdentifier(
const std::string& assetPath,
const ArResolvedPath& anchorAssetPath) const override;
AR_API
std::string _CreateIdentifierForNewAsset(
const std::string& assetPath,
const ArResolvedPath& anchorAssetPath) const override;
AR_API
ArResolvedPath _Resolve(
const std::string& assetPath) const override;
AR_API
ArResolvedPath _ResolveForNewAsset(
const std::string& assetPath) const override;
AR_API
ArResolverContext _CreateDefaultContext() const override;
/// Creates a context that adds the directory containing \p assetPath
/// as a first directory to be searched, when the resulting context is
/// bound (\see ArResolverContextBinder).
///
/// If \p assetPath is empty, returns an empty context; otherwise, if
/// \p assetPath is not an absolute filesystem path, it will first be
/// anchored to the process's current working directory.
AR_API
ArResolverContext _CreateDefaultContextForAsset(
const std::string& assetPath) const override;
/// Creates an ArDefaultResolverContext from \p contextStr. This
/// string is expected to be a list of directories delimited by
/// the platform's standard path separator.
AR_API
ArResolverContext _CreateContextFromString(
const std::string& contextStr) const override;
AR_API
bool _IsContextDependentPath(
const std::string& assetPath) const override;
AR_API
ArTimestamp _GetModificationTimestamp(
const std::string& path,
const ArResolvedPath& resolvedPath) const override;
AR_API
std::shared_ptr<ArAsset> _OpenAsset(
const ArResolvedPath& resolvedPath) const override;
/// Creates an ArFilesystemWriteableAsset for the asset at the
/// given \p resolvedPath.
AR_API
std::shared_ptr<ArWritableAsset> _OpenAssetForWrite(
const ArResolvedPath& resolvedPath,
WriteMode writeMode) const override;
private:
const ArDefaultResolverContext* _GetCurrentContextPtr() const;
ArDefaultResolverContext _fallbackContext;
ArResolverContext _defaultContext;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_AR_DEFAULT_RESOLVER_H
@@ -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
+43
View File
@@ -0,0 +1,43 @@
//
// 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/ar.h"
#define INCLUDE_AR_FILESYSTEM_ASSET
#if AR_VERSION == 1
#include "pxr/usd/ar/filesystemAsset_v1.h"
#elif AR_VERSION == 2
#include "pxr/usd/ar/filesystemAsset_v2.h"
#else
#error Unhandled AR_VERSION
#endif
#undef INCLUDE_AR_FILESYSTEM_ASSET
#endif // PXR_USD_AR_FILESYSTEM_ASSET_H
+101
View File
@@ -0,0 +1,101 @@
//
// Copyright 2021 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_FILESYSTEM_ASSET
#error This file should not be included directly. Include filesystemAsset.h instead.
#endif
#ifndef PXR_USD_AR_FILESYSTEM_ASSET_V2_H
#define PXR_USD_AR_FILESYSTEM_ASSET_V2_H
/// \file ar/filesystemAsset_v2.h
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include "pxr/usd/ar/asset.h"
#include "pxr/usd/ar/timestamp.h"
#include <cstdio>
#include <memory>
#include <utility>
PXR_NAMESPACE_OPEN_SCOPE
class ArResolvedPath;
/// \class ArFilesystemAsset
///
/// ArAsset implementation for asset represented by a file on a filesystem.
class ArFilesystemAsset
: public ArAsset
{
public:
/// Constructs a new ArFilesystemAsset for the file at \p resolvedPath.
/// Returns a null pointer if the file could not be opened.
AR_API
static std::shared_ptr<ArFilesystemAsset> Open(
const ArResolvedPath& resolvedPath);
/// Returns an ArTimestamp holding the mtime of the file at \p resolvedPath.
/// Returns an invalid ArTimestamp if the mtime could not be retrieved.
AR_API
static ArTimestamp GetModificationTimestamp(
const ArResolvedPath& resolvedPath);
/// 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() const 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() const 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) const 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() const override;
private:
FILE* _file;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_AR_FILESYSTEM_ASSET_V2_H
@@ -0,0 +1,85 @@
//
// 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_FILESYSTEM_WRITABLE_ASSET_H
#define PXR_USD_AR_FILESYSTEM_WRITABLE_ASSET_H
/// \file ar/filesystemWritableAsset.h
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include "pxr/usd/ar/resolver.h"
#include "pxr/usd/ar/writableAsset.h"
#include "pxr/base/tf/safeOutputFile.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \class ArFilesystemWritableAsset
///
/// ArWritableAsset implementation for asset represented by a file on a
/// filesystem.
///
/// This implementation uses TfSafeOutputFile; in the case where the asset
/// has been opened for replacement, data will be written to a temporary
/// file which will be renamed over the destination file when this object
/// is destroyed. See documentation for TfSafeOutputFile for more details.
class ArFilesystemWritableAsset
: public ArWritableAsset
{
public:
/// Constructs a new ArFilesystemWritableAsset for the file at
/// \p resolvedPath with the given \p writeMode. Returns a null pointer
/// if the file could not be opened.
AR_API
static std::shared_ptr<ArFilesystemWritableAsset> Create(
const ArResolvedPath& resolvedPath,
ArResolver::WriteMode writeMode);
/// Constructs an ArFilesystemWritableAsset for the given \p file.
/// The ArFilesystemWritableAsset takes ownership of \p file.
AR_API
explicit ArFilesystemWritableAsset(TfSafeOutputFile&& file);
AR_API
virtual ~ArFilesystemWritableAsset();
/// Closes the file owned by this asset. If the TfSafeOutputFile was
/// opened for replacement, the temporary file that was being written
/// to be will be renamed over the destination file.
AR_API
virtual bool Close() override;
/// Writes \p count bytes from \p buffer at \p offset from the beginning
/// of the file held by this object. Returns number of bytes written, or
/// 0 on error.
AR_API
virtual size_t Write(
const void* buffer, size_t count, size_t offset) override;
private:
TfSafeOutputFile _file;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+118
View File
@@ -0,0 +1,118 @@
//
// Copyright 2021 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_NOTICE_H
#define PXR_USD_AR_NOTICE_H
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include "pxr/usd/ar/resolverContext.h"
#include "pxr/base/tf/notice.h"
#include <functional>
PXR_NAMESPACE_OPEN_SCOPE
template <class ContextObj>
bool Ar_ContextIsHolding(
const ContextObj& contextObj, const ArResolverContext& ctx)
{
const ContextObj* testObj = ctx.Get<ContextObj>();
return testObj && *testObj == contextObj;
}
/// \class ArNotice
///
class ArNotice
{
public:
/// \class ResolverNotice
/// Base class for all ArResolver-related notices.
class ResolverNotice
: public TfNotice
{
public:
AR_API virtual ~ResolverNotice();
protected:
AR_API ResolverNotice();
};
/// \class ResolverChanged
/// Notice sent when asset paths may resolve to a different path than
/// before due to a change in the resolver.
class ResolverChanged
: public ResolverNotice
{
public:
/// Create a notice indicating that the results of asset resolution
/// might have changed, regardless of what ArResolverContext object
/// is bound.
AR_API
ResolverChanged();
/// Create a notice using \p affectsFn to determine the
/// ArResolverContext objects that are affected by this resolver
/// change. If \p affectsFn returns true, it means the results of asset
/// resolution when the given ArResolverContext is bound might have
/// changed.
AR_API
ResolverChanged(
const std::function<bool(const ArResolverContext&)>& affectsFn);
/// Create a notice indicating that the results of asset resolution when
/// any ArResolverContext containing \p contextObj is bound might have
/// changed.
template <
class ContextObj,
typename std::enable_if<ArIsContextObject<ContextObj>::value>::type*
= nullptr>
ResolverChanged(
const ContextObj& contextObj)
// XXX: Ideally this would just use a lambda and forward it to
// the other c'tor. Both of those cause issues in MSVC 2015; the
// first causes an unspecified type error and the second causes
// odd linker errors.
: _affects(std::bind(&Ar_ContextIsHolding<ContextObj>, contextObj,
std::placeholders::_1))
{
}
AR_API
virtual ~ResolverChanged();
/// Returns true if the results of asset resolution when \p ctx
/// is bound may be affected by this resolver change.
AR_API
bool AffectsContext(const ArResolverContext& ctx) const;
private:
std::function<bool(const ArResolverContext&)> _affects;
};
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+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
+63
View File
@@ -0,0 +1,63 @@
//
// 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_V2_H
#define PXR_USD_AR_PY_RESOLVER_CONTEXT_V2_H
/// \file ar/pyResolverContext_v2.h
/// Macros for creating Python bindings for objects used with
/// ArResolverContext.
#include <boost/python/implicit.hpp>
#include "pxr/pxr.h"
#include "pxr/usd/ar/resolverContext.h"
PXR_NAMESPACE_OPEN_SCOPE
/// Register the specified type as a context object that may be converted from
/// Python into a ArResolverContext object in C++. 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
template <class Context>
void
ArWrapResolverContextForPython()
{
boost::python::implicitly_convertible<Context, ArResolverContext>();
};
#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
+350
View File
@@ -0,0 +1,350 @@
//
// 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_V2_H
#define PXR_USD_AR_RESOLVER_CONTEXT_V2_H
/// \file ar/resolverContext_v2.h
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include "pxr/base/tf/hash.h"
#include "pxr/base/tf/safeTypeCompare.h"
#ifdef PXR_PYTHON_SUPPORT_ENABLED
// XXX: This include is a hack to avoid build errors due to
// incompatible macro definitions in pyport.h on macOS.
#include <locale>
#include "pxr/base/tf/pyLock.h"
#include "pxr/base/tf/pyObjWrapper.h"
#endif
#include <algorithm>
#include <memory>
#include <string>
#include <type_traits>
#include <typeinfo>
#include <vector>
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);
// Metafunctions for determining if a variadic list of objects
// are valid for use with the ArResolverContext c'tor.
class ArResolverContext;
template <class ...Objects> struct Ar_AllValidForContext;
template <class Object, class ...Other>
struct Ar_AllValidForContext<Object, Other...>
{
static const bool value =
(std::is_same<Object, ArResolverContext>::value ||
ArIsContextObject<Object>::value) &&
Ar_AllValidForContext<Other...>::value;
};
template <>
struct Ar_AllValidForContext<>
{
static const bool value = true;
};
/// \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 context objects of their own (subject to restrictions below).
/// An ArResolverContext is simply a wrapper around these objects that
/// allows it to be treated as a single type. Note that an ArResolverContext
/// may not hold multiple context objects with the same 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 given objects \p objs.
///
/// Each argument must either be an ArResolverContext or a registered
/// context object. See class documentation for requirements on context
/// objects.
///
/// If an argument is a context object, it will be added to the
/// constructed ArResolverContext. If an argument is an ArResolverContext,
/// all of the context objects it holds will be added to the constructed
/// ArResolverContext.
///
/// Arguments are ordered from strong-to-weak. If a context object is
/// encountered with the same type as a previously-added object, the
/// previously-added object will remain and the other context object
/// will be ignored.
template <
class ...Objects,
typename std::enable_if<Ar_AllValidForContext<Objects...>::value>::type*
= nullptr>
ArResolverContext(const Objects&... objs)
{
_AddObjects(objs...);
}
/// Construct a resolver context using the ArResolverContexts in \p ctxs.
///
/// All of the context objects held by each ArResolverContext in \p ctxs
/// will be added to the constructed ArResolverContext.
///
/// Arguments are ordered from strong-to-weak. If a context object is
/// encountered with the same type as a previously-added object, the
/// previously-added object will remain and the other context object
/// will be ignored.
AR_API
explicit ArResolverContext(const std::vector<ArResolverContext>& ctxs);
/// Returns whether this resolver context is empty.
bool IsEmpty() const
{
return _contexts.empty();
}
/// Returns pointer to the context object of the given type
/// held in this resolver context. Returns NULL if this resolver
/// context is not holding an object of the requested type.
template <class ContextObj>
const ContextObj* Get() const
{
for (const auto& context : _contexts) {
if (context->IsHolding(typeid(ContextObj))) {
return &_GetTyped<ContextObj>(*context)._context;
}
}
return nullptr;
}
/// Returns a debug string representing the contained context objects.
AR_API
std::string GetDebugString() const;
/// \name Operators
/// @{
AR_API
bool operator==(const ArResolverContext& rhs) const;
bool operator!=(const ArResolverContext& rhs) const
{
return !(*this == rhs);
}
AR_API
bool operator<(const ArResolverContext& rhs) const;
/// @}
/// Returns hash value for this asset resolver context.
friend size_t hash_value(const ArResolverContext& context)
{
return TfHash()(context._contexts);
}
private:
// Type-erased storage for context objects.
struct _Untyped;
template <class Context> struct _Typed;
void _AddObjects()
{
// Empty base case for unpacking parameter pack
}
template <class Object, class ...Other>
void _AddObjects(const Object& obj, const Other&... other)
{
_Add(obj);
_AddObjects(other...);
}
AR_API
void _Add(const ArResolverContext& ctx);
template <class Object>
void _Add(const Object& obj)
{
_Add(std::shared_ptr<_Untyped>(new _Typed<Object>(obj)));
}
AR_API
void _Add(std::shared_ptr<_Untyped>&& context);
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 _Untyped* Clone() const = 0;
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;
#ifdef PXR_PYTHON_SUPPORT_ENABLED
virtual TfPyObjWrapper GetPythonObj() const = 0;
#endif
};
template <class Context>
struct _Typed : public _Untyped
{
virtual ~_Typed() { }
_Typed(const Context& context) : _context(context)
{
}
virtual _Untyped* Clone() const
{
return new _Typed<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);
}
#ifdef PXR_PYTHON_SUPPORT_ENABLED
virtual TfPyObjWrapper GetPythonObj() const
{
TfPyLock lock;
return boost::python::object(_context);
}
#endif
Context _context;
};
template <class HashState>
friend void TfHashAppend(
HashState& h, const std::shared_ptr<_Untyped>& context)
{
h.Append(context->Hash());
}
#ifdef PXR_PYTHON_SUPPORT_ENABLED
friend class Ar_ResolverContextPythonAccess;
#endif
std::vector<std::shared_ptr<_Untyped>> _contexts;
};
// 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
+956
View File
@@ -0,0 +1,956 @@
//
// 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_V2_H
#define PXR_USD_AR_RESOLVER_V2_H
/// \file ar/resolver_v2.h
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include "pxr/usd/ar/resolvedPath.h"
#include "pxr/usd/ar/resolverContext.h"
#include "pxr/usd/ar/timestamp.h"
#include <memory>
#include <string>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
class ArAsset;
class ArAssetInfo;
class ArResolverContext;
class ArWritableAsset;
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_identifier
/// \name Identifiers
///
/// Identifiers are canonicalized asset paths that may be assigned
/// to a logical asset to facilitate comparisons and lookups. They
/// may be used to determine if different asset paths might refer to
/// the same asset without performing resolution.
///
/// Since identifiers are just a form of asset path, they may be used
/// with other functions on ArResolver that require an asset path, like
/// Resolve.
///
/// If two asset paths produce the same identifier, those asset paths
/// must refer to the same asset. However, in some cases comparing
/// identifiers may not be sufficient to determine if assets are equal.
/// For example, there could be two assets with the same identifier
/// but whose contents were read from different resolved paths because
/// different resolver contexts were bound when those assets were loaded.
///
/// @{
// --------------------------------------------------------------------- //
/// Returns an identifier for the asset specified by \p assetPath.
/// If \p anchorAssetPath is not empty, it is the resolved asset path
/// that \p assetPath should be anchored to if it is a relative path.
AR_API
std::string CreateIdentifier(
const std::string& assetPath,
const ArResolvedPath& anchorAssetPath = ArResolvedPath()) const;
/// Returns an identifier for a new asset specified by \p assetPath.
/// If \p anchorAssetPath is not empty, it is the resolved asset path
/// that \p assetPath should be anchored to if it is a relative path.
AR_API
std::string CreateIdentifierForNewAsset(
const std::string& assetPath,
const ArResolvedPath& anchorAssetPath = ArResolvedPath()) const;
/// @}
// --------------------------------------------------------------------- //
/// \anchor ArResolver_resolution
/// \name Path Resolution Operations
///
/// @{
// --------------------------------------------------------------------- //
/// Returns the resolved path for the asset identified by the given \p
/// assetPath if it exists. If the asset does not exist, returns an empty
/// ArResolvedPath.
AR_API
ArResolvedPath Resolve(
const std::string& assetPath) const;
/// Returns the resolved path for the given \p assetPath that may be used
/// to create a new asset. If such a path cannot be computed for
/// \p assetPath, returns an empty ArResolvedPath.
///
/// Note that an asset might or might not already exist at the returned
/// resolved path.
AR_API
ArResolvedPath ResolveForNewAsset(
const std::string& assetPath) const;
/// @}
// --------------------------------------------------------------------- //
/// \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
void BindContext(
const ArResolverContext& context,
VtValue* bindingData);
/// Unbind the given context from this resolver.
///
/// Clients should generally use ArResolverContextBinder instead of calling
/// this function directly.
///
/// \see ArResolverContextBinder
AR_API
void UnbindContext(
const ArResolverContext& context,
VtValue* bindingData);
/// Return an ArResolverContext that may be bound to this resolver
/// to resolve assets when no other context is explicitly specified.
///
/// The returned ArResolverContext will contain the default context
/// returned by the primary resolver and all URI resolvers.
AR_API
ArResolverContext CreateDefaultContext() const;
/// Return an ArResolverContext that may be bound to this resolver
/// to resolve the asset located at \p assetPath or referenced by
/// that asset when no other context is explicitly specified.
///
/// The returned ArResolverContext will contain the default context
/// for \p assetPath returned by the primary resolver and all URI resolvers.
AR_API
ArResolverContext CreateDefaultContextForAsset(
const std::string& assetPath) const;
/// Return an ArResolverContext created from the primary ArResolver
/// implementation using the given \p contextStr.
AR_API
ArResolverContext CreateContextFromString(
const std::string& contextStr) const;
/// Return an ArResolverContext created from the ArResolver registered
/// for the given \p uriScheme using the given \p contextStr.
///
/// An empty \p uriScheme indicates the primary resolver and is
/// equivalent to CreateContextFromString(string).
///
/// If no resolver is registered for \p uriScheme, returns an empty
/// ArResolverContext.
AR_API
ArResolverContext CreateContextFromString(
const std::string& uriScheme, const std::string& contextStr) const;
/// Return an ArResolverContext created by combining the ArResolverContext
/// objects created from the given \p contextStrs.
///
/// \p contextStrs is a list of pairs of strings. The first element in the
/// pair is the URI scheme for the ArResolver that will be used to create
/// the ArResolverContext from the second element in the pair. An empty
/// URI scheme indicates the primary resolver.
///
/// For example:
///
/// \code
/// ArResolverContext ctx = ArGetResolver().CreateContextFromStrings(
/// { {"", "context str 1"},
/// {"my_scheme", "context str 2"} });
/// \endcode
///
/// This will use the primary resolver to create an ArResolverContext
/// using the string "context str 1" and use the resolver registered for
/// the "my_scheme" URI scheme to create an ArResolverContext using
/// "context str 2". These contexts will be combined into a single
/// ArResolverContext and returned.
///
/// If no resolver is registered for a URI scheme in an entry in
/// \p contextStrs, that entry will be ignored.
AR_API
ArResolverContext CreateContextFromStrings(
const std::vector<
std::pair<std::string, std::string>>& contextStrs) const;
/// Refresh any caches associated with the given context. If doing so
/// would invalidate asset paths that had previously been resolved,
/// an ArNotice::ResolverChanged notice will be sent to inform clients
/// of this.
AR_API
void RefreshContext(
const ArResolverContext& context);
/// Returns the asset resolver context currently bound in this thread.
///
/// \see ArResolver::BindContext, ArResolver::UnbindContext
AR_API
ArResolverContext GetCurrentContext() const;
/// Returns true if \p assetPath is a context-dependent path, false
/// otherwise.
///
/// A context-dependent path may result in different resolved paths
/// depending on what asset resolver context is bound when Resolve
/// is called. Assets located at the same context-dependent path may not
/// be the same since those assets may have been loaded from different
/// resolved paths. In this case, the assets' resolved paths must be
/// consulted to determine if they are the same.
AR_API
bool IsContextDependentPath(
const std::string& assetPath) const;
/// @}
// --------------------------------------------------------------------- //
/// \anchor ArResolver_files
/// \name File/asset-specific Operations
///
/// @{
// --------------------------------------------------------------------- //
/// Returns the file extension for the given \p assetPath. The returned
/// extension does not include a "." at the beginning.
AR_API
std::string GetExtension(
const std::string& assetPath) const;
/// Returns an ArAssetInfo populated with additional metadata (if any)
/// about the asset at the given \p assetPath. \p resolvedPath is the
/// resolved path computed for the given \p assetPath.
AR_API
ArAssetInfo GetAssetInfo(
const std::string& assetPath,
const ArResolvedPath& resolvedPath) const;
/// Returns an ArTimestamp representing the last time the asset at
/// \p assetPath was modified. \p resolvedPath is the resolved path
/// computed for the given \p assetPath. If a timestamp cannot be
/// retrieved, return an invalid ArTimestamp.
AR_API
ArTimestamp GetModificationTimestamp(
const std::string& assetPath,
const ArResolvedPath& resolvedPath) const;
/// 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.
AR_API
std::shared_ptr<ArAsset> OpenAsset(
const ArResolvedPath& resolvedPath) const;
/// Enumeration of write modes for OpenAssetForWrite
enum class WriteMode
{
/// Open asset for in-place updates. If the asset exists, its contents
/// will not be discarded and writes may overwrite existing data.
/// Otherwise, the asset will be created.
Update = 0,
/// Open asset for replacement. If the asset exists, its contents will
/// be discarded by the time the ArWritableAsset is destroyed.
/// Otherwise, the asset will be created.
Replace
};
/// Returns an ArWritableAsset object for the asset located at \p
/// resolvedPath using the specified \p writeMode. Returns an invalid
/// std::shared_ptr if object could not be created.
///
/// The returned ArWritableAsset object provides functions for writing data
/// to the specified asset.
///
/// Note that support for reading an asset through other APIs while it
/// is open for write is implementation-specific. For example, writes to
/// an asset may or may not be immediately visible to other threads or
/// processes depending on the implementation.
AR_API
std::shared_ptr<ArWritableAsset> OpenAssetForWrite(
const ArResolvedPath& resolvedPath,
WriteMode writeMode) const;
/// Returns true if an asset may be written to the given \p resolvedPath,
/// false otherwise. If this function returns false and \p whyNot is not
/// \c nullptr, it may be filled with an explanation.
AR_API
bool CanWriteAssetToPath(
const ArResolvedPath& resolvedPath,
std::string* whyNot = nullptr) const;
/// @}
// --------------------------------------------------------------------- //
/// \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
void BeginCacheScope(
VtValue* cacheScopeData);
/// 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
void EndCacheScope(
VtValue* cacheScopeData);
/// @}
// --------------------------------------------------------------------- //
/// \anchor ArResolver_deprecated
/// \name Deprecated APIs
///
/// The functions in this section are deprecated in Ar 2.0 and slated
/// for removal. Most have default implementations to allow subclasses
/// to ignore them completely.
///
/// @{
// --------------------------------------------------------------------- //
/// \deprecated
/// Returns true if the given path is a repository path.
AR_API
bool IsRepositoryPath(const std::string& path) const;
/// @}
protected:
AR_API
ArResolver();
// --------------------------------------------------------------------- //
/// \anchor ArResolver_implementation
/// \name Implementation
///
/// @{
/// Return an identifier for the asset at the given \p assetPath.
/// See \ref ArResolver_identifier "Identifiers" for more information.
///
/// If \p anchorAssetPath is non-empty, it should be used as the anchoring
/// asset if \p assetPath is relative. For example, for a filesystem-based
/// implementation _CreateIdentifier might return:
///
/// _CreateIdentifier(
/// /* assetPath = */ "/abs/path/to/model.usd",
/// /* anchorAssetPath = */ ArResolvedPath("/abs/path/to/shot.usd"))
/// => "/abs/path/to/model.usd"
///
/// _CreateIdentifier(
/// /* assetPath = */ "relative/model.usd",
/// /* anchorAssetPath = */ ArResolvedPath("/abs/path/to/shot.usd"))
/// => "/abs/path/to/relative/model.usd"
///
/// Identifiers may be compared to determine if given paths refer to the
/// same asset, so implementations should take care to canonicalize and
/// normalize the returned identifier to a consistent format.
///
/// If either \p assetPath or \p anchorAssetPath have a URI scheme, this
/// function will be called on the resolver associated with that URI scheme,
/// if any.
///
/// Example uses:
/// - When opening a layer via SdfLayer::FindOrOpen or Find,
/// CreateIdentifier will be called with the asset path given to those
/// functions and no anchoring asset path. The result will be used as the
/// layer's identifier.
///
/// - When processing composition arcs that refer to other layers, this
/// function will be called with the asset path of the referenced layer
/// and the resolved path of the layer where the composition arc was
/// authored. The result will be passed to SdfLayer::FindOrOpen to
/// open the referenced layer.
virtual std::string _CreateIdentifier(
const std::string& assetPath,
const ArResolvedPath& anchorAssetPath) const = 0;
/// Return an identifier for a new asset at the given \p assetPath.
///
/// This is similar to _CreateIdentifier but is used to create identifiers
/// for assets that may not exist yet and are being created.
///
/// Example uses:
/// - When creating a new layer via SdfLayer::CreateNew,
/// CreateIdentifierForNewAsset will be called with the asset path given
/// to the function. The result will be used as the new layer's
/// identifier.
virtual std::string _CreateIdentifierForNewAsset(
const std::string& assetPath,
const ArResolvedPath& anchorAssetPath) const = 0;
/// Return the resolved path for the given \p assetPath or an empty
/// ArResolvedPath if no asset exists at that path.
virtual ArResolvedPath _Resolve(
const std::string& assetPath) const = 0;
/// Return the resolved path for the given \p assetPath that may be used
/// to create a new asset or an empty ArResolvedPath if such a path cannot
/// be computed.
virtual ArResolvedPath _ResolveForNewAsset(
const std::string& assetPath) const = 0;
/// @}
// --------------------------------------------------------------------- //
/// \anchor ArResolver_contextImplementation
/// \name Context Operations Implementation
///
/// If any of these functions are implemented in a subclass, the plugin
/// metadata for that subclass in the plugin library's plugInfo.json
/// must specify:
/// \code
/// "implementsContexts" : true.
/// \endcode
///
/// If a subclass indicates that it implements any of these functions,
/// its plugin library will be loaded and these functions will be called
/// when the corresponding public ArResolver API is called. Otherwise,
/// these functions will not be called.
///
/// @{
/// Bind the given \p context to this resolver. \p bindingData may be
/// populated with additional information that will be kept alive while
/// \p context is bound. Both \p context and \p bindingData will be
/// passed to UnbindContext when the context is being unbound.
///
/// Contexts may be nested; if multiple contexts are bound, the context
/// that was most recently bound must take precedence and block all
/// previously bound contexts.
///
/// Context binding is thread-specific; contexts bound in a thread must
/// only affect other resolver calls in the same thread.
///
/// ArResolver itself manages thread-local stacks of bound contexts.
/// Subclasses can retrieve the most recent context object which was passed
/// to BindContext using _GetCurrentContextObject. Because of this,
/// subclasses typically do not need to implement this function unless they
/// need to be informed when a context object is bound. For example, this
/// may be needed if the context needs to be passed on to another subsystem
/// that manages these bindings itself.
///
/// The default implementation does nothing.
AR_API
virtual void _BindContext(
const ArResolverContext& context,
VtValue* bindingData);
/// Unbind the given \p context from this resolver.
///
/// It is an error if the context being unbound is not the currently
/// bound context.
///
/// Subclasses typically do not need to implement this function since
/// ArResolver itself keeps track of the contexts that are bound via calls
/// to BindContext. However, subclasses may need to implement this function
/// if they are managing these bindings itself.
///
/// The default implementation does nothing.
AR_API
virtual void _UnbindContext(
const ArResolverContext& context,
VtValue* bindingData);
/// Return a default ArResolverContext that may be bound to this resolver
/// to resolve assets when no other context is explicitly specified.
///
/// When CreateDefaultContext is called on the configured asset resolver,
/// Ar will call this method on the primary resolver and all URI resolvers
/// and merge the results into a single ArResolverContext that will be
/// returned to the consumer.
///
/// This function should not automatically bind this context, but should
/// create one that may be used later.
///
/// The default implementation returns a default-constructed
/// ArResolverContext.
///
/// Example uses:
/// - UsdStage will call CreateDefaultContext when creating a new stage with
/// an anonymous root layer and without a given context. The returned
/// context will be bound when resolving asset paths on that stage.
AR_API
virtual ArResolverContext _CreateDefaultContext() const;
/// Return an ArResolverContext that may be bound to this resolver
/// to resolve the asset located at \p assetPath or referenced by
/// that asset when no other context is explicitly specified.
///
/// When CreateDefaultContextForAsset is called on the configured asset
/// resolver, Ar will call this method on the primary resolver and all URI
/// resolvers and merge the results into a single ArResolverContext that
/// will be returned to the consumer.
///
/// Note that this means this method may be called with asset paths that
/// are not associated with this resolver. For example, this method may
/// be called on a URI resolver with a non-URI asset path. This is to
/// support cases where the asset at \p assetPath references other
/// assets with URI schemes that differ from the URI scheme (if any)
/// in \p assetPath.
///
/// This function should not automatically bind this context, but should
/// create one that may be used later.
///
/// The default implementation returns a default-constructed
/// ArResolverContext.
///
/// Example uses:
/// - UsdStage will call CreateDefaultContextForAsset when creating a new
/// stage with a non-anonymous root layer and without a given context. The
/// resolved path of the root layer will be passed in as the
/// \p assetPath. The returned context will be bound when resolving asset
/// paths on that stage.
AR_API
virtual ArResolverContext _CreateDefaultContextForAsset(
const std::string& assetPath) const;
/// Return an ArResolverContext created from the given \p contextStr.
///
/// The default implementation returns a default-constructed
/// ArResolverContext.
AR_API
virtual ArResolverContext _CreateContextFromString(
const std::string& contextStr) const;
/// Refresh any caches associated with the given context. If doing so
/// would invalidate asset paths that had previously been resolved,
/// this function should send an ArNotice::ResolverChanged notice to
/// inform clients of this. See documentation on that class for more
/// details.
///
/// The default implementation does nothing.
AR_API
virtual void _RefreshContext(
const ArResolverContext& context);
/// Return the currently bound context. Since context binding is
/// thread-specific, this should return the context that was most recently
/// bound in this thread.
///
/// Subclasses typically do not need to implement this function since
/// ArResolver itself keeps track of the contexts that are bound via calls
/// to BindContext. However, if a subclass is managing bound contexts itself
/// and allows clients to bind context objects via other API outside of
/// BindContext, this function should return the context object as described
/// above. This typically happens with subclasses that are wrappers around
/// other resolution subsystems. \see _BindContext for more information.
///
/// The default implementation returns a default-constructed
/// ArResolverContext.
AR_API
virtual ArResolverContext _GetCurrentContext() const;
/// Return true if the result of resolving the given \p assetPath may
/// differ depending on the asset resolver context that is bound when
/// Resolve is called, false otherwise.
///
/// The default implementation returns false.
///
/// Example uses:
/// - SdfLayer will call this function to check if the identifier given
/// to SdfLayer::Find or SdfLayer::FindOrOpen is context-dependent.
/// If it is and a layer exists with the same identifier, SdfLayer
/// can return it without resolving the identifier. If it is not,
/// SdfLayer must resolve the identifier and search for a layer with
/// the same resolved path, even if a layer exists with the same
/// identifier.
AR_API
virtual bool _IsContextDependentPath(
const std::string& assetPath) const;
/// @}
// --------------------------------------------------------------------- //
/// \anchor ArResolver_assetImplementation
/// \name Asset Operations Implementation
///
/// @{
/// Return the file extension for the given \p assetPath. This extension
/// should not include a "." at the beginning of the string.
///
/// The default implementation returns the string after the last "."
/// in \p assetPath. If \p assetPath begins with a ".", the extension
/// will be empty unless there is another "." in the path. If
/// \p assetPath has components separated by '/' (or '\' on Windows),
/// only the last component will be considered.
AR_API
virtual std::string _GetExtension(
const std::string& assetPath) const;
/// Return an ArAssetInfo populated with additional metadata (if any)
/// about the asset at the given \p assetPath. \p resolvedPath is the
/// resolved path computed for the given \p assetPath.
/// The default implementation returns a default-constructed ArAssetInfo.
AR_API
virtual ArAssetInfo _GetAssetInfo(
const std::string& assetPath,
const ArResolvedPath& resolvedPath) const;
/// Return an ArTimestamp representing the last time the asset at
/// \p assetPath was modified. \p resolvedPath is the resolved path
/// computed for the given \p assetPath. If a timestamp cannot be
/// retrieved, return an invalid ArTimestamp.
///
/// The default implementation returns an invalid ArTimestamp.
///
/// Example uses:
/// - SdfLayer will call GetModificationTimestamp when opening a
/// layer and store the returned timestamp. When SdfLayer::Reload
/// is called on that layer, this method will be called again.
/// If the returned timestamp differs from the stored timestamp,
/// or if it is invalid, the layer will be reloaded.
AR_API
virtual ArTimestamp _GetModificationTimestamp(
const std::string& assetPath,
const ArResolvedPath& resolvedPath) const;
/// Return an ArAsset object for the asset located at \p resolvedPath.
/// Return an invalid std::shared_ptr if object could not be created
/// (for example, if the asset at the given path could not be opened).
///
/// Note that clients may still be using the data associated with
/// this object even after the last shared_ptr has been destroyed. For
/// example, a client may have created a memory mapping using the FILE*
/// presented in the ArAsset object; this would preclude truncating or
/// overwriting any of the contents of that file.
AR_API
virtual std::shared_ptr<ArAsset> _OpenAsset(
const ArResolvedPath& resolvedPath) const = 0;
/// Return true if an asset may be written to the given \p resolvedPath,
/// false otherwise. If this function returns false and \p whyNot is not
/// \c nullptr, it may be filled with an explanation. The default
/// implementation returns true.
AR_API
virtual bool _CanWriteAssetToPath(
const ArResolvedPath& resolvedPath,
std::string* whyNot) const;
/// Return an ArWritableAsset object for the asset at \p resolvedPath
/// using the specified \p writeMode. Return an invalid std::shared_ptr
/// if object could not be created (for example, if writing to the
/// given path is not allowed).
///
/// Implementations should create any parent paths that are necessary
/// to write this asset. The returned ArWritableAsset must obey the
/// behaviors for the given \p writeMode, see the documentation for
/// the WriteMode enum for more details.
AR_API
virtual std::shared_ptr<ArWritableAsset>
_OpenAssetForWrite(
const ArResolvedPath& resolvedPath,
WriteMode writeMode) const = 0;
/// @}
// --------------------------------------------------------------------- //
/// \anchor ArResolver_scopedCacheImplementation
/// \name Scoped Resolution Cache Implementation
///
/// If any of these functions are implemented in a subclass, the plugin
/// metadata for that subclass in the plugin library's plugInfo.json
/// must specify:
/// \code
/// "implementsScopedCaches" : true.
/// \endcode
///
/// If a subclass indicates that it implements these functions, ArResolver
/// will assume the subclass is handling all caching of resolved paths
/// and will call these functions when a caching scope is opened and closed.
/// Otherwise, these functions will not be called. Instead, ArResolver
/// itself will handle caching and returning resolved paths as needed.
///
/// @{
/// Mark the start of a resolution caching scope.
///
/// 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 \ref ArResolver_scopedCacheImplementation "Scoped Resolution Cache Implementation"
/// for more implementation details.
AR_API
virtual void _BeginCacheScope(
VtValue* cacheScopeData);
/// Mark the end of a resolution caching scope.
///
/// \p cacheScopeData should contain the data that was populated by the
/// previous corresponding call to BeginCacheScope.
///
/// See \ref ArResolver_scopedCacheImplementation "Scoped Resolution Cache Implementation"
/// for more implementation details.
AR_API
virtual void _EndCacheScope(
VtValue* cacheScopeData);
/// @}
/// \deprecated
/// Return true if the given path is a repository path, false otherwise.
/// Default implementation returns false.
AR_API
virtual bool _IsRepositoryPath(
const std::string& path) const;
// --------------------------------------------------------------------- //
/// \anchor ArResolver_implementationUtils
/// \name Implementation Utilities
///
/// Utility functions for implementations.
///
/// @{
/// Returns a pointer to the context object of type \p ContextObj from
/// the last ArResolverContext that was bound via a call to BindContext,
/// or \c NULL if no context object of that type exists.
///
/// Typically, a subclass might use this in their _Resolve function to
/// get the currently bound context to drive their resolution behavior.
///
/// \code
/// if (const MyContextObject* ctx =
/// _GetCurrentContextObject<MyContextObject>()) {
///
/// // Use information in ctx to resolve given path
/// }
/// else {
/// // Resolve given path with no context object
/// }
/// \endcode
///
/// This is the same as GetCurrentContext().Get<ContextObj>() but more
/// efficient, since it does not make a copy of the ArResolverContext.
/// However, it is *not* the same as _GetCurrentContext().Get<ContextObj>().
/// Subclasses that manage context binding themselves may have overridden
/// _GetCurrentContext to return a context that was bound without calling
/// BindContext. These subclasses should not use this function and should
/// retrieve the current context from their own internal data structures.
template <class ContextObj>
const ContextObj* _GetCurrentContextObject() const
{
const ArResolverContext* ctx = _GetInternallyManagedCurrentContext();
return ctx ? ctx->Get<ContextObj>() : nullptr;
}
/// @}
private:
// Returns pointer to ArResolverContext that was most recently bound
// via BindContext. This is *not* the same as GetCurrentContext,
// since subclasses may return an ArResolverContext that hasn't
// been bound via BindContext in their implementations.
AR_API
const ArResolverContext* _GetInternallyManagedCurrentContext() const;
};
/// 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
+129
View File
@@ -0,0 +1,129 @@
//
// Copyright 2021 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_TIMESTAMP_H
#define PXR_USD_AR_TIMESTAMP_H
/// \file ar/timestamp.h
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include "pxr/base/arch/hints.h"
#include "pxr/base/tf/hash.h"
#include <limits>
PXR_NAMESPACE_OPEN_SCOPE
/// \class ArTimestamp
/// Represents a timestamp for an asset. Timestamps are represented by
/// Unix time, the number of seconds elapsed since 00:00:00 UTC 1/1/1970.
class ArTimestamp
{
public:
/// Create an invalid timestamp.
ArTimestamp()
: _time(std::numeric_limits<double>::quiet_NaN())
{
}
/// Create a timestamp at \p time, which must be a Unix time value.
explicit ArTimestamp(double time)
: _time(time)
{
}
/// Return true if this timestamp is valid, false otherwise.
bool IsValid() const
{
return !std::isnan(_time);
}
/// Return the time represented by this timestamp as a double.
/// If this timestamp is invalid, issue a coding error and
/// return a quiet NaN value.
double GetTime() const
{
if (ARCH_UNLIKELY(!IsValid())) {
_IssueInvalidGetTimeError();
}
return _time;
}
/// Comparison operators
/// Note that invalid timestamps are considered less than all
/// other timestamps.
/// @{
friend bool operator==(const ArTimestamp& lhs, const ArTimestamp& rhs)
{
return (!lhs.IsValid() && !rhs.IsValid()) ||
(lhs.IsValid() && rhs.IsValid() && lhs._time == rhs._time);
}
friend bool operator!=(const ArTimestamp& lhs, const ArTimestamp& rhs)
{
return !(lhs == rhs);
}
friend bool operator<(const ArTimestamp& lhs, const ArTimestamp& rhs)
{
return (!lhs.IsValid() && rhs.IsValid()) ||
(lhs.IsValid() && rhs.IsValid() && lhs._time < rhs._time);
}
friend bool operator>=(const ArTimestamp& lhs, const ArTimestamp& rhs)
{
return !(lhs < rhs);
}
friend bool operator<=(const ArTimestamp& lhs, const ArTimestamp& rhs)
{
return !lhs.IsValid() || (rhs.IsValid() && lhs._time <= rhs._time);
}
friend bool operator>(const ArTimestamp& lhs, const ArTimestamp& rhs)
{
return !(lhs <= rhs);
}
/// @}
private:
AR_API
void _IssueInvalidGetTimeError() const;
// TfHash support.
template <class HashState>
friend void TfHashAppend(HashState& h, const ArTimestamp& t)
{
h.Append(t._time);
}
double _time;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+72
View File
@@ -0,0 +1,72 @@
//
// 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_WRITABLE_ASSET_H
#define PXR_USD_AR_WRITABLE_ASSET_H
/// \file ar/writableAsset.h
#include "pxr/pxr.h"
#include "pxr/usd/ar/api.h"
#include <cstdio>
PXR_NAMESPACE_OPEN_SCOPE
/// \class ArWritableAsset
///
/// Interface for writing data to an asset.
///
/// \see ArResolver::OpenAssetForWrite for how to retrieve instances of
/// this object.
class ArWritableAsset
{
public:
AR_API
virtual ~ArWritableAsset();
ArWritableAsset(const ArWritableAsset&) = delete;
ArWritableAsset& operator=(const ArWritableAsset&) = delete;
/// Close this asset, performing any necessary finalization or commits
/// of data that was previously written. Returns true on success, false
/// otherwise.
///
/// If successful, reads to the written asset in the same process should
/// reflect the fully written state by the time this function returns.
/// Also, further calls to any functions on this interface are invalid.
virtual bool Close() = 0;
/// Writes \p count bytes from \p buffer at \p offset from the beginning
/// of the asset. Returns number of bytes written, or 0 on error.
virtual size_t Write(const void* buffer, size_t count, size_t offset) = 0;
protected:
AR_API
ArWritableAsset();
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif