add usd-21-05-win64_py37
This commit is contained in:
1 parent
41d23e71ba
commit
66bc054336
15675 files changed
+3061008
No files matched your search
@@ -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
|
||||
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// Copyright 2020 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_USD_AR_AR_H
|
||||
#define PXR_USD_AR_AR_H
|
||||
|
||||
#define AR_VERSION 1
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,102 @@
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_USD_AR_ASSET_H
|
||||
#define PXR_USD_AR_ASSET_H
|
||||
|
||||
/// \file ar/asset.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/ar/api.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class ArAsset
|
||||
///
|
||||
/// Interface for accessing the contents of an asset.
|
||||
///
|
||||
/// \see ArResolver::OpenAsset for how to retrieve instances of this object.
|
||||
class ArAsset {
|
||||
public:
|
||||
AR_API
|
||||
virtual ~ArAsset();
|
||||
|
||||
ArAsset(const ArAsset&) = delete;
|
||||
|
||||
ArAsset& operator=(const ArAsset&) = delete;
|
||||
|
||||
/// Returns size of the asset.
|
||||
AR_API
|
||||
virtual size_t GetSize() = 0;
|
||||
|
||||
/// Returns a pointer to a buffer with the contents of the asset,
|
||||
/// with size given by GetSize(). Returns an invalid std::shared_ptr
|
||||
/// if the contents could not be retrieved.
|
||||
///
|
||||
/// The data in the returned buffer must remain valid while there are
|
||||
/// outstanding copies of the returned std::shared_ptr. Note that the
|
||||
/// deleter stored in the std::shared_ptr may contain additional data
|
||||
/// needed to maintain the buffer's validity.
|
||||
AR_API
|
||||
virtual std::shared_ptr<const char> GetBuffer() = 0;
|
||||
|
||||
/// Read \p count bytes at \p offset from the beginning of the asset
|
||||
/// into \p buffer. Returns number of bytes read, or 0 on error.
|
||||
///
|
||||
/// Implementers should range-check calls and return zero for out-of-bounds
|
||||
/// reads.
|
||||
AR_API
|
||||
virtual size_t Read(void* buffer, size_t count, size_t offset) = 0;
|
||||
|
||||
/// Returns a read-only FILE* handle and offset for this asset if
|
||||
/// available, or (nullptr, 0) otherwise.
|
||||
///
|
||||
/// The returned handle must remain valid for the lifetime of this
|
||||
/// ArAsset object. The returned offset is the offset from the beginning
|
||||
/// of the FILE* where the asset's contents begins.
|
||||
///
|
||||
/// This function is marked unsafe because the handle may wind up
|
||||
/// being used in multiple threads depending on the underlying
|
||||
/// resolver implementation. For instance, a resolver may cache
|
||||
/// and return ArAsset objects with the same FILE* to multiple
|
||||
/// threads.
|
||||
///
|
||||
/// Clients MUST NOT use this handle with functions that cannot be
|
||||
/// called concurrently on the same file descriptor, e.g. read,
|
||||
/// fread, fseek, etc. See ArchPRead for a function that can be used
|
||||
/// to read data from this handle safely.
|
||||
AR_API
|
||||
virtual std::pair<FILE*, size_t> GetFileUnsafe() = 0;
|
||||
|
||||
protected:
|
||||
AR_API
|
||||
ArAsset();
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_AR_ASSET_H
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -0,0 +1,227 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_INCLUDED_FROM_AR_DEFAULT_RESOLVER_H
|
||||
#error This file should not be included directly. Include resolverContext.h instead
|
||||
#endif
|
||||
|
||||
#ifndef PXR_USD_AR_DEFAULT_RESOLVER_V1_H
|
||||
#define PXR_USD_AR_DEFAULT_RESOLVER_V1_H
|
||||
|
||||
/// \file ar/defaultResolver_v1.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/ar/api.h"
|
||||
#include "pxr/usd/ar/defaultResolverContext.h"
|
||||
#include "pxr/usd/ar/resolver.h"
|
||||
#include "pxr/usd/ar/threadLocalScopedCache.h"
|
||||
|
||||
#include <tbb/enumerable_thread_specific.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class ArDefaultResolver
|
||||
///
|
||||
/// Default asset resolution implementation used when no plugin
|
||||
/// implementation is provided.
|
||||
///
|
||||
/// In order to resolve assets specified by relative paths, this resolver
|
||||
/// implements a simple "search path" scheme. The resolver will anchor the
|
||||
/// relative path to a series of directories and return the first absolute
|
||||
/// path where the asset exists.
|
||||
///
|
||||
/// The first directory will always be the current working directory. The
|
||||
/// resolver will then examine the directories specified via the following
|
||||
/// mechanisms (in order):
|
||||
///
|
||||
/// - The currently-bound ArDefaultResolverContext for the calling thread
|
||||
/// - ArDefaultResolver::SetDefaultSearchPath
|
||||
/// - The environment variable PXR_AR_DEFAULT_SEARCH_PATH. This is
|
||||
/// expected to be a list of directories delimited by the platform's
|
||||
/// standard path separator.
|
||||
///
|
||||
class ArDefaultResolver
|
||||
: public ArResolver
|
||||
{
|
||||
public:
|
||||
AR_API
|
||||
ArDefaultResolver();
|
||||
|
||||
AR_API
|
||||
virtual ~ArDefaultResolver();
|
||||
|
||||
/// Set the default search path that will be used during asset
|
||||
/// resolution. This must be called before the first call
|
||||
/// to \ref ArGetResolver.
|
||||
/// The specified paths will be searched *in addition to, and before*
|
||||
/// paths specified via the environment variable PXR_AR_DEFAULT_SEARCH_PATH
|
||||
AR_API
|
||||
static void SetDefaultSearchPath(
|
||||
const std::vector<std::string>& searchPath);
|
||||
|
||||
// ArResolver overrides
|
||||
|
||||
/// Sets the resolver's default context (returned by CreateDefaultContext())
|
||||
/// to the same context you would get by calling
|
||||
/// CreateDefaultContextForAsset(). Has no other effect on the resolver's
|
||||
/// configuration.
|
||||
AR_API
|
||||
virtual void ConfigureResolverForAsset(const std::string& path) override;
|
||||
|
||||
AR_API
|
||||
virtual std::string AnchorRelativePath(
|
||||
const std::string& anchorPath,
|
||||
const std::string& path) override;
|
||||
|
||||
AR_API
|
||||
virtual bool IsRelativePath(const std::string& path) override;
|
||||
|
||||
AR_API
|
||||
virtual bool IsRepositoryPath(const std::string& path) override;
|
||||
|
||||
AR_API
|
||||
virtual bool IsSearchPath(const std::string& path) override;
|
||||
|
||||
AR_API
|
||||
virtual std::string GetExtension(const std::string& path) override;
|
||||
|
||||
AR_API
|
||||
virtual std::string ComputeNormalizedPath(const std::string& path) override;
|
||||
|
||||
AR_API
|
||||
virtual std::string ComputeRepositoryPath(const std::string& path) override;
|
||||
|
||||
AR_API
|
||||
virtual std::string ComputeLocalPath(const std::string& path) override;
|
||||
|
||||
AR_API
|
||||
virtual std::string Resolve(const std::string& path) override;
|
||||
|
||||
AR_API
|
||||
virtual std::string ResolveWithAssetInfo(
|
||||
const std::string& path,
|
||||
ArAssetInfo* assetInfo) override;
|
||||
|
||||
AR_API
|
||||
virtual void UpdateAssetInfo(
|
||||
const std::string& identifier,
|
||||
const std::string& filePath,
|
||||
const std::string& fileVersion,
|
||||
ArAssetInfo* assetInfo) override;
|
||||
|
||||
AR_API
|
||||
virtual VtValue GetModificationTimestamp(
|
||||
const std::string& path,
|
||||
const std::string& resolvedPath) override;
|
||||
|
||||
AR_API
|
||||
virtual bool FetchToLocalResolvedPath(
|
||||
const std::string& path,
|
||||
const std::string& resolvedPath) override;
|
||||
|
||||
AR_API
|
||||
virtual std::shared_ptr<ArAsset> OpenAsset(
|
||||
const std::string& resolvedPath) override;
|
||||
|
||||
AR_API
|
||||
virtual bool CreatePathForLayer(
|
||||
const std::string& path) override;
|
||||
|
||||
AR_API
|
||||
virtual bool CanWriteLayerToPath(
|
||||
const std::string& path,
|
||||
std::string* whyNot) override;
|
||||
|
||||
AR_API
|
||||
virtual bool CanCreateNewLayerWithIdentifier(
|
||||
const std::string& identifier,
|
||||
std::string* whyNot) override;
|
||||
|
||||
AR_API
|
||||
virtual ArResolverContext CreateDefaultContext() override;
|
||||
|
||||
/// Creates a context that adds the directory containing \p filePath
|
||||
/// as a first directory to be searched, when the resulting context is
|
||||
/// bound (\see ArResolverContextBinder).
|
||||
///
|
||||
/// If \p filePath is empty, returns an empty context; otherwise, if
|
||||
/// \p filePath is not an absolute filesystem path, it will first be
|
||||
/// anchored to the process's current working directory.
|
||||
AR_API
|
||||
virtual ArResolverContext CreateDefaultContextForAsset(
|
||||
const std::string& filePath) override;
|
||||
|
||||
AR_API
|
||||
virtual void RefreshContext(const ArResolverContext& context) override;
|
||||
|
||||
AR_API
|
||||
virtual ArResolverContext GetCurrentContext() override;
|
||||
|
||||
AR_API
|
||||
virtual void BeginCacheScope(
|
||||
VtValue* cacheScopeData) override;
|
||||
|
||||
AR_API
|
||||
virtual void EndCacheScope(
|
||||
VtValue* cacheScopeData) override;
|
||||
|
||||
AR_API
|
||||
virtual void BindContext(
|
||||
const ArResolverContext& context,
|
||||
VtValue* bindingData) override;
|
||||
|
||||
AR_API
|
||||
virtual void UnbindContext(
|
||||
const ArResolverContext& context,
|
||||
VtValue* bindingData) override;
|
||||
|
||||
private:
|
||||
struct _Cache;
|
||||
using _PerThreadCache = ArThreadLocalScopedCache<_Cache>;
|
||||
using _CachePtr = _PerThreadCache::CachePtr;
|
||||
_CachePtr _GetCurrentCache();
|
||||
|
||||
const ArDefaultResolverContext* _GetCurrentContext();
|
||||
|
||||
std::string _ResolveNoCache(const std::string& path);
|
||||
|
||||
private:
|
||||
ArDefaultResolverContext _fallbackContext;
|
||||
ArResolverContext _defaultContext;
|
||||
|
||||
_PerThreadCache _threadCache;
|
||||
|
||||
using _ContextStack = std::vector<const ArDefaultResolverContext*>;
|
||||
using _PerThreadContextStack =
|
||||
tbb::enumerable_thread_specific<_ContextStack>;
|
||||
_PerThreadContextStack _threadContextStack;
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,88 @@
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_USD_AR_DEFINE_PACKAGE_RESOLVER_H
|
||||
#define PXR_USD_AR_DEFINE_PACKAGE_RESOLVER_H
|
||||
|
||||
/// \file ar/definePackageResolver.h
|
||||
/// Macros for defining a package resolver implementation.
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/ar/api.h"
|
||||
#include "pxr/usd/ar/packageResolver.h"
|
||||
|
||||
#include "pxr/base/tf/registryManager.h"
|
||||
#include "pxr/base/tf/type.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \def AR_DEFINE_PACKAGE_RESOLVER
|
||||
///
|
||||
/// Performs registrations required for the specified package resolver
|
||||
/// class to be discovered by Ar's plugin mechanism. This typically would be
|
||||
/// invoked in the source file defining the resolver class. For example:
|
||||
///
|
||||
/// \code
|
||||
/// // in .cpp file
|
||||
/// AR_DEFINE_PACKAGE_RESOLVER(CustomPackageResolverClass, ArPackageResolver);
|
||||
/// \endcode
|
||||
#ifdef doxygen
|
||||
#define AR_DEFINE_PACKAGE_RESOLVER(PackageResolverClass, BaseClass1, ...)
|
||||
#else
|
||||
|
||||
#define AR_DEFINE_PACKAGE_RESOLVER(...) \
|
||||
TF_REGISTRY_FUNCTION(TfType) { \
|
||||
Ar_DefinePackageResolver<__VA_ARGS__>(); \
|
||||
}
|
||||
|
||||
class Ar_PackageResolverFactoryBase
|
||||
: public TfType::FactoryBase
|
||||
{
|
||||
public:
|
||||
AR_API
|
||||
virtual ArPackageResolver* New() const = 0;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class Ar_PackageResolverFactory
|
||||
: public Ar_PackageResolverFactoryBase
|
||||
{
|
||||
public:
|
||||
virtual ArPackageResolver* New() const override
|
||||
{
|
||||
return new T;
|
||||
}
|
||||
};
|
||||
|
||||
template <class PackageResolver, class ...Bases>
|
||||
void Ar_DefinePackageResolver()
|
||||
{
|
||||
TfType::Define<PackageResolver, TfType::Bases<Bases...>>()
|
||||
.template SetFactory<Ar_PackageResolverFactory<PackageResolver>>();
|
||||
}
|
||||
|
||||
#endif // doxygen
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_AR_DEFINE_PACKAGE_RESOLVER_H
|
||||
@@ -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
|
||||
@@ -0,0 +1,81 @@
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
#ifndef PXR_USD_AR_FILESYSTEM_ASSET_H
|
||||
#define PXR_USD_AR_FILESYSTEM_ASSET_H
|
||||
|
||||
/// \file ar/filesystemAsset.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/ar/api.h"
|
||||
#include "pxr/usd/ar/asset.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class ArFilesystemAsset
|
||||
///
|
||||
/// ArAsset implementation for asset represented by a file on a filesystem.
|
||||
class ArFilesystemAsset
|
||||
: public ArAsset
|
||||
{
|
||||
public:
|
||||
/// Constructs an ArFilesystemAsset for the given \p file.
|
||||
/// The ArFilesystemAsset object takes ownership of \p file and will
|
||||
/// close the file handle on destruction.
|
||||
AR_API
|
||||
explicit ArFilesystemAsset(FILE* file);
|
||||
|
||||
/// Closes the file owned by this object.
|
||||
AR_API
|
||||
~ArFilesystemAsset();
|
||||
|
||||
/// Returns the size of the file held by this object.
|
||||
AR_API
|
||||
virtual size_t GetSize() override;
|
||||
|
||||
/// Creates a read-only memory map for the file held by this object
|
||||
/// and returns a pointer to the start of the mapped contents.
|
||||
AR_API
|
||||
virtual std::shared_ptr<const char> GetBuffer() override;
|
||||
|
||||
/// Reads \p count bytes from the file held by this object at the
|
||||
/// given \p offset into \p buffer.
|
||||
AR_API
|
||||
virtual size_t Read(void* buffer, size_t count, size_t offset) override;
|
||||
|
||||
/// Returns the FILE* handle this object was created with and an offset
|
||||
/// of 0, since the asset's contents are located at the beginning of the
|
||||
/// file.
|
||||
AR_API
|
||||
virtual std::pair<FILE*, size_t> GetFileUnsafe() override;
|
||||
|
||||
private:
|
||||
FILE* _file;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_AR_FILESYSTEM_ASSET_H
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -0,0 +1,132 @@
|
||||
//
|
||||
// Copyright 2020 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef INCLUDE_AR_PY_RESOLVER_CONTEXT
|
||||
#error This file should not be included directly. Include pyResolverContext.h instead
|
||||
#endif
|
||||
|
||||
#ifndef PXR_USD_AR_PY_RESOLVER_CONTEXT_V1_H
|
||||
#define PXR_USD_AR_PY_RESOLVER_CONTEXT_V1_H
|
||||
|
||||
/// \file ar/pyResolverContext_v1.h
|
||||
/// Macros for creating Python bindings for objects used with
|
||||
/// ArResolverContext.
|
||||
|
||||
#include "pxr/base/tf/pySafePython.h"
|
||||
|
||||
#include <boost/python/extract.hpp>
|
||||
#include <boost/python/object.hpp>
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/ar/api.h"
|
||||
#include "pxr/usd/ar/resolverContext.h"
|
||||
|
||||
#include "pxr/base/tf/pyLock.h"
|
||||
#include "pxr/base/tf/pyObjWrapper.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// Register the specified type as a context object that may be
|
||||
/// converted from a Python into a ArResolverContext object
|
||||
/// in C++ and vice versa. This typically would be called in the
|
||||
/// source file where the Python wrapping for the context object
|
||||
/// is defined.
|
||||
template <class Context>
|
||||
void
|
||||
ArWrapResolverContextForPython();
|
||||
|
||||
#ifndef doxygen
|
||||
// Private helper functions for converting ArResolverContext
|
||||
// objects to and from Python.
|
||||
|
||||
template <class Context>
|
||||
bool
|
||||
Ar_ConvertResolverContextFromPython(
|
||||
PyObject* obj,
|
||||
ArResolverContext* context)
|
||||
{
|
||||
boost::python::extract<const Context&> x(obj);
|
||||
if (x.check()) {
|
||||
if (context) {
|
||||
*context = ArResolverContext(x());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class Context>
|
||||
bool
|
||||
Ar_ConvertResolverContextToPython(
|
||||
const ArResolverContext& context,
|
||||
TfPyObjWrapper* obj)
|
||||
{
|
||||
if (const Context* contextObj = context.Get<Context>()) {
|
||||
if (obj) {
|
||||
TfPyLock lock;
|
||||
*obj = boost::python::object(*contextObj);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
typedef std::function<bool(PyObject*, ArResolverContext*)>
|
||||
Ar_MakeResolverContextFromPythonFn;
|
||||
typedef std::function<bool(const ArResolverContext&, TfPyObjWrapper*)>
|
||||
Ar_ResolverContextToPythonFn;
|
||||
|
||||
AR_API
|
||||
void
|
||||
Ar_RegisterResolverContextPythonConversion(
|
||||
const Ar_MakeResolverContextFromPythonFn& convertFunc,
|
||||
const Ar_ResolverContextToPythonFn& getObjectFunc);
|
||||
|
||||
AR_API
|
||||
bool
|
||||
Ar_CanConvertResolverContextFromPython(PyObject* pyObj);
|
||||
|
||||
AR_API
|
||||
ArResolverContext
|
||||
Ar_ConvertResolverContextFromPython(PyObject* pyObj);
|
||||
|
||||
AR_API
|
||||
TfPyObjWrapper
|
||||
Ar_ConvertResolverContextToPython(const ArResolverContext& context);
|
||||
|
||||
template <class Context>
|
||||
void
|
||||
ArWrapResolverContextForPython()
|
||||
{
|
||||
Ar_RegisterResolverContextPythonConversion(
|
||||
Ar_ConvertResolverContextFromPython<Context>,
|
||||
Ar_ConvertResolverContextToPython<Context>);
|
||||
};
|
||||
|
||||
#endif //doxygen
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -0,0 +1,256 @@
|
||||
//
|
||||
// Copyright 2020 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef INCLUDE_AR_RESOLVER_CONTEXT
|
||||
#error This file should not be included directly. Include resolverContext.h instead
|
||||
#endif
|
||||
|
||||
#ifndef PXR_USD_AR_RESOLVER_CONTEXT_V1_H
|
||||
#define PXR_USD_AR_RESOLVER_CONTEXT_V1_H
|
||||
|
||||
/// \file ar/resolverContext_v1.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/ar/api.h"
|
||||
#include "pxr/base/tf/safeTypeCompare.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <typeinfo>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class ArIsContextObject
|
||||
///
|
||||
/// Metafunction to determine whether the templated object type is a
|
||||
/// valid context object.
|
||||
///
|
||||
template <class T>
|
||||
struct ArIsContextObject
|
||||
{
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
/// Default implementation for providing debug info on the contained context.
|
||||
template <class Context>
|
||||
std::string ArGetDebugString(const Context& context);
|
||||
|
||||
/// \class ArResolverContext
|
||||
///
|
||||
/// An asset resolver context allows clients to provide additional data
|
||||
/// to the resolver for use during resolution. Clients may provide this
|
||||
/// data via a context object of their own (subject to restrictions below).
|
||||
/// An ArResolverContext is simply a wrapper around this object that
|
||||
/// allows it to be treated as a single type.
|
||||
///
|
||||
/// A client-defined context object must provide the following:
|
||||
/// - Default and copy constructors
|
||||
/// - operator<
|
||||
/// - operator==
|
||||
/// - An overload for size_t hash_value(const T&)
|
||||
///
|
||||
/// Note that the user may define a free function:
|
||||
///
|
||||
/// std::string ArGetDebugString(const Context& ctx);
|
||||
/// (Where Context is the type of the user's path resolver context.)
|
||||
///
|
||||
/// This is optional; a default generic implementation has been predefined.
|
||||
/// This function should return a string representation of the context
|
||||
/// to be utilized for debugging purposes(such as in TF_DEBUG statements).
|
||||
///
|
||||
/// The ArIsContextObject template must also be specialized for this
|
||||
/// object to declare that it can be used as a context object. This is to
|
||||
/// avoid accidental use of an unexpected object as a context object.
|
||||
/// The AR_DECLARE_RESOLVER_CONTEXT macro can be used to do this
|
||||
/// as a convenience.
|
||||
///
|
||||
/// \sa AR_DECLARE_RESOLVER_CONTEXT
|
||||
/// \sa ArResolver::BindContext
|
||||
/// \sa ArResolver::UnbindContext
|
||||
/// \sa ArResolverContextBinder
|
||||
class ArResolverContext
|
||||
{
|
||||
public:
|
||||
/// Construct an empty asset resolver context.
|
||||
ArResolverContext()
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a resolver context using the context object \p context.
|
||||
/// See class documentation for requirements.
|
||||
template <class Context,
|
||||
typename std::enable_if<ArIsContextObject<Context>::value>
|
||||
::type* = nullptr>
|
||||
ArResolverContext(const Context& context)
|
||||
: _context(new _Typed<Context>(context))
|
||||
{
|
||||
}
|
||||
|
||||
/// Returns whether this context object is empty.
|
||||
bool IsEmpty() const
|
||||
{
|
||||
return !_context;
|
||||
}
|
||||
|
||||
/// Return pointer to the context object held in this asset resolver
|
||||
/// context if the context is holding an object of the requested type,
|
||||
/// NULL otherwise.
|
||||
template <class Context>
|
||||
const Context* Get() const
|
||||
{
|
||||
return _context && _context->IsHolding(typeid(Context)) ?
|
||||
&_GetTyped<Context>(*_context)._context : NULL;
|
||||
}
|
||||
|
||||
/// Returns a debug string representing the contained context
|
||||
std::string GetDebugString() const
|
||||
{
|
||||
return _context ? _context->GetDebugString() : std::string();
|
||||
}
|
||||
|
||||
/// \name Operators
|
||||
/// @{
|
||||
bool operator==(const ArResolverContext& rhs) const
|
||||
{
|
||||
if (_context && rhs._context) {
|
||||
return (_context->IsHolding(rhs._context->GetTypeid())
|
||||
&& _context->Equals(*rhs._context));
|
||||
}
|
||||
return (!_context && !rhs._context);
|
||||
}
|
||||
|
||||
bool operator!=(const ArResolverContext& rhs) const
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
bool operator<(const ArResolverContext& rhs) const
|
||||
{
|
||||
if (_context && rhs._context) {
|
||||
if (_context->IsHolding(rhs._context->GetTypeid())) {
|
||||
return _context->LessThan(*rhs._context);
|
||||
}
|
||||
return (std::string(_context->GetTypeid().name()) <
|
||||
std::string(rhs._context->GetTypeid().name()));
|
||||
}
|
||||
else if (_context && !rhs._context) {
|
||||
return false;
|
||||
}
|
||||
else if (!_context && rhs._context) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
/// Returns hash value for this asset resolver context.
|
||||
friend size_t hash_value(const ArResolverContext& context)
|
||||
{
|
||||
return context._context ? context._context->Hash() : 0;
|
||||
}
|
||||
|
||||
private:
|
||||
// Type-erased storage for context objects.
|
||||
struct _Untyped;
|
||||
template <class Context> struct _Typed;
|
||||
|
||||
template <class Context>
|
||||
static const _Typed<Context>& _GetTyped(const _Untyped& untyped)
|
||||
{
|
||||
return static_cast<const _Typed<Context>&>(untyped);
|
||||
}
|
||||
|
||||
struct _Untyped
|
||||
{
|
||||
AR_API
|
||||
virtual ~_Untyped();
|
||||
|
||||
bool IsHolding(const std::type_info& ti) const
|
||||
{
|
||||
return TfSafeTypeCompare(ti, GetTypeid());
|
||||
}
|
||||
|
||||
virtual const std::type_info& GetTypeid() const = 0;
|
||||
virtual bool LessThan(const _Untyped& rhs) const = 0;
|
||||
virtual bool Equals(const _Untyped& rhs) const = 0;
|
||||
virtual size_t Hash() const = 0;
|
||||
virtual std::string GetDebugString() const = 0;
|
||||
};
|
||||
|
||||
template <class Context>
|
||||
struct _Typed : public _Untyped
|
||||
{
|
||||
virtual ~_Typed() { }
|
||||
|
||||
_Typed(const Context& context) : _context(context)
|
||||
{
|
||||
}
|
||||
|
||||
virtual const std::type_info& GetTypeid() const
|
||||
{
|
||||
return typeid(Context);
|
||||
}
|
||||
|
||||
virtual bool LessThan(const _Untyped& rhs) const
|
||||
{
|
||||
return _context < _GetTyped<Context>(rhs)._context;
|
||||
}
|
||||
|
||||
virtual bool Equals(const _Untyped& rhs) const
|
||||
{
|
||||
return _context == _GetTyped<Context>(rhs)._context;
|
||||
}
|
||||
|
||||
virtual size_t Hash() const
|
||||
{
|
||||
return hash_value(_context);
|
||||
}
|
||||
|
||||
virtual std::string GetDebugString() const
|
||||
{
|
||||
return ArGetDebugString(_context);
|
||||
}
|
||||
|
||||
Context _context;
|
||||
};
|
||||
|
||||
std::shared_ptr<_Untyped> _context;
|
||||
};
|
||||
|
||||
|
||||
// Default implementation for streaming out held contexts.
|
||||
AR_API
|
||||
std::string Ar_GetDebugString(const std::type_info&, void const*);
|
||||
|
||||
template <class Context>
|
||||
std::string ArGetDebugString(const Context& context)
|
||||
{
|
||||
return Ar_GetDebugString(typeid(Context),
|
||||
static_cast<void const*>(&context));
|
||||
}
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -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
|
||||
@@ -0,0 +1,483 @@
|
||||
//
|
||||
// Copyright 2020 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef INCLUDE_AR_RESOLVER
|
||||
#error This file should not be included directly. Include resolver.h instead.
|
||||
#endif
|
||||
|
||||
#ifndef PXR_USD_AR_RESOLVER_V1_H
|
||||
#define PXR_USD_AR_RESOLVER_V1_H
|
||||
|
||||
/// \file ar/resolver_v1.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/ar/api.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class ArAsset;
|
||||
class ArAssetInfo;
|
||||
class ArResolverContext;
|
||||
class TfType;
|
||||
class VtValue;
|
||||
|
||||
/// \class ArResolver
|
||||
///
|
||||
/// Interface for the asset resolution system. An asset resolver is
|
||||
/// responsible for resolving asset information (including the asset's
|
||||
/// physical path) from a logical path.
|
||||
///
|
||||
/// See \ref ar_implementing_resolver for information on how to customize
|
||||
/// asset resolution behavior by implementing a subclass of ArResolver.
|
||||
/// Clients may use #ArGetResolver to access the configured asset resolver.
|
||||
///
|
||||
class ArResolver
|
||||
{
|
||||
public:
|
||||
AR_API
|
||||
virtual ~ArResolver();
|
||||
|
||||
// Disallow copies
|
||||
ArResolver(const ArResolver&) = delete;
|
||||
ArResolver& operator=(const ArResolver&) = delete;
|
||||
|
||||
// --------------------------------------------------------------------- //
|
||||
/// \anchor ArResolver_resolution
|
||||
/// \name Path Resolution Operations
|
||||
///
|
||||
/// @{
|
||||
// --------------------------------------------------------------------- //
|
||||
|
||||
/// Configures the resolver for a given asset path
|
||||
AR_API
|
||||
virtual void ConfigureResolverForAsset(const std::string& path) = 0;
|
||||
|
||||
/// Returns the path formed by anchoring \p path to \p anchorPath.
|
||||
///
|
||||
/// If \p anchorPath ends with a trailing '/', it is treated as
|
||||
/// a directory to which \p path will be anchored. Otherwise, it
|
||||
/// is treated as a file and \p path will be anchored to its
|
||||
/// containing directory.
|
||||
///
|
||||
/// If \p anchorPath is empty, \p path will be returned as-is.
|
||||
///
|
||||
/// If \p path is empty or not a relative path, it will be
|
||||
/// returned as-is.
|
||||
AR_API
|
||||
virtual std::string AnchorRelativePath(
|
||||
const std::string& anchorPath,
|
||||
const std::string& path) = 0;
|
||||
|
||||
/// Returns true if the given path is a relative path.
|
||||
AR_API
|
||||
virtual bool IsRelativePath(const std::string& path) = 0;
|
||||
|
||||
/// Returns true if the given path is a repository path.
|
||||
AR_API
|
||||
virtual bool IsRepositoryPath(const std::string& path) = 0;
|
||||
|
||||
/// Returns whether this path is a search path.
|
||||
AR_API
|
||||
virtual bool IsSearchPath(const std::string& path) = 0;
|
||||
|
||||
/// Returns the normalized extension for the given \p path.
|
||||
AR_API
|
||||
virtual std::string GetExtension(const std::string& path) = 0;
|
||||
|
||||
/// Returns a normalized version of the given \p path
|
||||
AR_API
|
||||
virtual std::string ComputeNormalizedPath(const std::string& path) = 0;
|
||||
|
||||
/// Returns the computed repository path using the current resolver
|
||||
AR_API
|
||||
virtual std::string ComputeRepositoryPath(const std::string& path) = 0;
|
||||
|
||||
/// Returns the local path for the given \p path.
|
||||
AR_API
|
||||
virtual std::string ComputeLocalPath(const std::string& path) = 0;
|
||||
|
||||
/// Returns the resolved filesystem path for the file identified by
|
||||
/// the given \p path if it exists. If the file does not exist,
|
||||
/// returns an empty string.
|
||||
AR_API
|
||||
virtual std::string Resolve(const std::string& path) = 0;
|
||||
|
||||
/// @}
|
||||
|
||||
// --------------------------------------------------------------------- //
|
||||
/// \anchor ArResolver_context
|
||||
/// \name Asset Resolver Context Operations
|
||||
///
|
||||
/// @{
|
||||
// --------------------------------------------------------------------- //
|
||||
|
||||
/// Binds the given context to this resolver.
|
||||
///
|
||||
/// Clients should generally use ArResolverContextBinder instead of calling
|
||||
/// this function directly.
|
||||
///
|
||||
/// \see ArResolverContextBinder
|
||||
AR_API
|
||||
virtual void BindContext(
|
||||
const ArResolverContext& context,
|
||||
VtValue* bindingData) = 0;
|
||||
|
||||
/// Unbind the given context from this resolver.
|
||||
///
|
||||
/// Clients should generally use ArResolverContextBinder instead of calling
|
||||
/// this function directly.
|
||||
///
|
||||
/// \see ArResolverContextBinder
|
||||
AR_API
|
||||
virtual void UnbindContext(
|
||||
const ArResolverContext& context,
|
||||
VtValue* bindingData) = 0;
|
||||
|
||||
/// Return a default ArResolverContext that may be bound to this resolver
|
||||
/// to resolve assets when no other context is explicitly specified.
|
||||
///
|
||||
/// This function should not automatically bind this context, but should
|
||||
/// create one that may be used later.
|
||||
AR_API
|
||||
virtual ArResolverContext CreateDefaultContext() = 0;
|
||||
|
||||
/// Return a default ArResolverContext that may be bound to this resolver
|
||||
/// to resolve the asset located at \p filePath when no other context is
|
||||
/// explicitly specified.
|
||||
///
|
||||
/// This function should not automatically bind this context, but should
|
||||
/// create one that may be used later.
|
||||
AR_API
|
||||
virtual ArResolverContext CreateDefaultContextForAsset(
|
||||
const std::string& filePath) = 0;
|
||||
|
||||
/// Refresh any caches associated with the given context.
|
||||
AR_API
|
||||
virtual void RefreshContext(const ArResolverContext& context) = 0;
|
||||
|
||||
/// Returns the currently-bound asset resolver context.
|
||||
///
|
||||
/// \see ArResolver::BindContext, ArResolver::UnbindContext
|
||||
AR_API
|
||||
virtual ArResolverContext GetCurrentContext() = 0;
|
||||
|
||||
/// @}
|
||||
|
||||
// --------------------------------------------------------------------- //
|
||||
/// \anchor ArResolver_files
|
||||
/// \name File/asset-specific Operations
|
||||
///
|
||||
/// @{
|
||||
// --------------------------------------------------------------------- //
|
||||
|
||||
/// Returns the resolved filesystem path for the file identified
|
||||
/// by \p path following the same path resolution behavior as in
|
||||
/// \ref Resolve(const std::string&).
|
||||
///
|
||||
/// If the file identified by \p path represents an asset and
|
||||
/// \p assetInfo is not \c nullptr, the resolver should populate
|
||||
/// \p assetInfo with whatever additional metadata it knows or can
|
||||
/// reasonably compute about the asset without actually opening it.
|
||||
///
|
||||
/// \see Resolve(const std::string&).
|
||||
AR_API
|
||||
virtual std::string ResolveWithAssetInfo(
|
||||
const std::string& path,
|
||||
ArAssetInfo* assetInfo) = 0;
|
||||
|
||||
/// Update \p assetInfo with respect to the given \p fileVersion .
|
||||
/// \note This API is currently in flux. In general, you should prefer
|
||||
/// to call ResolveWithAssetInfo()
|
||||
AR_API
|
||||
virtual void UpdateAssetInfo(
|
||||
const std::string& identifier,
|
||||
const std::string& filePath,
|
||||
const std::string& fileVersion,
|
||||
ArAssetInfo* assetInfo) = 0;
|
||||
|
||||
/// Returns a value representing the last time the asset identified
|
||||
/// by \p path was modified. \p resolvedPath is the resolved path
|
||||
/// of the asset.
|
||||
///
|
||||
/// Implementations may use whatever value is most appropriate
|
||||
/// for this timestamp. The value must be equality comparable,
|
||||
/// and this function must return a different timestamp whenever
|
||||
/// an asset has been modified. For instance, if an asset is stored
|
||||
/// as a file on disk, the timestamp may simply be that file's mtime.
|
||||
///
|
||||
/// If a timestamp cannot be retrieved, returns an empty VtValue.
|
||||
AR_API
|
||||
virtual VtValue GetModificationTimestamp(
|
||||
const std::string& path,
|
||||
const std::string& resolvedPath) = 0;
|
||||
|
||||
/// Fetch the asset identified by \p path to the filesystem location
|
||||
/// specified by \p resolvedPath. \p resolvedPath is the resolved path
|
||||
/// that results from calling Resolve or ResolveWithAssetInfo on
|
||||
/// \p path.
|
||||
///
|
||||
/// This method provides a way for consumers that expect assets
|
||||
/// to exist as physical files on disk to retrieve data from
|
||||
/// systems that store data in external data stores, e.g. databases,
|
||||
/// etc.
|
||||
///
|
||||
/// Returns true if the asset was successfully fetched to the specified
|
||||
/// \p resolvedPath or if no fetching was required. If \p resolvedPath
|
||||
/// is not a local path or the asset could not be fetched to that path,
|
||||
/// returns false.
|
||||
AR_API
|
||||
virtual bool FetchToLocalResolvedPath(
|
||||
const std::string& path,
|
||||
const std::string& resolvedPath) = 0;
|
||||
|
||||
/// Returns an ArAsset object for the asset located at \p resolvedPath.
|
||||
/// Returns an invalid std::shared_ptr if object could not be created.
|
||||
///
|
||||
/// The returned ArAsset object provides functions for accessing the
|
||||
/// contents of the specified asset.
|
||||
///
|
||||
/// Note that clients may still be using the data associated with
|
||||
/// this object even after the last shared_ptr has been destroyed. For
|
||||
/// example, a client may have created a memory mapping using the FILE*
|
||||
/// presented in the ArAsset object; this would preclude truncating or
|
||||
/// overwriting any of the contents of that file.
|
||||
AR_API
|
||||
virtual std::shared_ptr<ArAsset> OpenAsset(
|
||||
const std::string& resolvedPath) = 0;
|
||||
|
||||
/// Create path needed to write a file to the given \p path.
|
||||
///
|
||||
/// For example:
|
||||
/// - A filesystem-based resolver might create the directories specified
|
||||
/// in \p path.
|
||||
/// - A database-based resolver might create a new table, or it might
|
||||
/// ignore this altogether.
|
||||
///
|
||||
/// In practice, when writing a layer, CanWriteLayerToPath will be called
|
||||
/// first to check if writing is permitted. If this returns true, then
|
||||
/// CreatePathForLayer will be called before writing the layer out.
|
||||
///
|
||||
/// Returns true on success, false otherwise.
|
||||
AR_API
|
||||
virtual bool CreatePathForLayer(
|
||||
const std::string& path) = 0;
|
||||
|
||||
/// Returns true if a file may be written to the given \p path, false
|
||||
/// otherwise.
|
||||
///
|
||||
/// In practice, when writing a layer, CanWriteLayerToPath will be called
|
||||
/// first to check if writing is permitted. If this returns true, then
|
||||
/// CreatePathForLayer will be called before writing the layer out.
|
||||
///
|
||||
/// If this function returns false and \p whyNot is not \c nullptr,
|
||||
/// it will be filled in with an explanation.
|
||||
AR_API
|
||||
virtual bool CanWriteLayerToPath(
|
||||
const std::string& path,
|
||||
std::string* whyNot) = 0;
|
||||
|
||||
/// Returns true if a new file may be created using the given
|
||||
/// \p identifier, false otherwise.
|
||||
///
|
||||
/// If this function returns false and \p whyNot is not \c nullptr,
|
||||
/// it will be filled in with an explanation.
|
||||
AR_API
|
||||
virtual bool CanCreateNewLayerWithIdentifier(
|
||||
const std::string& identifier,
|
||||
std::string* whyNot) = 0;
|
||||
|
||||
/// @}
|
||||
|
||||
// --------------------------------------------------------------------- //
|
||||
/// \anchor ArResolver_scopedCache
|
||||
/// \name Scoped Resolution Cache
|
||||
///
|
||||
/// A scoped resolution cache indicates to the resolver that results of
|
||||
/// calls to Resolve should be cached for a certain scope. This is
|
||||
/// important for performance and also for consistency -- it ensures
|
||||
/// that repeated calls to Resolve with the same parameters will
|
||||
/// return the same result.
|
||||
///
|
||||
/// A resolution cache scope is opened by a call to BeginCacheScope and
|
||||
/// must be closed with a matching call to EndCacheScope. The resolver must
|
||||
/// cache the results of Resolve until the scope is closed. Note that these
|
||||
/// calls may be nested.
|
||||
///
|
||||
/// Cache scopes are thread-specific: if multiple threads are running and
|
||||
/// a cache scope is opened in one of those threads, caching should be
|
||||
/// enabled in that thread only.
|
||||
///
|
||||
/// When opening a scope, a resolver may return additional data for
|
||||
/// implementation-specific purposes. This data may be shared across
|
||||
/// threads, so long as it is safe to access this data concurrently.
|
||||
///
|
||||
/// ArResolverScopedCache is an RAII object for managing cache scope
|
||||
/// lifetimes and data. Clients should generally use that class rather
|
||||
/// than calling the BeginCacheScope and EndCacheScope functions manually.
|
||||
///
|
||||
/// \see ArResolverScopedCache
|
||||
/// @{
|
||||
// --------------------------------------------------------------------- //
|
||||
|
||||
/// Mark the start of a resolution caching scope.
|
||||
///
|
||||
/// Clients should generally use ArResolverScopedCache instead of calling
|
||||
/// this function directly.
|
||||
///
|
||||
/// Resolvers may fill \p cacheScopeData with arbitrary data. Clients may
|
||||
/// also pass in a \p cacheScopeData populated by an earlier call to
|
||||
/// BeginCacheScope to allow the resolver access to that information.
|
||||
///
|
||||
/// \see ArResolverScopedCache
|
||||
AR_API
|
||||
virtual void BeginCacheScope(
|
||||
VtValue* cacheScopeData) = 0;
|
||||
|
||||
/// Mark the end of a resolution caching scope.
|
||||
///
|
||||
/// Clients should generally use ArResolverScopedCache instead of calling
|
||||
/// this function directly.
|
||||
///
|
||||
/// \p cacheScopeData should contain the data that was populated by the
|
||||
/// previous corresponding call to BeginCacheScope.
|
||||
///
|
||||
/// \see ArResolverScopedCache
|
||||
AR_API
|
||||
virtual void EndCacheScope(
|
||||
VtValue* cacheScopeData) = 0;
|
||||
|
||||
/// @}
|
||||
|
||||
protected:
|
||||
AR_API
|
||||
ArResolver();
|
||||
};
|
||||
|
||||
/// Returns the configured asset resolver.
|
||||
///
|
||||
/// When first called, this function will determine the ArResolver subclass
|
||||
/// to use for asset resolution via the following process:
|
||||
///
|
||||
/// - If a preferred resolver has been set via \ref ArSetPreferredResolver,
|
||||
/// it will be selected.
|
||||
///
|
||||
/// - Otherwise, a list of available ArResolver subclasses in plugins will
|
||||
/// be generated. If multiple ArResolver subclasses are found, the list
|
||||
/// will be sorted by typename. ArDefaultResolver will be added as the last
|
||||
/// element of this list, and the first resolver in the list will be
|
||||
/// selected.
|
||||
///
|
||||
/// - The plugin for the selected subclass will be loaded and an instance
|
||||
/// of the subclass will be constructed.
|
||||
///
|
||||
/// - If an error occurs, an ArDefaultResolver will be constructed.
|
||||
///
|
||||
/// The constructed ArResolver subclass will be cached and used to service
|
||||
/// function calls made on the returned resolver.
|
||||
///
|
||||
/// Note that this function may not return the constructed subclass itself,
|
||||
/// meaning that dynamic casts to the subclass type may fail. See
|
||||
/// ArGetUnderlyingResolver if access to this object is needed.
|
||||
AR_API
|
||||
ArResolver& ArGetResolver();
|
||||
|
||||
/// Set the preferred ArResolver subclass used by ArGetResolver.
|
||||
///
|
||||
/// Consumers may override ArGetResolver's plugin resolver discovery and
|
||||
/// force the use of a specific resolver subclass by calling this
|
||||
/// function with the typename of the implementation to use.
|
||||
///
|
||||
/// If the subclass specified by \p resolverTypeName cannot be found,
|
||||
/// ArGetResolver will issue a warning and fall back to using
|
||||
/// ArDefaultResolver.
|
||||
///
|
||||
/// This must be called before the first call to ArGetResolver.
|
||||
AR_API
|
||||
void ArSetPreferredResolver(const std::string& resolverTypeName);
|
||||
|
||||
/// \name Advanced API
|
||||
///
|
||||
/// \warning These functions should typically not be used by consumers except
|
||||
/// in very specific cases. Consumers who want to retrieve an ArResolver to
|
||||
/// perform asset resolution should use \ref ArGetResolver.
|
||||
///
|
||||
/// @{
|
||||
|
||||
/// Returns the underlying ArResolver instance used by ArGetResolver.
|
||||
///
|
||||
/// This function returns the instance of the ArResolver subclass used by
|
||||
/// ArGetResolver and can be dynamic_cast to that type.
|
||||
///
|
||||
/// \warning This functions should typically not be used by consumers except
|
||||
/// in very specific cases. Consumers who want to retrieve an ArResolver to
|
||||
/// perform asset resolution should use \ref ArGetResolver.
|
||||
AR_API
|
||||
ArResolver& ArGetUnderlyingResolver();
|
||||
|
||||
/// Returns list of TfTypes for available ArResolver subclasses.
|
||||
///
|
||||
/// This function returns the list of ArResolver subclasses used to determine
|
||||
/// the resolver implementation returned by \ref ArGetResolver. See
|
||||
/// documentation on that function for more details.
|
||||
///
|
||||
/// If this function is called from within a call (or calls) to
|
||||
/// \ref ArCreateResolver, the ArResolver subclass(es) being created will
|
||||
/// be removed from the returned list.
|
||||
///
|
||||
/// This function is not safe to call concurrently with itself or
|
||||
/// \ref ArCreateResolver.
|
||||
///
|
||||
/// \warning This functions should typically not be used by consumers except
|
||||
/// in very specific cases. Consumers who want to retrieve an ArResolver to
|
||||
/// perform asset resolution should use \ref ArGetResolver.
|
||||
AR_API
|
||||
std::vector<TfType> ArGetAvailableResolvers();
|
||||
|
||||
/// Construct an instance of the ArResolver subclass specified by
|
||||
/// \p resolverType.
|
||||
///
|
||||
/// This function will load the plugin for the given \p resolverType and
|
||||
/// construct and return a new instance of the specified ArResolver subclass.
|
||||
/// If an error occurs, coding errors will be emitted and this function
|
||||
/// will return an ArDefaultResolver instance.
|
||||
///
|
||||
/// Note that this function *does not* change the resolver used by
|
||||
/// \ref ArGetResolver to an instance of \p resolverType.
|
||||
///
|
||||
/// This function is not safe to call concurrently with itself or
|
||||
/// \ref ArGetAvailableResolvers.
|
||||
///
|
||||
/// \warning This functions should typically not be used by consumers except
|
||||
/// in very specific cases. Consumers who want to retrieve an ArResolver to
|
||||
/// perform asset resolution should use \ref ArGetResolver.
|
||||
AR_API
|
||||
std::unique_ptr<ArResolver> ArCreateResolver(const TfType& resolverType);
|
||||
|
||||
/// @}
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -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
|
||||
@@ -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_KIND_API_H
|
||||
#define PXR_USD_KIND_API_H
|
||||
|
||||
#include "pxr/base/arch/export.h"
|
||||
|
||||
#if defined(PXR_STATIC)
|
||||
# define KIND_API
|
||||
# define KIND_API_TEMPLATE_CLASS(...)
|
||||
# define KIND_API_TEMPLATE_STRUCT(...)
|
||||
# define KIND_LOCAL
|
||||
#else
|
||||
# if defined(KIND_EXPORTS)
|
||||
# define KIND_API ARCH_EXPORT
|
||||
# define KIND_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define KIND_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# else
|
||||
# define KIND_API ARCH_IMPORT
|
||||
# define KIND_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define KIND_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# endif
|
||||
# define KIND_LOCAL ARCH_HIDDEN
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,136 @@
|
||||
//
|
||||
// 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_KIND_REGISTRY_H
|
||||
#define PXR_USD_KIND_REGISTRY_H
|
||||
|
||||
/// \file kind/registry.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/kind/api.h"
|
||||
#include "pxr/base/tf/weakBase.h"
|
||||
#include "pxr/base/tf/singleton.h"
|
||||
#include "pxr/base/tf/staticTokens.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \hideinitializer
|
||||
#define KIND_TOKENS \
|
||||
(model) \
|
||||
(component) \
|
||||
(group) \
|
||||
(assembly) \
|
||||
(subcomponent)
|
||||
|
||||
/// \anchor KindTokens
|
||||
/// Provides static, efficient TfToken's for built-in Kinds
|
||||
///
|
||||
/// See \ref kind_coreKinds for description of the builtin kinds.
|
||||
TF_DECLARE_PUBLIC_TOKENS(KindTokens, KIND_API, KIND_TOKENS);
|
||||
|
||||
/// \class KindRegistry
|
||||
///
|
||||
/// A singleton that holds known kinds and information about them. See
|
||||
/// \ref mainpage_kind "Kind Overview" for a description of why kind exists,
|
||||
/// what the builtin registered kinds are, and how to extend the core kinds.
|
||||
///
|
||||
/// \section kind_threadsafety KindRegistry Threadsafty
|
||||
///
|
||||
/// KindRegistry serves performance-critical clients that operate under the
|
||||
/// stl threading model, and therefore itself follows that model in order
|
||||
/// to avoid locking during HasKind() and IsA() queries.
|
||||
///
|
||||
/// To make this robust, KindRegistry exposes no means to mutate the registry.
|
||||
/// All extensions must be accomplished via plugInfo.json files, which are
|
||||
/// consumed once during the registry initialization (See \ref kind_extensions )
|
||||
class KindRegistry : public TfWeakBase, boost::noncopyable
|
||||
{
|
||||
public:
|
||||
/// Return the single \c KindRegistry instance.
|
||||
KIND_API static KindRegistry& GetInstance();
|
||||
|
||||
/// Test whether \a kind is known to the registry.
|
||||
KIND_API static bool HasKind(const TfToken& kind);
|
||||
|
||||
/// Return the base kind of the given kind.
|
||||
/// If there is no base, the result will be an empty token.
|
||||
/// Issues a coding error if \a kind is unknown to the registry.
|
||||
KIND_API static TfToken GetBaseKind(const TfToken &kind);
|
||||
|
||||
/// Test whether \a derivedKind is the same as \a baseKind or
|
||||
/// has it as a base kind (either directly or indirectly).
|
||||
///
|
||||
/// It is \em not required that \a derivedKind or \a baseKind
|
||||
/// be known to the registry: if they are unknown but equal,
|
||||
/// IsA will return \c true; otherwise if either is unknown, we
|
||||
/// will simply return false.
|
||||
///
|
||||
/// Therefore this method will not raise any errors.
|
||||
KIND_API static bool IsA(const TfToken& derivedKind, const TfToken &baseKind);
|
||||
|
||||
/// Return an unordered vector of all kinds known to the registry.
|
||||
KIND_API static std::vector<TfToken> GetAllKinds();
|
||||
|
||||
private:
|
||||
friend class TfSingleton<KindRegistry>;
|
||||
|
||||
KindRegistry();
|
||||
virtual ~KindRegistry();
|
||||
|
||||
bool _HasKind(const TfToken& kind) const;
|
||||
|
||||
TfToken _GetBaseKind(const TfToken &kind) const;
|
||||
|
||||
bool _IsA(const TfToken& derivedKind, const TfToken &baseKind) const;
|
||||
|
||||
std::vector<TfToken> _GetAllKinds() const;
|
||||
|
||||
/// Register the given \a kind with the given \a baseKind.
|
||||
/// It is valid for \a baseKind to be empty (the default),
|
||||
/// in which case \a kind represents a root of the kind hierarchy.
|
||||
void _Register(const TfToken& kind,
|
||||
const TfToken& baseKind = TfToken());
|
||||
|
||||
void _RegisterDefaults();
|
||||
|
||||
struct _KindData {
|
||||
TfToken baseKind;
|
||||
};
|
||||
|
||||
typedef std::unordered_map<TfToken, _KindData, TfToken::HashFunctor>
|
||||
_KindMap;
|
||||
|
||||
private:
|
||||
_KindMap _kindMap;
|
||||
};
|
||||
|
||||
KIND_API_TEMPLATE_CLASS(TfSingleton<KindRegistry>);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_KIND_REGISTRY_H
|
||||
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// 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_NDR_API_H
|
||||
#define PXR_USD_NDR_API_H
|
||||
|
||||
#include "pxr/base/arch/export.h"
|
||||
|
||||
#if defined(PXR_STATIC)
|
||||
# define NDR_API
|
||||
# define NDR_API_TEMPLATE_CLASS(...)
|
||||
# define NDR_API_TEMPLATE_STRUCT(...)
|
||||
# define NDR_LOCAL
|
||||
#else
|
||||
# if defined(NDR_EXPORTS)
|
||||
# define NDR_API ARCH_EXPORT
|
||||
# define NDR_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define NDR_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# else
|
||||
# define NDR_API ARCH_IMPORT
|
||||
# define NDR_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define NDR_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# endif
|
||||
# define NDR_LOCAL ARCH_HIDDEN
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// 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_NDR_DEBUG_CODES_H
|
||||
#define PXR_USD_NDR_DEBUG_CODES_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/base/tf/debug.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
TF_DEBUG_CODES(
|
||||
|
||||
NDR_DISCOVERY,
|
||||
NDR_PARSING,
|
||||
NDR_INFO,
|
||||
NDR_STATS,
|
||||
NDR_DEBUG
|
||||
);
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_NDR_DEBUG_CODES_H
|
||||
@@ -0,0 +1,211 @@
|
||||
//
|
||||
// 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_NDR_DECLARE_H
|
||||
#define PXR_USD_NDR_DECLARE_H
|
||||
|
||||
/// \file ndr/declare.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/ndr/api.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class NdrNode;
|
||||
class NdrProperty;
|
||||
class SdfValueTypeName;
|
||||
|
||||
/// \file declare.h
|
||||
///
|
||||
/// Common typedefs that are used throughout the NDR library.
|
||||
|
||||
typedef TfToken NdrIdentifier;
|
||||
typedef TfToken::HashFunctor NdrIdentifierHashFunctor;
|
||||
inline const std::string&
|
||||
NdrGetIdentifierString(const NdrIdentifier& id) { return id.GetString(); }
|
||||
typedef std::vector<NdrIdentifier> NdrIdentifierVec;
|
||||
typedef std::unordered_set<NdrIdentifier,
|
||||
NdrIdentifierHashFunctor> NdrIdentifierSet;
|
||||
|
||||
// Token
|
||||
typedef std::vector<TfToken> NdrTokenVec;
|
||||
typedef std::unordered_map<TfToken, std::string,
|
||||
TfToken::HashFunctor> NdrTokenMap;
|
||||
|
||||
// Property
|
||||
typedef NdrProperty* NdrPropertyPtr;
|
||||
typedef NdrProperty const* NdrPropertyConstPtr;
|
||||
typedef std::unique_ptr<NdrProperty> NdrPropertyUniquePtr;
|
||||
typedef std::vector<NdrPropertyUniquePtr> NdrPropertyUniquePtrVec;
|
||||
typedef std::unordered_map<TfToken, NdrPropertyConstPtr,
|
||||
TfToken::HashFunctor> NdrPropertyPtrMap;
|
||||
|
||||
// Node
|
||||
typedef NdrNode* NdrNodePtr;
|
||||
typedef NdrNode const* NdrNodeConstPtr;
|
||||
typedef std::unique_ptr<NdrNode> NdrNodeUniquePtr;
|
||||
typedef std::vector<NdrNodeConstPtr> NdrNodeConstPtrVec;
|
||||
typedef std::vector<NdrNodeUniquePtr> NdrNodeUniquePtrVec;
|
||||
|
||||
// Misc
|
||||
typedef std::vector<std::string> NdrStringVec;
|
||||
typedef std::pair<TfToken, TfToken> NdrOption;
|
||||
typedef std::vector<NdrOption> NdrOptionVec;
|
||||
typedef std::unordered_set<std::string> NdrStringSet;
|
||||
typedef std::pair<SdfValueTypeName, TfToken> SdfTypeIndicator;
|
||||
|
||||
// Version
|
||||
class NdrVersion {
|
||||
public:
|
||||
/// Create an invalid version.
|
||||
NDR_API
|
||||
NdrVersion() = default;
|
||||
/// Create a version with the given major and minor numbers.
|
||||
/// Numbers must be non-negative, and at least one must be non-zero.
|
||||
/// On failure generates an error and yields an invalid version.
|
||||
NDR_API
|
||||
NdrVersion(int major, int minor = 0);
|
||||
/// Create a version from a string. On failure generates an error and
|
||||
/// yields an invalid version.
|
||||
NDR_API
|
||||
NdrVersion(const std::string& x);
|
||||
|
||||
/// Return an equal version marked as default. It's permitted to mark
|
||||
/// an invalid version as the default.
|
||||
NDR_API
|
||||
NdrVersion GetAsDefault() const
|
||||
{
|
||||
return NdrVersion(*this, true);
|
||||
}
|
||||
|
||||
/// Return the major version number or zero for an invalid version.
|
||||
NDR_API
|
||||
int GetMajor() const { return _major; }
|
||||
/// Return the minor version number or zero for an invalid version.
|
||||
NDR_API
|
||||
int GetMinor() const { return _minor; }
|
||||
/// Return true iff this version is marked as default.
|
||||
NDR_API
|
||||
bool IsDefault() const { return _isDefault; }
|
||||
|
||||
/// Return the version as a string.
|
||||
NDR_API
|
||||
std::string GetString() const;
|
||||
|
||||
/// Return the version as a identifier suffix.
|
||||
NDR_API
|
||||
std::string GetStringSuffix() const;
|
||||
|
||||
/// Return a hash for the version.
|
||||
NDR_API
|
||||
std::size_t GetHash() const
|
||||
{
|
||||
return (static_cast<std::size_t>(_major) << 32) +
|
||||
static_cast<std::size_t>(_minor);
|
||||
}
|
||||
|
||||
/// Return true iff the version is valid.
|
||||
NDR_API
|
||||
explicit operator bool() const
|
||||
{
|
||||
return !!*this;
|
||||
}
|
||||
|
||||
/// Return true iff the version is invalid.
|
||||
NDR_API
|
||||
bool operator!() const
|
||||
{
|
||||
return _major == 0 && _minor == 0;
|
||||
}
|
||||
|
||||
/// Return true iff versions are equal.
|
||||
NDR_API
|
||||
friend bool operator==(const NdrVersion& lhs, const NdrVersion& rhs)
|
||||
{
|
||||
return lhs._major == rhs._major && lhs._minor == rhs._minor;
|
||||
}
|
||||
|
||||
/// Return true iff versions are not equal.
|
||||
NDR_API
|
||||
friend bool operator!=(const NdrVersion& lhs, const NdrVersion& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
/// Return true iff the left side is less than the right side.
|
||||
NDR_API
|
||||
friend bool operator<(const NdrVersion& lhs, const NdrVersion& rhs)
|
||||
{
|
||||
return lhs._major < rhs._major ||
|
||||
(lhs._major == rhs._major && lhs._minor < rhs._minor);
|
||||
}
|
||||
|
||||
/// Return true iff the left side is less than or equal to the right side.
|
||||
NDR_API
|
||||
friend bool operator<=(const NdrVersion& lhs, const NdrVersion& rhs)
|
||||
{
|
||||
return lhs._major < rhs._major ||
|
||||
(lhs._major == rhs._major && lhs._minor <= rhs._minor);
|
||||
}
|
||||
|
||||
/// Return true iff the left side is greater than the right side.
|
||||
NDR_API
|
||||
friend bool operator>(const NdrVersion& lhs, const NdrVersion& rhs)
|
||||
{
|
||||
return !(lhs <= rhs);
|
||||
}
|
||||
|
||||
/// Return true iff the left side is greater than or equal to the right side.
|
||||
NDR_API
|
||||
friend bool operator>=(const NdrVersion& lhs, const NdrVersion& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
private:
|
||||
NdrVersion(const NdrVersion& x, bool)
|
||||
: _major(x._major), _minor(x._minor), _isDefault(true) { }
|
||||
|
||||
private:
|
||||
int _major = 0, _minor = 0;
|
||||
bool _isDefault = false;
|
||||
};
|
||||
|
||||
/// Enumeration used to select nodes by version.
|
||||
enum NdrVersionFilter {
|
||||
NdrVersionFilterDefaultOnly,
|
||||
NdrVersionFilterAllVersions,
|
||||
NdrNumVersionFilters
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_NDR_DECLARE_H
|
||||
@@ -0,0 +1,188 @@
|
||||
//
|
||||
// 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_NDR_DISCOVERY_PLUGIN_H
|
||||
#define PXR_USD_NDR_DISCOVERY_PLUGIN_H
|
||||
|
||||
/// \file ndr/registry.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/ndr/api.h"
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
#include "pxr/base/tf/type.h"
|
||||
#include "pxr/base/tf/weakBase.h"
|
||||
#include "pxr/usd/ndr/declare.h"
|
||||
#include "pxr/usd/ndr/nodeDiscoveryResult.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// Register a discovery plugin (`DiscoveryPluginClass`) with the plugin system.
|
||||
/// If registered, the discovery plugin will execute its discovery process when
|
||||
/// the registry is instantiated.
|
||||
#define NDR_REGISTER_DISCOVERY_PLUGIN(DiscoveryPluginClass) \
|
||||
TF_REGISTRY_FUNCTION(TfType) \
|
||||
{ \
|
||||
TfType::Define<DiscoveryPluginClass, TfType::Bases<NdrDiscoveryPlugin>>() \
|
||||
.SetFactory<NdrDiscoveryPluginFactory<DiscoveryPluginClass>>(); \
|
||||
}
|
||||
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(NdrDiscoveryPluginContext);
|
||||
|
||||
/// A context for discovery. Discovery plugins can use this to get
|
||||
/// a limited set of non-local information without direct coupling
|
||||
/// between plugins.
|
||||
class NdrDiscoveryPluginContext : public TfRefBase, public TfWeakBase
|
||||
{
|
||||
public:
|
||||
NDR_API
|
||||
virtual ~NdrDiscoveryPluginContext() = default;
|
||||
|
||||
/// Returns the source type associated with the discovery type.
|
||||
/// This may return an empty token if there is no such association.
|
||||
NDR_API
|
||||
virtual TfToken GetSourceType(const TfToken& discoveryType) const = 0;
|
||||
};
|
||||
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(NdrDiscoveryPlugin);
|
||||
|
||||
/// \class NdrDiscoveryPlugin
|
||||
///
|
||||
/// Interface for discovery plugins.
|
||||
///
|
||||
/// Discovery plugins, like the name implies, find nodes. Where the plugin
|
||||
/// searches is up to the plugin that implements this interface. Examples
|
||||
/// of discovery plugins could include plugins that look for nodes on the
|
||||
/// filesystem, another that finds nodes in a cloud service, and another that
|
||||
/// searches a local database. Multiple discovery plugins that search the
|
||||
/// filesystem in specific locations/ways could also be created. All discovery
|
||||
/// plugins are executed as soon as the registry is instantiated.
|
||||
///
|
||||
/// These plugins simply report back to the registry what nodes they found in
|
||||
/// a generic way. The registry doesn't know much about the innards of the
|
||||
/// nodes yet, just that the nodes exist. Understanding the nodes is the
|
||||
/// responsibility of another set of plugins defined by the `NdrParserPlugin`
|
||||
/// interface.
|
||||
///
|
||||
/// Discovery plugins report back to the registry via `NdrNodeDiscoveryResult`s.
|
||||
/// These are small, lightweight classes that contain the information for a
|
||||
/// single node that was found during discovery. The discovery result only
|
||||
/// includes node information that can be gleaned pre-parse, so the data is
|
||||
/// fairly limited; to see exactly what's included, and what is expected to
|
||||
/// be populated, see the documentation for `NdrNodeDiscoveryResult`.
|
||||
///
|
||||
/// \section create How to Create a Discovery Plugin
|
||||
/// There are three steps to creating a discovery plugin:
|
||||
/// <ul>
|
||||
/// <li>
|
||||
/// Implement the discovery plugin interface, `NdrDiscoveryPlugin`
|
||||
/// </li>
|
||||
/// <li>
|
||||
/// Register your new plugin with the registry. The registration macro
|
||||
/// must be called in your plugin's implementation file:
|
||||
/// \code{.cpp}
|
||||
/// NDR_REGISTER_DISCOVERY_PLUGIN(YOUR_DISCOVERY_PLUGIN_CLASS_NAME)
|
||||
/// \endcode
|
||||
/// This macro is available in discoveryPlugin.h.
|
||||
/// </li>
|
||||
/// <li>
|
||||
/// In the same folder as your plugin, create a `plugInfo.json` file.
|
||||
/// This file must be formatted like so, substituting
|
||||
/// `YOUR_LIBRARY_NAME`, `YOUR_CLASS_NAME`, and `YOUR_DISPLAY_NAME`:
|
||||
/// \code{.json}
|
||||
/// {
|
||||
/// "Plugins": [{
|
||||
/// "Type": "library",
|
||||
/// "Name": "YOUR_LIBRARY_NAME",
|
||||
/// "Root": "@PLUG_INFO_ROOT@",
|
||||
/// "LibraryPath": "@PLUG_INFO_LIBRARY_PATH@",
|
||||
/// "ResourcePath": "@PLUG_INFO_RESOURCE_PATH@",
|
||||
/// "Info": {
|
||||
/// "Types": {
|
||||
/// "YOUR_CLASS_NAME" : {
|
||||
/// "bases": ["NdrDiscoveryPlugin"],
|
||||
/// "displayName": "YOUR_DISPLAY_NAME"
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
/// }]
|
||||
/// }
|
||||
/// \endcode
|
||||
///
|
||||
/// The NDR ships with one discovery plugin, the
|
||||
/// `_NdrFilesystemDiscoveryPlugin`. Take a look at NDR's plugInfo.json
|
||||
/// file for example values for `YOUR_LIBRARY_NAME`, `YOUR_CLASS_NAME`,
|
||||
/// and `YOUR_DISPLAY_NAME`. If multiple discovery plugins exist in the
|
||||
/// same folder, you can continue adding additional plugins under the
|
||||
/// `Types` key in the JSON. More detailed information about the
|
||||
/// plugInfo.json format can be found in the documentation for the
|
||||
/// `plug` library (in pxr/base).
|
||||
/// </li>
|
||||
/// </ul>
|
||||
///
|
||||
class NdrDiscoveryPlugin : public TfRefBase, public TfWeakBase
|
||||
{
|
||||
public:
|
||||
using Context = NdrDiscoveryPluginContext;
|
||||
|
||||
NDR_API
|
||||
NdrDiscoveryPlugin();
|
||||
NDR_API
|
||||
virtual ~NdrDiscoveryPlugin();
|
||||
|
||||
/// Finds and returns all nodes that the implementing plugin should be
|
||||
/// aware of.
|
||||
NDR_API
|
||||
virtual NdrNodeDiscoveryResultVec DiscoverNodes(const Context&) = 0;
|
||||
|
||||
/// Gets the URIs that this plugin is searching for nodes in.
|
||||
NDR_API
|
||||
virtual const NdrStringVec& GetSearchURIs() const = 0;
|
||||
};
|
||||
|
||||
|
||||
/// \cond
|
||||
/// Factory classes should be hidden from the documentation.
|
||||
|
||||
class NdrDiscoveryPluginFactoryBase : public TfType::FactoryBase
|
||||
{
|
||||
public:
|
||||
NDR_API
|
||||
virtual NdrDiscoveryPluginRefPtr New() const = 0;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class NdrDiscoveryPluginFactory : public NdrDiscoveryPluginFactoryBase
|
||||
{
|
||||
public:
|
||||
NdrDiscoveryPluginRefPtr New() const override
|
||||
{
|
||||
return TfCreateRefPtr(new T);
|
||||
}
|
||||
};
|
||||
|
||||
/// \endcond
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_NDR_DISCOVERY_PLUGIN_H
|
||||
@@ -0,0 +1,110 @@
|
||||
//
|
||||
// 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_NDR_FILESYSTEM_DISCOVERY_H
|
||||
#define PXR_USD_NDR_FILESYSTEM_DISCOVERY_H
|
||||
|
||||
/// \file ndrDiscovery/filesystemDiscovery.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/ndr/api.h"
|
||||
#include "pxr/usd/ndr/discoveryPlugin.h"
|
||||
#include <functional>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(_NdrFilesystemDiscoveryPlugin);
|
||||
|
||||
/// \class _NdrFilesystemDiscoveryPlugin
|
||||
///
|
||||
/// Discovers nodes on the filesystem. The provided search paths are walked to
|
||||
/// find files that have certain extensions. If a file with a matching extension
|
||||
/// is found, it is turned into a `NdrNodeDiscoveryResult` and will be parsed
|
||||
/// into a node when its information is accessed.
|
||||
///
|
||||
/// Parameters for this plugin are specified via environment variables (which
|
||||
/// must be set before the library is loaded):
|
||||
///
|
||||
/// PXR_NDR_FS_PLUGIN_SEARCH_PATHS - The paths that should be searched,
|
||||
/// recursively, for files that represent nodes. Paths should be separated by
|
||||
/// either a ':' or a ';' depending on your platform (it should mimic the PATH
|
||||
/// env var on your platform). See ARCH_PATH_LIST_SEP.
|
||||
///
|
||||
/// PXR_NDR_FS_PLUGIN_ALLOWED_EXTS - The extensions on files that define nodes.
|
||||
/// Do not include the leading ".". Extensions should be separated by a colon.
|
||||
///
|
||||
/// PXR_NDR_FS_PLUGIN_FOLLOW_SYMLINKS - Whether symlinks should be followed
|
||||
/// while walking the search paths. Set to "true" (case sensitive) if they
|
||||
/// should be followed.
|
||||
///
|
||||
class _NdrFilesystemDiscoveryPlugin final : public NdrDiscoveryPlugin
|
||||
{
|
||||
public:
|
||||
/// A filter for discovered nodes. If the function returns false
|
||||
/// then the discovered node is discarded. Otherwise the function
|
||||
/// can modify the discovery result.
|
||||
using Filter = std::function<bool(NdrNodeDiscoveryResult&)>;
|
||||
|
||||
/// Constructor.
|
||||
NDR_API
|
||||
_NdrFilesystemDiscoveryPlugin();
|
||||
|
||||
/// DiscoverNodes() will pass each result to the given function for
|
||||
/// modification. If the function returns false then the result is
|
||||
/// discarded.
|
||||
NDR_API
|
||||
_NdrFilesystemDiscoveryPlugin(Filter filter);
|
||||
|
||||
/// Destructor
|
||||
NDR_API
|
||||
~_NdrFilesystemDiscoveryPlugin() {}
|
||||
|
||||
/// Discover all of the nodes that appear within the the search paths
|
||||
/// provided and match the extensions provided.
|
||||
NDR_API
|
||||
NdrNodeDiscoveryResultVec DiscoverNodes(const Context&) override;
|
||||
|
||||
/// Gets the paths that this plugin is searching for nodes in.
|
||||
NDR_API
|
||||
const NdrStringVec& GetSearchURIs() const override { return _searchPaths; }
|
||||
|
||||
private:
|
||||
/// The paths (abs) indicating where the plugin should search for nodes.
|
||||
NdrStringVec _searchPaths;
|
||||
|
||||
/// The extensions (excluding leading '.') that signify a valid node file.
|
||||
/// The extension will be used as the `type` member in the resulting
|
||||
/// `NdrNodeDiscoveryResult` instance.
|
||||
NdrStringVec _allowedExtensions;
|
||||
|
||||
/// Whether or not to follow symlinks while scanning directories for files.
|
||||
bool _followSymlinks;
|
||||
|
||||
// The filter to run on the results.
|
||||
Filter _filter;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_NDR_FILESYSTEM_DISCOVERY_H
|
||||
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// 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_NDR_FILESYSTEM_DISCOVERY_HELPERS_H
|
||||
#define PXR_USD_NDR_FILESYSTEM_DISCOVERY_HELPERS_H
|
||||
|
||||
/// \file ndr/filesystemDiscoveryHelpers.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/ndr/api.h"
|
||||
#include "pxr/usd/ndr/declare.h"
|
||||
#include "pxr/usd/ndr/nodeDiscoveryResult.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class NdrDiscoveryPluginContext;
|
||||
|
||||
/// \file filesystemDiscoveryHelpers.h
|
||||
///
|
||||
/// Provides utilities that the default filesystem discovery plugin uses. If
|
||||
/// a custom filesystem discovery plugin is needed, these can be used to fill
|
||||
/// in a large chunk of the functionality.
|
||||
///
|
||||
|
||||
/// Walks the specified search paths, optionally following symlinks. Paths
|
||||
/// are walked recursively, and each directory has `FsHelpersExamineFiles()`
|
||||
/// called on it. Only files that match one of the provided extensions (case
|
||||
/// insensitive) are candidates for being turned into `NdrDiscoveryResult`s.
|
||||
/// Returns a vector of discovery results that have been found while walking
|
||||
/// the search paths. In each result the name and identifier will be the
|
||||
/// same, the version will be invalid and default, and the family will
|
||||
/// be empty. The caller is expected to adjust these as appropriate. A
|
||||
/// naive client with no versions and no family will work correctly.
|
||||
NDR_API
|
||||
NdrNodeDiscoveryResultVec
|
||||
NdrFsHelpersDiscoverNodes(
|
||||
const NdrStringVec& searchPaths,
|
||||
const NdrStringVec& allowedExtensions,
|
||||
bool followSymlinks = true,
|
||||
const NdrDiscoveryPluginContext* context = nullptr
|
||||
);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_NDR_FILESYSTEM_DISCOVERY_HELPERS_H
|
||||
@@ -0,0 +1,223 @@
|
||||
//
|
||||
// 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_NDR_NODE_H
|
||||
#define PXR_USD_NDR_NODE_H
|
||||
|
||||
/// \file ndr/node.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/ndr/api.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/usd/ndr/declare.h"
|
||||
#include "pxr/usd/ndr/nodeDiscoveryResult.h"
|
||||
#include "pxr/usd/ndr/property.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class NdrNode
|
||||
///
|
||||
/// Represents an abstract node. Describes information like the name of the
|
||||
/// node, what its inputs and outputs are, and any associated metadata.
|
||||
///
|
||||
/// In almost all cases, this class will not be used directly. More specialized
|
||||
/// nodes can be created that derive from `NdrNode`; those specialized nodes can
|
||||
/// add their own domain-specific data and methods.
|
||||
///
|
||||
class NdrNode
|
||||
{
|
||||
public:
|
||||
/// Constructor.
|
||||
NDR_API
|
||||
NdrNode(const NdrIdentifier& identifier,
|
||||
const NdrVersion& version,
|
||||
const std::string& name,
|
||||
const TfToken& family,
|
||||
const TfToken& context,
|
||||
const TfToken& sourceType,
|
||||
const std::string& definitionURI,
|
||||
const std::string& implementationURI,
|
||||
NdrPropertyUniquePtrVec&& properties,
|
||||
const NdrTokenMap& metadata = NdrTokenMap(),
|
||||
const std::string &sourceCode = std::string());
|
||||
|
||||
/// Destructor.
|
||||
NDR_API
|
||||
virtual ~NdrNode();
|
||||
|
||||
/// \name The Basics
|
||||
/// @{
|
||||
|
||||
/// Return the identifier of the node.
|
||||
const NdrIdentifier& GetIdentifier() const { return _identifier; }
|
||||
|
||||
/// Return the version of the node
|
||||
NdrVersion GetVersion() const { return _version; }
|
||||
|
||||
/// Gets the name of the node.
|
||||
const std::string& GetName() const { return _name; }
|
||||
|
||||
/// Gets the name of the family that the node belongs to. An empty token
|
||||
/// will be returned if the node does not belong to a family.
|
||||
const TfToken& GetFamily() const { return _family; }
|
||||
|
||||
/// Gets the context of the node.
|
||||
///
|
||||
/// The context is the context that the node declares itself as having (or,
|
||||
/// if a particular node does not declare a context, it will be assigned a
|
||||
/// default context by the parser).
|
||||
///
|
||||
/// As a concrete example from the `Sdr` library, a shader with a specific
|
||||
/// source type may perform different duties vs. another shader with the
|
||||
/// same source type. For example, one shader with a source type of
|
||||
/// `SdrArgsParser::SourceType` may declare itself as having a context of
|
||||
/// 'pattern', while another shader of the same source type may say it is
|
||||
/// used for lighting, and thus has a context of 'light'.
|
||||
const TfToken& GetContext() const { return _context; }
|
||||
|
||||
/// Gets the type of source that this node originated from.
|
||||
///
|
||||
/// Note that this is distinct from `GetContext()`, which is the type that
|
||||
/// the node declares itself as having.
|
||||
///
|
||||
/// As a concrete example from the `Sdr` library, several shader parsers
|
||||
/// exist and operate on different types of shaders. In this scenario, each
|
||||
/// distinct type of shader (OSL, Args, etc) is considered a different
|
||||
/// _source_, even though they are all shaders. In addition, the shaders
|
||||
/// under each source type may declare themselves as having a specific
|
||||
/// context (shaders can serve different roles). See `GetContext()` for
|
||||
/// more information on this.
|
||||
const TfToken& GetSourceType() const { return _sourceType; }
|
||||
|
||||
/// Gets the URI to the resource that provided this node's
|
||||
/// definition. Could be a path to a file, or some other resource
|
||||
/// identifier. This URI should be fully resolved.
|
||||
///
|
||||
/// \sa NdrNode::GetResolvedImplementationURI()
|
||||
const std::string& GetResolvedDefinitionURI() const { return _definitionURI; }
|
||||
|
||||
/// Gets the URI to the resource that provides this node's
|
||||
/// implementation. Could be a path to a file, or some other resource
|
||||
/// identifier. This URI should be fully resolved.
|
||||
///
|
||||
/// \sa NdrNode::GetResolvedDefinitionURI()
|
||||
const std::string& GetResolvedImplementationURI() const { return _implementationURI; }
|
||||
|
||||
/// Returns the source code for this node. This will be empty for most
|
||||
/// nodes. It will be non-empty only for the nodes that are constructed
|
||||
/// using \ref NdrRegistry::GetNodeFromSourceCode(), in which case, the
|
||||
/// source code has not been parsed (or even compiled) yet.
|
||||
///
|
||||
/// An unparsed node with non-empty source-code but no properties is
|
||||
/// considered to be invalid. Once the node is parsed and the relevant
|
||||
/// properties and metadata are extracted from the source code, the node
|
||||
/// becomes valid.
|
||||
///
|
||||
/// \sa NdrNode::IsValid
|
||||
const std::string &GetSourceCode() const { return _sourceCode; }
|
||||
|
||||
/// Whether or not this node is valid. A node that is valid indicates that
|
||||
/// the parser plugin was able to successfully parse the contents of this
|
||||
/// node.
|
||||
///
|
||||
/// Note that if a node is not valid, some data like its name, URI, source
|
||||
/// code etc. could still be available (data that was obtained during the
|
||||
/// discovery process). However, other data that must be gathered from the
|
||||
/// parsing process will NOT be available (eg, inputs and outputs).
|
||||
NDR_API
|
||||
virtual bool IsValid() const { return _isValid; }
|
||||
|
||||
/// Gets a string with basic information about this node. Helpful for
|
||||
/// things like adding this node to a log.
|
||||
NDR_API
|
||||
virtual std::string GetInfoString() const;
|
||||
|
||||
/// @}
|
||||
|
||||
|
||||
/// \name Inputs and Outputs
|
||||
/// An input or output is also generically referred to as a "property".
|
||||
/// @{
|
||||
|
||||
/// Get an ordered list of all the input names on this node.
|
||||
NDR_API
|
||||
const NdrTokenVec& GetInputNames() const;
|
||||
|
||||
/// Get an ordered list of all the output names on this node.
|
||||
NDR_API
|
||||
const NdrTokenVec& GetOutputNames() const;
|
||||
|
||||
/// Get an input property by name. `nullptr` is returned if an input with
|
||||
/// the given name does not exist.
|
||||
NDR_API
|
||||
NdrPropertyConstPtr GetInput(const TfToken& inputName) const;
|
||||
|
||||
/// Get an output property by name. `nullptr` is returned if an output with
|
||||
/// the given name does not exist.
|
||||
NDR_API
|
||||
NdrPropertyConstPtr GetOutput(const TfToken& outputName) const;
|
||||
|
||||
/// @}
|
||||
|
||||
|
||||
/// \name Metadata
|
||||
/// The metadata returned here is a direct result of what the parser plugin
|
||||
/// is able to determine about the node. See the documentation for a
|
||||
/// specific parser plugin to get help on what the parser is looking for to
|
||||
/// populate these values.
|
||||
/// @{
|
||||
|
||||
/// All metadata that came from the parse process. Specialized nodes may
|
||||
/// isolate values in the metadata (with possible manipulations and/or
|
||||
/// additional parsing) and expose those values in their API.
|
||||
NDR_API
|
||||
const NdrTokenMap& GetMetadata() const;
|
||||
|
||||
/// @}
|
||||
|
||||
protected:
|
||||
NdrNode& operator=(const NdrNode&) = delete;
|
||||
|
||||
bool _isValid;
|
||||
NdrIdentifier _identifier;
|
||||
NdrVersion _version;
|
||||
std::string _name;
|
||||
TfToken _family;
|
||||
TfToken _context;
|
||||
TfToken _sourceType;
|
||||
std::string _definitionURI;
|
||||
std::string _implementationURI;
|
||||
NdrPropertyUniquePtrVec _properties;
|
||||
NdrTokenMap _metadata;
|
||||
std::string _sourceCode;
|
||||
|
||||
NdrPropertyPtrMap _inputs;
|
||||
NdrTokenVec _inputNames;
|
||||
NdrPropertyPtrMap _outputs;
|
||||
NdrTokenVec _outputNames;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_NDR_NODE_H
|
||||
@@ -0,0 +1,162 @@
|
||||
//
|
||||
// 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_NDR_NODE_DISCOVERY_RESULT_H
|
||||
#define PXR_USD_NDR_NODE_DISCOVERY_RESULT_H
|
||||
|
||||
#include "pxr/usd/ndr/declare.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// Represents the raw data of a node, and some other bits of metadata, that
|
||||
/// were determined via a `NdrDiscoveryPlugin`.
|
||||
struct NdrNodeDiscoveryResult {
|
||||
/// Constructor.
|
||||
NdrNodeDiscoveryResult(
|
||||
const NdrIdentifier& identifier,
|
||||
const NdrVersion& version,
|
||||
const std::string& name,
|
||||
const TfToken& family,
|
||||
const TfToken& discoveryType,
|
||||
const TfToken& sourceType,
|
||||
const std::string& uri,
|
||||
const std::string& resolvedUri,
|
||||
const std::string &sourceCode=std::string(),
|
||||
const NdrTokenMap &metadata=NdrTokenMap(),
|
||||
const std::string& blindData=std::string(),
|
||||
const TfToken& subIdentifier=TfToken(),
|
||||
const NdrTokenVec& aliases=NdrTokenVec()
|
||||
) : identifier(identifier),
|
||||
version(version),
|
||||
name(name),
|
||||
family(family),
|
||||
discoveryType(discoveryType),
|
||||
sourceType(sourceType),
|
||||
uri(uri),
|
||||
resolvedUri(resolvedUri),
|
||||
sourceCode(sourceCode),
|
||||
metadata(metadata),
|
||||
blindData(blindData),
|
||||
subIdentifier(subIdentifier),
|
||||
aliases(aliases)
|
||||
{ }
|
||||
|
||||
/// The node's identifier.
|
||||
///
|
||||
/// How the node is identified. In many cases this will be the
|
||||
/// name of the file or resource that this node originated from.
|
||||
/// E.g. "mix_float_2_1". The identifier must be unique for a
|
||||
/// given sourceType.
|
||||
NdrIdentifier identifier;
|
||||
|
||||
/// The node's version. This may or may not be embedded in the
|
||||
/// identifier, it's up to implementations. E.g a node with
|
||||
/// identifier "mix_float_2_1" might have version 2.1.
|
||||
NdrVersion version;
|
||||
|
||||
/// The node's name.
|
||||
///
|
||||
/// A version independent identifier for the node type. This will
|
||||
/// often embed type parameterization but should not embed the
|
||||
/// version. E.g a node with identifier "mix_float_2_1" might have
|
||||
/// name "mix_float".
|
||||
std::string name;
|
||||
|
||||
/// The node's family.
|
||||
///
|
||||
/// A node's family is an optional piece of metadata that specifies a
|
||||
/// generic grouping of nodes. E.g a node with identifier
|
||||
/// "mix_float_2_1" might have family "mix".
|
||||
TfToken family;
|
||||
|
||||
/// The node's discovery type.
|
||||
///
|
||||
/// The type could be the file extension, or some other type of metadata
|
||||
/// that can signify a type prior to parsing. See the documentation for
|
||||
/// `NdrParserPlugin` and `NdrParserPlugin::DiscoveryTypes` for more
|
||||
/// information on how this value is used.
|
||||
TfToken discoveryType;
|
||||
|
||||
/// The node's source type.
|
||||
///
|
||||
/// This type is unique to the parsing plugin
|
||||
/// (`NdrParserPlugin::SourceType`), and determines the source of the node.
|
||||
/// See `NdrNode::GetSourceType()` for more information.
|
||||
TfToken sourceType;
|
||||
|
||||
/// The node's origin.
|
||||
///
|
||||
/// This may be a filesystem path, a URL pointing to a resource in the
|
||||
/// cloud, or some other type of resource identifier.
|
||||
std::string uri;
|
||||
|
||||
/// The node's fully-resolved URI.
|
||||
///
|
||||
/// For example, this might be an absolute path when the original URI was
|
||||
/// a relative path. In most cases, this is the path that `Ar`'s
|
||||
/// `Resolve()` returns. In any case, this path should be locally
|
||||
/// accessible.
|
||||
std::string resolvedUri;
|
||||
|
||||
/// The node's entire source code.
|
||||
///
|
||||
/// The source code is parsed (if non-empty) by parser plugins when the
|
||||
/// resolvedUri value is empty.
|
||||
std::string sourceCode;
|
||||
|
||||
/// The node's metadata collected during the discovery process.
|
||||
///
|
||||
/// Additional metadata may be present in the node's source, in the asset
|
||||
/// pointed to by resolvedUri or in sourceCode (if resolvedUri is empty).
|
||||
/// In general, parsers should override this data with metadata from the
|
||||
/// shader source.
|
||||
NdrTokenMap metadata;
|
||||
|
||||
/// An optional detail for the parser plugin. The parser plugin
|
||||
/// defines the meaning of this data so the discovery plugin must
|
||||
/// be written to match.
|
||||
std::string blindData;
|
||||
|
||||
/// The subIdentifier is associated with a particular asset and refers to a
|
||||
/// specific definition within the asset. The asset is the one referred to
|
||||
/// by `NdrRegistry::GetNodeFromAsset()`. The subIdentifier is not needed
|
||||
/// for all cases where the node definition is not associated with an asset.
|
||||
/// Even if the node definition is associated with an asset, the
|
||||
/// subIdentifier is only needed if the asset specifies multiple definitions
|
||||
/// rather than a single definition.
|
||||
TfToken subIdentifier;
|
||||
|
||||
/// A list of aliases that can be used when looking up the node by
|
||||
/// identifier in the NdrRegistry.
|
||||
///
|
||||
/// See NdrRegistry::GetNodesByIdentifier, NdrRegistry::GetNodeByIdentifier,
|
||||
/// and NdrRegistry::GetNodeByIdentifierAndType.
|
||||
NdrTokenVec aliases;
|
||||
};
|
||||
|
||||
typedef std::vector<NdrNodeDiscoveryResult> NdrNodeDiscoveryResultVec;
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_NDR_NODE_DISCOVERY_RESULT_H
|
||||
@@ -0,0 +1,190 @@
|
||||
//
|
||||
// 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_NDR_PARSER_PLUGIN_H
|
||||
#define PXR_USD_NDR_PARSER_PLUGIN_H
|
||||
|
||||
/// \file ndr/parserPlugin.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/ndr/api.h"
|
||||
#include "pxr/base/tf/type.h"
|
||||
#include "pxr/base/tf/weakBase.h"
|
||||
#include "pxr/base/tf/weakPtr.h"
|
||||
#include "pxr/usd/ndr/declare.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
// Forward declarations
|
||||
struct NdrNodeDiscoveryResult;
|
||||
|
||||
/// Register a parser plugin with the plugin system.
|
||||
#define NDR_REGISTER_PARSER_PLUGIN(ParserPluginClass) \
|
||||
TF_REGISTRY_FUNCTION(TfType) \
|
||||
{ \
|
||||
TfType::Define<ParserPluginClass, TfType::Bases<NdrParserPlugin>>() \
|
||||
.SetFactory<NdrParserPluginFactory<ParserPluginClass>>(); \
|
||||
}
|
||||
|
||||
/// \class NdrParserPlugin
|
||||
///
|
||||
/// Interface for parser plugins.
|
||||
///
|
||||
/// Parser plugins take a `NdrNodeDiscoveryResult` from the discovery process
|
||||
/// and creates a full `NdrNode` instance (or, in the case of a real-world
|
||||
/// scenario, a specialized node that derives from `NdrNode`). The parser that
|
||||
/// is selected to run is ultimately decided by the registry, and depends on the
|
||||
/// `NdrNodeDiscoveryResult`'s `discoveryType` member. A parser plugin's
|
||||
/// `GetDiscoveryTypes()` method is how this link is made. If a discovery result
|
||||
/// has a `discoveryType` of 'foo', and `SomeParserPlugin` has 'foo' included
|
||||
/// in its `GetDiscoveryTypes()` return value, `SomeParserPlugin` will parse
|
||||
/// that discovery result.
|
||||
///
|
||||
/// Another kind of 'type' within the parser plugin is the 'source type'. The
|
||||
/// discovery type simply acts as a way to link a discovery result to a parser
|
||||
/// plugin. On the other hand, a 'source type' acts as an umbrella type that
|
||||
/// groups all of the discovery types together. For example, if a plugin handled
|
||||
/// discovery types 'foo', 'bar', and 'baz' (which are all related because they
|
||||
/// are all handled by the same parser), they may all be grouped under one
|
||||
/// unifying source type. This type is available on the node via
|
||||
/// `NdrNode::GetSourceType()`.
|
||||
///
|
||||
/// \section create How to Create a Parser Plugin
|
||||
/// There are three steps to creating a parser plugin:
|
||||
/// <ul>
|
||||
/// <li>
|
||||
/// Implement the parser plugin interface. An example parser plugin is
|
||||
/// available in the plugin folder under `sdrOsl`. The `Parse()` method
|
||||
/// should return the specialized node that derives from `NdrNode` (and
|
||||
/// this node should also be constructed with its specialized
|
||||
/// properties). Examples of a specialized node and property class are
|
||||
/// `SdrShaderNode` and `SdrShaderProperty`.
|
||||
/// </li>
|
||||
/// <li>
|
||||
/// Register your new plugin with the registry. The registration macro
|
||||
/// must be called in your plugin's implementation file:
|
||||
/// \code{.cpp}
|
||||
/// NDR_REGISTER_PARSER_PLUGIN(<YOUR_PARSER_PLUGIN_CLASS_NAME>)
|
||||
/// \endcode
|
||||
/// This macro is available in parserPlugin.h.
|
||||
/// </li>
|
||||
/// <li>
|
||||
/// In the same folder as your plugin, create a `plugInfo.json` file.
|
||||
/// This file must be formatted like so, substituting
|
||||
/// `YOUR_LIBRARY_NAME`, `YOUR_CLASS_NAME`, and `YOUR_DISPLAY_NAME`:
|
||||
/// \code{.json}
|
||||
/// {
|
||||
/// "Plugins": [{
|
||||
/// "Type": "library",
|
||||
/// "Name": "YOUR_LIBRARY_NAME",
|
||||
/// "Root": "@PLUG_INFO_ROOT@",
|
||||
/// "LibraryPath": "@PLUG_INFO_LIBRARY_PATH@",
|
||||
/// "ResourcePath": "@PLUG_INFO_RESOURCE_PATH@",
|
||||
/// "Info": {
|
||||
/// "Types": {
|
||||
/// "YOUR_CLASS_NAME" : {
|
||||
/// "bases": ["NdrParserPlugin"],
|
||||
/// "displayName": "YOUR_DISPLAY_NAME"
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
/// }]
|
||||
/// }
|
||||
/// \endcode
|
||||
///
|
||||
/// The SDR ships with one parser plugin, the `SdrOslParserPlugin`. Take
|
||||
/// a look at its plugInfo.json file for example values for
|
||||
/// `YOUR_LIBRARY_NAME`, `YOUR_CLASS_NAME`, and `YOUR_DISPLAY_NAME`. If
|
||||
/// multiple parser plugins exist in the same folder, you can continue
|
||||
/// adding additional plugins under the `Types` key in the JSON. More
|
||||
/// detailed information about the plugInfo.json format can be found in
|
||||
/// the documentation for the `plug` library (in pxr/base).
|
||||
/// </li>
|
||||
/// </ul>
|
||||
class NdrParserPlugin : public TfWeakBase
|
||||
{
|
||||
public:
|
||||
NDR_API
|
||||
NdrParserPlugin();
|
||||
NDR_API
|
||||
virtual ~NdrParserPlugin();
|
||||
|
||||
/// Takes the specified `NdrNodeDiscoveryResult` instance, which was a
|
||||
/// result of the discovery process, and generates a new `NdrNode`.
|
||||
/// The node's name, source type, and family must match.
|
||||
NDR_API
|
||||
virtual NdrNodeUniquePtr Parse(
|
||||
const NdrNodeDiscoveryResult& discoveryResult) = 0;
|
||||
|
||||
/// Returns the types of nodes that this plugin can parse.
|
||||
///
|
||||
/// "Type" here is the discovery type (in the case of files, this will
|
||||
/// probably be the file extension, but in other systems will be data that
|
||||
/// can be determined during discovery). This type should only be used to
|
||||
/// match up a `NdrNodeDiscoveryResult` to its parser plugin; this value is
|
||||
/// not exposed in the node's API.
|
||||
NDR_API
|
||||
virtual const NdrTokenVec& GetDiscoveryTypes() const = 0;
|
||||
|
||||
/// Returns the source type that this parser operates on.
|
||||
///
|
||||
/// A source type is the most general type for a node. The parser plugin is
|
||||
/// responsible for parsing all discovery results that have the types
|
||||
/// declared under `GetDiscoveryTypes()`, and those types are collectively
|
||||
/// identified as one "source type".
|
||||
NDR_API
|
||||
virtual const TfToken& GetSourceType() const = 0;
|
||||
|
||||
/// Gets an invalid node based on the discovery result provided. An invalid
|
||||
/// node is a node that has no properties, but may have basic data found
|
||||
/// during discovery.
|
||||
NDR_API
|
||||
static NdrNodeUniquePtr GetInvalidNode(const NdrNodeDiscoveryResult& dr);
|
||||
};
|
||||
|
||||
|
||||
/// \cond
|
||||
/// Factory classes should be hidden from the documentation.
|
||||
|
||||
class NdrParserPluginFactoryBase : public TfType::FactoryBase
|
||||
{
|
||||
public:
|
||||
virtual NdrParserPlugin* New() const = 0;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class NdrParserPluginFactory : public NdrParserPluginFactoryBase
|
||||
{
|
||||
public:
|
||||
virtual NdrParserPlugin* New() const
|
||||
{
|
||||
return new T;
|
||||
}
|
||||
};
|
||||
|
||||
/// \endcond
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_NDR_PARSER_PLUGIN_H
|
||||
@@ -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_NDR_PROPERTY_H
|
||||
#define PXR_USD_NDR_PROPERTY_H
|
||||
|
||||
/// \file ndr/property.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/ndr/api.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
#include "pxr/usd/ndr/declare.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class NdrProperty
|
||||
///
|
||||
/// Represents a property (input or output) that is part of a `NdrNode`
|
||||
/// instance.
|
||||
///
|
||||
/// A property must have a name and type, but may also specify a host of
|
||||
/// additional metadata. Instances can also be queried to determine if another
|
||||
/// `NdrProperty` instance can be connected to it.
|
||||
///
|
||||
/// In almost all cases, this class will not be used directly. More specialized
|
||||
/// properties can be created that derive from `NdrProperty`; those specialized
|
||||
/// properties can add their own domain-specific data and methods.
|
||||
class NdrProperty
|
||||
{
|
||||
public:
|
||||
/// Constructor.
|
||||
NDR_API
|
||||
NdrProperty(
|
||||
const TfToken& name,
|
||||
const TfToken& type,
|
||||
const VtValue& defaultValue,
|
||||
bool isOutput,
|
||||
size_t arraySize,
|
||||
bool isDynamicArray,
|
||||
const NdrTokenMap& metadata
|
||||
);
|
||||
|
||||
/// Destructor.
|
||||
NDR_API
|
||||
virtual ~NdrProperty();
|
||||
|
||||
/// \name The Basics
|
||||
/// @{
|
||||
|
||||
/// Gets the name of the property.
|
||||
NDR_API
|
||||
const TfToken& GetName() const { return _name; }
|
||||
|
||||
/// Gets the type of the property.
|
||||
NDR_API
|
||||
const TfToken& GetType() const { return _type; }
|
||||
|
||||
/// Gets this property's default value.
|
||||
NDR_API
|
||||
const VtValue& GetDefaultValue() const { return _defaultValue; }
|
||||
|
||||
/// Whether this property is an output.
|
||||
NDR_API
|
||||
bool IsOutput() const { return _isOutput; }
|
||||
|
||||
/// Whether this property's type is an array type.
|
||||
NDR_API
|
||||
bool IsArray() const { return (_arraySize > 0) || _isDynamicArray; }
|
||||
|
||||
/// Whether this property's array type is dynamically-sized.
|
||||
NDR_API
|
||||
bool IsDynamicArray() const { return _isDynamicArray; };
|
||||
|
||||
/// Gets this property's array size.
|
||||
///
|
||||
/// If this property is a fixed-size array type, the array size is returned.
|
||||
/// In the case of a dynamically-sized array, this method returns the array
|
||||
/// size that the parser reports, and should not be relied upon to be
|
||||
/// accurate. A parser may report -1 for the array size, for example, to
|
||||
/// indicate a dynamically-sized array. For types that are not a fixed-size
|
||||
/// array or dynamic array, this returns 0.
|
||||
NDR_API
|
||||
int GetArraySize() const { return _arraySize; }
|
||||
|
||||
/// Gets a string with basic information about this property. Helpful for
|
||||
/// things like adding this property to a log.
|
||||
NDR_API
|
||||
virtual std::string GetInfoString() const;
|
||||
|
||||
/// @}
|
||||
|
||||
|
||||
/// \name Metadata
|
||||
/// The metadata returned here is a direct result of what the parser plugin
|
||||
/// is able to determine about the node. See the documentation for a
|
||||
/// specific parser plugin to get help on what the parser is looking for to
|
||||
/// populate these values.
|
||||
/// @{
|
||||
|
||||
/// All of the metadata that came from the parse process.
|
||||
NDR_API
|
||||
virtual const NdrTokenMap& GetMetadata() const { return _metadata; }
|
||||
|
||||
/// @}
|
||||
|
||||
|
||||
/// \name Connection Information
|
||||
/// @{
|
||||
|
||||
/// Whether this property can be connected to other properties.
|
||||
NDR_API
|
||||
virtual bool IsConnectable() const;
|
||||
|
||||
/// Determines if this property can be connected to the specified property.
|
||||
NDR_API
|
||||
virtual bool CanConnectTo(const NdrProperty& other) const;
|
||||
|
||||
/// @}
|
||||
|
||||
|
||||
/// \name Utilities
|
||||
/// @{
|
||||
|
||||
/// Converts the property's type from `GetType()` into a `SdfValueTypeName`.
|
||||
///
|
||||
/// Two scenarios can result: an exact mapping from property type to Sdf
|
||||
/// type, and an inexact mapping. In the first scenario, the first element
|
||||
/// in the pair will be the cleanly-mapped Sdf type, and the second element,
|
||||
/// a TfToken, will be empty. In the second scenario, the Sdf type will be
|
||||
/// set to `Token` to indicate an unclean mapping, and the second element
|
||||
/// will be set to the original type returned by `GetType()`.
|
||||
///
|
||||
/// This base property class is generic and cannot know ahead of time how to
|
||||
/// perform this mapping reliably, thus it will always fall into the second
|
||||
/// scenario. It is up to specialized properties to perform the mapping.
|
||||
NDR_API
|
||||
virtual const SdfTypeIndicator GetTypeAsSdfType() const;
|
||||
|
||||
/// @}
|
||||
|
||||
protected:
|
||||
NdrProperty& operator=(const NdrProperty&) = delete;
|
||||
|
||||
TfToken _name;
|
||||
TfToken _type;
|
||||
VtValue _defaultValue;
|
||||
bool _isOutput;
|
||||
size_t _arraySize;
|
||||
bool _isDynamicArray;
|
||||
bool _isConnectable;
|
||||
NdrTokenMap _metadata;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_NDR_PROPERTY_H
|
||||
@@ -0,0 +1,403 @@
|
||||
//
|
||||
// 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_NDR_REGISTRY_H
|
||||
#define PXR_USD_NDR_REGISTRY_H
|
||||
|
||||
/// \file ndr/registry.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/ndr/api.h"
|
||||
#include "pxr/base/tf/weakBase.h"
|
||||
#include "pxr/usd/ndr/declare.h"
|
||||
#include "pxr/usd/ndr/discoveryPlugin.h"
|
||||
#include "pxr/usd/ndr/node.h"
|
||||
#include "pxr/usd/ndr/nodeDiscoveryResult.h"
|
||||
#include "pxr/usd/ndr/parserPlugin.h"
|
||||
#include "pxr/usd/sdf/assetPath.h"
|
||||
#include <mutex>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class NdrRegistry
|
||||
///
|
||||
/// The registry provides access to node information. "Discovery Plugins" are
|
||||
/// responsible for finding the nodes that should be included in the registry.
|
||||
///
|
||||
/// Discovery plugins are found through the plugin system. If additional
|
||||
/// discovery plugins need to be specified, a client can pass them to
|
||||
/// `SetExtraDiscoveryPlugins()`.
|
||||
///
|
||||
/// When the registry is first told about the discovery plugins, the plugins
|
||||
/// will be asked to discover nodes. These plugins will generate
|
||||
/// `NdrNodeDiscoveryResult` instances, which only contain basic metadata. Once
|
||||
/// the client asks for information that would require the node's contents to
|
||||
/// be parsed (eg, what its inputs and outputs are), the registry will begin the
|
||||
/// parsing process on an as-needed basis. See `NdrNodeDiscoveryResult` for the
|
||||
/// information that can be retrieved without triggering a parse.
|
||||
///
|
||||
/// Some methods in this library may allow for a "family" to be provided. A
|
||||
/// family is simply a generic grouping which is optional.
|
||||
///
|
||||
class NdrRegistry : public TfWeakBase
|
||||
{
|
||||
public:
|
||||
using DiscoveryPluginRefPtrVec = NdrDiscoveryPluginRefPtrVector;
|
||||
|
||||
/// Allows the client to set any additional discovery plugins that would
|
||||
/// otherwise NOT be found through the plugin system. Runs the discovery
|
||||
/// process for the specified plugins immediately.
|
||||
///
|
||||
/// Note that this method cannot be called after any nodes in the registry
|
||||
/// have been parsed (eg, through GetNode*()), otherwise an error will
|
||||
/// result.
|
||||
NDR_API
|
||||
void SetExtraDiscoveryPlugins(DiscoveryPluginRefPtrVec plugins);
|
||||
|
||||
/// Allows the client to set any additional discovery plugins that would
|
||||
/// otherwise NOT be found through the plugin system. Runs the discovery
|
||||
/// process for the specified plugins immediately.
|
||||
///
|
||||
/// Note that this method cannot be called after any nodes in the registry
|
||||
/// have been parsed (eg, through GetNode*()), otherwise an error will
|
||||
/// result.
|
||||
NDR_API
|
||||
void SetExtraDiscoveryPlugins(const std::vector<TfType>& pluginTypes);
|
||||
|
||||
/// Allows the client to set any additional parser plugins that would
|
||||
/// otherwise NOT be found through the plugin system.
|
||||
///
|
||||
/// Note that this method cannot be called after any nodes in the registry
|
||||
/// have been parsed (eg, through GetNode*()), otherwise an error will
|
||||
/// result.
|
||||
NDR_API
|
||||
void SetExtraParserPlugins(const std::vector<TfType>& pluginTypes);
|
||||
|
||||
/// Parses the given \p asset, constructs a NdrNode from it and adds it to
|
||||
/// the registry.
|
||||
///
|
||||
/// Nodes created from an asset using this API can be looked up by the
|
||||
/// unique identifier and sourceType of the returned node, or by URI,
|
||||
/// which will be set to the unresolved asset path value.
|
||||
///
|
||||
/// \p metadata contains additional metadata needed for parsing and
|
||||
/// compiling the source code in the file pointed to by \p asset correctly.
|
||||
/// This metadata supplements the metadata available in the asset and
|
||||
/// overrides it in cases where there are key collisions.
|
||||
///
|
||||
/// \p subidentifier is optional, and it would be used to indicate a
|
||||
/// particular definition in the asset file if the asset contains multiple
|
||||
/// node definitions.
|
||||
///
|
||||
/// \p sourceType is optional, and it is only needed to indicate a
|
||||
/// particular type if the asset file is capable of representing a node
|
||||
/// definition of multiple source types.
|
||||
///
|
||||
/// Returns a valid node if the asset is parsed successfully using one
|
||||
/// of the registered parser plugins.
|
||||
NDR_API
|
||||
NdrNodeConstPtr GetNodeFromAsset(const SdfAssetPath &asset,
|
||||
const NdrTokenMap &metadata,
|
||||
const TfToken &subIdentifier=TfToken(),
|
||||
const TfToken &sourceType=TfToken());
|
||||
|
||||
/// Parses the given \p sourceCode string, constructs a NdrNode from it and
|
||||
/// adds it to the registry. The parser to be used is determined by the
|
||||
/// specified \p sourceType.
|
||||
///
|
||||
/// Nodes created from source code using this API can be looked up by the
|
||||
/// unique identifier and sourceType of the returned node.
|
||||
///
|
||||
/// \p metadata contains additional metadata needed for parsing and
|
||||
/// compiling the source code correctly. This metadata supplements the
|
||||
/// metadata available in \p sourceCode and overrides it cases where there
|
||||
/// are key collisions.
|
||||
///
|
||||
/// Returns a valid node if the given source code is parsed successfully
|
||||
/// using the parser plugins that is registered for the specified
|
||||
/// \p sourceType.
|
||||
NDR_API
|
||||
NdrNodeConstPtr GetNodeFromSourceCode(const std::string &sourceCode,
|
||||
const TfToken &sourceType,
|
||||
const NdrTokenMap &metadata);
|
||||
|
||||
/// Get the locations where the registry is searching for nodes.
|
||||
///
|
||||
/// Depending on which discovery plugins were used, this may include
|
||||
/// non-filesystem paths.
|
||||
NDR_API
|
||||
NdrStringVec GetSearchURIs() const;
|
||||
|
||||
/// Get the identifiers of all the nodes that the registry is aware of.
|
||||
///
|
||||
/// This will not run the parsing plugins on the nodes that have been
|
||||
/// discovered, so this method is relatively quick. Optionally, a "family"
|
||||
/// name can be specified to only get the identifiers of nodes that belong
|
||||
/// to that family and a filter can be specified to get just the default
|
||||
/// version (the default) or all versions of the node.
|
||||
NDR_API
|
||||
NdrIdentifierVec
|
||||
GetNodeIdentifiers(const TfToken& family = TfToken(),
|
||||
NdrVersionFilter filter =
|
||||
NdrVersionFilterDefaultOnly) const;
|
||||
|
||||
/// Get the names of all the nodes that the registry is aware of.
|
||||
///
|
||||
/// This will not run the parsing plugins on the nodes that have been
|
||||
/// discovered, so this method is relatively quick. Optionally, a "family"
|
||||
/// name can be specified to only get the names of nodes that belong to
|
||||
/// that family.
|
||||
NDR_API
|
||||
NdrStringVec GetNodeNames(const TfToken& family = TfToken()) const;
|
||||
|
||||
/// Get the node with the specified \p identifier, and an optional
|
||||
/// \p sourceTypePriority list specifying the set of node SOURCE types (see
|
||||
/// `NdrNode::GetSourceType()`) that should be searched.
|
||||
///
|
||||
/// If no sourceTypePriority is specified, the first encountered node with
|
||||
/// the specified identifier will be returned (first is arbitrary) if found.
|
||||
/// If no matching node is found then the first node found with an alias
|
||||
/// matching the identifier will be returned if one exists.
|
||||
///
|
||||
/// If a sourceTypePriority list is specified, then this will iterate
|
||||
/// through each source type and try to find a node matching by identifier
|
||||
/// or alias. This is equivalent to calling
|
||||
/// NdrRegistry::GetNodeByIdentifierAndType for each source type until a
|
||||
/// node is found.
|
||||
///
|
||||
/// Nodes of the same identifier but different source type can exist
|
||||
/// in the registry. If a node 'Foo' with source types 'abc' and 'xyz'
|
||||
/// exist in the registry, and you want to make sure the 'abc' version
|
||||
/// is fetched before the 'xyz' version, the priority list would be
|
||||
/// specified as ['abc', 'xyz']. If the 'abc' version did not exist in
|
||||
/// the registry, then the 'xyz' version would be returned.
|
||||
///
|
||||
/// Returns `nullptr` if a node matching the arguments can't be found.
|
||||
///
|
||||
/// \sa NdrNodeDiscoveryResult::aliases
|
||||
NDR_API
|
||||
NdrNodeConstPtr GetNodeByIdentifier(const NdrIdentifier& identifier,
|
||||
const NdrTokenVec& sourceTypePriority = NdrTokenVec());
|
||||
|
||||
/// Get the node with the specified \p identifier and \p sourceType. If,
|
||||
/// for the given sourceType, there is no node with the given identifier,
|
||||
/// this will instead search for a node which has an alias that matches the
|
||||
/// identifier and return it if it exists. Otherwise there is no matching
|
||||
/// node for the sourceType and nullptr is returned.
|
||||
///
|
||||
/// \sa NdrNodeDiscoveryResult::aliases
|
||||
NDR_API
|
||||
NdrNodeConstPtr GetNodeByIdentifierAndType(const NdrIdentifier& identifier,
|
||||
const TfToken& sourceType);
|
||||
|
||||
/// Get the node with the specified name. An optional priority list
|
||||
/// specifies the set of node SOURCE types (\sa NdrNode::GetSourceType())
|
||||
/// that should be searched and in what order.
|
||||
///
|
||||
/// Optionally, a filter can be specified to consider just the default
|
||||
/// versions of nodes matching \p name (the default) or all versions
|
||||
/// of the nodes.
|
||||
///
|
||||
/// \sa GetNodeByIdentifier().
|
||||
NDR_API
|
||||
NdrNodeConstPtr GetNodeByName(const std::string& name,
|
||||
const NdrTokenVec& sourceTypePriority = NdrTokenVec(),
|
||||
NdrVersionFilter filter = NdrVersionFilterDefaultOnly);
|
||||
|
||||
/// A convenience wrapper around \c GetNodeByName(). Instead of
|
||||
/// providing a priority list, an exact type is specified, and
|
||||
/// `nullptr` is returned if a node with the exact identifier and
|
||||
/// type does not exist.
|
||||
///
|
||||
/// Optionally, a filter can be specified to consider just the default
|
||||
/// versions of nodes matching \p name (the default) or all versions
|
||||
/// of the nodes.
|
||||
NDR_API
|
||||
NdrNodeConstPtr GetNodeByNameAndType(const std::string& name,
|
||||
const TfToken& sourceType,
|
||||
NdrVersionFilter filter =
|
||||
NdrVersionFilterDefaultOnly);
|
||||
|
||||
/// Get all nodes matching the specified identifier (multiple nodes of
|
||||
/// the same identifier, but different source types, may exist) as well as
|
||||
/// any nodes which have an alias that matches the identifier. If no nodes
|
||||
/// match the identifier, an empty vector is returned.
|
||||
///
|
||||
/// \sa NdrNodeDiscoveryResult::aliases
|
||||
NDR_API
|
||||
NdrNodeConstPtrVec GetNodesByIdentifier(const NdrIdentifier& identifier);
|
||||
|
||||
/// Get all nodes matching the specified name. Only nodes matching the
|
||||
/// specified name will be parsed. Optionally, a filter can be specified
|
||||
/// to get just the default version (the default) or all versions of the
|
||||
/// node. If no nodes match an empty vector is returned.
|
||||
NDR_API
|
||||
NdrNodeConstPtrVec GetNodesByName(const std::string& name,
|
||||
NdrVersionFilter filter =
|
||||
NdrVersionFilterDefaultOnly);
|
||||
|
||||
/// Get all nodes from the registry, optionally restricted to the nodes
|
||||
/// that fall under a specified family and/or the default version.
|
||||
///
|
||||
/// Note that this will parse \em all nodes that the registry is aware of
|
||||
/// (unless a family is specified), so this may take some time to run
|
||||
/// the first time it is called.
|
||||
NDR_API
|
||||
NdrNodeConstPtrVec GetNodesByFamily(const TfToken& family = TfToken(),
|
||||
NdrVersionFilter filter =
|
||||
NdrVersionFilterDefaultOnly);
|
||||
|
||||
/// Get a sorted list of all node source types that may be present on the
|
||||
/// nodes in the registry.
|
||||
///
|
||||
/// Source types originate from the discovery process, but there is no
|
||||
/// guarantee that the discovered source types will also have a registered
|
||||
/// parser plugin. The actual supported source types here depend on the
|
||||
/// parsers that are available. Also note that some parser plugins may not
|
||||
/// advertise a source type.
|
||||
///
|
||||
/// See the documentation for `NdrParserPlugin` and
|
||||
/// `NdrNode::GetSourceType()` for more information.
|
||||
NDR_API
|
||||
NdrTokenVec GetAllNodeSourceTypes() const;
|
||||
|
||||
protected:
|
||||
NdrRegistry(const NdrRegistry&) = delete;
|
||||
NdrRegistry& operator=(const NdrRegistry&) = delete;
|
||||
|
||||
NDR_API
|
||||
NdrRegistry();
|
||||
|
||||
NDR_API
|
||||
~NdrRegistry();
|
||||
|
||||
private:
|
||||
class _DiscoveryContext;
|
||||
friend class _DiscoveryContext;
|
||||
|
||||
typedef std::unordered_map<TfToken, NdrParserPlugin*,
|
||||
TfToken::HashFunctor> TypeToParserPluginMap;
|
||||
typedef std::pair<NdrIdentifier, TfToken> NodeMapKey;
|
||||
struct NodeMapKeyHashFunctor {
|
||||
size_t operator()(const NodeMapKey& x) const {
|
||||
return NdrIdentifierHashFunctor()(x.first) ^
|
||||
TfToken::HashFunctor()(x.second);
|
||||
}
|
||||
};
|
||||
typedef std::unordered_multimap<NodeMapKey, NdrNodeUniquePtr,
|
||||
NodeMapKeyHashFunctor> NodeMap;
|
||||
|
||||
// The discovery result vec is not a concurrent data structure, thus it
|
||||
// needs some locking infrastructure.
|
||||
mutable std::mutex _discoveryResultMutex;
|
||||
|
||||
// The node map is not a concurrent data structure, thus it needs some
|
||||
// locking infrastructure.
|
||||
mutable std::mutex _nodeMapMutex;
|
||||
|
||||
// Runs each discovery plugin provided and appends the results to the
|
||||
// internal discovery results vector
|
||||
void _RunDiscoveryPlugins(const DiscoveryPluginRefPtrVec& discoveryPlugins);
|
||||
|
||||
// Finds and instantiates the discovery plugins
|
||||
void _FindAndInstantiateDiscoveryPlugins();
|
||||
|
||||
// Finds and instantiates the parser plugins
|
||||
void _FindAndInstantiateParserPlugins();
|
||||
|
||||
// Instantiates the specified parser plugins and adds them to
|
||||
// the registry.
|
||||
void _InstantiateParserPlugins(const std::set<TfType>& parserPluginTypes);
|
||||
|
||||
// Returns the cached or newly parsed node for the discovery result if its
|
||||
// identifier matches the given identifier.
|
||||
NdrNodeConstPtr _ParseNodeMatchingIdentifier(
|
||||
const NdrNodeDiscoveryResult& dr, const NdrIdentifier& identifier);
|
||||
|
||||
// Returns the cached or newly parsed node for the discovery result if it
|
||||
// has an alias that matches the given identifier.
|
||||
NdrNodeConstPtr _ParseNodeMatchingAlias(
|
||||
const NdrNodeDiscoveryResult& dr, const NdrIdentifier& identifier);
|
||||
|
||||
// Returns the cached or newly parsed node for the discovery result if its
|
||||
// name and version match the given name and version filter.
|
||||
NdrNodeConstPtr _ParseNodeMatchingNameAndFilter(
|
||||
const NdrNodeDiscoveryResult& dr, const std::string& name,
|
||||
NdrVersionFilter filter);
|
||||
|
||||
// Implementation helper for getting the first node of the given sourceType
|
||||
// that matches the given indentifier. This includes node that match the
|
||||
// identifier through an alias.
|
||||
NdrNodeConstPtr _GetNodeByIdentifierAndTypeImpl(
|
||||
const NdrIdentifier& identifier, const TfToken& sourceType);
|
||||
|
||||
// Implementation helper for getting the first node of the given sourceType
|
||||
// that matches the given name and version filter.
|
||||
NdrNodeConstPtr _GetNodeByNameAndTypeImpl(
|
||||
const std::string& name, const TfToken& sourceType,
|
||||
NdrVersionFilter filter);
|
||||
|
||||
// Inserts a new node into the node cache. If a node with the
|
||||
// same name and type already exists in the cache, the pointer to the
|
||||
// existing node will be returned. If there was an error inserting the node,
|
||||
// `nullptr` will be returned.
|
||||
NdrNodeConstPtr _InsertNodeIntoCache(const NdrNodeDiscoveryResult& dr);
|
||||
|
||||
// Get a vector of all of the node unique_ptrs in the node map as raw ptrs
|
||||
NdrNodeConstPtrVec _GetNodeMapAsNodePtrVec(const TfToken& family,
|
||||
NdrVersionFilter filter) const;
|
||||
|
||||
// Return the parser plugin for a discovery type. Returns null if no parser
|
||||
// plugin has that discovery type.
|
||||
NdrParserPlugin*
|
||||
_GetParserForDiscoveryType(const TfToken& discoveryType) const;
|
||||
|
||||
// The discovery plugins that were found through libplug and/or provided by
|
||||
// the client
|
||||
DiscoveryPluginRefPtrVec _discoveryPlugins;
|
||||
|
||||
// The parser plugins that have been discovered via the plugin system. Maps
|
||||
// a discovery result's "discovery type" to a specific parser.
|
||||
TypeToParserPluginMap _parserPluginMap;
|
||||
|
||||
// The parser plugins. This has ownership of the plugin objects.
|
||||
std::vector<std::unique_ptr<NdrParserPlugin>> _parserPlugins;
|
||||
|
||||
// The preliminary discovery results prior to parsing. If accessing or
|
||||
// mutating, _discoveryResultMutex should be used.
|
||||
NdrNodeDiscoveryResultVec _discoveryResults;
|
||||
|
||||
// Additional mapping of discovery results by grouped source type to aid in
|
||||
// getting nodes by type priority. Stored as indices into the
|
||||
// _disoveryResults vector.
|
||||
std::map<TfToken, std::vector<size_t>> _discoveryResultIndicesBySourceType;
|
||||
|
||||
// Maps a node's name to a node instance. If accessing or mutating,
|
||||
// _nodeMapMutex should be used.
|
||||
NodeMap _nodeMap;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_NDR_REGISTRY_H
|
||||
@@ -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_PCP_API_H
|
||||
#define PXR_USD_PCP_API_H
|
||||
|
||||
#include "pxr/base/arch/export.h"
|
||||
|
||||
#if defined(PXR_STATIC)
|
||||
# define PCP_API
|
||||
# define PCP_API_TEMPLATE_CLASS(...)
|
||||
# define PCP_API_TEMPLATE_STRUCT(...)
|
||||
# define PCP_LOCAL
|
||||
#else
|
||||
# if defined(PCP_EXPORTS)
|
||||
# define PCP_API ARCH_EXPORT
|
||||
# define PCP_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define PCP_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# else
|
||||
# define PCP_API ARCH_IMPORT
|
||||
# define PCP_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define PCP_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# endif
|
||||
# define PCP_LOCAL ARCH_HIDDEN
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// 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_PCP_ARC_H
|
||||
#define PXR_USD_PCP_ARC_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/pcp/mapExpression.h"
|
||||
#include "pxr/usd/pcp/node.h"
|
||||
#include "pxr/usd/pcp/types.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class PcpPrimIndex_Graph;
|
||||
|
||||
/// \class PcpArc
|
||||
///
|
||||
/// Represents an arc connecting two nodes in the prim index.
|
||||
/// The arc is owned by a node (source) and points to its parent node (target)
|
||||
/// in the index.
|
||||
///
|
||||
class PcpArc
|
||||
{
|
||||
public:
|
||||
PcpArc()
|
||||
: type(PcpArcTypeRoot)
|
||||
, siblingNumAtOrigin(0)
|
||||
, namespaceDepth(0)
|
||||
{ }
|
||||
|
||||
/// The type of this arc.
|
||||
PcpArcType type;
|
||||
|
||||
/// The parent (or target) node of this arc.
|
||||
/// If this arc's source node is a root node (i.e., type == PcpArcTypeRoot),
|
||||
/// this will be an invalid node.
|
||||
PcpNodeRef parent;
|
||||
|
||||
/// The origin node of this arc.
|
||||
/// This is the node that caused this arc's source node to be brought into
|
||||
/// the prim index. In most cases, this will be the same as the parent node.
|
||||
/// For implied inherits, this is the node from which this inherit arc was
|
||||
/// propagated. This affects strength ordering.
|
||||
PcpNodeRef origin;
|
||||
|
||||
/// The value-mapping function used to map values from this arc's source
|
||||
/// node to its parent node.
|
||||
PcpMapExpression mapToParent;
|
||||
|
||||
// index among sibling arcs at origin; lower is stronger
|
||||
int siblingNumAtOrigin;
|
||||
|
||||
// Absolute depth in namespace of node that introduced this node.
|
||||
// Note that this does *not* count any variant selections.
|
||||
int namespaceDepth;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_ARC_H
|
||||
@@ -0,0 +1,733 @@
|
||||
//
|
||||
// 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_PCP_CACHE_H
|
||||
#define PXR_USD_PCP_CACHE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/pcp/dependency.h"
|
||||
#include "pxr/usd/pcp/errors.h"
|
||||
#include "pxr/usd/pcp/mapFunction.h"
|
||||
#include "pxr/usd/pcp/primIndex.h"
|
||||
#include "pxr/usd/pcp/propertyIndex.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/usd/sdf/pathTable.h"
|
||||
|
||||
#include "pxr/usd/ar/ar.h"
|
||||
#include "pxr/usd/ar/resolverContext.h"
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
#include "pxr/base/tf/hashset.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
// Forward declarations:
|
||||
class PcpChanges;
|
||||
class PcpCacheChanges;
|
||||
class Pcp_Dependencies;
|
||||
class PcpLayerStackIdentifier;
|
||||
class PcpLifeboat;
|
||||
class PcpNodeRef;
|
||||
class PcpMapFunction;
|
||||
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(PcpLayerStack);
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(Pcp_LayerStackRegistry);
|
||||
SDF_DECLARE_HANDLES(SdfSpec);
|
||||
|
||||
/// \class PcpCache
|
||||
///
|
||||
/// PcpCache is the context required to make requests of the Pcp
|
||||
/// composition algorithm and cache the results.
|
||||
///
|
||||
/// Because the algorithms are recursive -- making a request typically
|
||||
/// makes other internal requests to solve subproblems -- caching
|
||||
/// subproblem results is required for reasonable performance, and
|
||||
/// so this cache is the only entrypoint to the algorithms.
|
||||
///
|
||||
/// There is a set of parameters that affect the composition results:
|
||||
///
|
||||
/// \li variant fallbacks: per named variant set, an ordered list of
|
||||
/// fallback values to use when composing a prim that defines
|
||||
/// a variant set but does not specify a selection
|
||||
/// \li payload inclusion set: an SdfPath set used to identify which
|
||||
/// prims should have their payloads included during composition;
|
||||
/// this is the basis for explicit control over the "working set"
|
||||
/// of composition
|
||||
/// \li file format target: the file format target that Pcp will request
|
||||
/// when opening scene description layers
|
||||
/// \li "USD mode" configures the Pcp composition algorithm to provide
|
||||
/// only a custom, lighter subset of the full feature set, as needed
|
||||
/// by the Universal Scene Description system
|
||||
///
|
||||
/// There are a number of different computations that can be requested.
|
||||
/// These include computing a layer stack from a PcpLayerStackIdentifier,
|
||||
/// computing a prim index or prim stack, and computing a property index.
|
||||
///
|
||||
class PcpCache
|
||||
{
|
||||
PcpCache(PcpCache const &) = delete;
|
||||
PcpCache &operator=(PcpCache const &) = delete;
|
||||
public:
|
||||
/// Construct a PcpCache to compose results for the layer stack identified
|
||||
/// by \a layerStackIdentifier.
|
||||
///
|
||||
/// If \p fileFormatTarget is given, Pcp will specify \p fileFormatTarget
|
||||
/// as the file format target when searching for or opening a layer.
|
||||
///
|
||||
/// If \p usd is true, computation of prim indices and composition of prim
|
||||
/// child names are performed without relocates, inherits, permissions,
|
||||
/// symmetry, or payloads, and without populating the prim stack and
|
||||
/// gathering its dependencies.
|
||||
PCP_API
|
||||
PcpCache(const PcpLayerStackIdentifier & layerStackIdentifier,
|
||||
const std::string& fileFormatTarget = std::string(),
|
||||
bool usd = false);
|
||||
PCP_API ~PcpCache();
|
||||
|
||||
/// \name Parameters
|
||||
/// @{
|
||||
|
||||
/// Get the identifier of the layerStack used for composition.
|
||||
PCP_API
|
||||
const PcpLayerStackIdentifier& GetLayerStackIdentifier() const;
|
||||
|
||||
/// Get the layer stack for GetLayerStackIdentifier(). Note that
|
||||
/// this will neither compute the layer stack nor report errors.
|
||||
/// So if the layer stack has not been computed yet this will
|
||||
/// return \c NULL. Use ComputeLayerStack() if you need to
|
||||
/// compute the layer stack if it hasn't been computed already
|
||||
/// and/or get errors caused by computing the layer stack.
|
||||
PCP_API
|
||||
PcpLayerStackPtr GetLayerStack() const;
|
||||
|
||||
/// Return true if the cache is configured in Usd mode.
|
||||
PCP_API
|
||||
bool IsUsd() const;
|
||||
|
||||
/// Returns the file format target this cache is configured for.
|
||||
PCP_API
|
||||
const std::string& GetFileFormatTarget() const;
|
||||
|
||||
/// Get the list of fallbacks to attempt to use when evaluating
|
||||
/// variant sets that lack an authored selection.
|
||||
PCP_API
|
||||
PcpVariantFallbackMap GetVariantFallbacks() const;
|
||||
|
||||
/// Set the list of fallbacks to attempt to use when evaluating
|
||||
/// variant sets that lack an authored selection.
|
||||
///
|
||||
/// If \p changes is not \c NULL then it's adjusted to reflect the
|
||||
/// changes necessary to see the change in standin preferences,
|
||||
/// otherwise those changes are applied immediately.
|
||||
PCP_API
|
||||
void SetVariantFallbacks( const PcpVariantFallbackMap & map,
|
||||
PcpChanges* changes = NULL );
|
||||
|
||||
/// Return true if the payload is included for the given path.
|
||||
PCP_API
|
||||
bool IsPayloadIncluded(const SdfPath &path) const;
|
||||
|
||||
/// Returns the payloads requested for inclusion.
|
||||
using PayloadSet = std::unordered_set<SdfPath, SdfPath::Hash>;
|
||||
PCP_API
|
||||
PayloadSet const &GetIncludedPayloads() const;
|
||||
|
||||
/// Request payloads to be included or excluded from composition.
|
||||
/// \param pathsToInclude is a set of paths to add to the set for
|
||||
/// payload inclusion.
|
||||
/// \param pathsToExclude is a set of paths to remove from the set for
|
||||
/// payload inclusion.
|
||||
/// \param changes if not \c NULL, is adjusted to reflect the changes
|
||||
/// necessary to see the change in payloads; otherwise those
|
||||
/// changes are applied immediately.
|
||||
/// \note If a path is listed in both pathsToInclude and pathsToExclude,
|
||||
/// it will be treated as an inclusion only.
|
||||
///
|
||||
PCP_API
|
||||
void RequestPayloads( const SdfPathSet & pathsToInclude,
|
||||
const SdfPathSet & pathsToExclude,
|
||||
PcpChanges* changes = NULL );
|
||||
|
||||
/// Request layers to be muted or unmuted in this cache. Muted layers
|
||||
/// are ignored during composition and do not appear in any layer
|
||||
/// stacks. The root layer of this stage may not be muted; attempting
|
||||
/// to do so will generate a coding error. If the root layer of a
|
||||
/// reference or payload layer stack is muted, the behavior is as if
|
||||
/// the muted layer did not exist, which means a composition error will
|
||||
/// be generated.
|
||||
///
|
||||
#if AR_VERSION == 1
|
||||
/// A canonical identifier for each layer in \p layersToMute will be
|
||||
/// computed using ArResolver::ComputeRepositoryPath. Any layer
|
||||
/// encountered during composition with the same repository path will
|
||||
/// be considered muted and ignored. Relative paths will be assumed to
|
||||
/// be relative to the cache's root layer. Search paths are immediately
|
||||
/// resolved and the result is used for computing the canonical path.
|
||||
#else
|
||||
/// A canonical identifier for each layer in \p layersToMute will be
|
||||
/// computed using ArResolver::CreateIdentifier using the cache's root
|
||||
/// layer as the anchoring asset. Any layer encountered during composition
|
||||
/// with the same identifier will be considered muted and ignored.
|
||||
#endif
|
||||
///
|
||||
/// Note that muting a layer will cause this cache to release all
|
||||
/// references to that layer. If no other client is holding on to
|
||||
/// references to that layer, it will be unloaded. In this case, if
|
||||
/// there are unsaved edits to the muted layer, those edits are lost.
|
||||
/// Since anonymous layers are not serialized, muting an anonymous
|
||||
/// layer will cause that layer and its contents to be lost in this
|
||||
/// case.
|
||||
///
|
||||
/// If \p changes is not \c nullptr, it is adjusted to reflect the
|
||||
/// changes necessary to see the change in muted layers. Otherwise,
|
||||
/// those changes are applied immediately.
|
||||
///
|
||||
/// \p newLayersMuted and \p newLayersUnmuted contains the pruned vector
|
||||
/// of layers which are muted or unmuted by this call to RequestLayerMuting.
|
||||
///
|
||||
PCP_API
|
||||
void RequestLayerMuting(const std::vector<std::string>& layersToMute,
|
||||
const std::vector<std::string>& layersToUnmute,
|
||||
PcpChanges* changes = nullptr,
|
||||
std::vector<std::string>* newLayersMuted = nullptr,
|
||||
std::vector<std::string>* newLayersUnmuted =
|
||||
nullptr);
|
||||
|
||||
/// Returns the list of canonical identifiers for muted layers
|
||||
/// in this cache. See documentation on RequestLayerMuting for
|
||||
/// more details.
|
||||
PCP_API
|
||||
const std::vector<std::string>& GetMutedLayers() const;
|
||||
|
||||
/// Returns true if the layer specified by \p layerIdentifier is
|
||||
/// muted in this cache, false otherwise. If \p layerIdentifier
|
||||
/// is relative, it is assumed to be relative to this cache's
|
||||
/// root layer. See documentation on RequestLayerMuting for
|
||||
/// more details.
|
||||
PCP_API
|
||||
bool IsLayerMuted(const std::string& layerIdentifier) const;
|
||||
|
||||
/// Returns true if the layer specified by \p layerIdentifier is
|
||||
/// muted in this cache, false otherwise. If \p layerIdentifier
|
||||
/// is relative, it is assumed to be relative to \p anchorLayer.
|
||||
/// If \p canonicalMutedLayerIdentifier is supplied, it will be
|
||||
/// populated with the canonical identifier of the muted layer if this
|
||||
/// function returns true. See documentation on RequestLayerMuting
|
||||
/// for more details.
|
||||
PCP_API
|
||||
bool IsLayerMuted(const SdfLayerHandle& anchorLayer,
|
||||
const std::string& layerIdentifier,
|
||||
std::string* canonicalMutedLayerIdentifier
|
||||
= nullptr) const;
|
||||
|
||||
/// Returns parameter object containing all inputs for the prim index
|
||||
/// computation used by this cache.
|
||||
PCP_API
|
||||
PcpPrimIndexInputs GetPrimIndexInputs();
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name Computations
|
||||
/// @{
|
||||
|
||||
/// Returns the layer stack for \p identifier if it exists, otherwise
|
||||
/// creates a new layer stack for \p identifier. This returns \c NULL
|
||||
/// if \p identifier is invalid (i.e. its root layer is \c NULL).
|
||||
/// \p allErrors will contain any errors encountered while creating a
|
||||
/// new layer stack. It'll be unchanged if the layer stack already existed.
|
||||
PCP_API
|
||||
PcpLayerStackRefPtr
|
||||
ComputeLayerStack(const PcpLayerStackIdentifier &identifier,
|
||||
PcpErrorVector *allErrors);
|
||||
|
||||
/// Returns the layer stack for \p identifier if it has been computed
|
||||
/// and cached, otherwise returns \c NULL.
|
||||
PCP_API
|
||||
PcpLayerStackPtr
|
||||
FindLayerStack(const PcpLayerStackIdentifier &identifier) const;
|
||||
|
||||
/// Compute and return a reference to the cached result for the
|
||||
/// prim index for the given path. \p allErrors will contain any errors
|
||||
/// encountered while performing this operation.
|
||||
PCP_API
|
||||
const PcpPrimIndex &
|
||||
ComputePrimIndex(const SdfPath &primPath, PcpErrorVector *allErrors);
|
||||
|
||||
/// Compute PcpPrimIndexes in the subtree rooted at path in parallel,
|
||||
/// recursing to children based on the supplied \p childrenPred. Also
|
||||
/// include payloads not already in this cache's included payloads (see
|
||||
/// GetIncludedPayloads()) according to \p payloadPred.
|
||||
///
|
||||
/// This is similar to ComputePrimIndex(), except it computes an entire
|
||||
/// subtree of indexes in parallel so it can be much more efficient. This
|
||||
/// function invokes both \p childrenPred and \p payloadPred concurrently,
|
||||
/// so it must be safe to do so.
|
||||
///
|
||||
/// When a PcpPrimIndex computation completes invoke \p childrenPred,
|
||||
/// passing it the PcpPrimIndex. If \p childrenPred returns true, continue
|
||||
/// indexing children prim indexes. In this case, \p childrenPred may
|
||||
/// provide a list of names of the children prim indexes to compute.
|
||||
/// If it does not, all children prim indexes will be computed.
|
||||
/// If \p childrenPred returns false, stop indexing in that subtree.
|
||||
///
|
||||
/// If payloads discovered during indexing do not already appear in this
|
||||
/// cache's set of included payloads, invoke \p payloadPred, passing it the
|
||||
/// path for the prim with the payload. If \p payloadPred returns true,
|
||||
/// include its payload and add it to the cache's set of included payloads
|
||||
/// upon completion.
|
||||
template <class ChildrenPredicate, class PayloadPredicate>
|
||||
void ComputePrimIndexesInParallel(const SdfPath &path,
|
||||
PcpErrorVector *allErrors,
|
||||
const ChildrenPredicate &childrenPred,
|
||||
const PayloadPredicate &payloadPred) {
|
||||
ComputePrimIndexesInParallel(SdfPathVector(1, path), allErrors,
|
||||
childrenPred, payloadPred,
|
||||
"Pcp", "ComputePrimIndexesInParallel");
|
||||
}
|
||||
|
||||
/// \overload
|
||||
/// XXX Do not add new callers of this method. It is needed as a workaround
|
||||
/// for bug #132031, which we hope to tackle soon (as of 6/2016)
|
||||
template <class ChildrenPredicate, class PayloadPredicate>
|
||||
void ComputePrimIndexesInParallel(const SdfPath &path,
|
||||
PcpErrorVector *allErrors,
|
||||
const ChildrenPredicate &childrenPred,
|
||||
const PayloadPredicate &payloadPred,
|
||||
const char *mallocTag1,
|
||||
const char *mallocTag2) {
|
||||
ComputePrimIndexesInParallel(SdfPathVector(1, path), allErrors,
|
||||
childrenPred, payloadPred,
|
||||
mallocTag1, mallocTag2);
|
||||
}
|
||||
|
||||
/// Vectorized form of ComputePrimIndexesInParallel(). Equivalent to
|
||||
/// invoking that method for each path in \p paths, but more efficient.
|
||||
template <class ChildrenPredicate, class PayloadPredicate>
|
||||
void ComputePrimIndexesInParallel(const SdfPathVector &paths,
|
||||
PcpErrorVector *allErrors,
|
||||
const ChildrenPredicate &childrenPred,
|
||||
const PayloadPredicate &payloadPred) {
|
||||
_UntypedIndexingChildrenPredicate cp(&childrenPred);
|
||||
_UntypedIndexingPayloadPredicate pp(&payloadPred);
|
||||
_ComputePrimIndexesInParallel(paths, allErrors, cp, pp,
|
||||
"Pcp", "ComputePrimIndexesInParallel");
|
||||
}
|
||||
|
||||
/// \overload
|
||||
/// XXX Do not add new callers of this method. It is needed as a workaround
|
||||
/// for bug #132031, which we hope to tackle soon (as of 6/2016)
|
||||
template <class ChildrenPredicate, class PayloadPredicate>
|
||||
void ComputePrimIndexesInParallel(const SdfPathVector &paths,
|
||||
PcpErrorVector *allErrors,
|
||||
const ChildrenPredicate &childrenPred,
|
||||
const PayloadPredicate &payloadPred,
|
||||
const char *mallocTag1,
|
||||
const char *mallocTag2) {
|
||||
_UntypedIndexingChildrenPredicate cp(&childrenPred);
|
||||
_UntypedIndexingPayloadPredicate pp(&payloadPred);
|
||||
_ComputePrimIndexesInParallel(paths, allErrors, cp, pp,
|
||||
mallocTag1, mallocTag2);
|
||||
}
|
||||
|
||||
/// Returns a pointer to the cached computed prim index for the given
|
||||
/// path, or NULL if it has not been computed.
|
||||
PCP_API
|
||||
const PcpPrimIndex *
|
||||
FindPrimIndex(const SdfPath &primPath) const;
|
||||
|
||||
/// Compute and return a reference to the cached result for the
|
||||
/// property index for the given path. \p allErrors will contain any
|
||||
/// errors encountered while performing this operation.
|
||||
PCP_API
|
||||
const PcpPropertyIndex &
|
||||
ComputePropertyIndex(const SdfPath &propPath, PcpErrorVector *allErrors);
|
||||
|
||||
/// Returns a pointer to the cached computed property index for the given
|
||||
/// path, or NULL if it has not been computed.
|
||||
PCP_API
|
||||
const PcpPropertyIndex *
|
||||
FindPropertyIndex(const SdfPath &propPath) const;
|
||||
|
||||
/// Compute the relationship target paths for the relationship at
|
||||
/// \p relationshipPath into \p paths. If \p localOnly is \c true then
|
||||
/// this will compose relationship targets from local nodes only. If
|
||||
/// \p stopProperty is not \c NULL then this will stop composing
|
||||
/// relationship targets at \p stopProperty, including \p stopProperty
|
||||
/// iff \p includeStopProperty is \c true. If not \c NULL, \p deletedPaths
|
||||
/// will be populated with target paths whose deletion contributed to
|
||||
/// the computed result. \p allErrors will contain any errors encountered
|
||||
/// while performing this operation.
|
||||
PCP_API
|
||||
void
|
||||
ComputeRelationshipTargetPaths(const SdfPath &relationshipPath,
|
||||
SdfPathVector *paths,
|
||||
bool localOnly,
|
||||
const SdfSpecHandle &stopProperty,
|
||||
bool includeStopProperty,
|
||||
SdfPathVector *deletedPaths,
|
||||
PcpErrorVector *allErrors);
|
||||
|
||||
/// Compute the attribute connection paths for the attribute at
|
||||
/// \p attributePath into \p paths. If \p localOnly is \c true then
|
||||
/// this will compose attribute connections from local nodes only. If
|
||||
/// \p stopProperty is not \c NULL then this will stop composing
|
||||
/// attribute connections at \p stopProperty, including \p stopProperty
|
||||
/// iff \p includeStopProperty is \c true. If not \c NULL, \p deletedPaths
|
||||
/// will be populated with connection paths whose deletion contributed to
|
||||
/// the computed result. \p allErrors will contain any errors encountered
|
||||
/// while performing this operation.
|
||||
PCP_API
|
||||
void
|
||||
ComputeAttributeConnectionPaths(const SdfPath &attributePath,
|
||||
SdfPathVector *paths,
|
||||
bool localOnly,
|
||||
const SdfSpecHandle &stopProperty,
|
||||
bool includeStopProperty,
|
||||
SdfPathVector *deletedPaths,
|
||||
PcpErrorVector *allErrors);
|
||||
|
||||
/// @}
|
||||
/// \name Dependencies
|
||||
/// @{
|
||||
|
||||
/// Returns set of all layers used by this cache.
|
||||
PCP_API
|
||||
SdfLayerHandleSet GetUsedLayers() const;
|
||||
|
||||
/// Returns set of all root layers used by this cache.
|
||||
PCP_API
|
||||
SdfLayerHandleSet GetUsedRootLayers() const;
|
||||
|
||||
/// Returns every computed & cached layer stack that includes \p layer.
|
||||
PCP_API
|
||||
const PcpLayerStackPtrVector&
|
||||
FindAllLayerStacksUsingLayer(const SdfLayerHandle& layer) const;
|
||||
|
||||
/// Returns dependencies on the given site of scene description,
|
||||
/// as discovered by the cached index computations.
|
||||
///
|
||||
/// \param depMask specifies what classes of dependency to include;
|
||||
/// see PcpDependencyFlags for details
|
||||
/// \param recurseOnSite includes incoming dependencies on
|
||||
/// children of sitePath
|
||||
/// \param recurseOnIndex extends the result to include all PcpCache
|
||||
/// child indexes below discovered results
|
||||
/// \param filterForExistingCachesOnly filters the results to only
|
||||
/// paths representing computed prim and property index caches;
|
||||
/// otherwise a recursively-expanded result can include
|
||||
/// un-computed paths that are expected to depend on the site
|
||||
PCP_API
|
||||
PcpDependencyVector
|
||||
FindSiteDependencies(const PcpLayerStackPtr& siteLayerStack,
|
||||
const SdfPath& sitePath,
|
||||
PcpDependencyFlags depMask,
|
||||
bool recurseOnSite,
|
||||
bool recurseOnIndex,
|
||||
bool filterForExistingCachesOnly) const;
|
||||
|
||||
/// Returns dependencies on the given site of scene description,
|
||||
/// as discovered by the cached index computations.
|
||||
///
|
||||
/// This method overload takes a site layer rather than a layer
|
||||
/// stack. It will check every layer stack using that layer, and
|
||||
/// apply any relevant sublayer offsets to the map functions in the
|
||||
/// returned PcpDependencyVector.
|
||||
///
|
||||
/// See the other method for parameter details.
|
||||
PCP_API
|
||||
PcpDependencyVector
|
||||
FindSiteDependencies(const SdfLayerHandle& siteLayer,
|
||||
const SdfPath& sitePath,
|
||||
PcpDependencyFlags depMask,
|
||||
bool recurseOnSite,
|
||||
bool recurseOnIndex,
|
||||
bool filterForExistingCachesOnly) const;
|
||||
|
||||
/// Returns \c true if an opinion for the site at \p localPcpSitePath
|
||||
/// in the cache's layer stack can be provided by an opinion in \p layer,
|
||||
/// \c false otherwise. If \c true and \p allowedPathInLayer is not
|
||||
/// \c NULL then it's set to a path in \p layer that would provide an
|
||||
/// opinion.
|
||||
///
|
||||
/// This returns \c false if no prim index has yet been computed for
|
||||
/// \p localPcpSitePath.
|
||||
PCP_API
|
||||
bool CanHaveOpinionForSite(const SdfPath& localPcpSitePath,
|
||||
const SdfLayerHandle& layer,
|
||||
SdfPath* allowedPathInLayer) const;
|
||||
|
||||
/// Returns a vector of sublayer asset paths used in the layer stack
|
||||
/// that didn't resolve to valid assets.
|
||||
PCP_API
|
||||
std::vector<std::string> GetInvalidSublayerIdentifiers() const;
|
||||
|
||||
/// Returns true if \p identifier was used as a sublayer path in a
|
||||
/// layer stack but did not identify a valid layer. This is functionally
|
||||
/// equivalent to examining the values in the vector returned by
|
||||
/// GetInvalidSublayerIdentifiers, but more efficient.
|
||||
PCP_API
|
||||
bool IsInvalidSublayerIdentifier(const std::string& identifier) const;
|
||||
|
||||
/// Returns a map of prim paths to asset paths used by that prim
|
||||
/// (e.g. in a reference) that didn't resolve to valid assets.
|
||||
PCP_API
|
||||
std::map<SdfPath, std::vector<std::string>, SdfPath::FastLessThan>
|
||||
GetInvalidAssetPaths() const;
|
||||
|
||||
/// Returns true if \p resolvedAssetPath was used by a prim (e.g. in
|
||||
/// a reference) but did not resolve to a valid asset. This is
|
||||
/// functionally equivalent to examining the values in the map returned
|
||||
/// by GetInvalidAssetPaths, but more efficient.
|
||||
PCP_API
|
||||
bool IsInvalidAssetPath(const std::string& resolvedAssetPath) const;
|
||||
|
||||
/// Returns true if any prim index in this cache has a dependency on a
|
||||
/// dynamic file format argument field.
|
||||
PCP_API
|
||||
bool HasAnyDynamicFileFormatArgumentDependencies() const;
|
||||
|
||||
/// Returns true if the given \p field is the name of a field that
|
||||
/// was composed while generating dynamic file format arguments for any prim
|
||||
/// index in this cache.
|
||||
PCP_API
|
||||
bool IsPossibleDynamicFileFormatArgumentField(const TfToken &field) const;
|
||||
|
||||
/// Returns the dynamic file format dependency data object for the prim
|
||||
/// index with the given \p primIndexPath. This will return an empty
|
||||
/// dependency data if either there is no cache prim index for the path or
|
||||
/// if the prim index has no dynamic file formats that it depends on.
|
||||
PCP_API
|
||||
const PcpDynamicFileFormatDependencyData &
|
||||
GetDynamicFileFormatArgumentDependencyData(
|
||||
const SdfPath &primIndexPath) const;
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name Change handling
|
||||
/// @{
|
||||
|
||||
/// Apply the changes in \p changes. This blows caches. It's up to
|
||||
/// the client to pull on those caches again as needed.
|
||||
///
|
||||
/// Objects that are no longer needed and would be destroyed are
|
||||
/// retained in \p lifeboat and won't be destroyed until \p lifeboat is
|
||||
/// itself destroyed. This gives the client control over the timing
|
||||
/// of the destruction of those objects. Clients may choose to pull
|
||||
/// on the caches before destroying \p lifeboat. That may cause the
|
||||
/// caches to again retain the objects, meaning they won't be destroyed
|
||||
/// when \p lifeboat is destroyed.
|
||||
///
|
||||
/// For example, if blowing a cache means an SdfLayer is no longer
|
||||
/// needed then \p lifeboat will hold an SdfLayerRefPtr to that layer.
|
||||
/// The client can then pull on that cache, which could cause the
|
||||
/// cache to hold an SdfLayerRefPtr to the layer again. If so then
|
||||
/// destroying \p changes will not destroy the layer. In any case,
|
||||
/// we don't destroy the layer and then read it again. However, if
|
||||
/// the client destroys \p lifeboat before pulling on the cache then
|
||||
/// we would destroy the layer then read it again.
|
||||
PCP_API
|
||||
void Apply(const PcpCacheChanges& changes, PcpLifeboat* lifeboat);
|
||||
|
||||
/// Reload the layers of the layer stack, except session layers
|
||||
/// and sublayers of session layers. This will also try to load
|
||||
/// sublayers in this cache's layer stack that could not be loaded
|
||||
/// previously. It will also try to load any referenced or payloaded
|
||||
/// layer that could not be loaded previously. Clients should
|
||||
/// subsequently \c Apply() \p changes to use any now-valid layers.
|
||||
PCP_API
|
||||
void Reload(PcpChanges* changes);
|
||||
|
||||
/// Reload every layer used by the prim at \p primPath that's across
|
||||
/// a reference or payload. Clients should subsequently apply the
|
||||
/// changes to use any now valid layers.
|
||||
///
|
||||
/// Note: If a reference or payload was to an invalid asset and this
|
||||
/// asset is valid upon reloading then this call will not necessarily
|
||||
/// reload every layer accessible across the reference or payload.
|
||||
/// For example, say prim R has an invalid reference and prim Q has a
|
||||
/// valid reference to layer X with sublayer Y. If on reload R now
|
||||
/// has a valid reference to layer Z with sublayer Y, we will load Z
|
||||
/// but we will not reload Y.
|
||||
PCP_API
|
||||
void ReloadReferences(PcpChanges* changes, const SdfPath& primPath);
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name Diagnostics
|
||||
/// @{
|
||||
|
||||
/// Prints various statistics about the data stored in this cache.
|
||||
PCP_API
|
||||
void PrintStatistics() const;
|
||||
|
||||
/// @}
|
||||
|
||||
private:
|
||||
friend class PcpChanges;
|
||||
friend class Pcp_Statistics;
|
||||
|
||||
struct _ParallelIndexer;
|
||||
|
||||
// Helper struct to type-erase a children predicate for the duration of
|
||||
// ComputePrimIndexesInParallel.
|
||||
//
|
||||
// This lets us achieve two goals. First, clients may pass any arbitrary
|
||||
// type as a predicate (e.g. they do not have to derive some base class).
|
||||
// Second, it lets us keep the parallel indexing implementation in the .cpp
|
||||
// file, avoiding any large template code instantiation.
|
||||
//
|
||||
// The cost we pay is this very thin indirect call. We instantiate a
|
||||
// function template with the client's predicate type that simply does a
|
||||
// typecast and predicate invocation, and pass that function pointer into
|
||||
// the implementation. There is no heap allocation, no predicate copy, no
|
||||
// argument marshalling, etc.
|
||||
struct _UntypedIndexingChildrenPredicate {
|
||||
_UntypedIndexingChildrenPredicate() : pred(nullptr), invoke(nullptr) {}
|
||||
template <class Pred>
|
||||
explicit _UntypedIndexingChildrenPredicate(const Pred *pred)
|
||||
: pred(pred), invoke(_Invoke<Pred>) {}
|
||||
|
||||
inline bool operator()(const PcpPrimIndex &index,
|
||||
TfTokenVector *childNamesToCompose) const {
|
||||
return invoke(pred, index, childNamesToCompose);
|
||||
}
|
||||
private:
|
||||
template <class Pred>
|
||||
static bool _Invoke(const void *pred, const PcpPrimIndex &index,
|
||||
TfTokenVector *namesToCompose) {
|
||||
return (*static_cast<const Pred *>(pred))(index, namesToCompose);
|
||||
}
|
||||
const void *pred;
|
||||
bool (*invoke)(const void *, const PcpPrimIndex &, TfTokenVector *);
|
||||
};
|
||||
|
||||
// See doc for _UntypedIndexingChildrenPredicate above. This does the same
|
||||
// for the payload inclusion predicate.
|
||||
struct _UntypedIndexingPayloadPredicate {
|
||||
template <class Pred>
|
||||
explicit _UntypedIndexingPayloadPredicate(const Pred *pred)
|
||||
: pred(pred), invoke(_Invoke<Pred>) {}
|
||||
|
||||
inline bool operator()(const SdfPath &path) const {
|
||||
return invoke(pred, path);
|
||||
}
|
||||
private:
|
||||
template <class Pred>
|
||||
static bool _Invoke(const void *pred, const SdfPath &path) {
|
||||
return (*static_cast<const Pred *>(pred))(path);
|
||||
}
|
||||
const void *pred;
|
||||
bool (*invoke)(const void *, const SdfPath &);
|
||||
};
|
||||
|
||||
// Internal helper for recursive indexing.
|
||||
const PcpPrimIndex &
|
||||
_ComputePrimIndexWithCompatibleInputs(
|
||||
const SdfPath & path, const PcpPrimIndexInputs &inputs,
|
||||
PcpErrorVector *allErrors);
|
||||
|
||||
// Friend to allow low-level indexing code access to the above.
|
||||
friend const PcpPrimIndex &
|
||||
Pcp_ComputePrimIndexWithCompatibleInputs(
|
||||
PcpCache &cache,
|
||||
const SdfPath & path, const PcpPrimIndexInputs &inputs,
|
||||
PcpErrorVector *allErrors);
|
||||
|
||||
// Parallel indexing implementation.
|
||||
PCP_API
|
||||
void _ComputePrimIndexesInParallel(
|
||||
const SdfPathVector &paths,
|
||||
PcpErrorVector *allErrors,
|
||||
_UntypedIndexingChildrenPredicate childrenPred,
|
||||
_UntypedIndexingPayloadPredicate payloadPred,
|
||||
const char *mallocTag1,
|
||||
const char *mallocTag2);
|
||||
|
||||
void _RemovePrimCache(const SdfPath& primPath, PcpLifeboat* lifeboat);
|
||||
void _RemovePrimAndPropertyCaches(const SdfPath& root,
|
||||
PcpLifeboat* lifeboat);
|
||||
void _RemovePropertyCache(const SdfPath& root, PcpLifeboat* lifeboat);
|
||||
void _RemovePropertyCaches(const SdfPath& root, PcpLifeboat* lifeboat);
|
||||
|
||||
// Returns the prim index for \p path if it exists, NULL otherwise.
|
||||
PcpPrimIndex* _GetPrimIndex(const SdfPath& path);
|
||||
const PcpPrimIndex* _GetPrimIndex(const SdfPath& path) const;
|
||||
|
||||
// Returns the property index for \p path if it exists, NULL otherwise.
|
||||
PcpPropertyIndex* _GetPropertyIndex(const SdfPath& path);
|
||||
const PcpPropertyIndex* _GetPropertyIndex(const SdfPath& path) const;
|
||||
|
||||
private:
|
||||
// Fixed evaluation parameters, set when the cache is created. Note that
|
||||
// _rootLayer and _sessionLayer are not const because we want to mutate them
|
||||
// to enable parallel teardown in the destructor.
|
||||
SdfLayerRefPtr _rootLayer;
|
||||
SdfLayerRefPtr _sessionLayer;
|
||||
const PcpLayerStackIdentifier _layerStackIdentifier;
|
||||
|
||||
// Flag that configures PcpCache to use the restricted set of USD features.
|
||||
// Currently it governs whether relocates, inherits, permissions,
|
||||
// symmetry, or payloads are considered, and whether the prim stack
|
||||
// is populated and its depdencies gathered during computation of
|
||||
// prim indices and composition of prim child names.
|
||||
const bool _usd;
|
||||
|
||||
// File format target for all scene description layers this cache will
|
||||
// find or open during prim index computation.
|
||||
const std::string _fileFormatTarget;
|
||||
|
||||
// The layer stack for this cache. Holding this by ref ptr means we
|
||||
// hold all of our local layers by ref ptr (including the root and
|
||||
// session layers, again).
|
||||
PcpLayerStackRefPtr _layerStack;
|
||||
|
||||
// Modifiable evaluation parameters.
|
||||
// Anything that changes these should also yield a PcpChanges
|
||||
// value describing the necessary cache invalidation.
|
||||
PayloadSet _includedPayloads;
|
||||
PcpVariantFallbackMap _variantFallbackMap;
|
||||
|
||||
// Cached computation types.
|
||||
typedef Pcp_LayerStackRegistryRefPtr _LayerStackCache;
|
||||
typedef SdfPathTable<PcpPrimIndex> _PrimIndexCache;
|
||||
typedef SdfPathTable<PcpPropertyIndex> _PropertyIndexCache;
|
||||
|
||||
// Cached computations.
|
||||
_LayerStackCache _layerStackCache;
|
||||
_PrimIndexCache _primIndexCache;
|
||||
_PropertyIndexCache _propertyIndexCache;
|
||||
std::unique_ptr<Pcp_Dependencies> _primDependencies;
|
||||
|
||||
// Parallel indexer state.
|
||||
std::unique_ptr<_ParallelIndexer> _parallelIndexer;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_CACHE_H
|
||||
@@ -0,0 +1,406 @@
|
||||
//
|
||||
// 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_PCP_CHANGES_H
|
||||
#define PXR_USD_PCP_CHANGES_H
|
||||
|
||||
/// \file pcp/changes.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/sdf/changeList.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/usd/sdf/types.h"
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
#include "pxr/base/tf/span.h"
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
SDF_DECLARE_HANDLES(SdfLayer);
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(PcpLayerStack);
|
||||
|
||||
class PcpCache;
|
||||
class PcpSite;
|
||||
|
||||
/// \class PcpLayerStackChanges
|
||||
///
|
||||
/// Types of changes per layer stack.
|
||||
///
|
||||
class PcpLayerStackChanges {
|
||||
public:
|
||||
/// Must rebuild the layer tree. Implies didChangeLayerOffsets.
|
||||
bool didChangeLayers;
|
||||
|
||||
/// Must rebuild the layer offsets.
|
||||
bool didChangeLayerOffsets;
|
||||
|
||||
/// Must rebuild the relocation tables.
|
||||
bool didChangeRelocates;
|
||||
|
||||
/// A significant layer stack change means the composed opinions of
|
||||
/// the layer stack may have changed in arbitrary ways. This
|
||||
/// represents a coarse invalidation. By way of contrast, an example
|
||||
/// of an insignificant change is adding or removing a layer empty
|
||||
/// of opinions.
|
||||
bool didChangeSignificantly;
|
||||
|
||||
/// New relocation maps for this layer stack.
|
||||
/// If didChangeRelocates is true, these fields will be populated
|
||||
/// as part of determining the changes to this layer stack.
|
||||
/// However, we do not immediately apply those changes to the
|
||||
/// layer stack; we store them here and commit them in Apply().
|
||||
SdfRelocatesMap newRelocatesTargetToSource;
|
||||
SdfRelocatesMap newRelocatesSourceToTarget;
|
||||
SdfRelocatesMap newIncrementalRelocatesSourceToTarget;
|
||||
SdfRelocatesMap newIncrementalRelocatesTargetToSource;
|
||||
SdfPathVector newRelocatesPrimPaths;
|
||||
|
||||
/// Paths that are affected by the above relocation changes.
|
||||
SdfPathSet pathsAffectedByRelocationChanges;
|
||||
|
||||
PcpLayerStackChanges() :
|
||||
didChangeLayers(false),
|
||||
didChangeLayerOffsets(false),
|
||||
didChangeRelocates(false),
|
||||
didChangeSignificantly(false)
|
||||
{}
|
||||
};
|
||||
|
||||
/// \class PcpCacheChanges
|
||||
///
|
||||
/// Types of changes per cache.
|
||||
///
|
||||
class PcpCacheChanges {
|
||||
public:
|
||||
enum TargetType {
|
||||
TargetTypeConnection = 1 << 0,
|
||||
TargetTypeRelationshipTarget = 1 << 1
|
||||
};
|
||||
|
||||
/// Must rebuild the indexes at and below each path. This
|
||||
/// implies rebuilding the prim/property stacks at
|
||||
/// and below each path.
|
||||
SdfPathSet didChangeSignificantly;
|
||||
|
||||
/// Must rebuild the prim/property stacks at each path.
|
||||
SdfPathSet didChangeSpecs;
|
||||
|
||||
/// Must rebuild the prim indexes at each path. This implies rebuilding
|
||||
/// the prim stack at each path.
|
||||
SdfPathSet didChangePrims;
|
||||
|
||||
/// Must rebuild the connections/targets at each path.
|
||||
std::map<SdfPath, int, SdfPath::FastLessThan> didChangeTargets;
|
||||
|
||||
/// Must update the path on every namespace object at and below each
|
||||
/// given path. The first path is the old path to the object and the
|
||||
/// second path is the new path. The order of the vector matters and
|
||||
/// indicates the order in which the namespace edits occur.
|
||||
std::vector<std::pair<SdfPath, SdfPath>> didChangePath;
|
||||
|
||||
private:
|
||||
friend class PcpCache;
|
||||
friend class PcpChanges;
|
||||
|
||||
// Must rebuild the prim/property stacks at each path due to a change
|
||||
// that only affects the internal representation of the stack and
|
||||
// not its contents. Because this causes no externally-observable
|
||||
// changes in state, clients do not need to be aware of these changes.
|
||||
SdfPathSet _didChangeSpecsInternal;
|
||||
};
|
||||
|
||||
/// Structure used to temporarily retain layers and layerStacks within
|
||||
/// a code block. Analogous to the autorelease pool in obj-c.
|
||||
class PcpLifeboat {
|
||||
public:
|
||||
PcpLifeboat();
|
||||
~PcpLifeboat();
|
||||
|
||||
/// Ensure that \p layer exists until this object is destroyed.
|
||||
void Retain(const SdfLayerRefPtr& layer);
|
||||
|
||||
/// Ensure that \p layerStack exists until this object is destroyed.
|
||||
void Retain(const PcpLayerStackRefPtr& layerStack);
|
||||
|
||||
/// Returns reference to the set of layer stacks currently being held
|
||||
/// in the lifeboat.
|
||||
const std::set<PcpLayerStackRefPtr>& GetLayerStacks() const;
|
||||
|
||||
/// Swap the contents of this and \p other.
|
||||
void Swap(PcpLifeboat& other);
|
||||
|
||||
private:
|
||||
std::set<SdfLayerRefPtr> _layers;
|
||||
std::set<PcpLayerStackRefPtr> _layerStacks;
|
||||
};
|
||||
|
||||
/// \class PcpChanges
|
||||
///
|
||||
/// Describes Pcp changes.
|
||||
///
|
||||
/// Collects changes to Pcp necessary to reflect changes in Sd. It does
|
||||
/// not cause any changes to any Pcp caches, layer stacks, etc; it only
|
||||
/// computes what changes would be necessary to Pcp to reflect the Sd
|
||||
/// changes.
|
||||
///
|
||||
class PcpChanges {
|
||||
public:
|
||||
PCP_API PcpChanges();
|
||||
PCP_API ~PcpChanges();
|
||||
|
||||
/// Breaks down \p changes into individual changes on the caches in
|
||||
/// \p caches. This simply translates data in \p changes into other
|
||||
/// Did...() calls on this object.
|
||||
///
|
||||
/// Clients will typically call this method once then call \c Apply() or
|
||||
/// get the changes using \c GetLayerStackChanges() and
|
||||
/// \c GetCacheChanges().
|
||||
PCP_API
|
||||
void DidChange(const TfSpan<const PcpCache*> &caches,
|
||||
const SdfLayerChangeListVec& changes);
|
||||
|
||||
/// Tries to load the sublayer of \p layer at \p sublayerPath. If
|
||||
/// successful, any layer stack using \p layer is marked as having changed
|
||||
/// and all prims in \p cache using any prim in any of those layer stacks
|
||||
/// are marked as changed.
|
||||
PCP_API
|
||||
void DidMaybeFixSublayer(const PcpCache* cache,
|
||||
const SdfLayerHandle& layer,
|
||||
const std::string& assetPath);
|
||||
|
||||
/// Tries to load the asset at \p assetPath. If successful, any prim
|
||||
/// in \p cache using the site \p site is marked as changed.
|
||||
PCP_API
|
||||
void DidMaybeFixAsset(const PcpCache* cache,
|
||||
const PcpSite& site,
|
||||
const SdfLayerHandle& srcLayer,
|
||||
const std::string& assetPath);
|
||||
|
||||
/// The layer identified by \p layerId was muted in \p cache.
|
||||
PCP_API
|
||||
void DidMuteLayer(const PcpCache* cache, const std::string& layerId);
|
||||
|
||||
/// The layer identified by \p layerId was unmuted in \p cache.
|
||||
PCP_API
|
||||
void DidUnmuteLayer(const PcpCache* cache, const std::string& layerId);
|
||||
|
||||
/// The sublayer tree changed. This often, but doesn't always, imply that
|
||||
/// anything and everything may have changed. If clients want to indicate
|
||||
/// that anything and everything may have changed they should call this
|
||||
/// method and \c DidChangePrimGraph() with the absolute root path.
|
||||
PCP_API
|
||||
void DidChangeLayers(const PcpCache* cache);
|
||||
|
||||
/// The sublayer offsets changed.
|
||||
PCP_API
|
||||
void DidChangeLayerOffsets(const PcpCache* cache);
|
||||
|
||||
/// The object at \p path changed significantly enough to require
|
||||
/// recomputing the entire prim or property index. A significant change
|
||||
/// implies changes to every namespace descendant's index, specs, and
|
||||
/// dependencies.
|
||||
PCP_API
|
||||
void DidChangeSignificantly(const PcpCache* cache, const SdfPath& path);
|
||||
|
||||
/// The spec stack for the prim or property has changed, due to the
|
||||
/// addition or removal of the spec in \p changedLayer at \p changedPath.
|
||||
/// This is used when inert prims/properties are added or removed or when
|
||||
/// any change requires rebuilding the property stack. It implies that
|
||||
/// dependencies on those specs has changed.
|
||||
PCP_API
|
||||
void DidChangeSpecs(const PcpCache* cache, const SdfPath& path,
|
||||
const SdfLayerHandle& changedLayer,
|
||||
const SdfPath& changedPath);
|
||||
|
||||
/// The spec stack for the prim or property at \p path in \p cache has
|
||||
/// changed.
|
||||
PCP_API
|
||||
void DidChangeSpecStack(const PcpCache* cache, const SdfPath& path);
|
||||
|
||||
/// The connections on the attribute or targets on the relationship have
|
||||
/// changed.
|
||||
PCP_API
|
||||
void DidChangeTargets(const PcpCache* cache, const SdfPath& path,
|
||||
PcpCacheChanges::TargetType targetType);
|
||||
|
||||
/// The relocates that affect prims and properties at and below
|
||||
/// the given cache path have changed.
|
||||
PCP_API
|
||||
void DidChangeRelocates(const PcpCache* cache, const SdfPath& path);
|
||||
|
||||
/// The composed object at \p oldPath was moved to \p newPath. This
|
||||
/// implies every corresponding Sd change. This object will subsume
|
||||
/// those Sd changes under this higher-level move. Sd path changes
|
||||
/// that are not so subsumed will be converted to DidChangePrimGraph()
|
||||
/// and/or DidChangeSpecs() changes.
|
||||
PCP_API
|
||||
void DidChangePaths(const PcpCache* cache,
|
||||
const SdfPath& oldPath, const SdfPath& newPath);
|
||||
|
||||
/// Remove any changes for \p cache.
|
||||
PCP_API
|
||||
void DidDestroyCache(const PcpCache* cache);
|
||||
|
||||
/// Swap the contents of this and \p other.
|
||||
PCP_API
|
||||
void Swap(PcpChanges& other);
|
||||
|
||||
/// Returns \c true iff there are no changes.
|
||||
PCP_API
|
||||
bool IsEmpty() const;
|
||||
|
||||
typedef std::map<PcpLayerStackPtr, PcpLayerStackChanges> LayerStackChanges;
|
||||
typedef std::map<PcpCache*, PcpCacheChanges> CacheChanges;
|
||||
|
||||
/// Returns a map of all of the layer stack changes. Note that some
|
||||
/// keys may be to expired layer stacks.
|
||||
PCP_API
|
||||
const LayerStackChanges& GetLayerStackChanges() const;
|
||||
|
||||
/// Returns a map of all of the cache changes.
|
||||
PCP_API
|
||||
const CacheChanges& GetCacheChanges() const;
|
||||
|
||||
/// Returns the lifeboat responsible for maintaining the lifetime of
|
||||
/// layers and layer stacks during change processing. Consumers may
|
||||
/// inspect this object to determine which of these objects, if any,
|
||||
/// had their lifetimes affected during change processing.
|
||||
PCP_API
|
||||
const PcpLifeboat& GetLifeboat() const;
|
||||
|
||||
/// Applies the changes to the layer stacks and caches.
|
||||
PCP_API
|
||||
void Apply() const;
|
||||
|
||||
private:
|
||||
// Internal data types for namespace edits from Sd.
|
||||
typedef std::map<SdfPath, SdfPath> _PathEditMap;
|
||||
typedef std::map<PcpCache*, _PathEditMap> _RenameChanges;
|
||||
|
||||
// Returns the PcpLayerStackChanges for the given cache's layer stack.
|
||||
PcpLayerStackChanges& _GetLayerStackChanges(const PcpCache* cache);
|
||||
|
||||
// Returns the PcpLayerStackChanges for the given layer stack.
|
||||
PcpLayerStackChanges& _GetLayerStackChanges(const PcpLayerStackPtr&);
|
||||
|
||||
// Returns the PcpCacheChanges for the given cache.
|
||||
PcpCacheChanges& _GetCacheChanges(const PcpCache* cache);
|
||||
|
||||
// Returns the _PathEditMap for the given cache.
|
||||
_PathEditMap& _GetRenameChanges(const PcpCache* cache);
|
||||
|
||||
|
||||
// Optimize the changes.
|
||||
void _Optimize() const;
|
||||
|
||||
// Optimize the changes.
|
||||
void _Optimize();
|
||||
|
||||
// Optimize the changes for a given cache.
|
||||
void _Optimize(PcpCacheChanges*);
|
||||
|
||||
// Optimize path changes.
|
||||
void _OptimizePathChanges(const PcpCache* cache, PcpCacheChanges* changes,
|
||||
const _PathEditMap* pathChanges);
|
||||
|
||||
// Sublayer change type for _DidChangeSublayer.
|
||||
enum _SublayerChangeType {
|
||||
_SublayerAdded,
|
||||
_SublayerRemoved
|
||||
};
|
||||
|
||||
// Helper function for loading a sublayer of \p layer at \p sublayerPath
|
||||
// for processing changes described by \p sublayerChange.
|
||||
SdfLayerRefPtr _LoadSublayerForChange(const PcpCache* cache,
|
||||
const SdfLayerHandle& layer,
|
||||
const std::string& sublayerPath,
|
||||
_SublayerChangeType changeType) const;
|
||||
|
||||
// Helper function for loading a sublayer at \p sublayerPath
|
||||
// for processing changes described by \p sublayerChange.
|
||||
SdfLayerRefPtr _LoadSublayerForChange(const PcpCache* cache,
|
||||
const std::string& sublayerPath,
|
||||
_SublayerChangeType changeType) const;
|
||||
|
||||
// Propagates changes to \p sublayer specified by \p sublayerChange to
|
||||
// the dependents of that sublayer. This includes all layer stacks
|
||||
// that include the sublayer.
|
||||
void _DidChangeSublayerAndLayerStacks(const PcpCache* cache,
|
||||
const PcpLayerStackPtrVector& stacks,
|
||||
const std::string& sublayerPath,
|
||||
const SdfLayerHandle& sublayer,
|
||||
_SublayerChangeType sublayerChange,
|
||||
std::string* debugSummary);
|
||||
|
||||
// Propagates changes to \p sublayer specified by \p sublayerChange to
|
||||
// the dependents of that sublayer.
|
||||
void _DidChangeSublayer(const PcpCache* cache,
|
||||
const PcpLayerStackPtrVector& layerStacks,
|
||||
const std::string& sublayerPath,
|
||||
const SdfLayerHandle& sublayer,
|
||||
_SublayerChangeType sublayerChange,
|
||||
std::string* debugSummary,
|
||||
bool *significant);
|
||||
|
||||
// Mark the layer stack as having changed.
|
||||
void _DidChangeLayerStack(const PcpLayerStackPtr& layerStack,
|
||||
bool requiresLayerStackChange,
|
||||
bool requiresLayerStackOffsetsChange,
|
||||
bool requiresSignificantChange);
|
||||
|
||||
// Mark the layer stack's relocations as having changed.
|
||||
// Recompute the new relocations, storing the result in the Changes,
|
||||
// so that change-processing can determine which other caches it
|
||||
// needs to invalidate.
|
||||
void _DidChangeLayerStackRelocations(
|
||||
const TfSpan<const PcpCache*>& caches,
|
||||
const PcpLayerStackPtr & layerStack,
|
||||
std::string* debugSummary);
|
||||
|
||||
// Register changes to any prim indexes in \p caches that are affected
|
||||
// by a change to a layer's resolved path used by \p layerStack.
|
||||
void _DidChangeLayerStackResolvedPath(
|
||||
const TfSpan<const PcpCache*>& caches,
|
||||
const PcpLayerStackPtr& layerStack,
|
||||
std::string* debugSummary);
|
||||
|
||||
// The spec stack for the prim or property index at \p path must be
|
||||
// recomputed due to a change that affects only the internal representation
|
||||
// of the stack and not its contents.
|
||||
void _DidChangeSpecStackInternal(
|
||||
const PcpCache* cache, const SdfPath& path);
|
||||
|
||||
private:
|
||||
LayerStackChanges _layerStackChanges;
|
||||
CacheChanges _cacheChanges;
|
||||
_RenameChanges _renameChanges;
|
||||
mutable PcpLifeboat _lifeboat;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_CHANGES_H
|
||||
@@ -0,0 +1,297 @@
|
||||
//
|
||||
// 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_PCP_COMPOSE_SITE_H
|
||||
#define PXR_USD_PCP_COMPOSE_SITE_H
|
||||
|
||||
/// \file pcp/composeSite.h
|
||||
///
|
||||
/// Single-site composition.
|
||||
///
|
||||
/// These are helpers that compose specific fields at single sites.
|
||||
/// They compose the field for a given path across a layer stack,
|
||||
/// using field-specific rules to combine the values.
|
||||
///
|
||||
/// These helpers are low-level utilities used by the rest of the
|
||||
/// Pcp algorithms, to discover composition arcs in scene description.
|
||||
/// These arcs are what guide the algorithm to pull additional
|
||||
/// sites of scene description into the PcpPrimIndex.
|
||||
///
|
||||
/// Some of these field types support list-editing. (See SdListOp.)
|
||||
/// List-editing for these fields is applied across the fixed domain
|
||||
/// of a single site; you cannot apply list-ops across sites.
|
||||
/// The intention is to avoid subtle ordering issues in composition
|
||||
/// semantics.
|
||||
///
|
||||
/// Note that these helpers do not take PcpSite as a literal parameter;
|
||||
/// instead, they require the actual computed layer stack that a site
|
||||
/// identified. Rather than tying these helpers to PcpCache and its
|
||||
/// process of computing layer stacks, they just employ the result.
|
||||
/// Conceptually, though, they are operating on the scene description
|
||||
/// identified by a PcpSite.
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/pcp/node.h"
|
||||
#include "pxr/usd/sdf/layerOffset.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/usd/sdf/payload.h"
|
||||
#include "pxr/usd/sdf/reference.h"
|
||||
#include "pxr/usd/sdf/types.h"
|
||||
#include "pxr/usd/sdf/site.h"
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(PcpLayerStack);
|
||||
|
||||
class PcpLayerStackSite;
|
||||
|
||||
/// \struct PcpSourceArcInfo
|
||||
///
|
||||
/// Information about the source of the target of an arc.
|
||||
/// All arcs have a layer that the arc comes from. References and payloads
|
||||
/// have a resolved layer offset and authored asset path as well.
|
||||
///
|
||||
struct PcpSourceArcInfo {
|
||||
SdfLayerHandle layer;
|
||||
SdfLayerOffset layerOffset;
|
||||
std::string authoredAssetPath;
|
||||
};
|
||||
|
||||
/// A vector of reference or payload arc information.
|
||||
typedef std::vector<PcpSourceArcInfo> PcpSourceArcInfoVector;
|
||||
|
||||
/// References
|
||||
PCP_API
|
||||
void
|
||||
PcpComposeSiteReferences(PcpLayerStackRefPtr const &layerStack,
|
||||
SdfPath const &path,
|
||||
SdfReferenceVector *result,
|
||||
PcpSourceArcInfoVector *info);
|
||||
inline void
|
||||
PcpComposeSiteReferences(PcpNodeRef const &node,
|
||||
SdfReferenceVector *result,
|
||||
PcpSourceArcInfoVector *info)
|
||||
{
|
||||
return PcpComposeSiteReferences(node.GetLayerStack(), node.GetPath(),
|
||||
result, info);
|
||||
}
|
||||
|
||||
/// Payloads
|
||||
PCP_API
|
||||
void
|
||||
PcpComposeSitePayloads(PcpLayerStackRefPtr const &layerStack,
|
||||
SdfPath const &path,
|
||||
SdfPayloadVector *result,
|
||||
PcpSourceArcInfoVector *info);
|
||||
inline void
|
||||
PcpComposeSitePayloads(PcpNodeRef const &node,
|
||||
SdfPayloadVector *result,
|
||||
PcpSourceArcInfoVector *info)
|
||||
{
|
||||
return PcpComposeSitePayloads(node.GetLayerStack(), node.GetPath(),
|
||||
result, info);
|
||||
}
|
||||
|
||||
/// Permission
|
||||
PCP_API
|
||||
SdfPermission
|
||||
PcpComposeSitePermission(PcpLayerStackRefPtr const &layerStack,
|
||||
SdfPath const &path);
|
||||
|
||||
inline SdfPermission
|
||||
PcpComposeSitePermission(PcpNodeRef const &node)
|
||||
{
|
||||
return PcpComposeSitePermission(node.GetLayerStack(), node.GetPath());
|
||||
}
|
||||
|
||||
/// Prim sites
|
||||
PCP_API
|
||||
void
|
||||
PcpComposeSitePrimSites(PcpLayerStackRefPtr const &layerStack,
|
||||
SdfPath const &path,
|
||||
SdfSiteVector *result);
|
||||
|
||||
inline void
|
||||
PcpComposeSitePrimSites(PcpNodeRef const &node, SdfSiteVector *result)
|
||||
{
|
||||
return PcpComposeSitePrimSites(
|
||||
node.GetLayerStack(), node.GetPath(), result);
|
||||
}
|
||||
|
||||
/// Relocates
|
||||
PCP_API
|
||||
void
|
||||
PcpComposeSiteRelocates(PcpLayerStackRefPtr const &layerStack,
|
||||
SdfPath const &path,
|
||||
SdfRelocatesMap *result);
|
||||
|
||||
inline void
|
||||
PcpComposeSiteRelocates(PcpNodeRef const &node, SdfRelocatesMap *result)
|
||||
{
|
||||
return PcpComposeSiteRelocates(
|
||||
node.GetLayerStack(), node.GetPath(), result);
|
||||
}
|
||||
|
||||
/// Has prim specs.
|
||||
PCP_API
|
||||
bool
|
||||
PcpComposeSiteHasPrimSpecs(PcpLayerStackRefPtr const &layerStack,
|
||||
SdfPath const &path);
|
||||
inline bool
|
||||
PcpComposeSiteHasPrimSpecs(PcpNodeRef const &node)
|
||||
{
|
||||
return PcpComposeSiteHasPrimSpecs(node.GetLayerStack(), node.GetPath());
|
||||
}
|
||||
|
||||
/// Symmetry
|
||||
PCP_API
|
||||
bool
|
||||
PcpComposeSiteHasSymmetry(PcpLayerStackRefPtr const &layerStack,
|
||||
SdfPath const &path);
|
||||
inline bool
|
||||
PcpComposeSiteHasSymmetry(PcpNodeRef const &node)
|
||||
{
|
||||
return PcpComposeSiteHasSymmetry(node.GetLayerStack(), node.GetPath());
|
||||
}
|
||||
|
||||
/// Inherits
|
||||
PCP_API
|
||||
void
|
||||
PcpComposeSiteInherits(PcpLayerStackRefPtr const &layerStack,
|
||||
SdfPath const &path, SdfPathVector *result,
|
||||
PcpSourceArcInfoVector *info);
|
||||
|
||||
PCP_API
|
||||
void
|
||||
PcpComposeSiteInherits(PcpLayerStackRefPtr const &layerStack,
|
||||
SdfPath const &path, SdfPathVector *result);
|
||||
|
||||
inline void
|
||||
PcpComposeSiteInherits(PcpNodeRef const &node, SdfPathVector *result)
|
||||
{
|
||||
return PcpComposeSiteInherits(node.GetLayerStack(), node.GetPath(), result);
|
||||
}
|
||||
|
||||
/// Specializes
|
||||
PCP_API
|
||||
void
|
||||
PcpComposeSiteSpecializes(PcpLayerStackRefPtr const &layerStack,
|
||||
SdfPath const &path, SdfPathVector *result,
|
||||
PcpSourceArcInfoVector *info);
|
||||
|
||||
PCP_API
|
||||
void
|
||||
PcpComposeSiteSpecializes(PcpLayerStackRefPtr const &layerStack,
|
||||
SdfPath const &path, SdfPathVector *result);
|
||||
|
||||
inline void
|
||||
PcpComposeSiteSpecializes(PcpNodeRef const &node, SdfPathVector *result)
|
||||
{
|
||||
return PcpComposeSiteSpecializes(
|
||||
node.GetLayerStack(), node.GetPath(), result);
|
||||
}
|
||||
|
||||
/// VariantSets
|
||||
PCP_API
|
||||
void
|
||||
PcpComposeSiteVariantSets(PcpLayerStackRefPtr const &layerStack,
|
||||
SdfPath const &path,
|
||||
std::vector<std::string> *result,
|
||||
PcpSourceArcInfoVector *info);
|
||||
|
||||
PCP_API
|
||||
void
|
||||
PcpComposeSiteVariantSets(PcpLayerStackRefPtr const &layerStack,
|
||||
SdfPath const &path,
|
||||
std::vector<std::string> *result);
|
||||
inline void
|
||||
PcpComposeSiteVariantSets(PcpNodeRef const &node,
|
||||
std::vector<std::string> *result) {
|
||||
return PcpComposeSiteVariantSets(
|
||||
node.GetLayerStack(), node.GetPath(), result);
|
||||
}
|
||||
|
||||
/// VariantSetOptions
|
||||
PCP_API
|
||||
void
|
||||
PcpComposeSiteVariantSetOptions(PcpLayerStackRefPtr const &layerStack,
|
||||
SdfPath const &path,
|
||||
std::string const &vsetName,
|
||||
std::set<std::string> *result);
|
||||
inline void
|
||||
PcpComposeSiteVariantSetOptions(PcpNodeRef const &node,
|
||||
std::string const &vsetName,
|
||||
std::set<std::string> *result)
|
||||
{
|
||||
return PcpComposeSiteVariantSetOptions(
|
||||
node.GetLayerStack(), node.GetPath(), vsetName, result);
|
||||
}
|
||||
|
||||
/// VariantSelection
|
||||
PCP_API
|
||||
bool
|
||||
PcpComposeSiteVariantSelection(PcpLayerStackRefPtr const &layerStack,
|
||||
SdfPath const &path,
|
||||
std::string const &vsetName,
|
||||
std::string *result);
|
||||
inline bool
|
||||
PcpComposeSiteVariantSelection(PcpNodeRef const &node,
|
||||
std::string const &vsetName,
|
||||
std::string *result)
|
||||
{
|
||||
return PcpComposeSiteVariantSelection(node.GetLayerStack(), node.GetPath(),
|
||||
vsetName, result);
|
||||
}
|
||||
|
||||
/// VariantSelections
|
||||
PCP_API
|
||||
void
|
||||
PcpComposeSiteVariantSelections(PcpLayerStackRefPtr const &layerStack,
|
||||
SdfPath const &path,
|
||||
SdfVariantSelectionMap *result);
|
||||
inline void
|
||||
PcpComposeSiteVariantSelections(PcpNodeRef const &node,
|
||||
SdfVariantSelectionMap *result)
|
||||
{
|
||||
return PcpComposeSiteVariantSelections(node.GetLayerStack(), node.GetPath(),
|
||||
result);
|
||||
}
|
||||
|
||||
/// Compose child names.
|
||||
/// If the optional \p orderField is provided, its order will be applied.
|
||||
PCP_API
|
||||
void
|
||||
PcpComposeSiteChildNames(SdfLayerRefPtrVector const &layers,
|
||||
SdfPath const &path,
|
||||
const TfToken & namesField,
|
||||
TfTokenVector *nameOrder,
|
||||
PcpTokenSet *nameSet,
|
||||
const TfToken *orderField = nullptr);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_COMPOSE_SITE_H
|
||||
@@ -0,0 +1,147 @@
|
||||
//
|
||||
// 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_PCP_DEPENDENCY_H
|
||||
#define PXR_USD_PCP_DEPENDENCY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/pcp/mapFunction.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class PcpNodeRef;
|
||||
|
||||
/// \enum PcpDependencyType
|
||||
///
|
||||
/// A classification of PcpPrimIndex->PcpSite dependencies
|
||||
/// by composition structure.
|
||||
///
|
||||
enum PcpDependencyType {
|
||||
/// No type of dependency.
|
||||
PcpDependencyTypeNone = 0,
|
||||
|
||||
/// The root dependency of a cache on its root site.
|
||||
/// This may be useful to either include, as when invalidating
|
||||
/// caches in response to scene edits, or to exclude, as when
|
||||
/// scanning dependency arcs to compensate for a namespace edit.
|
||||
PcpDependencyTypeRoot = (1 << 0),
|
||||
|
||||
/// Purely direct dependencies involve only arcs introduced
|
||||
/// directly at this level of namespace.
|
||||
PcpDependencyTypePurelyDirect = (1 << 1),
|
||||
|
||||
/// Partly direct dependencies involve at least one arc introduced
|
||||
/// directly at this level of namespace; they may also involve
|
||||
/// ancestral arcs along the chain as well.
|
||||
PcpDependencyTypePartlyDirect = (1 << 2),
|
||||
|
||||
/// Ancestral dependencies involve only arcs from ancestral
|
||||
/// levels of namespace, and no direct arcs.
|
||||
PcpDependencyTypeAncestral = (1 << 3),
|
||||
|
||||
/// Virtual dependencies do not contribute scene description,
|
||||
/// yet represent sites whose scene description (or ancestral
|
||||
/// scene description) informed the structure of the cache.
|
||||
///
|
||||
/// One case of this is when a reference or payload arc
|
||||
/// does not specify a prim, and the target layerStack does
|
||||
/// not provide defaultPrim metadata either. In that case
|
||||
/// a virtual dependency to the root of that layer stack will
|
||||
/// represent the latent dependency on that site's metadata.
|
||||
///
|
||||
/// Another case of this is "spooky ancestral" dependencies from
|
||||
/// relocates. These are referred to as "spooky" dependencies
|
||||
/// because they can be seen as a form of action-at-a-distance. They
|
||||
/// only occur as a result of relocation arcs.
|
||||
PcpDependencyTypeVirtual = (1 << 4),
|
||||
PcpDependencyTypeNonVirtual = (1 << 5),
|
||||
|
||||
/// Combined mask value representing both pure and partly direct
|
||||
/// deps.
|
||||
PcpDependencyTypeDirect =
|
||||
PcpDependencyTypePartlyDirect
|
||||
| PcpDependencyTypePurelyDirect,
|
||||
|
||||
/// Combined mask value representing any kind of dependency,
|
||||
/// except virtual ones.
|
||||
PcpDependencyTypeAnyNonVirtual =
|
||||
PcpDependencyTypeRoot
|
||||
| PcpDependencyTypeDirect
|
||||
| PcpDependencyTypeAncestral
|
||||
| PcpDependencyTypeNonVirtual,
|
||||
|
||||
/// Combined mask value representing any kind of dependency.
|
||||
PcpDependencyTypeAnyIncludingVirtual =
|
||||
PcpDependencyTypeAnyNonVirtual
|
||||
| PcpDependencyTypeVirtual,
|
||||
};
|
||||
|
||||
/// A typedef for a bitmask of flags from PcpDependencyType.
|
||||
typedef unsigned int PcpDependencyFlags;
|
||||
|
||||
/// Description of a dependency.
|
||||
struct PcpDependency {
|
||||
/// The path in this PcpCache's root layer stack that depends
|
||||
/// on the site.
|
||||
SdfPath indexPath;
|
||||
/// The site path. When using recurseDownNamespace, this may
|
||||
/// be a path beneath the initial sitePath.
|
||||
SdfPath sitePath;
|
||||
/// The map function that applies to values from the site.
|
||||
PcpMapFunction mapFunc;
|
||||
|
||||
bool operator==(const PcpDependency &rhs) const {
|
||||
return indexPath == rhs.indexPath &&
|
||||
sitePath == rhs.sitePath &&
|
||||
mapFunc == rhs.mapFunc;
|
||||
}
|
||||
bool operator!=(const PcpDependency &rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::vector<PcpDependency> PcpDependencyVector;
|
||||
|
||||
/// Returns true if this node introduces a dependency in its
|
||||
/// PcpPrimIndex, false otherwise. This is equivalent to
|
||||
/// PcpClassifyNodeDependency(n) != PcpDependencyTypeNone, but
|
||||
/// is faster.
|
||||
PCP_API
|
||||
bool PcpNodeIntroducesDependency(const PcpNodeRef &n);
|
||||
|
||||
/// Classify the dependency represented by a node, by analyzing
|
||||
/// its structural role in its PcpPrimIndex. Returns a
|
||||
/// bitmask of flags from PcpDependencyType.
|
||||
PCP_API
|
||||
PcpDependencyFlags PcpClassifyNodeDependency(const PcpNodeRef &n);
|
||||
|
||||
PCP_API
|
||||
std::string PcpDependencyFlagsToString(const PcpDependencyFlags flags);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_DEPENDENCY_H
|
||||
@@ -0,0 +1,108 @@
|
||||
//
|
||||
// Copyright 2019 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_PCP_DYNAMIC_FILE_FORMAT_CONTEXT_H
|
||||
#define PXR_USD_PCP_DYNAMIC_FILE_FORMAT_CONTEXT_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/pcp/node.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class PcpPrimIndex_StackFrame;
|
||||
class PcpCache;
|
||||
|
||||
/// \class PcpDynamicFileFormatContext
|
||||
///
|
||||
/// Context object for the current state of a prim index that is being built
|
||||
/// that allows implementations of PcpDynamicFileFormatInterface to compose
|
||||
/// field values when generating dynamic file format arguments. The context
|
||||
/// allows us to iterate over all nodes that have already been composed looking
|
||||
/// for the strongest opinion for a relevant field.
|
||||
class PcpDynamicFileFormatContext
|
||||
{
|
||||
public:
|
||||
using VtValueVector = std::vector<VtValue>;
|
||||
|
||||
PCP_API
|
||||
~PcpDynamicFileFormatContext() = default;
|
||||
|
||||
/// Compose the \p value of the given \p field and return its current
|
||||
/// strongest opinion. For dictionary valued fields this will be a
|
||||
/// dictionary containing the strongest value for each individual key.
|
||||
/// Returns true if a value for the field was found.
|
||||
PCP_API
|
||||
bool ComposeValue(const TfToken &field, VtValue *value) const;
|
||||
|
||||
/// Compose the \p values of the given \p field returning all available
|
||||
/// opinions ordered from strongest to weakest. For dictionary valued
|
||||
/// fields, the dictionaries from each opinion are not composed together
|
||||
/// at each step and are instead returned in the list as is.
|
||||
/// Returns true if a value for the field was found.
|
||||
///
|
||||
/// Note that this is slower than ComposeValue, especially for
|
||||
/// non-dictionary valued fields, and should only be used if knowing more
|
||||
/// than just the strongest value is necessary.
|
||||
PCP_API
|
||||
bool ComposeValueStack(const TfToken &field,
|
||||
VtValueVector *values) const;
|
||||
|
||||
private:
|
||||
// Callback function for ComposeValue. This callback function will
|
||||
// be passed values for the field given to ComposeValue from
|
||||
// strongest to weakest available opinion and is free to copy or
|
||||
// swap out the value as desired.
|
||||
using _ComposeFunction = std::function<void(VtValue &&)>;
|
||||
|
||||
/// Constructs a context.
|
||||
/// \p parentNode and \p previousFrame are used to traverse the
|
||||
/// current state of the prim index graph when composing the opinions on
|
||||
/// fields. \p composedFieldNames is the set of field names that is
|
||||
/// to be updated with the names of fields that ComposeValue and
|
||||
/// ComposeValueStack are called on for dependency tracking.
|
||||
PcpDynamicFileFormatContext(
|
||||
const PcpNodeRef &parentNode,
|
||||
PcpPrimIndex_StackFrame *previousFrame,
|
||||
TfToken::Set *composedFieldNames);
|
||||
/// Access to private constructor. Should only be called by prim indexing.
|
||||
friend PcpDynamicFileFormatContext Pcp_CreateDynamicFileFormatContext(
|
||||
const PcpNodeRef &, PcpPrimIndex_StackFrame *, TfToken::Set *);
|
||||
|
||||
/// Returns whether the given \p field is allowed to be used to generate
|
||||
/// file format arguments. It can also return whether the value type of
|
||||
/// the field is a dictionary if needed.
|
||||
bool _IsAllowedFieldForArguments(
|
||||
const TfToken &field, bool *fieldValueIsDictionary = nullptr) const;
|
||||
|
||||
private:
|
||||
PcpNodeRef _parentNode;
|
||||
PcpPrimIndex_StackFrame *_previousStackFrame;
|
||||
|
||||
// Cached names of fields that had values composed by this context.
|
||||
TfToken::Set *_composedFieldNames;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_DYNAMIC_FILE_FORMAT_CONTEXT_H
|
||||
@@ -0,0 +1,147 @@
|
||||
//
|
||||
// Copyright 2019 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_PCP_DYNAMIC_FILE_FORMAT_DEPENDENCY_DATA_H
|
||||
#define PXR_USD_PCP_DYNAMIC_FILE_FORMAT_DEPENDENCY_DATA_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class PcpDynamicFileFormatInterface;
|
||||
class VtValue;
|
||||
|
||||
TF_DECLARE_WEAK_PTRS(SdfFileFormat);
|
||||
|
||||
/// \class PcpDynamicFileFormatDependencyData
|
||||
///
|
||||
/// Contains the necessary information for storing a prim index's dependency
|
||||
/// on dynamic file format arguments and determining if a field change affects
|
||||
/// the prim index. This data structure does not store the prim index or its
|
||||
/// path itself and is expected to be the data in some other data structure
|
||||
/// that maps prim indexes to its dependencies.
|
||||
///
|
||||
class PcpDynamicFileFormatDependencyData
|
||||
{
|
||||
public:
|
||||
/// Default constructor. This data will be empty.
|
||||
PCP_API
|
||||
PcpDynamicFileFormatDependencyData() = default;
|
||||
|
||||
/// Move constructor.
|
||||
PCP_API
|
||||
PcpDynamicFileFormatDependencyData(
|
||||
PcpDynamicFileFormatDependencyData &&) = default;
|
||||
|
||||
/// Copy constructor.
|
||||
PCP_API
|
||||
PcpDynamicFileFormatDependencyData(
|
||||
const PcpDynamicFileFormatDependencyData &rhs);
|
||||
|
||||
/// Move assignment operator
|
||||
PcpDynamicFileFormatDependencyData &operator=(
|
||||
PcpDynamicFileFormatDependencyData &&rhs) {
|
||||
Swap(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Copy assignment operator
|
||||
PcpDynamicFileFormatDependencyData &operator=(
|
||||
const PcpDynamicFileFormatDependencyData &rhs) {
|
||||
PcpDynamicFileFormatDependencyData(rhs).Swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Swap the contents of this dependency data with \p rhs.
|
||||
inline void Swap(PcpDynamicFileFormatDependencyData& rhs) {
|
||||
_data.swap(rhs._data);
|
||||
}
|
||||
|
||||
/// Same as Swap(), but standard name.
|
||||
inline void swap(PcpDynamicFileFormatDependencyData &rhs) { Swap(rhs); }
|
||||
|
||||
/// Returns whether this dependency data is empty.
|
||||
inline bool IsEmpty() const {
|
||||
return !_data;
|
||||
}
|
||||
|
||||
/// Adds dependency info from a single context that generated dynamic file
|
||||
/// format arguments (usually a payload arc in the graph).
|
||||
/// \p dynamicFileFormat is the file format that generated the arguments.
|
||||
/// \p dependencyContextData is custom dependency information generated when
|
||||
/// the file format generated its arguments. \p composedFieldNames is a
|
||||
/// list of the fields that were composed on the prim to generate arguments.
|
||||
PCP_API
|
||||
void AddDependencyContext(
|
||||
const PcpDynamicFileFormatInterface *dynamicFileFormat,
|
||||
VtValue &&dependencyContextData,
|
||||
TfToken::Set &&composedFieldNames);
|
||||
|
||||
/// Takes all the dependency data from \p dependencyData and adds it to this
|
||||
/// dependency.
|
||||
PCP_API
|
||||
void AppendDependencyData(
|
||||
PcpDynamicFileFormatDependencyData &&dependencyData);
|
||||
|
||||
/// Returns a list of field names that were composed for any of the
|
||||
/// dependency contexts that were added to this dependency.
|
||||
PCP_API
|
||||
const TfToken::Set &GetRelevantFieldNames() const;
|
||||
|
||||
/// Given a \p field name and the changed field values in \p oldAndNewValues
|
||||
/// this return whether this change can affect any of the file format
|
||||
/// arguments generated by any of the contexts stored in this dependency.
|
||||
PCP_API
|
||||
bool CanFieldChangeAffectFileFormatArguments(const TfToken &fieldName,
|
||||
const VtValue& oldValue,
|
||||
const VtValue& newValue) const;
|
||||
|
||||
private:
|
||||
// Struct containing the entire contents of the dependency.
|
||||
struct _Data
|
||||
{
|
||||
using _ContextData =
|
||||
std::pair<const PcpDynamicFileFormatInterface *, VtValue>;
|
||||
using _ContextDataVector = std::vector<_ContextData>;
|
||||
|
||||
_ContextDataVector dependencyContexts;
|
||||
TfToken::Set relevantFieldNames;
|
||||
|
||||
// Helper for adding relevant fields. We avoid copying by taking the
|
||||
// input set if our set is empty.
|
||||
void _AddRelevantFieldNames(TfToken::Set &&fieldNames);
|
||||
};
|
||||
|
||||
// Pointer to data. Will be null if this an empty data object.
|
||||
std::unique_ptr<_Data> _data;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_DYNAMIC_FILE_FORMAT_DEPENDENCY_DATA_H
|
||||
@@ -0,0 +1,97 @@
|
||||
//
|
||||
// Copyright 2019 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_PCP_DYNAMIC_FILE_FORMAT_INTERFACE_H
|
||||
#define PXR_USD_PCP_DYNAMIC_FILE_FORMAT_INTERFACE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/sdf/fileFormat.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class PcpDynamicFileFormatContext;
|
||||
class VtValue;
|
||||
|
||||
/// \class PcpDynamicFileFormatInterface
|
||||
///
|
||||
/// Interface mixin that can be included by SdfFileFormat subclasses to enable
|
||||
/// dynamic file format argument generation for a file format plugin.
|
||||
/// When prim index composition encounters a payload to an asset of a file
|
||||
/// format that implements this interface, it will call
|
||||
/// ComposeFieldsForFileFormatArguments to generate arguments from the current
|
||||
/// composition context at which the payload is being added. The derived file
|
||||
/// format is on the hook for using the provided context to compute any prim
|
||||
/// field values it needs and generate the relevant file format arguments for
|
||||
/// its content.
|
||||
class PcpDynamicFileFormatInterface
|
||||
{
|
||||
public:
|
||||
/// Empty virtual destructor to prevent build errors with some compilers.
|
||||
PCP_API
|
||||
virtual ~PcpDynamicFileFormatInterface();
|
||||
|
||||
/// Derived classes must implement this function to compose prim fields
|
||||
/// using the given \p context and use them to generate file format
|
||||
/// arguments for the layer at \p assetPath. The context provides methods
|
||||
/// to compose field values at the current point in prim index composition
|
||||
/// which can be used to generate the relevant file format arguments. These
|
||||
/// arguments need to be added to the set of file format arguments provided
|
||||
/// by \p args.
|
||||
///
|
||||
/// Additionally, implementations can output \p dependencyContextData of
|
||||
/// any value type that will then be passed back in to calls to
|
||||
/// CanFieldChangeAffectFileFormatArguments during change processing.
|
||||
/// This can be used to provide more that context that is specific to the
|
||||
/// file format when determining whether a field change really does affect
|
||||
/// the arguments generated by a particular call to this function.
|
||||
PCP_API
|
||||
virtual void ComposeFieldsForFileFormatArguments(
|
||||
const std::string& assetPath,
|
||||
const PcpDynamicFileFormatContext &context,
|
||||
SdfFileFormat::FileFormatArguments* args,
|
||||
VtValue *dependencyContextData) const = 0;
|
||||
|
||||
/// Derived classes must implement this function to return true if the
|
||||
/// change to scene description of the field named \p field can affect the
|
||||
/// dynamic file format arguments generated by
|
||||
/// ComposeFieldsForFileFormatArguments. This function will be called during
|
||||
/// change processing to determine whether a change to a field affects
|
||||
/// the dynamic file format arguments of a payload that a prim index depends
|
||||
/// on.
|
||||
///
|
||||
/// \p oldValue and \p newValue contain the old and new values of the field.
|
||||
/// \p dependencyContextData is the arbitrary typed data that was generated
|
||||
/// by the call to ComposeFieldsForFileFormatArguments when the payload arc
|
||||
/// was computed.
|
||||
PCP_API
|
||||
virtual bool CanFieldChangeAffectFileFormatArguments(
|
||||
const TfToken& field,
|
||||
const VtValue& oldValue,
|
||||
const VtValue& newValue,
|
||||
const VtValue &dependencyContextData) const = 0;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_DYNAMIC_FILE_FORMAT_INTERFACE_H
|
||||
@@ -0,0 +1,893 @@
|
||||
//
|
||||
// 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_PCP_ERRORS_H
|
||||
#define PXR_USD_PCP_ERRORS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/pcp/site.h"
|
||||
#include "pxr/usd/pcp/types.h"
|
||||
#include "pxr/usd/sdf/layer.h"
|
||||
#include "pxr/usd/sdf/layerOffset.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include "pxr/base/tf/enum.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
// Forward declaration:
|
||||
class PcpCache;
|
||||
|
||||
/// \enum PcpErrorType
|
||||
///
|
||||
/// Enum to indicate the type represented by a Pcp error.
|
||||
///
|
||||
enum PcpErrorType {
|
||||
PcpErrorType_ArcCycle,
|
||||
PcpErrorType_ArcPermissionDenied,
|
||||
PcpErrorType_IndexCapacityExceeded,
|
||||
PcpErrorType_ArcCapacityExceeded,
|
||||
PcpErrorType_ArcNamespaceDepthCapacityExceeded,
|
||||
PcpErrorType_InconsistentPropertyType,
|
||||
PcpErrorType_InconsistentAttributeType,
|
||||
PcpErrorType_InconsistentAttributeVariability,
|
||||
PcpErrorType_InternalAssetPath,
|
||||
PcpErrorType_InvalidPrimPath,
|
||||
PcpErrorType_InvalidAssetPath,
|
||||
PcpErrorType_InvalidInstanceTargetPath,
|
||||
PcpErrorType_InvalidExternalTargetPath,
|
||||
PcpErrorType_InvalidTargetPath,
|
||||
PcpErrorType_InvalidReferenceOffset,
|
||||
PcpErrorType_InvalidSublayerOffset,
|
||||
PcpErrorType_InvalidSublayerOwnership,
|
||||
PcpErrorType_InvalidSublayerPath,
|
||||
PcpErrorType_InvalidVariantSelection,
|
||||
PcpErrorType_MutedAssetPath,
|
||||
PcpErrorType_OpinionAtRelocationSource,
|
||||
PcpErrorType_PrimPermissionDenied,
|
||||
PcpErrorType_PropertyPermissionDenied,
|
||||
PcpErrorType_SublayerCycle,
|
||||
PcpErrorType_TargetPermissionDenied,
|
||||
PcpErrorType_UnresolvedPrimPath
|
||||
};
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorBase;
|
||||
typedef std::shared_ptr<PcpErrorBase> PcpErrorBasePtr;
|
||||
typedef std::vector<PcpErrorBasePtr> PcpErrorVector;
|
||||
|
||||
/// \class PcpErrorBase
|
||||
///
|
||||
/// Base class for all error types.
|
||||
///
|
||||
class PcpErrorBase {
|
||||
public:
|
||||
/// Destructor.
|
||||
PCP_API virtual ~PcpErrorBase();
|
||||
/// Converts error to string message.
|
||||
virtual std::string ToString() const = 0;
|
||||
|
||||
/// The error code.
|
||||
const TfEnum errorType;
|
||||
|
||||
/// The site of the composed prim or property being computed when
|
||||
/// the error was encountered. (Note that some error types
|
||||
/// contain an additional site to capture more specific information
|
||||
/// about the site of the error.)
|
||||
PcpSiteStr rootSite;
|
||||
|
||||
/// Return true if this type of error should be reported at most
|
||||
/// once for a given prim.
|
||||
bool ShouldReportAtMostOnce() const {
|
||||
// Capacity errors are reported at most once. (If these limits are
|
||||
// reached, there is likely to be a very large number of whatever
|
||||
// caused it.)
|
||||
return errorType == PcpErrorType_IndexCapacityExceeded ||
|
||||
errorType == PcpErrorType_ArcCapacityExceeded ||
|
||||
errorType == PcpErrorType_ArcNamespaceDepthCapacityExceeded;
|
||||
}
|
||||
|
||||
protected:
|
||||
/// Constructor.
|
||||
PcpErrorBase(TfEnum errorType);
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorArcCycle;
|
||||
typedef std::shared_ptr<PcpErrorArcCycle> PcpErrorArcCyclePtr;
|
||||
|
||||
/// \class PcpErrorArcCycle
|
||||
///
|
||||
/// Arcs between PcpNodes that form a cycle.
|
||||
///
|
||||
class PcpErrorArcCycle : public PcpErrorBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorArcCyclePtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorArcCycle();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
PcpSiteTracker cycle;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorArcCycle();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorArcPermissionDenied;
|
||||
typedef std::shared_ptr<PcpErrorArcPermissionDenied>
|
||||
PcpErrorArcPermissionDeniedPtr;
|
||||
|
||||
/// \class PcpErrorArcPermissionDenied
|
||||
///
|
||||
/// Arcs that were not made between PcpNodes because of permission
|
||||
/// restrictions.
|
||||
///
|
||||
class PcpErrorArcPermissionDenied : public PcpErrorBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorArcPermissionDeniedPtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorArcPermissionDenied();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
/// The site where the invalid arc was expressed.
|
||||
PcpSite site;
|
||||
/// The private, invalid target of the arc.
|
||||
PcpSite privateSite;
|
||||
/// The type of arc.
|
||||
PcpArcType arcType;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorArcPermissionDenied();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorCapacityExceeded;
|
||||
typedef std::shared_ptr<PcpErrorCapacityExceeded> PcpErrorCapacityExceededPtr;
|
||||
|
||||
/// \class PcpErrorCapacityExceeded
|
||||
///
|
||||
/// Exceeded the capacity for composition arcs at a single site.
|
||||
///
|
||||
class PcpErrorCapacityExceeded : public PcpErrorBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorCapacityExceededPtr New(PcpErrorType errorType);
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorCapacityExceeded();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorCapacityExceeded(PcpErrorType errorType);
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class PcpErrorInconsistentPropertyBase : public PcpErrorBase {
|
||||
public:
|
||||
/// Destructor.
|
||||
PCP_API virtual ~PcpErrorInconsistentPropertyBase();
|
||||
|
||||
/// The identifier of the layer with the defining property spec.
|
||||
std::string definingLayerIdentifier;
|
||||
/// The path of the defining property spec.
|
||||
SdfPath definingSpecPath;
|
||||
|
||||
/// The identifier of the layer with the conflicting property spec.
|
||||
std::string conflictingLayerIdentifier;
|
||||
/// The path of the conflicting property spec.
|
||||
SdfPath conflictingSpecPath;
|
||||
|
||||
protected:
|
||||
/// Constructor.
|
||||
PcpErrorInconsistentPropertyBase(TfEnum errorType);
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorInconsistentPropertyType;
|
||||
typedef std::shared_ptr<PcpErrorInconsistentPropertyType>
|
||||
PcpErrorInconsistentPropertyTypePtr;
|
||||
|
||||
/// \class PcpErrorInconsistentPropertyType
|
||||
///
|
||||
/// Properties that have specs with conflicting definitions.
|
||||
///
|
||||
class PcpErrorInconsistentPropertyType :
|
||||
public PcpErrorInconsistentPropertyBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorInconsistentPropertyTypePtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorInconsistentPropertyType();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
/// The type of the defining spec.
|
||||
SdfSpecType definingSpecType;
|
||||
/// The type of the conflicting spec.
|
||||
SdfSpecType conflictingSpecType;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorInconsistentPropertyType();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorInconsistentAttributeType;
|
||||
typedef std::shared_ptr<PcpErrorInconsistentAttributeType>
|
||||
PcpErrorInconsistentAttributeTypePtr;
|
||||
|
||||
/// \class PcpErrorInconsistentAttributeType
|
||||
///
|
||||
/// Attributes that have specs with conflicting definitions.
|
||||
///
|
||||
class PcpErrorInconsistentAttributeType :
|
||||
public PcpErrorInconsistentPropertyBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorInconsistentAttributeTypePtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorInconsistentAttributeType();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
/// The value type from the defining spec.
|
||||
TfToken definingValueType;
|
||||
/// The value type from the conflicting spec.
|
||||
TfToken conflictingValueType;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorInconsistentAttributeType();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorInconsistentAttributeVariability;
|
||||
typedef std::shared_ptr<PcpErrorInconsistentAttributeVariability>
|
||||
PcpErrorInconsistentAttributeVariabilityPtr;
|
||||
|
||||
/// \class PcpErrorInconsistentAttributeVariability
|
||||
///
|
||||
/// Attributes that have specs with conflicting variability.
|
||||
///
|
||||
class PcpErrorInconsistentAttributeVariability :
|
||||
public PcpErrorInconsistentPropertyBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorInconsistentAttributeVariabilityPtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorInconsistentAttributeVariability();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
/// The variability of the defining spec.
|
||||
SdfVariability definingVariability;
|
||||
/// The variability of the conflicting spec.
|
||||
SdfVariability conflictingVariability;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorInconsistentAttributeVariability();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorInternalAssetPath;
|
||||
typedef std::shared_ptr<PcpErrorInternalAssetPath>
|
||||
PcpErrorInternalAssetPathPtr;
|
||||
|
||||
/// \class PcpErrorInternalAssetPath
|
||||
///
|
||||
/// Error about an arc that is prohibited due to being internal to an asset.
|
||||
///
|
||||
class PcpErrorInternalAssetPath : public PcpErrorBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorInternalAssetPathPtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorInternalAssetPath();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
/// The site where the invalid arc was expressed.
|
||||
PcpSite site;
|
||||
SdfPath targetPath;
|
||||
std::string assetPath;
|
||||
std::string resolvedAssetPath;
|
||||
PcpArcType arcType;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorInternalAssetPath();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorInvalidPrimPath;
|
||||
typedef std::shared_ptr<PcpErrorInvalidPrimPath>
|
||||
PcpErrorInvalidPrimPathPtr;
|
||||
|
||||
/// \class PcpErrorInvalidPrimPath
|
||||
///
|
||||
/// Invalid prim paths used by references or payloads.
|
||||
///
|
||||
class PcpErrorInvalidPrimPath : public PcpErrorBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorInvalidPrimPathPtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorInvalidPrimPath();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
/// The site where the invalid arc was expressed.
|
||||
PcpSite site;
|
||||
SdfPath primPath;
|
||||
PcpArcType arcType;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorInvalidPrimPath();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorInvalidAssetPathBase;
|
||||
typedef std::shared_ptr<PcpErrorInvalidAssetPathBase>
|
||||
PcpErrorInvalidAssetPathBasePtr;
|
||||
|
||||
class PcpErrorInvalidAssetPathBase : public PcpErrorBase {
|
||||
public:
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorInvalidAssetPathBase();
|
||||
|
||||
/// The site where the invalid arc was expressed.
|
||||
PcpSite site;
|
||||
SdfPath targetPath;
|
||||
std::string assetPath;
|
||||
std::string resolvedAssetPath;
|
||||
PcpArcType arcType;
|
||||
SdfLayerHandle layer;
|
||||
std::string messages;
|
||||
|
||||
protected:
|
||||
/// Constructor.
|
||||
PcpErrorInvalidAssetPathBase(TfEnum errorType);
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorInvalidAssetPath;
|
||||
typedef std::shared_ptr<PcpErrorInvalidAssetPath>
|
||||
PcpErrorInvalidAssetPathPtr;
|
||||
|
||||
/// \class PcpErrorInvalidAssetPath
|
||||
///
|
||||
/// Invalid asset paths used by references or payloads.
|
||||
///
|
||||
class PcpErrorInvalidAssetPath : public PcpErrorInvalidAssetPathBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorInvalidAssetPathPtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorInvalidAssetPath();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorInvalidAssetPath();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorMutedAssetPath;
|
||||
typedef std::shared_ptr<PcpErrorMutedAssetPath>
|
||||
PcpErrorMutedAssetPathPtr;
|
||||
|
||||
/// \class PcpErrorMutedAssetPath
|
||||
///
|
||||
/// Muted asset paths used by references or payloads.
|
||||
///
|
||||
class PcpErrorMutedAssetPath : public PcpErrorInvalidAssetPathBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorMutedAssetPathPtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorMutedAssetPath();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorMutedAssetPath();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorTargetPathBase;
|
||||
typedef std::shared_ptr<PcpErrorTargetPathBase>
|
||||
PcpErrorTargetPathBasePtr;
|
||||
|
||||
/// \class PcpErrorTargetPathBase
|
||||
///
|
||||
/// Base class for composition errors related to target or connection paths.
|
||||
///
|
||||
class PcpErrorTargetPathBase : public PcpErrorBase {
|
||||
public:
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorTargetPathBase();
|
||||
|
||||
/// The invalid target or connection path that was authored.
|
||||
SdfPath targetPath;
|
||||
/// The path to the property where the target was authored.
|
||||
SdfPath owningPath;
|
||||
/// The spec type of the property where the target was authored.
|
||||
SdfSpecType ownerSpecType;
|
||||
/// The layer containing the property where the target was authored.
|
||||
SdfLayerHandle layer;
|
||||
|
||||
/// The target or connection path in the composed scene.
|
||||
/// If this path could not be translated to the composed scene
|
||||
/// (e.g., in the case of an invalid external target path),
|
||||
/// this path will be empty.
|
||||
SdfPath composedTargetPath;
|
||||
|
||||
protected:
|
||||
PcpErrorTargetPathBase(TfEnum errorType);
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorInvalidInstanceTargetPath;
|
||||
typedef std::shared_ptr<PcpErrorInvalidInstanceTargetPath>
|
||||
PcpErrorInvalidInstanceTargetPathPtr;
|
||||
|
||||
/// \class PcpErrorInvalidInstanceTargetPath
|
||||
///
|
||||
/// Invalid target or connection path authored in an inherited
|
||||
/// class that points to an instance of that class.
|
||||
///
|
||||
class PcpErrorInvalidInstanceTargetPath : public PcpErrorTargetPathBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorInvalidInstanceTargetPathPtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorInvalidInstanceTargetPath();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorInvalidInstanceTargetPath();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorInvalidExternalTargetPath;
|
||||
typedef std::shared_ptr<PcpErrorInvalidExternalTargetPath>
|
||||
PcpErrorInvalidExternalTargetPathPtr;
|
||||
|
||||
/// \class PcpErrorInvalidExternalTargetPath
|
||||
///
|
||||
/// Invalid target or connection path in some scope that points to
|
||||
/// an object outside of that scope.
|
||||
///
|
||||
class PcpErrorInvalidExternalTargetPath : public PcpErrorTargetPathBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorInvalidExternalTargetPathPtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorInvalidExternalTargetPath();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
PcpArcType ownerArcType;
|
||||
SdfPath ownerIntroPath;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorInvalidExternalTargetPath();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorInvalidTargetPath;
|
||||
typedef std::shared_ptr<PcpErrorInvalidTargetPath>
|
||||
PcpErrorInvalidTargetPathPtr;
|
||||
|
||||
/// \class PcpErrorInvalidTargetPath
|
||||
///
|
||||
/// Invalid target or connection path.
|
||||
///
|
||||
class PcpErrorInvalidTargetPath : public PcpErrorTargetPathBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorInvalidTargetPathPtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorInvalidTargetPath();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorInvalidTargetPath();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorInvalidSublayerOffset;
|
||||
typedef std::shared_ptr<PcpErrorInvalidSublayerOffset>
|
||||
PcpErrorInvalidSublayerOffsetPtr;
|
||||
|
||||
/// \class PcpErrorInvalidSublayerOffset
|
||||
///
|
||||
/// Sublayers that use invalid layer offsets.
|
||||
///
|
||||
class PcpErrorInvalidSublayerOffset : public PcpErrorBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorInvalidSublayerOffsetPtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorInvalidSublayerOffset();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
SdfLayerHandle layer;
|
||||
SdfLayerHandle sublayer;
|
||||
SdfLayerOffset offset;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorInvalidSublayerOffset();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorInvalidReferenceOffset;
|
||||
typedef std::shared_ptr<PcpErrorInvalidReferenceOffset>
|
||||
PcpErrorInvalidReferenceOffsetPtr;
|
||||
|
||||
/// \class PcpErrorInvalidReferenceOffset
|
||||
///
|
||||
/// Sublayers that use invalid layer offsets.
|
||||
///
|
||||
class PcpErrorInvalidReferenceOffset : public PcpErrorBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorInvalidReferenceOffsetPtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorInvalidReferenceOffset();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
SdfLayerHandle layer;
|
||||
SdfPath sourcePath;
|
||||
std::string assetPath;
|
||||
SdfPath targetPath;
|
||||
SdfLayerOffset offset;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorInvalidReferenceOffset();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorInvalidSublayerOwnership;
|
||||
typedef std::shared_ptr<PcpErrorInvalidSublayerOwnership>
|
||||
PcpErrorInvalidSublayerOwnershipPtr;
|
||||
|
||||
/// \class PcpErrorInvalidSublayerOwnership
|
||||
///
|
||||
/// Sibling layers that have the same owner.
|
||||
///
|
||||
class PcpErrorInvalidSublayerOwnership : public PcpErrorBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorInvalidSublayerOwnershipPtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorInvalidSublayerOwnership();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
std::string owner;
|
||||
SdfLayerHandle layer;
|
||||
SdfLayerHandleVector sublayers;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorInvalidSublayerOwnership();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorInvalidSublayerPath;
|
||||
typedef std::shared_ptr<PcpErrorInvalidSublayerPath>
|
||||
PcpErrorInvalidSublayerPathPtr;
|
||||
|
||||
/// \class PcpErrorInvalidSublayerPath
|
||||
///
|
||||
/// Asset paths that could not be both resolved and loaded.
|
||||
///
|
||||
class PcpErrorInvalidSublayerPath : public PcpErrorBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorInvalidSublayerPathPtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorInvalidSublayerPath();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
SdfLayerHandle layer;
|
||||
std::string sublayerPath;
|
||||
std::string messages;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorInvalidSublayerPath();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorInvalidVariantSelection;
|
||||
typedef std::shared_ptr<PcpErrorInvalidVariantSelection>
|
||||
PcpErrorInvalidVariantSelectionPtr;
|
||||
|
||||
/// \class PcpErrorInvalidVariantSelection
|
||||
///
|
||||
/// Invalid variant selections.
|
||||
///
|
||||
class PcpErrorInvalidVariantSelection : public PcpErrorBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorInvalidVariantSelectionPtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorInvalidVariantSelection();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
std::string siteAssetPath;
|
||||
SdfPath sitePath;
|
||||
std::string vset, vsel;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorInvalidVariantSelection();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorOpinionAtRelocationSource;
|
||||
typedef std::shared_ptr<PcpErrorOpinionAtRelocationSource>
|
||||
PcpErrorOpinionAtRelocationSourcePtr;
|
||||
|
||||
/// \class PcpErrorOpinionAtRelocationSource
|
||||
///
|
||||
/// Opinions were found at a relocation source path.
|
||||
///
|
||||
class PcpErrorOpinionAtRelocationSource : public PcpErrorBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorOpinionAtRelocationSourcePtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorOpinionAtRelocationSource();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
SdfLayerHandle layer;
|
||||
SdfPath path;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorOpinionAtRelocationSource();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorPrimPermissionDenied;
|
||||
typedef std::shared_ptr<PcpErrorPrimPermissionDenied>
|
||||
PcpErrorPrimPermissionDeniedPtr;
|
||||
|
||||
/// \class PcpErrorPrimPermissionDenied
|
||||
///
|
||||
/// Layers with illegal opinions about private prims.
|
||||
///
|
||||
class PcpErrorPrimPermissionDenied : public PcpErrorBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorPrimPermissionDeniedPtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorPrimPermissionDenied();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
/// The site where the invalid arc was expressed.
|
||||
PcpSiteStr site;
|
||||
/// The private, invalid target of the arc.
|
||||
PcpSiteStr privateSite;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorPrimPermissionDenied();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorPropertyPermissionDenied;
|
||||
typedef std::shared_ptr<PcpErrorPropertyPermissionDenied>
|
||||
PcpErrorPropertyPermissionDeniedPtr;
|
||||
|
||||
/// \class PcpErrorPropertyPermissionDenied
|
||||
///
|
||||
/// Layers with illegal opinions about private properties.
|
||||
///
|
||||
class PcpErrorPropertyPermissionDenied : public PcpErrorBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorPropertyPermissionDeniedPtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorPropertyPermissionDenied();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
SdfPath propPath;
|
||||
SdfSpecType propType;
|
||||
std::string layerPath;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorPropertyPermissionDenied();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorSublayerCycle;
|
||||
typedef std::shared_ptr<PcpErrorSublayerCycle> PcpErrorSublayerCyclePtr;
|
||||
|
||||
/// \class PcpErrorSublayerCycle
|
||||
///
|
||||
/// Layers that recursively sublayer themselves.
|
||||
///
|
||||
class PcpErrorSublayerCycle : public PcpErrorBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorSublayerCyclePtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorSublayerCycle();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
SdfLayerHandle layer;
|
||||
SdfLayerHandle sublayer;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorSublayerCycle();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorTargetPermissionDenied;
|
||||
typedef std::shared_ptr<PcpErrorTargetPermissionDenied>
|
||||
PcpErrorTargetPermissionDeniedPtr;
|
||||
|
||||
/// \class PcpErrorTargetPermissionDenied
|
||||
///
|
||||
/// Paths with illegal opinions about private targets.
|
||||
///
|
||||
class PcpErrorTargetPermissionDenied : public PcpErrorTargetPathBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorTargetPermissionDeniedPtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorTargetPermissionDenied();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorTargetPermissionDenied();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Forward declarations:
|
||||
class PcpErrorUnresolvedPrimPath;
|
||||
typedef std::shared_ptr<PcpErrorUnresolvedPrimPath>
|
||||
PcpErrorUnresolvedPrimPathPtr;
|
||||
|
||||
/// \class PcpErrorUnresolvedPrimPath
|
||||
///
|
||||
/// Asset paths that could not be both resolved and loaded.
|
||||
///
|
||||
class PcpErrorUnresolvedPrimPath : public PcpErrorBase {
|
||||
public:
|
||||
/// Returns a new error object.
|
||||
static PcpErrorUnresolvedPrimPathPtr New();
|
||||
/// Destructor.
|
||||
PCP_API ~PcpErrorUnresolvedPrimPath();
|
||||
/// Converts error to string message.
|
||||
PCP_API virtual std::string ToString() const;
|
||||
|
||||
/// The site where the invalid arc was expressed.
|
||||
PcpSiteStr site;
|
||||
SdfPath unresolvedPath;
|
||||
PcpArcType arcType;
|
||||
|
||||
private:
|
||||
/// Constructor is private. Use New() instead.
|
||||
PcpErrorUnresolvedPrimPath();
|
||||
};
|
||||
|
||||
/// Raise the given errors as runtime errors.
|
||||
PCP_API
|
||||
void PcpRaiseErrors(const PcpErrorVector &errors);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_ERRORS_H
|
||||
@@ -0,0 +1,133 @@
|
||||
//
|
||||
// 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_PCP_INSTANCE_KEY_H
|
||||
#define PXR_USD_PCP_INSTANCE_KEY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/pcp/mapExpression.h"
|
||||
#include "pxr/usd/pcp/node.h"
|
||||
#include "pxr/usd/pcp/site.h"
|
||||
#include "pxr/usd/pcp/types.h"
|
||||
|
||||
#include "pxr/usd/sdf/layerOffset.h"
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class PcpPrimIndex;
|
||||
|
||||
/// \class PcpInstanceKey
|
||||
///
|
||||
/// A PcpInstanceKey identifies instanceable prim indexes that share the
|
||||
/// same set of opinions. Instanceable prim indexes with equal instance
|
||||
/// keys are guaranteed to have the same opinions for name children and
|
||||
/// properties beneath those name children. They are NOT guaranteed to have
|
||||
/// the same opinions for direct properties of the prim indexes themselves.
|
||||
///
|
||||
class PcpInstanceKey
|
||||
{
|
||||
public:
|
||||
PCP_API
|
||||
PcpInstanceKey();
|
||||
|
||||
/// Create an instance key for the given prim index.
|
||||
PCP_API
|
||||
explicit PcpInstanceKey(const PcpPrimIndex& primIndex);
|
||||
|
||||
/// Comparison operators
|
||||
PCP_API
|
||||
bool operator==(const PcpInstanceKey& rhs) const;
|
||||
PCP_API
|
||||
bool operator!=(const PcpInstanceKey& rhs) const;
|
||||
|
||||
/// Returns hash value for this instance key.
|
||||
friend size_t hash_value(const PcpInstanceKey& key)
|
||||
{
|
||||
return key._hash;
|
||||
}
|
||||
|
||||
/// \struct Hash
|
||||
///
|
||||
/// Hash functor.
|
||||
///
|
||||
struct Hash {
|
||||
inline size_t operator()(const PcpInstanceKey& key) const
|
||||
{
|
||||
return key._hash;
|
||||
}
|
||||
};
|
||||
|
||||
/// Returns string representation of this instance key
|
||||
/// for debugging purposes.
|
||||
PCP_API
|
||||
std::string GetString() const;
|
||||
|
||||
private:
|
||||
struct _Collector;
|
||||
|
||||
struct _Arc
|
||||
{
|
||||
explicit _Arc(const PcpNodeRef& node)
|
||||
: _arcType(node.GetArcType())
|
||||
, _sourceSite(node.GetSite())
|
||||
, _timeOffset(node.GetMapToRoot().GetTimeOffset())
|
||||
{
|
||||
}
|
||||
|
||||
bool operator==(const _Arc& rhs) const
|
||||
{
|
||||
return _arcType == rhs._arcType &&
|
||||
_sourceSite == rhs._sourceSite &&
|
||||
_timeOffset == rhs._timeOffset;
|
||||
}
|
||||
|
||||
size_t GetHash() const
|
||||
{
|
||||
size_t hash = _arcType;
|
||||
boost::hash_combine(hash, _sourceSite);
|
||||
boost::hash_combine(hash, _timeOffset.GetHash());
|
||||
return hash;
|
||||
}
|
||||
|
||||
PcpArcType _arcType;
|
||||
PcpSite _sourceSite;
|
||||
SdfLayerOffset _timeOffset;
|
||||
};
|
||||
std::vector<_Arc> _arcs;
|
||||
|
||||
typedef std::pair<std::string, std::string> _VariantSelection;
|
||||
std::vector<_VariantSelection> _variantSelection;
|
||||
|
||||
size_t _hash;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_INSTANCE_KEY_H
|
||||
@@ -0,0 +1,347 @@
|
||||
//
|
||||
// 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_PCP_ITERATOR_H
|
||||
#define PXR_USD_PCP_ITERATOR_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/pcp/node.h"
|
||||
|
||||
#include "pxr/usd/sdf/primSpec.h"
|
||||
#include "pxr/usd/sdf/propertySpec.h"
|
||||
#include "pxr/usd/sdf/site.h"
|
||||
|
||||
#include "pxr/base/tf/iterator.h"
|
||||
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
#include <boost/iterator/reverse_iterator.hpp>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class PcpPrimIndex;
|
||||
class PcpPrimIndex_Graph;
|
||||
class PcpPropertyIndex;
|
||||
|
||||
/// \class PcpNodeIterator
|
||||
///
|
||||
/// Object used to iterate over nodes in the prim index graph in strong-to-weak
|
||||
/// order.
|
||||
///
|
||||
class PcpNodeIterator
|
||||
: public boost::iterator_facade<
|
||||
/* Derived = */ PcpNodeIterator,
|
||||
/* ValueType = */ PcpNodeRef,
|
||||
/* Category = */ boost::random_access_traversal_tag,
|
||||
/* RefType = */ PcpNodeRef
|
||||
>
|
||||
{
|
||||
public:
|
||||
/// Constructs an invalid iterator.
|
||||
PcpNodeIterator() : _graph(0), _nodeIdx(PCP_INVALID_INDEX) {}
|
||||
|
||||
// Returns a compressed Sd site. For internal use only.
|
||||
Pcp_CompressedSdSite GetCompressedSdSite(size_t layerIndex) const
|
||||
{
|
||||
return Pcp_CompressedSdSite(_nodeIdx, layerIndex);
|
||||
}
|
||||
|
||||
private:
|
||||
friend class PcpPrimIndex;
|
||||
PcpNodeIterator(PcpPrimIndex_Graph* graph, size_t nodeIdx) :
|
||||
_graph(graph), _nodeIdx(nodeIdx) {}
|
||||
|
||||
friend class boost::iterator_core_access;
|
||||
|
||||
void increment() { ++_nodeIdx; }
|
||||
void decrement() { --_nodeIdx; }
|
||||
void advance(difference_type n) { _nodeIdx += n; }
|
||||
difference_type distance_to(const PcpNodeIterator& other) const {
|
||||
return (difference_type)(other._nodeIdx) - _nodeIdx;
|
||||
}
|
||||
bool equal(const PcpNodeIterator& other) const {
|
||||
return (_graph == other._graph) & (_nodeIdx == other._nodeIdx);
|
||||
}
|
||||
reference dereference() const {
|
||||
return PcpNodeRef(_graph, _nodeIdx);
|
||||
}
|
||||
|
||||
private:
|
||||
PcpPrimIndex_Graph* _graph;
|
||||
size_t _nodeIdx;
|
||||
};
|
||||
|
||||
/// \class PcpNodeReverseIterator
|
||||
///
|
||||
/// Object used to iterate over nodes in the prim index graph in weak-to-strong
|
||||
/// order.
|
||||
///
|
||||
class PcpNodeReverseIterator
|
||||
: public boost::reverse_iterator<PcpNodeIterator>
|
||||
{
|
||||
public:
|
||||
PcpNodeReverseIterator() { }
|
||||
explicit PcpNodeReverseIterator(const PcpNodeIterator& iter)
|
||||
: boost::reverse_iterator<PcpNodeIterator>(iter) { }
|
||||
};
|
||||
|
||||
/// \class PcpPrimIterator
|
||||
///
|
||||
/// Object used to iterate over prim specs in the prim index graph in
|
||||
/// strong-to-weak order.
|
||||
///
|
||||
class PcpPrimIterator
|
||||
: public boost::iterator_facade<
|
||||
/* Derived = */ PcpPrimIterator,
|
||||
/* Value = */ SdfSite,
|
||||
/* Category = */ boost::random_access_traversal_tag,
|
||||
/* Ref = */ SdfSite
|
||||
>
|
||||
{
|
||||
public:
|
||||
/// Constructs an invalid iterator.
|
||||
PCP_API
|
||||
PcpPrimIterator();
|
||||
|
||||
/// Constructs a prim iterator beginning at position \p pos in the
|
||||
/// prim stack of prim index \p primIndex.
|
||||
PCP_API
|
||||
PcpPrimIterator(const PcpPrimIndex* primIndex, size_t pos);
|
||||
|
||||
/// Returns the PcpNode from which the current prim originated.
|
||||
PCP_API
|
||||
PcpNodeRef GetNode() const;
|
||||
|
||||
// Returns the \c Pcp_SdSiteRef from which the current prim originated.
|
||||
// For internal use only.
|
||||
PCP_API
|
||||
Pcp_SdSiteRef _GetSiteRef() const;
|
||||
|
||||
private:
|
||||
friend class boost::iterator_core_access;
|
||||
PCP_API
|
||||
void increment();
|
||||
PCP_API
|
||||
void decrement();
|
||||
PCP_API
|
||||
void advance(difference_type n);
|
||||
PCP_API
|
||||
difference_type distance_to(const PcpPrimIterator& other) const;
|
||||
PCP_API
|
||||
bool equal(const PcpPrimIterator& other) const;
|
||||
PCP_API
|
||||
reference dereference() const;
|
||||
|
||||
private:
|
||||
const PcpPrimIndex* _primIndex;
|
||||
size_t _pos;
|
||||
};
|
||||
|
||||
/// \class PcpPrimReverseIterator
|
||||
///
|
||||
/// Object used to iterate over prim specs in the prim index graph in
|
||||
/// weak-to-strong order.
|
||||
///
|
||||
class PcpPrimReverseIterator
|
||||
: public boost::reverse_iterator<PcpPrimIterator>
|
||||
{
|
||||
public:
|
||||
PcpPrimReverseIterator() { }
|
||||
explicit PcpPrimReverseIterator(const PcpPrimIterator& iter)
|
||||
: boost::reverse_iterator<PcpPrimIterator>(iter) { }
|
||||
|
||||
PcpNodeRef GetNode() const
|
||||
{
|
||||
PcpPrimIterator tmp = base();
|
||||
return (--tmp).GetNode();
|
||||
}
|
||||
|
||||
Pcp_SdSiteRef _GetSiteRef() const
|
||||
{
|
||||
PcpPrimIterator tmp = base();
|
||||
return (--tmp)._GetSiteRef();
|
||||
}
|
||||
};
|
||||
|
||||
/// \class PcpPropertyIterator
|
||||
///
|
||||
/// Object used to iterate over property specs in a property index in
|
||||
/// strong-to-weak order.
|
||||
///
|
||||
class PcpPropertyIterator
|
||||
: public boost::iterator_facade<
|
||||
/* Derived = */ PcpPropertyIterator,
|
||||
/* Value = */ const SdfPropertySpecHandle,
|
||||
/* Category = */ boost::random_access_traversal_tag
|
||||
>
|
||||
{
|
||||
public:
|
||||
/// Constructs an invalid iterator.
|
||||
PCP_API
|
||||
PcpPropertyIterator();
|
||||
|
||||
/// Constructs a property iterator for \p index beginning at position
|
||||
/// \p pos in the property stack.
|
||||
PCP_API
|
||||
PcpPropertyIterator(const PcpPropertyIndex& index, size_t pos = 0);
|
||||
|
||||
/// Returns the PcpNode from which the current property originated.
|
||||
PCP_API
|
||||
PcpNodeRef GetNode() const;
|
||||
|
||||
/// Returns true if the current property is local to the owning
|
||||
/// property index's layer stack, false otherwise.
|
||||
PCP_API
|
||||
bool IsLocal() const;
|
||||
|
||||
private:
|
||||
friend class boost::iterator_core_access;
|
||||
PCP_API
|
||||
void increment();
|
||||
PCP_API
|
||||
void decrement();
|
||||
PCP_API
|
||||
void advance(difference_type n);
|
||||
PCP_API
|
||||
difference_type distance_to(const PcpPropertyIterator& other) const;
|
||||
PCP_API
|
||||
bool equal(const PcpPropertyIterator& other) const;
|
||||
PCP_API
|
||||
reference dereference() const;
|
||||
|
||||
private:
|
||||
const PcpPropertyIndex* _propertyIndex;
|
||||
size_t _pos;
|
||||
};
|
||||
|
||||
/// \class PcpPropertyReverseIterator
|
||||
///
|
||||
/// Object used to iterate over property specs in a property index in
|
||||
/// weak-to-strong order.
|
||||
///
|
||||
class PcpPropertyReverseIterator
|
||||
: public boost::reverse_iterator<PcpPropertyIterator>
|
||||
{
|
||||
public:
|
||||
PcpPropertyReverseIterator() { }
|
||||
explicit PcpPropertyReverseIterator(const PcpPropertyIterator& iter)
|
||||
: boost::reverse_iterator<PcpPropertyIterator>(iter) { }
|
||||
|
||||
PcpNodeRef GetNode() const
|
||||
{
|
||||
PcpPropertyIterator tmp = base();
|
||||
return (--tmp).GetNode();
|
||||
}
|
||||
|
||||
bool IsLocal() const
|
||||
{
|
||||
PcpPropertyIterator tmp = base();
|
||||
return (--tmp).IsLocal();
|
||||
}
|
||||
};
|
||||
|
||||
// Helper macro for defining iterator ranges, which are simply pairs of
|
||||
// iterators denoting the [start, end) of a series of values. These ranges
|
||||
// may be used with TF_FOR_ALL and TF_REVERSE_FOR_ALL.
|
||||
#define PCP_DEFINE_RANGE(Range, Iterator, ReverseIterator) \
|
||||
typedef std::pair<Iterator, Iterator> Range; \
|
||||
\
|
||||
inline Iterator begin(Range &range) { return range.first; } \
|
||||
inline Iterator begin(const Range &range) { return range.first; } \
|
||||
inline Iterator end(Range &range) { return range.second; } \
|
||||
inline Iterator end(const Range &range) { return range.second; } \
|
||||
\
|
||||
template <> \
|
||||
struct Tf_IteratorInterface<Range, false> { \
|
||||
typedef Iterator IteratorType; \
|
||||
static IteratorType Begin(Range &c) { return c.first; } \
|
||||
static IteratorType End(Range &c) { return c.second; } \
|
||||
}; \
|
||||
\
|
||||
template <> \
|
||||
struct Tf_IteratorInterface<const Range, false> { \
|
||||
typedef Iterator IteratorType; \
|
||||
static IteratorType Begin(Range const &c) { return c.first; } \
|
||||
static IteratorType End(Range const &c) { return c.second; } \
|
||||
}; \
|
||||
\
|
||||
template <> \
|
||||
struct Tf_IteratorInterface<Range, true> { \
|
||||
typedef ReverseIterator IteratorType; \
|
||||
static IteratorType Begin(Range &c) \
|
||||
{ return IteratorType(c.second); } \
|
||||
static IteratorType End(Range &c) \
|
||||
{ return IteratorType(c.first); } \
|
||||
}; \
|
||||
\
|
||||
template <> \
|
||||
struct Tf_IteratorInterface<const Range, true> { \
|
||||
typedef ReverseIterator IteratorType; \
|
||||
static IteratorType Begin(Range const &c) \
|
||||
{ return IteratorType(c.second); } \
|
||||
static IteratorType End(Range const &c) \
|
||||
{ return IteratorType(c.first); } \
|
||||
}; \
|
||||
\
|
||||
template <> \
|
||||
struct Tf_ShouldIterateOverCopy<Range> : boost::true_type {}; \
|
||||
\
|
||||
template <> \
|
||||
struct Tf_ShouldIterateOverCopy<const Range> : boost::true_type {}
|
||||
|
||||
PCP_DEFINE_RANGE(PcpNodeRange, PcpNodeIterator, PcpNodeReverseIterator);
|
||||
PCP_DEFINE_RANGE(PcpPrimRange, PcpPrimIterator, PcpPrimReverseIterator);
|
||||
PCP_DEFINE_RANGE(PcpPropertyRange, PcpPropertyIterator,
|
||||
PcpPropertyReverseIterator);
|
||||
|
||||
/// \class PcpIteratorTraits
|
||||
///
|
||||
/// Traits class for retrieving useful characteristics about one of the
|
||||
/// Pcp iterator types above.
|
||||
///
|
||||
template <class Iterator> struct PcpIteratorTraits;
|
||||
|
||||
template <>
|
||||
struct PcpIteratorTraits<PcpNodeIterator>
|
||||
{
|
||||
typedef PcpNodeRange RangeType;
|
||||
typedef PcpNodeReverseIterator ReverseIteratorType;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct PcpIteratorTraits<PcpPrimIterator>
|
||||
{
|
||||
typedef PcpPrimRange RangeType;
|
||||
typedef PcpPrimReverseIterator ReverseIteratorType;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct PcpIteratorTraits<PcpPropertyIterator>
|
||||
{
|
||||
typedef PcpPropertyRange RangeType;
|
||||
typedef PcpPropertyReverseIterator ReverseIteratorType;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_ITERATOR_H
|
||||
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// 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_PCP_LAYER_PREFETCH_REQUEST_H
|
||||
#define PXR_USD_PCP_LAYER_PREFETCH_REQUEST_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/sdf/layer.h"
|
||||
|
||||
#include <set>
|
||||
#include <utility>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class Pcp_MutedLayers;
|
||||
|
||||
/// \class PcpLayerPrefetchRequest
|
||||
///
|
||||
/// PcpLayerPrefetchRequest represents a request to pre-fetch and retain
|
||||
/// a set of layers in memory. It performs the fetch as a parallel
|
||||
/// operation using a thread pool. Fetched layers are retained by the
|
||||
/// request to keep them alive until the client can decide what to do
|
||||
/// with them.
|
||||
///
|
||||
class PcpLayerPrefetchRequest
|
||||
{
|
||||
public:
|
||||
/// Enqueue a request to pre-fetch of the sublayers of \a layer.
|
||||
/// This recursively includes any nested sublayers. Arguments in \a args
|
||||
/// will be passed to Sdf when finding or opening sublayers.
|
||||
PCP_API
|
||||
void RequestSublayerStack(
|
||||
const SdfLayerRefPtr &layer,
|
||||
const SdfLayer::FileFormatArguments &args);
|
||||
|
||||
/// Run the queued requests, returning when complete.
|
||||
PCP_API
|
||||
void Run(const Pcp_MutedLayers& mutedLayers);
|
||||
|
||||
private:
|
||||
// The request object retains both the layer requests and
|
||||
// the pre-fetched sublayers.
|
||||
typedef std::pair<SdfLayerRefPtr, SdfLayer::FileFormatArguments> _Request;
|
||||
std::set<_Request> _sublayerRequests;
|
||||
|
||||
std::set<SdfLayerRefPtr> _retainedLayers;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_LAYER_PREFETCH_REQUEST_H
|
||||
@@ -0,0 +1,353 @@
|
||||
//
|
||||
// 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_PCP_LAYER_STACK_H
|
||||
#define PXR_USD_PCP_LAYER_STACK_H
|
||||
|
||||
/// \file pcp/layerStack.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/pcp/errors.h"
|
||||
#include "pxr/usd/pcp/layerStackIdentifier.h"
|
||||
#include "pxr/usd/pcp/mapExpression.h"
|
||||
#include "pxr/usd/sdf/layerTree.h"
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
|
||||
#include <tbb/spin_mutex.h>
|
||||
#include <iosfwd>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
TF_DECLARE_REF_PTRS(SdfLayer);
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(PcpLayerStack);
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(Pcp_LayerStackRegistry);
|
||||
|
||||
class ArResolverContext;
|
||||
class Pcp_LayerStackRegistry;
|
||||
class Pcp_MutedLayers;
|
||||
class PcpLayerStackChanges;
|
||||
class PcpLifeboat;
|
||||
|
||||
/// \class PcpLayerStack
|
||||
///
|
||||
/// Represents a stack of layers that contribute opinions to composition.
|
||||
///
|
||||
/// Each PcpLayerStack is identified by a PcpLayerStackIdentifier. This
|
||||
/// identifier contains all of the parameters needed to construct a layer stack,
|
||||
/// such as the root layer, session layer, and path resolver context.
|
||||
///
|
||||
/// PcpLayerStacks are constructed and managed by a Pcp_LayerStackRegistry.
|
||||
///
|
||||
class PcpLayerStack : public TfRefBase, public TfWeakBase {
|
||||
PcpLayerStack(const PcpLayerStack&) = delete;
|
||||
PcpLayerStack& operator=(const PcpLayerStack&) = delete;
|
||||
|
||||
public:
|
||||
// See Pcp_LayerStackRegistry for creating layer stacks.
|
||||
PCP_API
|
||||
virtual ~PcpLayerStack();
|
||||
|
||||
/// Returns the identifier for this layer stack.
|
||||
PCP_API
|
||||
const PcpLayerStackIdentifier& GetIdentifier() const;
|
||||
|
||||
/// Returns the layers in this layer stack in strong-to-weak order.
|
||||
/// Note that this is only the *local* layer stack -- it does not
|
||||
/// include any layers brought in by references inside prims.
|
||||
PCP_API
|
||||
const SdfLayerRefPtrVector& GetLayers() const;
|
||||
|
||||
/// Returns only the session layers in the layer stack in strong-to-weak
|
||||
/// order.
|
||||
PCP_API
|
||||
SdfLayerHandleVector GetSessionLayers() const;
|
||||
|
||||
/// Returns the layer tree representing the structure of this layer
|
||||
/// stack.
|
||||
PCP_API
|
||||
const SdfLayerTreeHandle& GetLayerTree() const;
|
||||
|
||||
/// Returns the layer offset for the given layer, or NULL if the layer
|
||||
/// can't be found or is the identity.
|
||||
PCP_API
|
||||
const SdfLayerOffset* GetLayerOffsetForLayer(const SdfLayerHandle&) const;
|
||||
|
||||
/// Return the layer offset for the given layer, or NULL if the layer
|
||||
/// can't be found or is the identity.
|
||||
PCP_API
|
||||
const SdfLayerOffset* GetLayerOffsetForLayer(const SdfLayerRefPtr&) const;
|
||||
|
||||
/// Returns the layer offset for the layer at the given index in this
|
||||
/// layer stack. Returns NULL if the offset is the identity.
|
||||
PCP_API
|
||||
const SdfLayerOffset* GetLayerOffsetForLayer(size_t layerIdx) const;
|
||||
|
||||
/// Returns the set of layers that were muted in this layer
|
||||
/// stack.
|
||||
PCP_API
|
||||
const std::set<std::string>& GetMutedLayers() const;
|
||||
|
||||
/// Return the list of errors local to this layer stack.
|
||||
PcpErrorVector GetLocalErrors() const {
|
||||
return _localErrors ? *_localErrors.get() : PcpErrorVector();
|
||||
}
|
||||
|
||||
/// Returns true if this layer stack contains the given layer, false
|
||||
/// otherwise.
|
||||
PCP_API
|
||||
bool HasLayer(const SdfLayerHandle& layer) const;
|
||||
PCP_API
|
||||
bool HasLayer(const SdfLayerRefPtr& layer) const;
|
||||
|
||||
/// Return the time codes per second value of the layer stack. This is
|
||||
/// usually the same as the computed time codes per second of the root layer
|
||||
/// but may be computed from the session layer when its present.
|
||||
double GetTimeCodesPerSecond() const { return _timeCodesPerSecond; }
|
||||
|
||||
/// Returns relocation source-to-target mapping for this layer stack.
|
||||
///
|
||||
/// This map combines the individual relocation entries found across
|
||||
/// all layers in this layer stack; multiple entries that affect a single
|
||||
/// prim will be combined into a single entry. For instance, if this
|
||||
/// layer stack contains relocations { /A: /B } and { /A/C: /A/D }, this
|
||||
/// map will contain { /A: /B } and { /B/C: /B/D }. This allows consumers
|
||||
/// to go from unrelocated namespace to relocated namespace in a single
|
||||
/// step.
|
||||
PCP_API
|
||||
const SdfRelocatesMap& GetRelocatesSourceToTarget() const;
|
||||
|
||||
/// Returns relocation target-to-source mapping for this layer stack.
|
||||
///
|
||||
/// See GetRelocatesSourceToTarget for more details.
|
||||
PCP_API
|
||||
const SdfRelocatesMap& GetRelocatesTargetToSource() const;
|
||||
|
||||
/// Returns incremental relocation source-to-target mapping for this layer
|
||||
/// stack.
|
||||
///
|
||||
/// This map contains the individual relocation entries found across
|
||||
/// all layers in this layer stack; it does not combine ancestral
|
||||
/// entries with descendant entries. For instance, if this
|
||||
/// layer stack contains relocations { /A: /B } and { /A/C: /A/D }, this
|
||||
/// map will contain { /A: /B } and { /A/C: /A/D }.
|
||||
PCP_API
|
||||
const SdfRelocatesMap& GetIncrementalRelocatesSourceToTarget() const;
|
||||
|
||||
/// Returns incremental relocation target-to-source mapping for this layer
|
||||
/// stack.
|
||||
///
|
||||
/// See GetIncrementalRelocatesTargetToSource for more details.
|
||||
PCP_API
|
||||
const SdfRelocatesMap& GetIncrementalRelocatesTargetToSource() const;
|
||||
|
||||
/// Returns a list of paths to all prims across all layers in this
|
||||
/// layer stack that contained relocates.
|
||||
PCP_API
|
||||
const SdfPathVector& GetPathsToPrimsWithRelocates() const;
|
||||
|
||||
/// Apply the changes in \p changes. This blows caches. It's up to
|
||||
/// the client to pull on those caches again as needed.
|
||||
///
|
||||
/// Objects that are no longer needed and would be destroyed are
|
||||
/// retained in \p lifeboat and won't be destroyed until \p lifeboat is
|
||||
/// itself destroyed. This gives the client control over the timing
|
||||
/// of the destruction of those objects. Clients may choose to pull
|
||||
/// on the caches before destroying \p lifeboat. That may cause the
|
||||
/// caches to again retain the objects, meaning they won't be destroyed
|
||||
/// when \p lifeboat is destroyed.
|
||||
///
|
||||
/// For example, if blowing a cache means an SdfLayer is no longer
|
||||
/// needed then \p lifeboat will hold an SdfLayerRefPtr to that layer.
|
||||
/// The client can then pull on that cache, which could cause the
|
||||
/// cache to hold an SdfLayerRefPtr to the layer again. If so then
|
||||
/// destroying \p changes will not destroy the layer. In any case,
|
||||
/// we don't destroy the layer and then read it again. However, if
|
||||
/// the client destroys \p lifeboat before pulling on the cache then
|
||||
/// we would destroy the layer then read it again.
|
||||
PCP_API
|
||||
void Apply(const PcpLayerStackChanges& changes, PcpLifeboat* lifeboat);
|
||||
|
||||
/// Return a PcpMapExpression representing the relocations that affect
|
||||
/// namespace at and below the given path. The value of this
|
||||
/// expression will continue to track the effective relocations if
|
||||
/// they are changed later.
|
||||
PCP_API
|
||||
PcpMapExpression GetExpressionForRelocatesAtPath(const SdfPath &path);
|
||||
|
||||
private:
|
||||
// Only a registry can create a layer stack.
|
||||
friend class Pcp_LayerStackRegistry;
|
||||
// PcpCache needs access to check the _registry.
|
||||
friend class PcpCache;
|
||||
// Needs access to _sublayerSourceInfo
|
||||
friend bool Pcp_NeedToRecomputeDueToAssetPathChange(const PcpLayerStackPtr&);
|
||||
|
||||
// It's a coding error to construct a layer stack with a NULL root layer.
|
||||
PcpLayerStack(const PcpLayerStackIdentifier &identifier,
|
||||
const std::string &fileFormatTarget,
|
||||
const Pcp_MutedLayers &mutedLayers,
|
||||
bool isUsd);
|
||||
|
||||
void _BlowLayers();
|
||||
void _BlowRelocations();
|
||||
void _Compute(const std::string &fileFormatTarget,
|
||||
const Pcp_MutedLayers &mutedLayers);
|
||||
|
||||
SdfLayerTreeHandle _BuildLayerStack(
|
||||
const SdfLayerHandle & layer,
|
||||
const SdfLayerOffset & offset,
|
||||
double layerTcps,
|
||||
const ArResolverContext & pathResolverContext,
|
||||
const SdfLayer::FileFormatArguments & layerArgs,
|
||||
const std::string & sessionOwner,
|
||||
const Pcp_MutedLayers & mutedLayers,
|
||||
SdfLayerHandleSet *seenLayers,
|
||||
PcpErrorVector *errors);
|
||||
|
||||
private:
|
||||
/// The identifier that uniquely identifies this layer stack.
|
||||
const PcpLayerStackIdentifier _identifier;
|
||||
/// The registry (1:1 with a PcpCache) this layer stack belongs to. This
|
||||
/// may not be set, particularly when a registry is creating a layer stack
|
||||
/// but before it's been installed in the registry.
|
||||
Pcp_LayerStackRegistryPtr _registry;
|
||||
|
||||
/// Data representing the computed layer stack contents.
|
||||
///
|
||||
/// This is built by examining the session and root layers for
|
||||
/// sublayers, resolving their asset paths with the path resolver context,
|
||||
/// and recursively building up the layer stack.
|
||||
///
|
||||
/// Note that this is only the *local* layer stack -- it does not
|
||||
/// include any layers brought in by references inside prims.
|
||||
|
||||
/// Retained references to the layers in the stack,
|
||||
/// in strong-to-weak order.
|
||||
SdfLayerRefPtrVector _layers;
|
||||
|
||||
/// The corresponding map functions for each entry in 'layers'.
|
||||
/// Each map function contains a time offset that should be applied
|
||||
/// to its corresponding layer.
|
||||
std::vector<PcpMapFunction> _mapFunctions;
|
||||
|
||||
/// Stores the computed time codes per second value of the layer stack which
|
||||
/// has some special logic when a session layer is present.
|
||||
double _timeCodesPerSecond;
|
||||
|
||||
/// The tree structure of the layer stack.
|
||||
/// Stored separately because this is needed only occasionally.
|
||||
SdfLayerTreeHandle _layerTree;
|
||||
|
||||
/// Tracks information used to compute sublayer asset paths.
|
||||
struct _SublayerSourceInfo {
|
||||
_SublayerSourceInfo(
|
||||
const SdfLayerHandle& layer_,
|
||||
const std::string& authoredSublayerPath_,
|
||||
const std::string& computedSublayerPath_)
|
||||
: layer(layer_)
|
||||
, authoredSublayerPath(authoredSublayerPath_)
|
||||
, computedSublayerPath(computedSublayerPath_) { }
|
||||
|
||||
SdfLayerHandle layer;
|
||||
std::string authoredSublayerPath;
|
||||
std::string computedSublayerPath;
|
||||
};
|
||||
|
||||
/// List of source info for sublayer asset path computations.
|
||||
std::vector<_SublayerSourceInfo> _sublayerSourceInfo;
|
||||
|
||||
/// Set of asset paths that were muted in this layer stack.
|
||||
std::set<std::string> _mutedAssetPaths;
|
||||
|
||||
/// The errors, if any, discovered while computing this layer stack.
|
||||
/// NULL if no errors were found (the expected common case).
|
||||
std::unique_ptr<PcpErrorVector> _localErrors;
|
||||
|
||||
/// Pre-computed table of local relocates.
|
||||
SdfRelocatesMap _relocatesSourceToTarget;
|
||||
SdfRelocatesMap _relocatesTargetToSource;
|
||||
SdfRelocatesMap _incrementalRelocatesSourceToTarget;
|
||||
SdfRelocatesMap _incrementalRelocatesTargetToSource;
|
||||
|
||||
/// A map of PcpMapExpressions::Variable instances used to represent
|
||||
/// the current value of relocations given out by
|
||||
/// GetExpressionForRelocatesAtPath(). This map is used to update
|
||||
/// those values when relocations change.
|
||||
typedef std::map<SdfPath, PcpMapExpression::VariableUniquePtr,
|
||||
SdfPath::FastLessThan> _RelocatesVarMap;
|
||||
_RelocatesVarMap _relocatesVariables;
|
||||
tbb::spin_mutex _relocatesVariablesMutex;
|
||||
|
||||
/// List of all prim spec paths where relocations were found.
|
||||
SdfPathVector _relocatesPrimPaths;
|
||||
|
||||
bool _isUsd;
|
||||
};
|
||||
|
||||
PCP_API
|
||||
std::ostream& operator<<(std::ostream&, const PcpLayerStackPtr&);
|
||||
PCP_API
|
||||
std::ostream& operator<<(std::ostream&, const PcpLayerStackRefPtr&);
|
||||
|
||||
/// Compose the relocation arcs in the given stack of layers,
|
||||
/// putting the results into the given sourceToTarget and targetToSource
|
||||
/// maps.
|
||||
void
|
||||
Pcp_ComputeRelocationsForLayerStack(
|
||||
const SdfLayerRefPtrVector & layers,
|
||||
SdfRelocatesMap *relocatesSourceToTarget,
|
||||
SdfRelocatesMap *relocatesTargetToSource,
|
||||
SdfRelocatesMap *incrementalRelocatesSourceToTarget,
|
||||
SdfRelocatesMap *incrementalRelocatesTargetToSource,
|
||||
SdfPathVector *relocatesPrimPaths);
|
||||
|
||||
// Returns true if \p layerStack should be recomputed due to changes to
|
||||
// any computed asset paths that were used to find or open layers
|
||||
// when originally composing \p layerStack. This may be due to scene
|
||||
// description changes or external changes to asset resolution that
|
||||
// may affect the computation of those asset paths.
|
||||
bool
|
||||
Pcp_NeedToRecomputeDueToAssetPathChange(const PcpLayerStackPtr& layerStack);
|
||||
|
||||
// Returns true if the \p layerStack should be recomputed because
|
||||
// \p changedLayer has had changes that would cause the layer stack to have
|
||||
// a different computed overall time codes per second value.
|
||||
bool
|
||||
Pcp_NeedToRecomputeLayerStackTimeCodesPerSecond(
|
||||
const PcpLayerStackPtr& layerStack, const SdfLayerHandle &changedLayer);
|
||||
|
||||
/// Returns true when the environment variable has been set to disable the
|
||||
/// behavior where differing time codes per second metadata in layers sublayered
|
||||
/// or referenced by another layer are used to apply a layer offset scale to the
|
||||
/// map function.
|
||||
PCP_API
|
||||
bool
|
||||
PcpIsTimeScalingForLayerTimeCodesPerSecondDisabled();
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_LAYER_STACK_H
|
||||
@@ -0,0 +1,220 @@
|
||||
//
|
||||
// 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_PCP_LAYER_STACK_IDENTIFIER_H
|
||||
#define PXR_USD_PCP_LAYER_STACK_IDENTIFIER_H
|
||||
|
||||
/// \file pcp/layerStackIdentifier.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/usd/ar/resolverContext.h"
|
||||
|
||||
#include <boost/operators.hpp>
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
SDF_DECLARE_HANDLES(SdfLayer);
|
||||
|
||||
/// \class PcpLayerStackIdentifier
|
||||
///
|
||||
/// Arguments used to identify a layer stack.
|
||||
///
|
||||
/// Objects of this type are immutable.
|
||||
///
|
||||
class PcpLayerStackIdentifier :
|
||||
boost::totally_ordered<PcpLayerStackIdentifier> {
|
||||
public:
|
||||
typedef PcpLayerStackIdentifier This;
|
||||
|
||||
/// Construct with all empty pointers.
|
||||
PCP_API
|
||||
PcpLayerStackIdentifier();
|
||||
|
||||
/// Construct with given pointers. If all arguments are \c TfNullPtr
|
||||
/// then the result is identical to the default constructed object.
|
||||
PCP_API
|
||||
PcpLayerStackIdentifier(const SdfLayerHandle& rootLayer_,
|
||||
const SdfLayerHandle& sessionLayer_ = TfNullPtr,
|
||||
const ArResolverContext& pathResolverContext_ =
|
||||
ArResolverContext());
|
||||
|
||||
// XXX: Allow assignment because there are clients using this
|
||||
// as a member that themselves want to be assignable.
|
||||
PCP_API
|
||||
PcpLayerStackIdentifier& operator=(const PcpLayerStackIdentifier&);
|
||||
|
||||
// Validity.
|
||||
#if !defined(doxygen)
|
||||
typedef const size_t This::*UnspecifiedBoolType;
|
||||
#endif
|
||||
PCP_API
|
||||
operator UnspecifiedBoolType() const;
|
||||
|
||||
// Comparison.
|
||||
PCP_API
|
||||
bool operator==(const This &rhs) const;
|
||||
PCP_API
|
||||
bool operator<(const This &rhs) const;
|
||||
|
||||
// Hashing.
|
||||
struct Hash {
|
||||
size_t operator()(const This & x) const
|
||||
{
|
||||
return x.GetHash();
|
||||
}
|
||||
};
|
||||
size_t GetHash() const
|
||||
{
|
||||
return _hash;
|
||||
}
|
||||
|
||||
public:
|
||||
/// The root layer.
|
||||
const SdfLayerHandle rootLayer;
|
||||
|
||||
/// The session layer (optional).
|
||||
const SdfLayerHandle sessionLayer;
|
||||
|
||||
/// The path resolver context used for resolving asset paths. (optional)
|
||||
const ArResolverContext pathResolverContext;
|
||||
|
||||
private:
|
||||
size_t _ComputeHash() const;
|
||||
|
||||
private:
|
||||
const size_t _hash;
|
||||
};
|
||||
|
||||
|
||||
/// \class PcpLayerStackIdentifierStr
|
||||
///
|
||||
/// A "string"-based version of PcpLayerStackIdentifier. These are used in
|
||||
/// places where they should be stable wrt layer lifetimes. This is done by
|
||||
/// storing layer identifiers as strings rather than SdfLayerHandles.
|
||||
///
|
||||
class PcpLayerStackIdentifierStr :
|
||||
boost::totally_ordered<PcpLayerStackIdentifierStr> {
|
||||
public:
|
||||
typedef PcpLayerStackIdentifierStr This;
|
||||
|
||||
/// Construct with given identifier strings and context. If all arguments
|
||||
/// are empty strings and default-constructed ArResolverContext, then the
|
||||
/// result is identical to the default constructed object.
|
||||
PCP_API
|
||||
explicit PcpLayerStackIdentifierStr(
|
||||
std::string const &rootLayerId = std::string(),
|
||||
std::string const &sessionLayerId = std::string(),
|
||||
ArResolverContext const &resolverContext = ArResolverContext());
|
||||
|
||||
/// Allow implicit conversion from PcpLayerStackIdentifier
|
||||
PCP_API
|
||||
PcpLayerStackIdentifierStr(PcpLayerStackIdentifier const &lsid);
|
||||
|
||||
// Validity.
|
||||
#if !defined(doxygen)
|
||||
typedef const size_t This::*UnspecifiedBoolType;
|
||||
#endif
|
||||
PCP_API
|
||||
operator UnspecifiedBoolType() const;
|
||||
|
||||
// Comparison.
|
||||
PCP_API
|
||||
bool operator==(const This &rhs) const;
|
||||
PCP_API
|
||||
bool operator<(const This &rhs) const;
|
||||
|
||||
// Hashing.
|
||||
struct Hash {
|
||||
size_t operator()(const This & x) const
|
||||
{
|
||||
return x.GetHash();
|
||||
}
|
||||
};
|
||||
size_t GetHash() const
|
||||
{
|
||||
return _hash;
|
||||
}
|
||||
|
||||
public:
|
||||
/// The root layer.
|
||||
std::string rootLayerId;
|
||||
|
||||
/// The session layer (optional).
|
||||
std::string sessionLayerId;
|
||||
|
||||
/// The path resolver context used for resolving asset paths. (optional)
|
||||
ArResolverContext pathResolverContext;
|
||||
|
||||
private:
|
||||
size_t _ComputeHash() const;
|
||||
|
||||
private:
|
||||
size_t _hash;
|
||||
};
|
||||
|
||||
|
||||
inline
|
||||
size_t
|
||||
hash_value(const PcpLayerStackIdentifier& x)
|
||||
{
|
||||
return x.GetHash();
|
||||
}
|
||||
|
||||
inline
|
||||
size_t
|
||||
hash_value(const PcpLayerStackIdentifierStr& x)
|
||||
{
|
||||
return x.GetHash();
|
||||
}
|
||||
|
||||
PCP_API
|
||||
std::ostream& operator<<(std::ostream&, const PcpLayerStackIdentifier&);
|
||||
PCP_API
|
||||
std::ostream& operator<<(std::ostream&, const PcpLayerStackIdentifierStr&);
|
||||
|
||||
/// Manipulator to cause the next PcpLayerStackIdentifier or
|
||||
/// PcpLayerStackIdentifierStr written to the ostream to write the base name of
|
||||
/// its layers, rather than the full identifier.
|
||||
PCP_API
|
||||
std::ostream& PcpIdentifierFormatBaseName(std::ostream&);
|
||||
|
||||
/// Manipulator to cause the next PcpLayerStackIdentifier or
|
||||
/// PcpLayerStackIdentifierStr written to the ostream to write the real path of
|
||||
/// its layers, rather than the identifier.
|
||||
PCP_API
|
||||
std::ostream& PcpIdentifierFormatRealPath(std::ostream&);
|
||||
|
||||
/// Manipulator to cause the next PcpLayerStackIdentifier or
|
||||
/// PcpLayerStackIdentifierStr written to the ostream to write the identifier of
|
||||
/// its layers. This is the default state; this manipulator is only to nullify
|
||||
/// one of the above manipulators.
|
||||
PCP_API
|
||||
std::ostream& PcpIdentifierFormatIdentifier(std::ostream&);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_LAYER_STACK_IDENTIFIER_H
|
||||
@@ -0,0 +1,284 @@
|
||||
//
|
||||
// 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_PCP_MAP_EXPRESSION_H
|
||||
#define PXR_USD_PCP_MAP_EXPRESSION_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/pcp/mapFunction.h"
|
||||
|
||||
#include <boost/intrusive_ptr.hpp>
|
||||
|
||||
#include <tbb/atomic.h>
|
||||
#include <tbb/spin_mutex.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class PcpMapExpression
|
||||
///
|
||||
/// An expression that yields a PcpMapFunction value.
|
||||
///
|
||||
/// Expressions comprise constant values, variables, and operators
|
||||
/// applied to sub-expressions. Expressions cache their computed values
|
||||
/// internally. Assigning a new value to a variable automatically
|
||||
/// invalidates the cached values of dependent expressions. Common
|
||||
/// (sub-)expressions are automatically detected and shared.
|
||||
///
|
||||
/// PcpMapExpression exists solely to support efficient incremental
|
||||
/// handling of relocates edits. It represents a tree of the namespace
|
||||
/// mapping operations and their inputs, so we can narrowly redo the
|
||||
/// computation when one of the inputs changes.
|
||||
///
|
||||
class PcpMapExpression
|
||||
{
|
||||
public:
|
||||
/// The value type of PcpMapExpression is a PcpMapFunction.
|
||||
typedef PcpMapFunction Value;
|
||||
|
||||
/// Evaluate this expression, yielding a PcpMapFunction value.
|
||||
/// The computed result is cached.
|
||||
/// The return value is a reference to the internal cached value.
|
||||
/// The cache is automatically invalidated as needed.
|
||||
PCP_API
|
||||
const Value & Evaluate() const;
|
||||
|
||||
/// Default-construct a NULL expression.
|
||||
PCP_API
|
||||
PcpMapExpression();
|
||||
|
||||
/// Swap this expression with the other.
|
||||
PCP_API
|
||||
void Swap(PcpMapExpression &other);
|
||||
|
||||
/// Return true if this is a null expression.
|
||||
PCP_API
|
||||
bool IsNull() const;
|
||||
|
||||
/// \name Creating expressions
|
||||
/// @{
|
||||
|
||||
/// Return an expression representing PcpMapFunction::Identity().
|
||||
PCP_API
|
||||
static PcpMapExpression Identity();
|
||||
|
||||
/// Create a new constant.
|
||||
PCP_API
|
||||
static PcpMapExpression Constant( const Value & constValue );
|
||||
|
||||
/// A Variable is a mutable memory cell that holds a value.
|
||||
/// Changing a variable's value invalidates any expressions using
|
||||
/// that variable.
|
||||
class Variable {
|
||||
Variable(Variable const &) = delete;
|
||||
Variable &operator=(Variable const &) = delete;
|
||||
public:
|
||||
Variable() = default;
|
||||
virtual ~Variable();
|
||||
/// Return the current value.
|
||||
virtual const Value & GetValue() const = 0;
|
||||
/// Mutate the variable to have the new value.
|
||||
/// This will also invalidate dependant expressions.
|
||||
virtual void SetValue(Value && value) = 0;
|
||||
/// Return an expression representing the value of this variable.
|
||||
/// This lets you use the variable as a sub-term in other expressions.
|
||||
virtual PcpMapExpression GetExpression() const = 0;
|
||||
};
|
||||
|
||||
/// Variables are held by reference.
|
||||
typedef std::unique_ptr<Variable> VariableUniquePtr;
|
||||
|
||||
/// Create a new variable.
|
||||
/// The client is expected to retain the reference for as long as
|
||||
/// it wishes to continue being able to set the value of the variable.
|
||||
/// After the reference is dropped, expressions using the variable
|
||||
/// will continue to be valid, but there will be no way to further
|
||||
/// change the value of the variable.
|
||||
PCP_API
|
||||
static VariableUniquePtr NewVariable(Value && initialValue);
|
||||
|
||||
/// Create a new PcpMapExpression representing the application of
|
||||
/// f's value, followed by the application of this expression's value.
|
||||
PCP_API
|
||||
PcpMapExpression Compose(const PcpMapExpression &f) const;
|
||||
|
||||
/// Create a new PcpMapExpression representing the inverse of f.
|
||||
PCP_API
|
||||
PcpMapExpression Inverse() const;
|
||||
|
||||
/// Return a new expression representing this expression with an added
|
||||
/// (if necessary) mapping from </> to </>.
|
||||
PCP_API
|
||||
PcpMapExpression AddRootIdentity() const;
|
||||
|
||||
/// Return true if the map function is the constant identity function.
|
||||
bool IsConstantIdentity() const {
|
||||
return _node && _node->key.op == _OpConstant &&
|
||||
_node->key.valueForConstant.IsIdentity();
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name Convenience API
|
||||
/// The following API just forwards through to the underlying evaluated
|
||||
/// mapfunction value.
|
||||
/// @{
|
||||
|
||||
/// Return true if the evaluated map function is the identity function.
|
||||
/// For identity, MapSourceToTarget() always returns the path unchanged.
|
||||
bool IsIdentity() const {
|
||||
return Evaluate().IsIdentity();
|
||||
}
|
||||
|
||||
/// Map a path in the source namespace to the target.
|
||||
/// If the path is not in the domain, returns an empty path.
|
||||
SdfPath MapSourceToTarget(const SdfPath &path) const {
|
||||
return Evaluate().MapSourceToTarget(path);
|
||||
}
|
||||
|
||||
/// Map a path in the target namespace to the source.
|
||||
/// If the path is not in the co-domain, returns an empty path.
|
||||
SdfPath MapTargetToSource(const SdfPath &path) const {
|
||||
return Evaluate().MapTargetToSource(path);
|
||||
}
|
||||
|
||||
/// The time offset of the mapping.
|
||||
const SdfLayerOffset &GetTimeOffset() const {
|
||||
return Evaluate().GetTimeOffset();
|
||||
}
|
||||
|
||||
/// Returns a string representation of this mapping for debugging
|
||||
/// purposes.
|
||||
std::string GetString() const {
|
||||
return Evaluate().GetString();
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
private:
|
||||
// Allow Pcp_Statistics access to internal data for diagnostics.
|
||||
friend class Pcp_Statistics;
|
||||
friend struct Pcp_VariableImpl;
|
||||
|
||||
class _Node;
|
||||
typedef boost::intrusive_ptr<_Node> _NodeRefPtr;
|
||||
|
||||
explicit PcpMapExpression(const _NodeRefPtr & node) : _node(node) {}
|
||||
|
||||
private: // data
|
||||
enum _Op {
|
||||
_OpConstant,
|
||||
_OpVariable,
|
||||
_OpInverse,
|
||||
_OpCompose,
|
||||
_OpAddRootIdentity
|
||||
};
|
||||
|
||||
class _Node : public boost::noncopyable {
|
||||
public:
|
||||
// The Key holds all the state needed to uniquely identify
|
||||
// this (sub-)expression.
|
||||
struct Key {
|
||||
const _Op op;
|
||||
const _NodeRefPtr arg1, arg2;
|
||||
const Value valueForConstant;
|
||||
|
||||
Key( _Op op_,
|
||||
const _NodeRefPtr & arg1_,
|
||||
const _NodeRefPtr & arg2_,
|
||||
const Value & valueForConstant_ )
|
||||
: op(op_)
|
||||
, arg1(arg1_)
|
||||
, arg2(arg2_)
|
||||
, valueForConstant(valueForConstant_)
|
||||
{}
|
||||
inline size_t GetHash() const;
|
||||
bool operator==(const Key &key) const;
|
||||
};
|
||||
|
||||
// The Key of a node is const, and established when it is created.
|
||||
const Key key;
|
||||
|
||||
// Whether or not the expression tree up to and including this node
|
||||
// will always include an identity mapping.
|
||||
const bool expressionTreeAlwaysHasIdentity;
|
||||
|
||||
// Factory method to create new nodes.
|
||||
static _NodeRefPtr
|
||||
New( _Op op,
|
||||
const _NodeRefPtr & arg1 = _NodeRefPtr(),
|
||||
const _NodeRefPtr & arg2 = _NodeRefPtr(),
|
||||
const Value & valueForConstant = Value() );
|
||||
~_Node();
|
||||
|
||||
// Evaluate (and internally cache) the value of this node.
|
||||
const Value & EvaluateAndCache() const;
|
||||
|
||||
// For _OpVariable nodes, sets the variable's value.
|
||||
void SetValueForVariable(Value &&newValue);
|
||||
|
||||
// For _OpVariable nodes, returns the variable's value.
|
||||
const Value & GetValueForVariable() const {
|
||||
return _valueForVariable;
|
||||
}
|
||||
|
||||
private:
|
||||
explicit _Node( const Key &key_ );
|
||||
void _Invalidate();
|
||||
Value _EvaluateUncached() const;
|
||||
|
||||
// Helper to determine if the expression tree indicated by key
|
||||
// will always contains the root identity.
|
||||
static bool _ExpressionTreeAlwaysHasIdentity(const Key& key);
|
||||
|
||||
// Ref-counting ops manage _refCount.
|
||||
// Need to friend them here to have access to _refCount.
|
||||
friend PCP_API void intrusive_ptr_add_ref(_Node*);
|
||||
friend PCP_API void intrusive_ptr_release(_Node*);
|
||||
|
||||
// Registry of node instances, identified by Key.
|
||||
// Note: variable nodes are not tracked by the registry.
|
||||
struct _NodeMap;
|
||||
static TfStaticData<_NodeMap> _nodeRegistry;
|
||||
|
||||
mutable tbb::atomic<int> _refCount;
|
||||
mutable Value _cachedValue;
|
||||
mutable std::set<_Node*> _dependentExpressions;
|
||||
Value _valueForVariable;
|
||||
mutable tbb::spin_mutex _mutex;
|
||||
mutable std::atomic<bool> _hasCachedValue;
|
||||
};
|
||||
|
||||
// Need to friend them here to have visibility to private class _Node.
|
||||
friend PCP_API void intrusive_ptr_add_ref(_Node*);
|
||||
friend PCP_API void intrusive_ptr_release(_Node*);
|
||||
|
||||
_NodeRefPtr _node;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_MAP_EXPRESSION_H
|
||||
@@ -0,0 +1,309 @@
|
||||
//
|
||||
// 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_PCP_MAP_FUNCTION_H
|
||||
#define PXR_USD_PCP_MAP_FUNCTION_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/usd/sdf/layerOffset.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class PcpMapFunction
|
||||
///
|
||||
/// A function that maps values from one namespace (and time domain) to
|
||||
/// another. It represents the transformation that an arc such as a reference
|
||||
/// arc applies as it incorporates values across the arc.
|
||||
///
|
||||
/// Take the example of a reference arc, where a source path
|
||||
/// \</Model\> is referenced as a target path, \</Model_1\>.
|
||||
/// The source path \</Model\> is the source of the opinions;
|
||||
/// the target path \</Model_1\> is where they are incorporated in the scene.
|
||||
/// Values in the model that refer to paths relative to \</Model\> must be
|
||||
/// transformed to be relative to \</Model_1\> instead.
|
||||
/// The PcpMapFunction for the arc provides this service.
|
||||
///
|
||||
/// Map functions have a specific \em domain, or set of values they can
|
||||
/// operate on. Any values outside the domain cannot be mapped.
|
||||
/// The domain precisely tracks what areas of namespace can be
|
||||
/// referred to across various forms of arcs.
|
||||
///
|
||||
/// Map functions can be chained to represent a series of map
|
||||
/// operations applied in sequence. The map function represent the
|
||||
/// cumulative effect as efficiently as possible. For example, in
|
||||
/// the case of a chained reference from \</Model\> to \</Model\>
|
||||
/// to \</Model\> to \</Model_1\>, this is effectively the same as
|
||||
/// a mapping directly from \</Model\> to \</Model_1\>. Representing
|
||||
/// the cumulative effect of arcs in this way is important for
|
||||
/// handling larger scenes efficiently.
|
||||
///
|
||||
/// Map functions can be \em inverted. Formally, map functions are
|
||||
/// bijections (one-to-one and onto), which ensures that they can
|
||||
/// be inverted. Put differently, no information is lost by applying
|
||||
/// a map function to set of values within its domain; they retain
|
||||
/// their distinct identities and can always be mapped back.
|
||||
///
|
||||
/// One analogy that may or may not be helpful:
|
||||
/// In the same way a geometric transform maps a model's points in its
|
||||
/// rest space into the world coordinates for a particular instance,
|
||||
/// a PcpMapFunction maps values about a referenced model into the
|
||||
/// composed scene for a particular instance of that model. But rather
|
||||
/// than translating and rotating points, the map function shifts the
|
||||
/// values in namespace (and time).
|
||||
///
|
||||
///
|
||||
class PcpMapFunction
|
||||
{
|
||||
public:
|
||||
/// A mapping from path to path.
|
||||
typedef std::map<SdfPath, SdfPath, SdfPath::FastLessThan> PathMap;
|
||||
typedef std::pair<SdfPath, SdfPath> PathPair;
|
||||
typedef std::vector<PathPair> PathPairVector;
|
||||
|
||||
/// Construct a null function.
|
||||
PcpMapFunction() = default;
|
||||
|
||||
/// Constructs a map function with the given arguments.
|
||||
/// Returns a null map function on error (see IsNull()).
|
||||
///
|
||||
/// \param sourceToTargetMap The map from source paths to target paths.
|
||||
/// \param offset The time offset to apply from source to target.
|
||||
///
|
||||
PCP_API
|
||||
static PcpMapFunction
|
||||
Create(const PathMap &sourceToTargetMap,
|
||||
const SdfLayerOffset &offset);
|
||||
|
||||
/// Construct an identity map function.
|
||||
PCP_API
|
||||
static const PcpMapFunction &Identity();
|
||||
|
||||
/// Returns an identity path mapping.
|
||||
PCP_API
|
||||
static const PathMap &IdentityPathMap();
|
||||
|
||||
/// Swap the contents of this map function with \p map.
|
||||
PCP_API
|
||||
void Swap(PcpMapFunction &map);
|
||||
void swap(PcpMapFunction &map) { Swap(map); }
|
||||
|
||||
/// Equality.
|
||||
PCP_API
|
||||
bool operator==(const PcpMapFunction &map) const;
|
||||
|
||||
/// Inequality.
|
||||
PCP_API
|
||||
bool operator!=(const PcpMapFunction &map) const;
|
||||
|
||||
/// Return true if this map function is the null function.
|
||||
/// For a null function, MapSourceToTarget() always returns an empty path.
|
||||
PCP_API
|
||||
bool IsNull() const;
|
||||
|
||||
/// Return true if the map function is the identity function.
|
||||
/// For identity, MapSourceToTarget() always returns the path unchanged.
|
||||
PCP_API
|
||||
bool IsIdentity() const;
|
||||
|
||||
/// Return true if the map function maps the absolute root path to the
|
||||
/// absolute root path, false otherwise.
|
||||
bool HasRootIdentity() const { return _data.hasRootIdentity; }
|
||||
|
||||
/// Map a path in the source namespace to the target.
|
||||
/// If the path is not in the domain, returns an empty path.
|
||||
PCP_API
|
||||
SdfPath MapSourceToTarget(const SdfPath &path) const;
|
||||
|
||||
/// Map a path in the target namespace to the source.
|
||||
/// If the path is not in the co-domain, returns an empty path.
|
||||
PCP_API
|
||||
SdfPath MapTargetToSource(const SdfPath &path) const;
|
||||
|
||||
/// Compose this map over the given map function.
|
||||
/// The result will represent the application of f followed by
|
||||
/// the application of this function.
|
||||
PCP_API
|
||||
PcpMapFunction Compose(const PcpMapFunction &f) const;
|
||||
|
||||
/// Compose this map function over a hypothetical map function that has an
|
||||
/// identity path mapping and \p offset. This is equivalent to building
|
||||
/// such a map function and invoking Compose(), but is faster.
|
||||
PCP_API
|
||||
PcpMapFunction ComposeOffset(const SdfLayerOffset &newOffset) const;
|
||||
|
||||
/// Return the inverse of this map function.
|
||||
/// This returns a true inverse \p inv: for any path p in this function's
|
||||
/// domain that it maps to p', inv(p') -> p.
|
||||
PCP_API
|
||||
PcpMapFunction GetInverse() const;
|
||||
|
||||
/// The set of path mappings, from source to target.
|
||||
PCP_API
|
||||
PathMap GetSourceToTargetMap() const;
|
||||
|
||||
/// The time offset of the mapping.
|
||||
const SdfLayerOffset &GetTimeOffset() const { return _offset; }
|
||||
|
||||
/// Returns a string representation of this mapping for debugging
|
||||
/// purposes.
|
||||
PCP_API
|
||||
std::string GetString() const;
|
||||
|
||||
/// Return a size_t hash for this map function.
|
||||
PCP_API
|
||||
size_t Hash() const;
|
||||
|
||||
private:
|
||||
|
||||
PCP_API
|
||||
PcpMapFunction(PathPair const *sourceToTargetBegin,
|
||||
PathPair const *sourceToTargetEnd,
|
||||
SdfLayerOffset offset,
|
||||
bool hasRootIdentity);
|
||||
|
||||
private:
|
||||
friend PcpMapFunction *Pcp_MakeIdentity();
|
||||
|
||||
static const int _MaxLocalPairs = 2;
|
||||
struct _Data final {
|
||||
_Data() {};
|
||||
|
||||
_Data(PathPair const *begin, PathPair const *end, bool hasRootIdentity)
|
||||
: numPairs(end-begin)
|
||||
, hasRootIdentity(hasRootIdentity) {
|
||||
if (numPairs == 0)
|
||||
return;
|
||||
if (numPairs <= _MaxLocalPairs) {
|
||||
std::uninitialized_copy(begin, end, localPairs);
|
||||
}
|
||||
else {
|
||||
new (&remotePairs) std::shared_ptr<PathPair>(
|
||||
new PathPair[numPairs], std::default_delete<PathPair[]>());
|
||||
std::copy(begin, end, remotePairs.get());
|
||||
}
|
||||
}
|
||||
|
||||
_Data(_Data const &other)
|
||||
: numPairs(other.numPairs)
|
||||
, hasRootIdentity(other.hasRootIdentity) {
|
||||
if (numPairs <= _MaxLocalPairs) {
|
||||
std::uninitialized_copy(
|
||||
other.localPairs,
|
||||
other.localPairs + other.numPairs, localPairs);
|
||||
}
|
||||
else {
|
||||
new (&remotePairs) std::shared_ptr<PathPair>(other.remotePairs);
|
||||
}
|
||||
}
|
||||
_Data(_Data &&other)
|
||||
: numPairs(other.numPairs)
|
||||
, hasRootIdentity(other.hasRootIdentity) {
|
||||
if (numPairs <= _MaxLocalPairs) {
|
||||
PathPair *dst = localPairs;
|
||||
PathPair *src = other.localPairs;
|
||||
PathPair *srcEnd = other.localPairs + other.numPairs;
|
||||
for (; src != srcEnd; ++src, ++dst) {
|
||||
::new (static_cast<void*>(std::addressof(*dst)))
|
||||
PathPair(std::move(*src));
|
||||
}
|
||||
}
|
||||
else {
|
||||
new (&remotePairs)
|
||||
std::shared_ptr<PathPair>(std::move(other.remotePairs));
|
||||
}
|
||||
}
|
||||
_Data &operator=(_Data const &other) {
|
||||
if (this != &other) {
|
||||
this->~_Data();
|
||||
new (this) _Data(other);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
_Data &operator=(_Data &&other) {
|
||||
if (this != &other) {
|
||||
this->~_Data();
|
||||
new (this) _Data(std::move(other));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
~_Data() {
|
||||
if (numPairs <= _MaxLocalPairs) {
|
||||
for (PathPair *p = localPairs; numPairs--; ++p) {
|
||||
p->~PathPair();
|
||||
}
|
||||
}
|
||||
else {
|
||||
remotePairs.~shared_ptr<PathPair>();
|
||||
}
|
||||
}
|
||||
|
||||
bool IsNull() const {
|
||||
return numPairs == 0 && !hasRootIdentity;
|
||||
}
|
||||
|
||||
PathPair const *begin() const {
|
||||
return numPairs <= _MaxLocalPairs ? localPairs : remotePairs.get();
|
||||
}
|
||||
|
||||
PathPair const *end() const {
|
||||
return begin() + numPairs;
|
||||
}
|
||||
|
||||
bool operator==(_Data const &other) const {
|
||||
return numPairs == other.numPairs &&
|
||||
hasRootIdentity == other.hasRootIdentity &&
|
||||
std::equal(begin(), end(), other.begin());
|
||||
}
|
||||
|
||||
bool operator!=(_Data const &other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
union {
|
||||
PathPair localPairs[_MaxLocalPairs > 0 ? _MaxLocalPairs : 1];
|
||||
std::shared_ptr<PathPair> remotePairs;
|
||||
};
|
||||
typedef int PairCount;
|
||||
PairCount numPairs = 0;
|
||||
bool hasRootIdentity = false;
|
||||
};
|
||||
|
||||
_Data _data;
|
||||
SdfLayerOffset _offset;
|
||||
};
|
||||
|
||||
// Specialize hash_value for PcpMapFunction.
|
||||
inline
|
||||
size_t hash_value(const PcpMapFunction& x)
|
||||
{
|
||||
return x.Hash();
|
||||
}
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_MAP_FUNCTION_H
|
||||
@@ -0,0 +1,146 @@
|
||||
//
|
||||
// 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_PCP_NAMESPACE_EDITS_H
|
||||
#define PXR_USD_PCP_NAMESPACE_EDITS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/pcp/cache.h"
|
||||
#include "pxr/base/tf/hashset.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
// Forward declarations:
|
||||
class PcpChanges;
|
||||
class PcpCacheChanges;
|
||||
class Pcp_Dependencies;
|
||||
class PcpLayerStackIdentifier;
|
||||
class PcpLifeboat;
|
||||
class PcpNodeRef;
|
||||
class PcpMapFunction;
|
||||
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(PcpLayerStack);
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(Pcp_LayerStackRegistry);
|
||||
SDF_DECLARE_HANDLES(SdfSpec);
|
||||
|
||||
/// Sites that must respond to a namespace edit.
|
||||
struct PcpNamespaceEdits {
|
||||
|
||||
/// Types of namespace edits that a given layer stack site could need
|
||||
/// to perform to respond to a namespace edit.
|
||||
enum EditType {
|
||||
EditPath, ///< Must namespace edit spec
|
||||
EditInherit, ///< Must fixup inherits
|
||||
EditSpecializes, ///< Must fixup specializes
|
||||
EditReference, ///< Must fixup references
|
||||
EditPayload, ///< Must fixup payload
|
||||
EditRelocate, ///< Must fixup relocates
|
||||
};
|
||||
|
||||
void Swap(PcpNamespaceEdits& rhs)
|
||||
{
|
||||
cacheSites.swap(rhs.cacheSites);
|
||||
layerStackSites.swap(rhs.layerStackSites);
|
||||
invalidLayerStackSites.swap(rhs.invalidLayerStackSites);
|
||||
}
|
||||
|
||||
/// Cache site that must respond to a namespace edit.
|
||||
struct CacheSite {
|
||||
size_t cacheIndex; ///< Index of cache of site.
|
||||
SdfPath oldPath; ///< Old path of site.
|
||||
SdfPath newPath; ///< New path of site.
|
||||
};
|
||||
typedef std::vector<CacheSite> CacheSites;
|
||||
|
||||
/// Layer stack site that must respond to a namespace edit. All
|
||||
/// of the specs at the site will respond the same way.
|
||||
struct LayerStackSite {
|
||||
size_t cacheIndex; ///< Index of cache of site.
|
||||
EditType type; ///< Type of edit.
|
||||
PcpLayerStackPtr layerStack; ///< Layer stack needing fix.
|
||||
SdfPath sitePath; ///< Path of site needing fix.
|
||||
SdfPath oldPath; ///< Old path.
|
||||
SdfPath newPath; ///< New path.
|
||||
};
|
||||
typedef std::vector<LayerStackSite> LayerStackSites;
|
||||
|
||||
/// Cache sites that must respond to a namespace edit.
|
||||
CacheSites cacheSites;
|
||||
|
||||
/// Layer stack sites that must respond to a namespace edit.
|
||||
LayerStackSites layerStackSites;
|
||||
|
||||
/// Layer stack sites that are affected by a namespace edit but
|
||||
/// cannot respond properly. For example, in situations involving
|
||||
/// relocates, a valid namespace edit in one cache may result in
|
||||
/// an invalid edit in another cache in response.
|
||||
LayerStackSites invalidLayerStackSites;
|
||||
};
|
||||
|
||||
/// Returns the changes caused in any cache in \p caches due to
|
||||
/// namespace editing the object at \p curPath in this cache to
|
||||
/// have the path \p newPath. \p caches should have all caches,
|
||||
/// including this cache. If \p caches includes this cache then
|
||||
/// the result includes the changes caused at \p curPath in this
|
||||
/// cache itself.
|
||||
///
|
||||
/// To keep everything consistent, a namespace edit requires that
|
||||
/// everything using the namespace edited site to be changed in an
|
||||
/// appropriate way. For example, if a referenced prim /A is renamed
|
||||
/// to /B then everything referencing /A must be changed to reference
|
||||
/// /B instead. There are many other possibilities.
|
||||
///
|
||||
/// One possibility is that there are no opinions at \p curPath in
|
||||
/// this cache's layer stack and the site exists due to some ancestor
|
||||
/// arc. This requires a relocation and only sites using \p curPath
|
||||
/// that include the layer with the relocation must be changed in
|
||||
/// response. To find those sites, \p relocatesLayer indicates which
|
||||
/// layer the client will write the relocation to.
|
||||
///
|
||||
/// Clients must perform the changes to correctly perform a namespace
|
||||
/// edit. All changes must be performed in a change block, otherwise
|
||||
/// notices could be sent prematurely.
|
||||
///
|
||||
/// This method only works when the affected prim indexes have been
|
||||
/// computed. In general, this means you must have computed the prim
|
||||
/// index of everything in any existing cache, otherwise you might miss
|
||||
/// changes to objects in those caches that use the namespace edited
|
||||
/// object. Using the above example, if a prim with an uncomputed prim
|
||||
/// index referenced /A then this method would not report that prim.
|
||||
/// As a result that prim would continue to reference /A, which no
|
||||
/// longer exists.
|
||||
PCP_API
|
||||
PcpNamespaceEdits
|
||||
PcpComputeNamespaceEdits(const PcpCache *primaryCache,
|
||||
const std::vector<PcpCache*>& caches,
|
||||
const SdfPath& curPath,
|
||||
const SdfPath& newPath,
|
||||
const SdfLayerHandle& relocatesLayer);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_NAMESPACE_EDITS_H
|
||||
@@ -0,0 +1,454 @@
|
||||
//
|
||||
// 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_PCP_NODE_H
|
||||
#define PXR_USD_PCP_NODE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/pcp/types.h"
|
||||
#include "pxr/usd/sdf/types.h"
|
||||
#include "pxr/base/tf/iterator.h"
|
||||
#include "pxr/base/tf/hashset.h"
|
||||
|
||||
#include <boost/operators.hpp>
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
#include <boost/iterator/reverse_iterator.hpp>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class PcpArc;
|
||||
class PcpLayerStackSite;
|
||||
class PcpMapExpression;
|
||||
class PcpNodeRef;
|
||||
class PcpNodeRef_ChildrenIterator;
|
||||
class PcpNodeRef_ChildrenReverseIterator;
|
||||
class PcpErrorBase;
|
||||
typedef std::shared_ptr<PcpErrorBase> PcpErrorBasePtr;
|
||||
|
||||
TF_DECLARE_WEAK_PTRS(PcpPrimIndex_Graph);
|
||||
|
||||
/// \class PcpNodeRef
|
||||
///
|
||||
/// PcpNode represents a node in an expression tree for compositing
|
||||
/// scene description.
|
||||
///
|
||||
/// A node represents the opinions from a particular site. In addition,
|
||||
/// it may have child nodes, representing nested expressions that are
|
||||
/// composited over/under this node.
|
||||
///
|
||||
/// Child nodes are stored and composited in strength order.
|
||||
///
|
||||
/// Each node holds information about the arc to its parent.
|
||||
/// This captures both the relative strength of the sub-expression
|
||||
/// as well as any value-mapping needed, such as to rename opinions
|
||||
/// from a model to use in a particular instance.
|
||||
///
|
||||
class PcpNodeRef :
|
||||
public boost::totally_ordered<PcpNodeRef>
|
||||
{
|
||||
public:
|
||||
typedef PcpNodeRef_ChildrenIterator child_const_iterator;
|
||||
typedef PcpNodeRef_ChildrenReverseIterator child_const_reverse_iterator;
|
||||
typedef std::pair<child_const_iterator,
|
||||
child_const_iterator> child_const_range;
|
||||
|
||||
PcpNodeRef() : _graph(0), _nodeIdx(PCP_INVALID_INDEX) {}
|
||||
|
||||
/// \name Operators / Miscellaneous
|
||||
/// @{
|
||||
|
||||
/// Returns true if this is a valid node reference, false otherwise.
|
||||
typedef size_t PcpNodeRef::*UnspecifiedBoolType;
|
||||
inline operator UnspecifiedBoolType() const {
|
||||
return (_graph && _nodeIdx != PCP_INVALID_INDEX) ? &PcpNodeRef::_nodeIdx : 0;
|
||||
}
|
||||
|
||||
/// Returns true if this references the same node as \p rhs.
|
||||
inline bool operator==(const PcpNodeRef& rhs) const {
|
||||
return _nodeIdx == rhs._nodeIdx && _graph == rhs._graph;
|
||||
}
|
||||
|
||||
/// Returns true if this node is 'less' than \p rhs.
|
||||
/// The ordering of nodes is arbitrary and does not indicate the relative
|
||||
/// strength of the nodes.
|
||||
PCP_API
|
||||
bool operator<(const PcpNodeRef& rhs) const;
|
||||
|
||||
/// Hash functor.
|
||||
struct Hash {
|
||||
size_t operator()(const PcpNodeRef& rhs) const
|
||||
{ return (size_t)rhs.GetUniqueIdentifier(); }
|
||||
};
|
||||
|
||||
/// Returns the graph that this node belongs to.
|
||||
PcpPrimIndex_GraphPtr GetOwningGraph() const;
|
||||
|
||||
/// Returns a value that uniquely identifies this node.
|
||||
PCP_API
|
||||
void* GetUniqueIdentifier() const;
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name Arc information
|
||||
/// Information pertaining to the arcs connecting this node to its
|
||||
/// parent and child nodes.
|
||||
/// @{
|
||||
|
||||
/// Returns the type of arc connecting this node to its parent node.
|
||||
PCP_API
|
||||
PcpArcType GetArcType() const;
|
||||
|
||||
/// Returns this node's immediate parent node. Will return NULL if this
|
||||
/// node is a root node.
|
||||
PCP_API
|
||||
PcpNodeRef GetParentNode() const;
|
||||
|
||||
/// Returns an iterator range over the children nodes in strongest to
|
||||
/// weakest order.
|
||||
PCP_API
|
||||
child_const_range GetChildrenRange() const;
|
||||
|
||||
/// Inserts a new child node for \p site, connected to this node via
|
||||
/// \p arc.
|
||||
PCP_API
|
||||
PcpNodeRef InsertChild(const PcpLayerStackSite& site, const PcpArc& arc,
|
||||
PcpErrorBasePtr *error);
|
||||
|
||||
/// Inserts \p subgraph as a child of this node, with the root node of
|
||||
/// \p subtree connected to this node via \p arc.
|
||||
PCP_API
|
||||
PcpNodeRef InsertChildSubgraph(
|
||||
const PcpPrimIndex_GraphPtr& subgraph, const PcpArc& arc,
|
||||
PcpErrorBasePtr *error);
|
||||
|
||||
/// Returns the immediate origin node for this node. The origin node
|
||||
/// is the node that caused this node to be brought into the prim index.
|
||||
/// In most cases, this is the same as the parent node. For implied
|
||||
/// inherits, the origin is the node from which this node was propagated.
|
||||
PCP_API
|
||||
PcpNodeRef GetOriginNode() const;
|
||||
|
||||
/// Walk up to the root origin node for this node. This is the very
|
||||
/// first node that caused this node to be added to the graph. For
|
||||
/// instance, the root origin node of an implied inherit is the
|
||||
/// original inherit node.
|
||||
PCP_API
|
||||
PcpNodeRef GetOriginRootNode() const;
|
||||
|
||||
/// Walk up to the root node of this expression.
|
||||
PCP_API
|
||||
PcpNodeRef GetRootNode() const;
|
||||
|
||||
/// Returns mapping function used to translate paths and values from
|
||||
/// this node to its parent node.
|
||||
PCP_API
|
||||
const PcpMapExpression& GetMapToParent() const;
|
||||
|
||||
/// Returns mapping function used to translate paths and values from
|
||||
/// this node directly to the root node.
|
||||
PCP_API
|
||||
const PcpMapExpression& GetMapToRoot() const;
|
||||
|
||||
/// Returns this node's index among siblings with the same arc type
|
||||
/// at this node's origin.
|
||||
PCP_API
|
||||
int GetSiblingNumAtOrigin() const;
|
||||
|
||||
/// Returns the absolute namespace depth of the node that introduced
|
||||
/// this node. Note that this does *not* count any variant selections.
|
||||
PCP_API
|
||||
int GetNamespaceDepth() const;
|
||||
|
||||
/// Return the number of levels of namespace this node's site is
|
||||
/// below the level at which it was introduced by an arc.
|
||||
PCP_API
|
||||
int GetDepthBelowIntroduction() const;
|
||||
|
||||
/// Returns the path for this node's site when it was introduced.
|
||||
PCP_API
|
||||
SdfPath GetPathAtIntroduction() const;
|
||||
|
||||
/// Get the path that introduced this node.
|
||||
/// Specifically, this is the path the parent node had at the level
|
||||
/// of namespace where this node was added as a child.
|
||||
/// For a root node, this returns the absolute root path.
|
||||
/// See also GetDepthBelowIntroduction().
|
||||
PCP_API
|
||||
SdfPath GetIntroPath() const;
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name Node information
|
||||
/// Information pertaining specifically to this node and the opinions
|
||||
/// that it may or may not provide.
|
||||
/// @{
|
||||
|
||||
/// Get the site this node represents.
|
||||
PCP_API
|
||||
PcpLayerStackSite GetSite() const;
|
||||
|
||||
/// Returns the path for the site this node represents.
|
||||
PCP_API
|
||||
const SdfPath& GetPath() const;
|
||||
|
||||
/// Returns the layer stack for the site this node represents.
|
||||
PCP_API
|
||||
const PcpLayerStackRefPtr& GetLayerStack() const;
|
||||
|
||||
/// Returns true if this node is the root node of the prim index graph.
|
||||
PCP_API
|
||||
bool IsRootNode() const;
|
||||
|
||||
/// Returns true if this node is due to an ancestral opinion.
|
||||
PCP_API
|
||||
bool IsDueToAncestor() const;
|
||||
|
||||
/// Get/set whether this node provides any symmetry opinions, either
|
||||
/// directly or from a namespace ancestor.
|
||||
PCP_API
|
||||
void SetHasSymmetry(bool hasSymmetry);
|
||||
PCP_API
|
||||
bool HasSymmetry() const;
|
||||
|
||||
/// Get/set the permission for this node. This indicates whether specs
|
||||
/// on this node can be accessed from other nodes.
|
||||
PCP_API
|
||||
void SetPermission(SdfPermission perm);
|
||||
PCP_API
|
||||
SdfPermission GetPermission() const;
|
||||
|
||||
/// Get/set whether this node is inert. An inert node never provides
|
||||
/// any opinions to a prim index. Such a node may exist purely as a
|
||||
/// marker to represent certain composition structure, but should never
|
||||
/// contribute opinions.
|
||||
PCP_API
|
||||
void SetInert(bool inert);
|
||||
PCP_API
|
||||
bool IsInert() const;
|
||||
|
||||
/// Get/set whether this node is culled. If a node is culled, it and
|
||||
/// all descendant nodes provide no opinions to the index. A culled
|
||||
/// node is also considered inert.
|
||||
PCP_API
|
||||
void SetCulled(bool culled);
|
||||
PCP_API
|
||||
bool IsCulled() const;
|
||||
|
||||
/// Get/set whether this node is restricted. A restricted node is a
|
||||
/// node that cannot contribute opinions to the index due to permissions.
|
||||
PCP_API
|
||||
void SetRestricted(bool restricted);
|
||||
PCP_API
|
||||
bool IsRestricted() const;
|
||||
|
||||
/// Returns true if this node is allowed to contribute opinions
|
||||
/// for composition, false otherwise.
|
||||
PCP_API
|
||||
bool CanContributeSpecs() const;
|
||||
|
||||
/// Returns true if this node has opinions authored
|
||||
/// for composition, false otherwise.
|
||||
PCP_API
|
||||
void SetHasSpecs(bool hasSpecs);
|
||||
PCP_API
|
||||
bool HasSpecs() const;
|
||||
|
||||
/// @}
|
||||
|
||||
// Returns a compressed Sd site. For internal use only.
|
||||
Pcp_CompressedSdSite GetCompressedSdSite(size_t layerIndex) const
|
||||
{
|
||||
return Pcp_CompressedSdSite(_nodeIdx, layerIndex);
|
||||
}
|
||||
|
||||
private:
|
||||
friend class PcpPrimIndex_Graph;
|
||||
friend class PcpNodeIterator;
|
||||
friend class PcpNodeRef_ChildrenIterator;
|
||||
friend class PcpNodeRef_ChildrenReverseIterator;
|
||||
friend class PcpNodeRef_PrivateChildrenConstIterator;
|
||||
friend class PcpNodeRef_PrivateChildrenConstReverseIterator;
|
||||
|
||||
// Private constructor for internal use.
|
||||
PcpNodeRef(PcpPrimIndex_Graph* graph, size_t idx)
|
||||
: _graph(graph), _nodeIdx(idx)
|
||||
{}
|
||||
|
||||
size_t _GetNodeIndex() const { return _nodeIdx; }
|
||||
|
||||
size_t _GetParentIndex() const;
|
||||
size_t _GetOriginIndex() const;
|
||||
|
||||
private: // Data
|
||||
PcpPrimIndex_Graph* _graph;
|
||||
size_t _nodeIdx;
|
||||
};
|
||||
|
||||
/// Typedefs and support functions
|
||||
inline
|
||||
size_t
|
||||
hash_value(const PcpNodeRef& x)
|
||||
{
|
||||
return (size_t)x.GetUniqueIdentifier();
|
||||
}
|
||||
|
||||
typedef TfHashSet<PcpNodeRef, PcpNodeRef::Hash> PcpNodeRefHashSet;
|
||||
typedef std::vector<PcpNodeRef> PcpNodeRefVector;
|
||||
|
||||
/// \class PcpNodeRef_ChildrenIterator
|
||||
///
|
||||
/// Object used to iterate over child nodes (not all descendant nodes) of a
|
||||
/// node in the prim index graph in strong-to-weak order.
|
||||
///
|
||||
class PcpNodeRef_ChildrenIterator
|
||||
: public boost::iterator_facade<
|
||||
/* Derived = */ PcpNodeRef_ChildrenIterator,
|
||||
/* ValueType = */ PcpNodeRef,
|
||||
/* Category = */ boost::forward_traversal_tag,
|
||||
/* RefType = */ PcpNodeRef
|
||||
>
|
||||
{
|
||||
public:
|
||||
/// Constructs an invalid iterator.
|
||||
PCP_API
|
||||
PcpNodeRef_ChildrenIterator();
|
||||
|
||||
/// Constructs an iterator pointing to \p node. Passing a NULL value
|
||||
/// for \p node constructs an end iterator.
|
||||
PCP_API
|
||||
PcpNodeRef_ChildrenIterator(const PcpNodeRef& node, bool end = false);
|
||||
|
||||
private:
|
||||
friend class boost::iterator_core_access;
|
||||
PCP_API
|
||||
void increment();
|
||||
bool equal(const PcpNodeRef_ChildrenIterator& other) const
|
||||
{
|
||||
// Note: The default constructed iterator is *not* equal to any
|
||||
// other iterator.
|
||||
return (_node == other._node && _index == other._index);
|
||||
}
|
||||
reference dereference() const
|
||||
{
|
||||
return reference(_node._graph, _index);
|
||||
}
|
||||
|
||||
private:
|
||||
// Current graph node this iterator is pointing at.
|
||||
PcpNodeRef _node;
|
||||
|
||||
// Index of current child.
|
||||
size_t _index;
|
||||
|
||||
friend class PcpNodeRef_ChildrenReverseIterator;
|
||||
};
|
||||
|
||||
/// \class PcpNodeRef_ChildrenReverseIterator
|
||||
///
|
||||
/// Object used to iterate over nodes in the prim index graph in weak-to-strong
|
||||
/// order.
|
||||
///
|
||||
class PcpNodeRef_ChildrenReverseIterator
|
||||
: public boost::iterator_facade<
|
||||
/* Derived = */ PcpNodeRef_ChildrenReverseIterator,
|
||||
/* ValueType = */ PcpNodeRef,
|
||||
/* Category = */ boost::forward_traversal_tag,
|
||||
/* RefType = */ PcpNodeRef
|
||||
>
|
||||
{
|
||||
public:
|
||||
/// Constructs an invalid iterator.
|
||||
PCP_API
|
||||
PcpNodeRef_ChildrenReverseIterator();
|
||||
|
||||
/// Constructs a reverse iterator from a forward iterator.
|
||||
PCP_API
|
||||
PcpNodeRef_ChildrenReverseIterator(const PcpNodeRef_ChildrenIterator&);
|
||||
|
||||
/// Constructs an iterator pointing to \p node. Passing a NULL value
|
||||
/// for \p node constructs an end iterator.
|
||||
PCP_API
|
||||
PcpNodeRef_ChildrenReverseIterator(const PcpNodeRef& node,bool end = false);
|
||||
|
||||
private:
|
||||
friend class boost::iterator_core_access;
|
||||
PCP_API
|
||||
void increment();
|
||||
bool equal(const PcpNodeRef_ChildrenReverseIterator& other) const
|
||||
{
|
||||
// Note: The default constructed iterator is *not* equal to any
|
||||
// other iterator.
|
||||
return (_node == other._node && _index == other._index);
|
||||
}
|
||||
reference dereference() const
|
||||
{
|
||||
return reference(_node._graph, _index);
|
||||
}
|
||||
|
||||
private:
|
||||
// Current graph node this iterator is pointing at.
|
||||
PcpNodeRef _node;
|
||||
|
||||
// Index of current child.
|
||||
size_t _index;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Tf_IteratorInterface<PcpNodeRef::child_const_range, false> {
|
||||
typedef PcpNodeRef::child_const_iterator IteratorType;
|
||||
static IteratorType Begin(PcpNodeRef::child_const_range const &c)
|
||||
{
|
||||
return c.first;
|
||||
}
|
||||
static IteratorType End(PcpNodeRef::child_const_range const &c)
|
||||
{
|
||||
return c.second;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Tf_IteratorInterface<PcpNodeRef::child_const_range, true> {
|
||||
typedef PcpNodeRef::child_const_reverse_iterator IteratorType;
|
||||
static IteratorType Begin(PcpNodeRef::child_const_range const &c)
|
||||
{
|
||||
return c.second;
|
||||
}
|
||||
static IteratorType End(PcpNodeRef::child_const_range const &c)
|
||||
{
|
||||
return c.first;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Tf_ShouldIterateOverCopy<PcpNodeRef::child_const_range> :
|
||||
boost::true_type {};
|
||||
|
||||
// Helper to count the non-variant path components of a path; equivalent
|
||||
// to path.StripAllVariantSelections().GetPathElementCount() except
|
||||
// this method avoids constructing a new SdfPath value.
|
||||
int PcpNode_GetNonVariantPathElementCount(const SdfPath &path);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_NODE_H
|
||||
@@ -0,0 +1,116 @@
|
||||
//
|
||||
// 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_PCP_PATH_TRANSLATION_H
|
||||
#define PXR_USD_PCP_PATH_TRANSLATION_H
|
||||
|
||||
/// \file pcp/pathTranslation.h
|
||||
/// Path translation.
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class PcpMapFunction;
|
||||
class PcpNodeRef;
|
||||
class SdfPath;
|
||||
|
||||
/// Translates \p pathInNodeNamespace from the namespace of the prim index node
|
||||
/// \p sourceNode to the namespace of the prim index's root node. This applies
|
||||
/// all necessary namespace translations.
|
||||
///
|
||||
/// If the path is successfully translated and \p pathWasTranslated is supplied,
|
||||
/// it will be set to \c true. In some cases, paths may fail to translate
|
||||
/// because they fall outside the set of paths that are allowed by nodes in the
|
||||
/// prim index. For instance, for a referenced model, paths referring to
|
||||
/// locations outside that model will not be translated. In these cases, this
|
||||
/// function will return an empty SdfPath and \p pathWasTranslated will be set
|
||||
/// to \c false.
|
||||
///
|
||||
/// In Sd/Csd terminology, this is forward path translation from the
|
||||
/// namespace of the prim spec represented by \p sourceNode to the composed
|
||||
/// scene namespace.
|
||||
PCP_API
|
||||
SdfPath
|
||||
PcpTranslatePathFromNodeToRoot(
|
||||
const PcpNodeRef& sourceNode,
|
||||
const SdfPath& pathInNodeNamespace,
|
||||
bool* pathWasTranslated = 0);
|
||||
|
||||
/// Translates \p pathInRootNamespace from the namespace of the root of the
|
||||
/// prim index that \p destNode belongs to to the namespace of \p destNode
|
||||
/// itself. This applies all necessary namespace translations.
|
||||
///
|
||||
/// If the path is successfully translated and \p pathWasTranslated is supplied,
|
||||
/// it will be set to \c true. In some cases, paths may fail to translate
|
||||
/// because they fall outside the set of paths that are allowed by nodes in the
|
||||
/// prim index. For instance, for a referenced model, paths referring to
|
||||
/// locations outside that model will not be translated. In these cases, this
|
||||
/// function will return an empty SdfPath and \p pathWasTranslated will be set
|
||||
/// to \c false.
|
||||
///
|
||||
/// In Sd/Csd terminology, this is reverse path translation from the
|
||||
/// namespace of the composed scene to the namespace of the prim spec
|
||||
/// represented by \p destNode.
|
||||
PCP_API
|
||||
SdfPath
|
||||
PcpTranslatePathFromRootToNode(
|
||||
const PcpNodeRef& destNode,
|
||||
const SdfPath& pathInRootNamespace,
|
||||
bool* pathWasTranslated = 0);
|
||||
|
||||
/// Same as \a PcpTranslatePathFromRootToNode, but explicitly for use when
|
||||
/// translating paths intended for use as attribute connections or relationship
|
||||
/// targets. The primary difference is that variant selections will never
|
||||
/// be included in the translated path. This is functionally equivalent to
|
||||
/// calling StripAllVariantSelections() on the result of the referenced
|
||||
/// function, but is more efficient.
|
||||
PCP_API
|
||||
SdfPath
|
||||
PcpTranslateTargetPathFromRootToNode(
|
||||
const PcpNodeRef& destNode,
|
||||
const SdfPath& pathInRootNamespace,
|
||||
bool* pathWasTranslated = 0);
|
||||
|
||||
/// Convenience function like \a PcpTranslatePathFromRootToNode, but
|
||||
/// takes a function rather than a node.
|
||||
PCP_API
|
||||
SdfPath
|
||||
PcpTranslatePathFromRootToNodeUsingFunction(
|
||||
const PcpMapFunction &mapToRoot,
|
||||
const SdfPath &pathInRootNamespace,
|
||||
bool *pathWasTranslated = 0);
|
||||
|
||||
/// Convenience function like \a PcpTranslatePathFromNodeToRoot, but
|
||||
/// takes a function rather than a node.
|
||||
PCP_API
|
||||
SdfPath
|
||||
PcpTranslatePathFromNodeToRootUsingFunction(
|
||||
const PcpMapFunction &mapToRoot,
|
||||
const SdfPath &pathInNodeNamespace,
|
||||
bool *pathWasTranslated = 0);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_PATH_TRANSLATION_H
|
||||
@@ -0,0 +1,432 @@
|
||||
//
|
||||
// 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_PCP_PRIM_INDEX_H
|
||||
#define PXR_USD_PCP_PRIM_INDEX_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/pcp/composeSite.h"
|
||||
#include "pxr/usd/pcp/dynamicFileFormatDependencyData.h"
|
||||
#include "pxr/usd/pcp/errors.h"
|
||||
#include "pxr/usd/pcp/iterator.h"
|
||||
#include "pxr/usd/pcp/node.h"
|
||||
#include "pxr/usd/pcp/types.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/usd/sdf/site.h"
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
#include "pxr/base/tf/hashmap.h"
|
||||
#include "pxr/base/tf/hashset.h"
|
||||
|
||||
#include <tbb/spin_rw_mutex.h>
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
SDF_DECLARE_HANDLES(SdfLayer);
|
||||
SDF_DECLARE_HANDLES(SdfPrimSpec);
|
||||
|
||||
TF_DECLARE_REF_PTRS(PcpLayerStack);
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(PcpPrimIndex_Graph);
|
||||
|
||||
class ArResolver;
|
||||
class PcpCache;
|
||||
class PcpPrimIndex;
|
||||
class PcpPrimIndexInputs;
|
||||
class PcpPrimIndexOutputs;
|
||||
class SdfPath;
|
||||
|
||||
/// \class PcpPrimIndex
|
||||
///
|
||||
/// PcpPrimIndex is an index of the all sites of scene description that
|
||||
/// contribute opinions to a specific prim, under composition
|
||||
/// semantics.
|
||||
///
|
||||
/// PcpComputePrimIndex() builds an index ("indexes") the given prim site.
|
||||
/// At any site there may be scene description values expressing arcs
|
||||
/// that represent instructions to pull in further scene description.
|
||||
/// PcpComputePrimIndex() recursively follows these arcs, building and
|
||||
/// ordering the results.
|
||||
///
|
||||
class PcpPrimIndex
|
||||
{
|
||||
public:
|
||||
/// Default construct an empty, invalid prim index.
|
||||
PCP_API
|
||||
PcpPrimIndex();
|
||||
|
||||
/// Copy-construct a prim index.
|
||||
PCP_API
|
||||
PcpPrimIndex(const PcpPrimIndex& rhs);
|
||||
|
||||
/// Assignment.
|
||||
PcpPrimIndex &operator=(const PcpPrimIndex &rhs) {
|
||||
PcpPrimIndex(rhs).Swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Swap the contents of this prim index with \p index.
|
||||
PCP_API
|
||||
void Swap(PcpPrimIndex& rhs);
|
||||
|
||||
/// Same as Swap(), but standard name.
|
||||
inline void swap(PcpPrimIndex &rhs) { Swap(rhs); }
|
||||
|
||||
/// Return true if this index is valid.
|
||||
/// A default-constructed index is invalid.
|
||||
bool IsValid() const { return bool(_graph); }
|
||||
|
||||
PCP_API
|
||||
void SetGraph(const PcpPrimIndex_GraphRefPtr& graph);
|
||||
PCP_API
|
||||
PcpPrimIndex_GraphPtr GetGraph() const;
|
||||
|
||||
/// Returns the root node of the prim index graph.
|
||||
PCP_API
|
||||
PcpNodeRef GetRootNode() const;
|
||||
|
||||
/// Returns the path of the prim whose opinions are represented by this
|
||||
/// prim index.
|
||||
PCP_API
|
||||
const SdfPath& GetPath() const;
|
||||
|
||||
/// Returns true if this prim index contains any scene description
|
||||
/// opinions.
|
||||
PCP_API
|
||||
bool HasSpecs() const;
|
||||
|
||||
/// Returns true if the prim has any authored payload arcs.
|
||||
/// The payload contents are only resolved and included
|
||||
/// if this prim's path is in the payload inclusion set
|
||||
/// provided in PcpPrimIndexInputs.
|
||||
PCP_API
|
||||
bool HasAnyPayloads() const;
|
||||
|
||||
/// Returns true if this prim index was composed in USD mode.
|
||||
/// \see PcpCache::IsUsd().
|
||||
PCP_API
|
||||
bool IsUsd() const;
|
||||
|
||||
/// Returns true if this prim index is instanceable.
|
||||
/// Instanceable prim indexes with the same instance key are
|
||||
/// guaranteed to have the same set of opinions, but may not have
|
||||
/// local opinions about name children.
|
||||
/// \see PcpInstanceKey
|
||||
PCP_API
|
||||
bool IsInstanceable() const;
|
||||
|
||||
/// \name Iteration
|
||||
/// @{
|
||||
|
||||
/// Returns range of iterators that encompass all children of the root node
|
||||
/// with the given arc type as well as their descendants, in
|
||||
/// strong-to-weak order.
|
||||
///
|
||||
/// By default, this returns a range encompassing the entire index.
|
||||
PCP_API
|
||||
PcpNodeRange GetNodeRange(PcpRangeType rangeType = PcpRangeTypeAll) const;
|
||||
|
||||
/// Returns range of iterators that encompasses all prims, in
|
||||
/// strong-to-weak order.
|
||||
PCP_API
|
||||
PcpPrimRange GetPrimRange(PcpRangeType rangeType = PcpRangeTypeAll) const;
|
||||
|
||||
/// Returns range of iterators that encompasses all prims from the
|
||||
/// site of \p node. \p node must belong to this prim index.
|
||||
PCP_API
|
||||
PcpPrimRange GetPrimRangeForNode(const PcpNodeRef& node) const;
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name Lookup
|
||||
/// @{
|
||||
|
||||
/// Returns the node that brings opinions from \p primSpec into
|
||||
/// this prim index. If no such node exists, returns an invalid PcpNodeRef.
|
||||
PCP_API
|
||||
PcpNodeRef GetNodeProvidingSpec(const SdfPrimSpecHandle& primSpec) const;
|
||||
|
||||
/// Returns the node that brings opinions from the Sd prim spec at \p layer
|
||||
/// and \p path into this prim index. If no such node exists, returns an
|
||||
/// invalid PcpNodeRef.
|
||||
PCP_API
|
||||
PcpNodeRef GetNodeProvidingSpec(
|
||||
const SdfLayerHandle& layer, const SdfPath& path) const;
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name Diagnostics
|
||||
/// @{
|
||||
|
||||
/// Return the list of errors local to this prim.
|
||||
PcpErrorVector GetLocalErrors() const {
|
||||
return _localErrors ? *_localErrors.get() : PcpErrorVector();
|
||||
}
|
||||
|
||||
/// Prints various statistics about this prim index.
|
||||
PCP_API
|
||||
void PrintStatistics() const;
|
||||
|
||||
/// Dump the prim index contents to a string.
|
||||
///
|
||||
/// If \p includeInheritOriginInfo is \c true, output for implied inherit
|
||||
/// nodes will include information about the originating inherit node.
|
||||
/// If \p includeMaps is \c true, output for each node will include the
|
||||
/// mappings to the parent and root node.
|
||||
PCP_API
|
||||
std::string DumpToString(
|
||||
bool includeInheritOriginInfo = true,
|
||||
bool includeMaps = true) const;
|
||||
|
||||
/// Dump the prim index in dot format to the file named \p filename.
|
||||
/// See Dump(...) for information regarding arguments.
|
||||
PCP_API
|
||||
void DumpToDotGraph(
|
||||
const std::string& filename,
|
||||
bool includeInheritOriginInfo = true,
|
||||
bool includeMaps = false) const;
|
||||
|
||||
/// @}
|
||||
|
||||
|
||||
/// \name Derived computations
|
||||
/// @{
|
||||
|
||||
/// Compute the prim child names for the given path. \p errors will
|
||||
/// contain any errors encountered while performing this operation.
|
||||
PCP_API
|
||||
void ComputePrimChildNames(TfTokenVector *nameOrder,
|
||||
PcpTokenSet *prohibitedNameSet) const;
|
||||
|
||||
/// Compute the prim property names for the given path. \p errors will
|
||||
/// contain any errors encountered while performing this operation. The
|
||||
/// \p nameOrder vector must not contain any duplicate entries.
|
||||
PCP_API
|
||||
void ComputePrimPropertyNames(TfTokenVector *nameOrder) const;
|
||||
|
||||
/// Compose the authored prim variant selections.
|
||||
///
|
||||
/// These are the variant selections expressed in scene description.
|
||||
/// Note that these selections may not have actually been applied,
|
||||
/// if they are invalid.
|
||||
///
|
||||
/// \note This result is not cached, but computed each time.
|
||||
PCP_API
|
||||
SdfVariantSelectionMap ComposeAuthoredVariantSelections() const;
|
||||
|
||||
/// Return the variant selection applied for the named variant set.
|
||||
/// If none was applied, this returns an empty string.
|
||||
/// This can be different from the authored variant selection;
|
||||
/// for example, if the authored selection is invalid.
|
||||
PCP_API
|
||||
std::string GetSelectionAppliedForVariantSet(
|
||||
const std::string &variantSet) const;
|
||||
|
||||
/// @}
|
||||
|
||||
private:
|
||||
friend class PcpPrimIterator;
|
||||
friend struct Pcp_PrimIndexer;
|
||||
friend void Pcp_RescanForSpecs(PcpPrimIndex*, bool usd,
|
||||
bool updateHasSpecs);
|
||||
|
||||
// The node graph representing the compositional structure of this prim.
|
||||
PcpPrimIndex_GraphRefPtr _graph;
|
||||
|
||||
// The prim stack. This is just a derived structure representing
|
||||
// a cached strong-to-weak traversal of the graph collecting specs.
|
||||
Pcp_CompressedSdSiteVector _primStack;
|
||||
|
||||
// List of errors local to this prim, encountered during computation.
|
||||
// NULL if no errors were found (the expected common case).
|
||||
std::unique_ptr<PcpErrorVector> _localErrors;
|
||||
};
|
||||
|
||||
/// Free function version for generic code and ADL.
|
||||
inline void swap(PcpPrimIndex &l, PcpPrimIndex &r) { l.swap(r); }
|
||||
|
||||
/// \class PcpPrimIndexOutputs
|
||||
///
|
||||
/// Outputs of the prim indexing procedure.
|
||||
///
|
||||
class PcpPrimIndexOutputs
|
||||
{
|
||||
public:
|
||||
/// Enumerator whose enumerants describe the payload state of this prim
|
||||
/// index. NoPayload if the index has no payload arcs, otherwise whether
|
||||
/// payloads were included or excluded, and if done so by consulting either
|
||||
/// the cache's payload include set, or determined by a payload predicate.
|
||||
enum PayloadState { NoPayload,
|
||||
IncludedByIncludeSet, ExcludedByIncludeSet,
|
||||
IncludedByPredicate, ExcludedByPredicate };
|
||||
|
||||
/// Prim index describing the composition structure for the associated
|
||||
/// prim.
|
||||
PcpPrimIndex primIndex;
|
||||
|
||||
/// List of all errors encountered during indexing.
|
||||
PcpErrorVector allErrors;
|
||||
|
||||
/// Indicates the payload state of this index. See documentation for
|
||||
/// PayloadState enum for more information.
|
||||
PayloadState payloadState = NoPayload;
|
||||
|
||||
/// A list of names of fields that were composed to generate dynamic file
|
||||
/// format arguments for a node in primIndex. These are not necessarily
|
||||
/// fields that had values, but is the list of all fields that a composed
|
||||
/// value was requested for.
|
||||
PcpDynamicFileFormatDependencyData dynamicFileFormatDependency;
|
||||
|
||||
/// Swap content with \p r.
|
||||
inline void swap(PcpPrimIndexOutputs &r) {
|
||||
primIndex.swap(r.primIndex);
|
||||
allErrors.swap(r.allErrors);
|
||||
std::swap(payloadState, r.payloadState);
|
||||
dynamicFileFormatDependency.swap(r.dynamicFileFormatDependency);
|
||||
}
|
||||
|
||||
/// Appends the outputs from \p childOutputs to this object, using
|
||||
/// \p arcToParent to connect \p childOutputs' prim index to this object's
|
||||
/// prim index.
|
||||
///
|
||||
/// Returns the node in this object's prim index corresponding to the root
|
||||
/// node of \p childOutputs' prim index.
|
||||
PcpNodeRef Append(PcpPrimIndexOutputs&& childOutputs,
|
||||
const PcpArc& arcToParent,
|
||||
PcpErrorBasePtr *error);
|
||||
};
|
||||
|
||||
/// Free function version for generic code and ADL.
|
||||
inline void swap(PcpPrimIndexOutputs &l, PcpPrimIndexOutputs &r) { l.swap(r); }
|
||||
|
||||
/// \class PcpPrimIndexInputs
|
||||
///
|
||||
/// Inputs for the prim indexing procedure.
|
||||
///
|
||||
class PcpPrimIndexInputs {
|
||||
public:
|
||||
PcpPrimIndexInputs()
|
||||
: cache(nullptr)
|
||||
, variantFallbacks(nullptr)
|
||||
, includedPayloads(nullptr)
|
||||
, includedPayloadsMutex(nullptr)
|
||||
, parentIndex(nullptr)
|
||||
, cull(true)
|
||||
, usd(false)
|
||||
{ }
|
||||
|
||||
/// Returns true if prim index computations using this parameters object
|
||||
/// would be equivalent to computations using \p params.
|
||||
bool IsEquivalentTo(const PcpPrimIndexInputs& params) const;
|
||||
|
||||
/// If supplied, the given PcpCache will be used where possible to compute
|
||||
/// needed intermediate results.
|
||||
PcpPrimIndexInputs& Cache(PcpCache* cache_)
|
||||
{ cache = cache_; return *this; }
|
||||
|
||||
/// Ordered list of variant names to use for the "standin" variant set
|
||||
/// if there is no authored opinion in scene description.
|
||||
PcpPrimIndexInputs& VariantFallbacks(const PcpVariantFallbackMap* map)
|
||||
{ variantFallbacks = map; return *this; }
|
||||
|
||||
/// Set of paths to prims that should have their payloads included
|
||||
/// during composition.
|
||||
using PayloadSet = std::unordered_set<SdfPath, SdfPath::Hash>;
|
||||
PcpPrimIndexInputs& IncludedPayloads(const PayloadSet* payloadSet)
|
||||
{ includedPayloads = payloadSet; return *this; }
|
||||
|
||||
/// Optional mutex for accessing includedPayloads.
|
||||
PcpPrimIndexInputs &IncludedPayloadsMutex(tbb::spin_rw_mutex *mutex)
|
||||
{ includedPayloadsMutex = mutex; return *this; }
|
||||
|
||||
/// Optional predicate evaluated when a not-yet-included payload is
|
||||
/// discovered while indexing. If the predicate returns true, indexing
|
||||
/// includes the payload and sets the includedDiscoveredPayload bit in the
|
||||
/// outputs.
|
||||
PcpPrimIndexInputs &IncludePayloadPredicate(
|
||||
std::function<bool (const SdfPath &)> predicate)
|
||||
{ includePayloadPredicate = predicate; return *this; }
|
||||
|
||||
/// Whether subtrees that contribute no opinions should be culled
|
||||
/// from the index.
|
||||
PcpPrimIndexInputs& Cull(bool doCulling = true)
|
||||
{ cull = doCulling; return *this; }
|
||||
|
||||
/// Whether the prim stack should be computed, and
|
||||
/// whether relocates, inherits, permissions, symmetry, or payloads should
|
||||
/// be considered during prim index computation,
|
||||
PcpPrimIndexInputs& USD(bool doUSD = true)
|
||||
{ usd = doUSD; return *this; }
|
||||
|
||||
/// The file format target for scene description layers encountered during
|
||||
/// prim index computation.
|
||||
PcpPrimIndexInputs& FileFormatTarget(const std::string& target)
|
||||
{ fileFormatTarget = target; return *this; }
|
||||
|
||||
// private:
|
||||
PcpCache* cache;
|
||||
const PcpVariantFallbackMap* variantFallbacks;
|
||||
const PayloadSet* includedPayloads;
|
||||
tbb::spin_rw_mutex *includedPayloadsMutex;
|
||||
std::function<bool (const SdfPath &)> includePayloadPredicate;
|
||||
const PcpPrimIndex *parentIndex;
|
||||
std::string fileFormatTarget;
|
||||
bool cull;
|
||||
bool usd;
|
||||
};
|
||||
|
||||
/// Compute an index for the given path. \p errors will contain any errors
|
||||
/// encountered while performing this operation.
|
||||
PCP_API
|
||||
void
|
||||
PcpComputePrimIndex(
|
||||
const SdfPath& primPath,
|
||||
const PcpLayerStackPtr& layerStack,
|
||||
const PcpPrimIndexInputs& inputs,
|
||||
PcpPrimIndexOutputs* outputs,
|
||||
ArResolver* pathResolver = NULL);
|
||||
|
||||
/// Returns true if the 'new' default standin behavior is enabled.
|
||||
PCP_API
|
||||
bool
|
||||
PcpIsNewDefaultStandinBehaviorEnabled();
|
||||
|
||||
// Sets the prim stack in \p index.
|
||||
void
|
||||
Pcp_RescanForSpecs(PcpPrimIndex* index, bool usd);
|
||||
|
||||
// Returns true if \p index should be recomputed due to changes to
|
||||
// any computed asset paths that were used to find or open layers
|
||||
// when originally composing \p index. This may be due to scene
|
||||
// description changes or external changes to asset resolution that
|
||||
// may affect the computation of those asset paths.
|
||||
bool
|
||||
Pcp_NeedToRecomputeDueToAssetPathChange(const PcpPrimIndex& index);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_PRIM_INDEX_H
|
||||
@@ -0,0 +1,138 @@
|
||||
//
|
||||
// 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_PCP_PROPERTY_INDEX_H
|
||||
#define PXR_USD_PCP_PROPERTY_INDEX_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/pcp/errors.h"
|
||||
#include "pxr/usd/pcp/iterator.h"
|
||||
#include "pxr/usd/pcp/node.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/usd/sdf/propertySpec.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
// Forward declarations:
|
||||
class PcpCache;
|
||||
|
||||
/// \class Pcp_PropertyInfo
|
||||
///
|
||||
/// Private helper structure containing information about a property in the
|
||||
/// property stack.
|
||||
///
|
||||
struct Pcp_PropertyInfo
|
||||
{
|
||||
Pcp_PropertyInfo() { }
|
||||
Pcp_PropertyInfo(const SdfPropertySpecHandle& prop, const PcpNodeRef& node)
|
||||
: propertySpec(prop), originatingNode(node) { }
|
||||
|
||||
SdfPropertySpecHandle propertySpec;
|
||||
PcpNodeRef originatingNode;
|
||||
};
|
||||
|
||||
/// \class PcpPropertyIndex
|
||||
///
|
||||
/// PcpPropertyIndex is an index of all sites in scene description that
|
||||
/// contribute opinions to a specific property, under composition
|
||||
/// semantics.
|
||||
///
|
||||
class PcpPropertyIndex
|
||||
{
|
||||
public:
|
||||
/// Construct an empty property index.
|
||||
PCP_API
|
||||
PcpPropertyIndex();
|
||||
|
||||
/// Copy-construct a property index.
|
||||
PCP_API
|
||||
PcpPropertyIndex(const PcpPropertyIndex &rhs);
|
||||
|
||||
/// Swap the contents of this property index with \p index.
|
||||
PCP_API
|
||||
void Swap(PcpPropertyIndex& index);
|
||||
|
||||
/// Returns true if this property index contains no opinions, false
|
||||
/// otherwise.
|
||||
PCP_API
|
||||
bool IsEmpty() const;
|
||||
|
||||
/// Returns range of iterators that encompasses properties in this
|
||||
/// index's property stack.
|
||||
///
|
||||
/// By default, this returns a range encompassing all properties in the
|
||||
/// index. If \p localOnly is specified, the range will only include
|
||||
/// properties from local nodes in its owning prim's graph.
|
||||
PCP_API
|
||||
PcpPropertyRange GetPropertyRange(bool localOnly = false) const;
|
||||
|
||||
/// Return the list of errors local to this property.
|
||||
PcpErrorVector GetLocalErrors() const {
|
||||
return _localErrors ? *_localErrors.get() : PcpErrorVector();
|
||||
}
|
||||
|
||||
/// Returns the number of local properties in this prim index.
|
||||
PCP_API
|
||||
size_t GetNumLocalSpecs() const;
|
||||
|
||||
private:
|
||||
friend class PcpPropertyIterator;
|
||||
friend class Pcp_PropertyIndexer;
|
||||
|
||||
// The property stack is a list of Pcp_PropertyInfo objects in
|
||||
// strong-to-weak order.
|
||||
std::vector<Pcp_PropertyInfo> _propertyStack;
|
||||
|
||||
/// List of errors local to this property, encountered during computation.
|
||||
/// NULL if no errors were found (the expected common case).
|
||||
std::unique_ptr<PcpErrorVector> _localErrors;
|
||||
};
|
||||
|
||||
/// Builds a property index for the property at \p path,
|
||||
/// internally computing and caching an owning prim index as necessary.
|
||||
/// \p allErrors will contain any errors encountered.
|
||||
PCP_API
|
||||
void
|
||||
PcpBuildPropertyIndex( const SdfPath& propertyPath,
|
||||
PcpCache *cache,
|
||||
PcpPropertyIndex *propertyIndex,
|
||||
PcpErrorVector *allErrors );
|
||||
|
||||
/// Builds a prim property index for the property at \p propertyPath.
|
||||
/// \p allErrors will contain any errors encountered.
|
||||
PCP_API
|
||||
void
|
||||
PcpBuildPrimPropertyIndex( const SdfPath& propertyPath,
|
||||
const PcpCache& cache,
|
||||
const PcpPrimIndex& owningPrimIndex,
|
||||
PcpPropertyIndex *propertyIndex,
|
||||
PcpErrorVector *allErrors );
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_PROPERTY_INDEX_H
|
||||
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// 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_PCP_PY_UTILS_H
|
||||
#define PXR_USD_PCP_PY_UTILS_H
|
||||
|
||||
#include <boost/python/dict.hpp>
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/pcp/types.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// Convert the Python dictionary \p dict to a PcpVariantFallbackMap
|
||||
/// object and return it via \p result, returning true if successful.
|
||||
PCP_API
|
||||
bool
|
||||
PcpVariantFallbackMapFromPython(
|
||||
const boost::python::dict& dict,
|
||||
PcpVariantFallbackMap *result);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_PY_UTILS_H
|
||||
@@ -0,0 +1,171 @@
|
||||
//
|
||||
// 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_PCP_SITE_H
|
||||
#define PXR_USD_PCP_SITE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/pcp/layerStackIdentifier.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/usd/sdf/types.h"
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
|
||||
#include <boost/operators.hpp>
|
||||
#include <iosfwd>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(PcpLayerStack);
|
||||
class PcpLayerStackSite;
|
||||
|
||||
/// \class PcpSite
|
||||
///
|
||||
/// A site specifies a path in a layer stack of scene description.
|
||||
///
|
||||
class PcpSite : boost::totally_ordered<PcpSite>
|
||||
{
|
||||
public:
|
||||
PcpLayerStackIdentifier layerStackIdentifier;
|
||||
SdfPath path;
|
||||
|
||||
PCP_API
|
||||
PcpSite();
|
||||
|
||||
PCP_API
|
||||
PcpSite( const PcpLayerStackIdentifier &, const SdfPath & path );
|
||||
PCP_API
|
||||
PcpSite( const PcpLayerStackPtr &, const SdfPath & path );
|
||||
PCP_API
|
||||
PcpSite( const SdfLayerHandle &, const SdfPath & path );
|
||||
PCP_API
|
||||
explicit PcpSite( const PcpLayerStackSite & );
|
||||
|
||||
PCP_API
|
||||
bool operator==(const PcpSite &rhs) const;
|
||||
|
||||
PCP_API
|
||||
bool operator<(const PcpSite &rhs) const;
|
||||
|
||||
struct Hash {
|
||||
PCP_API
|
||||
size_t operator()(const PcpSite &) const;
|
||||
};
|
||||
};
|
||||
|
||||
/// \class PcpSiteStr
|
||||
///
|
||||
/// A "string-based" version of PcpSite. This stores layer identifiers as
|
||||
/// strings rather than SdfLayerHandles, making it stable wrt layer lifetimes.
|
||||
///
|
||||
class PcpSiteStr : boost::totally_ordered<PcpSiteStr>
|
||||
{
|
||||
public:
|
||||
PcpLayerStackIdentifierStr layerStackIdentifierStr;
|
||||
SdfPath path;
|
||||
|
||||
PCP_API
|
||||
PcpSiteStr();
|
||||
|
||||
PCP_API
|
||||
PcpSiteStr( const PcpLayerStackIdentifierStr &, const SdfPath & path );
|
||||
PCP_API
|
||||
PcpSiteStr( const PcpLayerStackIdentifier &, const SdfPath & path );
|
||||
PCP_API
|
||||
PcpSiteStr( const SdfLayerHandle &, const SdfPath & path );
|
||||
PCP_API
|
||||
PcpSiteStr(PcpLayerStackSite const &);
|
||||
PCP_API
|
||||
PcpSiteStr(PcpSite const &);
|
||||
|
||||
PCP_API
|
||||
bool operator==(const PcpSiteStr &rhs) const;
|
||||
|
||||
PCP_API
|
||||
bool operator<(const PcpSiteStr &rhs) const;
|
||||
|
||||
struct Hash {
|
||||
PCP_API
|
||||
size_t operator()(const PcpSiteStr &) const;
|
||||
};
|
||||
};
|
||||
|
||||
/// \class PcpLayerStackSite
|
||||
///
|
||||
/// A site specifies a path in a layer stack of scene description.
|
||||
///
|
||||
class PcpLayerStackSite : boost::totally_ordered<PcpLayerStackSite>
|
||||
{
|
||||
public:
|
||||
PcpLayerStackRefPtr layerStack;
|
||||
SdfPath path;
|
||||
|
||||
PCP_API
|
||||
PcpLayerStackSite();
|
||||
|
||||
PCP_API
|
||||
PcpLayerStackSite( const PcpLayerStackRefPtr &, const SdfPath & path );
|
||||
|
||||
PCP_API
|
||||
bool operator==(const PcpLayerStackSite &rhs) const;
|
||||
|
||||
PCP_API
|
||||
bool operator<(const PcpLayerStackSite &rhs) const;
|
||||
|
||||
struct Hash {
|
||||
PCP_API
|
||||
size_t operator()(const PcpLayerStackSite &) const;
|
||||
};
|
||||
};
|
||||
|
||||
PCP_API
|
||||
std::ostream& operator<<(std::ostream&, const PcpSite&);
|
||||
PCP_API
|
||||
std::ostream& operator<<(std::ostream&, const PcpSiteStr&);
|
||||
PCP_API
|
||||
std::ostream& operator<<(std::ostream&, const PcpLayerStackSite&);
|
||||
|
||||
static inline
|
||||
size_t
|
||||
hash_value(const PcpSite& site)
|
||||
{
|
||||
return PcpSite::Hash()(site);
|
||||
}
|
||||
|
||||
static inline
|
||||
size_t
|
||||
hash_value(const PcpSiteStr& site)
|
||||
{
|
||||
return PcpSiteStr::Hash()(site);
|
||||
}
|
||||
|
||||
static inline
|
||||
size_t
|
||||
hash_value(const PcpLayerStackSite& site)
|
||||
{
|
||||
return PcpLayerStackSite::Hash()(site);
|
||||
}
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_SITE_H
|
||||
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// 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_PCP_STRENGTH_ORDERING_H
|
||||
#define PXR_USD_PCP_STRENGTH_ORDERING_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class PcpNodeRef;
|
||||
|
||||
/// Compares the strength of nodes \p a and \p b. These nodes must be siblings;
|
||||
/// it is a coding error if \p a and \p b do not have the same parent node.
|
||||
///
|
||||
/// Returns -1 if a is stronger than b,
|
||||
/// 0 if a is equivalent to b,
|
||||
/// 1 if a is weaker than b
|
||||
PCP_API
|
||||
int
|
||||
PcpCompareSiblingNodeStrength(const PcpNodeRef& a, const PcpNodeRef& b);
|
||||
|
||||
/// Compares the strength of nodes \p a and \p b. These nodes must be part
|
||||
/// of the same graph; it is a coding error if \p a and \p b do not have the
|
||||
/// same root node.
|
||||
///
|
||||
/// Returns -1 if a is stronger than b,
|
||||
/// 0 if a is equivalent to b,
|
||||
/// 1 if a is weaker than b
|
||||
PCP_API
|
||||
int
|
||||
PcpCompareNodeStrength(const PcpNodeRef& a, const PcpNodeRef& b);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_STRENGTH_ORDERING_H
|
||||
@@ -0,0 +1,108 @@
|
||||
//
|
||||
// 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_PCP_TARGET_INDEX_H
|
||||
#define PXR_USD_PCP_TARGET_INDEX_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/pcp/errors.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
SDF_DECLARE_HANDLES(SdfSpec);
|
||||
class PcpCache;
|
||||
class PcpPropertyIndex;
|
||||
|
||||
/// \class PcpTargetIndex
|
||||
///
|
||||
/// A PcpTargetIndex represents the results of indexing the target
|
||||
/// paths of a relationship or attribute. Note that this is just
|
||||
/// the result; it does not retain all of the input arguments used
|
||||
/// in computing the index, such as the owning property.
|
||||
///
|
||||
struct PcpTargetIndex {
|
||||
SdfPathVector paths;
|
||||
PcpErrorVector localErrors;
|
||||
bool hasTargetOpinions = false;
|
||||
};
|
||||
|
||||
/// Build a PcpTargetIndex representing the target paths of the given
|
||||
/// property.
|
||||
///
|
||||
/// \p propIndex is a PcpPropertyIndex of the relationship or attribute.
|
||||
/// \p relOrAttrType indicates if the property is a relationship
|
||||
/// or attribute.
|
||||
/// \p allErrors will contain any errors encountered while
|
||||
/// performing this operation.
|
||||
///
|
||||
/// Note that this function will skip the validation checks performed
|
||||
/// by PcpBuildFilteredTargetIndex. See documentation below for details.
|
||||
PCP_API
|
||||
void
|
||||
PcpBuildTargetIndex(
|
||||
const PcpSite& propSite,
|
||||
const PcpPropertyIndex& propIndex,
|
||||
const SdfSpecType relOrAttrType,
|
||||
PcpTargetIndex *targetIndex,
|
||||
PcpErrorVector *allErrors);
|
||||
|
||||
/// Like PcpBuildTargetIndex, but optionally filters the result by
|
||||
/// enforcing permissions restrictions and a stopProperty.
|
||||
///
|
||||
/// If \p localOnly is \c true then this will compose relationship
|
||||
/// targets from local nodes only. If \p stopProperty is not \c
|
||||
/// NULL then this will stop composing relationship targets at \p
|
||||
/// stopProperty, including \p stopProperty iff \p includeStopProperty
|
||||
/// is \c true.
|
||||
///
|
||||
/// \p cacheForValidation is a PcpCache that will be used to compute
|
||||
/// additional prim indexes as needed for validation. NULL may be
|
||||
/// passed in, but doing so will disable validation that relies on
|
||||
/// this cache, which includes permissions checks.
|
||||
///
|
||||
/// \p deletedPaths, if not \c NULL, will be populated with target
|
||||
/// paths whose deletion contributed to the computed value of
|
||||
/// \c targetIndex->paths.
|
||||
///
|
||||
/// \p allErrors will contain any errors encountered while
|
||||
/// performing this operation.
|
||||
PCP_API
|
||||
void
|
||||
PcpBuildFilteredTargetIndex(
|
||||
const PcpSite& propSite,
|
||||
const PcpPropertyIndex& propIndex,
|
||||
const SdfSpecType relOrAttrType,
|
||||
const bool localOnly,
|
||||
const SdfSpecHandle &stopProperty,
|
||||
const bool includeStopProperty,
|
||||
PcpCache *cacheForValidation,
|
||||
PcpTargetIndex *targetIndex,
|
||||
SdfPathVector *deletedPaths,
|
||||
PcpErrorVector *allErrors);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_TARGET_INDEX_H
|
||||
@@ -0,0 +1,204 @@
|
||||
//
|
||||
// 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_PCP_TYPES_H
|
||||
#define PXR_USD_PCP_TYPES_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/pcp/api.h"
|
||||
#include "pxr/usd/pcp/site.h"
|
||||
#include "pxr/usd/sdf/layer.h"
|
||||
#include "pxr/base/tf/denseHashSet.h"
|
||||
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/operators.hpp>
|
||||
|
||||
/// \file pcp/types.h
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \enum PcpArcType
|
||||
///
|
||||
/// Describes the type of arc connecting two nodes in the prim index.
|
||||
///
|
||||
enum PcpArcType {
|
||||
// The root arc is a special value used for the root node of
|
||||
// the prim index. Unlike the following arcs, it has no parent node.
|
||||
PcpArcTypeRoot,
|
||||
|
||||
// The following arcs are listed in strength order.
|
||||
PcpArcTypeInherit,
|
||||
PcpArcTypeVariant,
|
||||
PcpArcTypeRelocate,
|
||||
PcpArcTypeReference,
|
||||
PcpArcTypePayload,
|
||||
PcpArcTypeSpecialize,
|
||||
|
||||
PcpNumArcTypes
|
||||
};
|
||||
|
||||
/// \enum PcpRangeType
|
||||
enum PcpRangeType {
|
||||
// Range including just the root node.
|
||||
PcpRangeTypeRoot,
|
||||
|
||||
// Ranges including child arcs, from the root node, of the specified type
|
||||
// as well as all descendants of those arcs.
|
||||
PcpRangeTypeInherit,
|
||||
PcpRangeTypeVariant,
|
||||
PcpRangeTypeReference,
|
||||
PcpRangeTypePayload,
|
||||
PcpRangeTypeSpecialize,
|
||||
|
||||
// Range including all nodes.
|
||||
PcpRangeTypeAll,
|
||||
|
||||
// Range including all nodes weaker than the root node.
|
||||
PcpRangeTypeWeakerThanRoot,
|
||||
|
||||
// Range including all nodes stronger than the payload
|
||||
// node.
|
||||
PcpRangeTypeStrongerThanPayload,
|
||||
|
||||
PcpRangeTypeInvalid
|
||||
};
|
||||
|
||||
/// Returns true if \p arcType represents an inherit arc, false
|
||||
/// otherwise.
|
||||
inline bool
|
||||
PcpIsInheritArc(PcpArcType arcType)
|
||||
{
|
||||
return (arcType == PcpArcTypeInherit);
|
||||
}
|
||||
|
||||
/// Returns true if \p arcType represents a specialize arc, false
|
||||
/// otherwise.
|
||||
inline bool
|
||||
PcpIsSpecializeArc(PcpArcType arcType)
|
||||
{
|
||||
return (arcType == PcpArcTypeSpecialize);
|
||||
}
|
||||
|
||||
/// Returns true if \p arcType represents a class-based
|
||||
/// composition arc, false otherwise.
|
||||
///
|
||||
/// The key characteristic of these arcs is that they imply
|
||||
/// additional sources of opinions outside of the site where
|
||||
/// the arc is introduced.
|
||||
inline bool
|
||||
PcpIsClassBasedArc(PcpArcType arcType)
|
||||
{
|
||||
return PcpIsInheritArc(arcType) || PcpIsSpecializeArc(arcType);
|
||||
}
|
||||
|
||||
/// \struct PcpSiteTrackerSegment
|
||||
///
|
||||
/// Used to keep track of which sites have been visited and through
|
||||
/// what type of arcs.
|
||||
///
|
||||
struct PcpSiteTrackerSegment {
|
||||
PcpSiteStr site;
|
||||
PcpArcType arcType;
|
||||
};
|
||||
|
||||
/// \typedef std::vector<PcpSiteTrackerSegment> PcpSiteTracker
|
||||
/// Represents a single path through the composition tree. As the tree
|
||||
/// is being built, we add segments to the tracker. If we encounter a
|
||||
/// site that we've already visited, we've found a cycle.
|
||||
typedef std::vector<PcpSiteTrackerSegment> PcpSiteTracker;
|
||||
|
||||
// Internal type for Sd sites.
|
||||
struct Pcp_SdSiteRef : boost::totally_ordered<Pcp_SdSiteRef> {
|
||||
Pcp_SdSiteRef(const SdfLayerRefPtr& layer_, const SdfPath& path_) :
|
||||
layer(layer_), path(path_)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
bool operator==(const Pcp_SdSiteRef& other) const
|
||||
{
|
||||
return layer == other.layer && path == other.path;
|
||||
}
|
||||
|
||||
bool operator<(const Pcp_SdSiteRef& other) const
|
||||
{
|
||||
return layer < other.layer ||
|
||||
(!(other.layer < layer) && path < other.path);
|
||||
}
|
||||
|
||||
// These are held by reference for performance,
|
||||
// to avoid extra ref-counting operations.
|
||||
const SdfLayerRefPtr & layer;
|
||||
const SdfPath & path;
|
||||
};
|
||||
|
||||
// Internal type for Sd sites.
|
||||
struct Pcp_CompressedSdSite {
|
||||
Pcp_CompressedSdSite(size_t nodeIndex_, size_t layerIndex_) :
|
||||
nodeIndex(static_cast<uint16_t>(nodeIndex_)),
|
||||
layerIndex(static_cast<uint16_t>(layerIndex_))
|
||||
{
|
||||
TF_VERIFY(nodeIndex_ < (size_t(1) << 16));
|
||||
TF_VERIFY(layerIndex_ < (size_t(1) << 16));
|
||||
}
|
||||
|
||||
// These are small to minimize the size of vectors of these.
|
||||
uint16_t nodeIndex; // The index of the node in its graph.
|
||||
uint16_t layerIndex; // The index of the layer in the node's layer stack.
|
||||
};
|
||||
typedef std::vector<Pcp_CompressedSdSite> Pcp_CompressedSdSiteVector;
|
||||
|
||||
// XXX Even with <map> included properly, doxygen refuses to acknowledge
|
||||
// the existence of std::map, so if we include the full typedef in the
|
||||
// \typedef directive, it will warn and fail to produce an entry for
|
||||
// PcpVariantFallbackMap. So we instead put the decl inline.
|
||||
/// \typedef PcpVariantFallbackMap
|
||||
/// typedef std::map<std::string, std::vector<std::string>> PcpVariantFallbackMap
|
||||
///
|
||||
/// A "map of lists" of fallbacks to attempt to use when evaluating
|
||||
/// variant sets that lack an authored selection.
|
||||
///
|
||||
/// This maps a name of a variant set (ex: "shadingComplexity") to a
|
||||
/// ordered list of variant selection names. If there is no variant
|
||||
/// selection in scene description, Pcp will check for each listed
|
||||
/// fallback in sequence, using the first one that exists.
|
||||
///
|
||||
typedef std::map<std::string, std::vector<std::string>> PcpVariantFallbackMap;
|
||||
|
||||
typedef TfDenseHashSet<TfToken, TfToken::HashFunctor> PcpTokenSet;
|
||||
|
||||
/// \var size_t PCP_INVALID_INDEX
|
||||
/// A value which indicates an invalid index. This is simply used inplace of
|
||||
/// either -1 or numeric_limits::max() (which are equivalent for size_t).
|
||||
/// for better clarity.
|
||||
#if defined(doxygen)
|
||||
constexpr size_t PCP_INVALID_INDEX = unspecified;
|
||||
#else
|
||||
constexpr size_t PCP_INVALID_INDEX = std::numeric_limits<size_t>::max();
|
||||
#endif
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_PCP_TYPES_H
|
||||
@@ -0,0 +1,587 @@
|
||||
//
|
||||
// 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_SDF_ABSTRACT_DATA_H
|
||||
#define PXR_USD_SDF_ABSTRACT_DATA_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/usd/sdf/types.h"
|
||||
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include "pxr/base/tf/staticTokens.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/tf/refBase.h"
|
||||
#include "pxr/base/tf/weakBase.h"
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
|
||||
#include <vector>
|
||||
#include <type_traits>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(SdfAbstractData);
|
||||
class SdfAbstractDataSpecVisitor;
|
||||
class SdfAbstractDataConstValue;
|
||||
class SdfAbstractDataValue;
|
||||
|
||||
|
||||
#define SDF_DATA_TOKENS \
|
||||
((TimeSamples, "timeSamples"))
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(SdfDataTokens, SDF_API, SDF_DATA_TOKENS);
|
||||
|
||||
|
||||
/// \class SdfAbstractData
|
||||
///
|
||||
/// Interface for scene description data storage.
|
||||
///
|
||||
/// This is not a layer. SdfAbstractData is an anonymous container holding
|
||||
/// scene description values. It is like an STL container, but specialized
|
||||
/// for holding scene description.
|
||||
///
|
||||
/// For any given SdfPath, an SdfAbstractData can hold one or more key/value
|
||||
/// pairs which we call Fields. Most of the API on SdfAbstractData accesses
|
||||
/// or modifies the value stored in a Field for a particular path and field
|
||||
/// name.
|
||||
///
|
||||
/// SdfAbstractData does not provide undo, change notification, or any strong
|
||||
/// consistency guarantees about the scene description it contains.
|
||||
/// Instead, it is a basis for building those things.
|
||||
///
|
||||
class SdfAbstractData : public TfRefBase, public TfWeakBase
|
||||
{
|
||||
public:
|
||||
SdfAbstractData() {}
|
||||
SDF_API
|
||||
virtual ~SdfAbstractData();
|
||||
|
||||
/// Copy the data in \p source into this data object.
|
||||
///
|
||||
/// The default implementation does a spec-by-spec, field-by-field
|
||||
/// copy of \p source into this object.
|
||||
SDF_API
|
||||
virtual void CopyFrom(const SdfAbstractDataConstPtr& source);
|
||||
|
||||
/// Returns true if this data object streams its data to and from its
|
||||
/// serialized data store on demand.
|
||||
///
|
||||
/// Sdf will treat layers with streaming data differently to avoid pulling
|
||||
/// in data unnecessarily. For example, reloading a streaming layer
|
||||
/// will not perform fine-grained change notification, since doing
|
||||
/// so would require the full contents of the layer to be loaded.
|
||||
SDF_API
|
||||
virtual bool StreamsData() const = 0;
|
||||
|
||||
/// Returns true if this data object has no specs, false otherwise.
|
||||
///
|
||||
/// The default implementation uses a visitor to check if any specs
|
||||
/// exist.
|
||||
SDF_API
|
||||
virtual bool IsEmpty() const;
|
||||
|
||||
/// Returns true if this data object contains the same specs and fields
|
||||
/// as \a lhs, false otherwise.
|
||||
///
|
||||
/// The default implementation does a spec-by-spec, field-by-field
|
||||
/// comparison.
|
||||
// XXX: What are the right semantics for this?
|
||||
// Does it matter if the underlying implementation matches?
|
||||
SDF_API
|
||||
virtual bool Equals(const SdfAbstractDataRefPtr &rhs) const;
|
||||
|
||||
/// Writes the contents of this data object to \p out. This is primarily
|
||||
/// for debugging purposes.
|
||||
///
|
||||
/// The default implementation writes out each field for each spec.
|
||||
SDF_API
|
||||
virtual void WriteToStream(std::ostream& out) const;
|
||||
|
||||
/// \name Spec API
|
||||
/// @{
|
||||
|
||||
/// Create a new spec at \a path with the given \a specType. If the spec
|
||||
/// already exists the spec type will be changed.
|
||||
SDF_API
|
||||
virtual void CreateSpec(const SdfPath &path,
|
||||
SdfSpecType specType) = 0;
|
||||
|
||||
/// Return true if this data has a spec for \a path.
|
||||
SDF_API
|
||||
virtual bool HasSpec(const SdfPath &path) const = 0;
|
||||
|
||||
/// Erase the spec at \a path and any fields that are on it.
|
||||
/// Note that this does not erase child specs.
|
||||
SDF_API
|
||||
virtual void EraseSpec(const SdfPath &path) = 0;
|
||||
|
||||
/// Move the spec at \a oldPath to \a newPath, including all the
|
||||
/// fields that are on it. This does not move any child specs.
|
||||
SDF_API
|
||||
virtual void MoveSpec(const SdfPath &oldPath,
|
||||
const SdfPath &newPath) = 0;
|
||||
|
||||
/// Return the spec type for the spec at \a path. Returns SdfSpecTypeUnknown
|
||||
/// if the spec doesn't exist.
|
||||
virtual SdfSpecType GetSpecType(const SdfPath &path) const = 0;
|
||||
|
||||
/// Visits every spec in this SdfAbstractData object with the given
|
||||
/// \p visitor. The order in which specs are visited is undefined.
|
||||
/// The visitor may not modify the SdfAbstractData object it is visiting.
|
||||
/// \sa SdfAbstractDataSpecVisitor
|
||||
SDF_API
|
||||
void VisitSpecs(SdfAbstractDataSpecVisitor* visitor) const;
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name Field API
|
||||
/// @{
|
||||
|
||||
/// Returns whether a value exists for the given \a path and \a fieldName.
|
||||
/// Optionally returns the value if it exists.
|
||||
SDF_API
|
||||
virtual bool Has(const SdfPath& path, const TfToken& fieldName,
|
||||
SdfAbstractDataValue* value) const = 0;
|
||||
|
||||
/// Return whether a value exists for the given \a path and \a fieldName.
|
||||
/// Optionally returns the value if it exists.
|
||||
SDF_API
|
||||
virtual bool Has(const SdfPath& path, const TfToken &fieldName,
|
||||
VtValue *value = NULL) const = 0;
|
||||
|
||||
/// Fill \p specType (which cannot be nullptr) as if by a call to
|
||||
/// GetSpecType(path). If the resulting specType is not SdfSpecTypeUnknown,
|
||||
/// then act as if Has(path, fieldName, value) was called and return its
|
||||
/// result. In other words, the semantics of this function must be
|
||||
/// identical to this sequence:
|
||||
///
|
||||
/// \code
|
||||
/// *specType = GetSpecType(path);
|
||||
/// return *specType != SdfSpecTypeUnknown && Has(path, fieldName, value);
|
||||
/// \endcode
|
||||
SDF_API
|
||||
virtual bool
|
||||
HasSpecAndField(const SdfPath &path, const TfToken &fieldName,
|
||||
SdfAbstractDataValue *value, SdfSpecType *specType) const;
|
||||
|
||||
/// Fill \p specType (which cannot be nullptr) as if by a call to
|
||||
/// GetSpecType(path). If the resulting specType is not SdfSpecTypeUnknown,
|
||||
/// then act as if Has(path, fieldName, value) was called and return its
|
||||
/// result. In other words, the semantics of this function must be
|
||||
/// identical to this sequence:
|
||||
///
|
||||
/// \code
|
||||
/// *specType = GetSpecType(path);
|
||||
/// return *specType != SdfSpecTypeUnknown && Has(path, fieldName, value);
|
||||
/// \endcode
|
||||
SDF_API
|
||||
virtual bool
|
||||
HasSpecAndField(const SdfPath &path, const TfToken &fieldName,
|
||||
VtValue *value, SdfSpecType *specType) const;
|
||||
|
||||
/// Return the value for the given \a path and \a fieldName. Returns an
|
||||
/// empty value if none is set.
|
||||
SDF_API
|
||||
virtual VtValue Get(const SdfPath& path,
|
||||
const TfToken& fieldName) const = 0;
|
||||
|
||||
/// Return the type of the value for \p fieldName on spec \p path. If no
|
||||
/// such field exists, return typeid(void). Derived classes may optionally
|
||||
/// override this for performance. The base implementation is equivalent
|
||||
/// to:
|
||||
///
|
||||
/// \code
|
||||
/// return Get(path, fieldName).GetTypeid();
|
||||
/// \endcode
|
||||
SDF_API
|
||||
virtual std::type_info const &
|
||||
GetTypeid(const SdfPath &path, const TfToken &fieldName) const;
|
||||
|
||||
/// Set the value of the given \a path and \a fieldName.
|
||||
///
|
||||
/// It's an error to set a field on a spec that does not exist. Setting a
|
||||
/// field to an empty VtValue is the same as calling Erase() on it.
|
||||
SDF_API
|
||||
virtual void Set(const SdfPath &path, const TfToken &fieldName,
|
||||
const VtValue &value) = 0;
|
||||
|
||||
/// Set the value of the given \a path and \a fieldName.
|
||||
///
|
||||
/// It's an error to set a field on a spec that does not exist.
|
||||
SDF_API
|
||||
virtual void Set(const SdfPath &path, const TfToken &fieldName,
|
||||
const SdfAbstractDataConstValue& value) = 0;
|
||||
|
||||
/// Remove the field at \p path and \p fieldName, if one exists.
|
||||
SDF_API
|
||||
virtual void Erase(const SdfPath& path,
|
||||
const TfToken& fieldName) = 0;
|
||||
|
||||
/// Return the names of all the fields that are set at \p path.
|
||||
SDF_API
|
||||
virtual std::vector<TfToken> List(const SdfPath& path) const = 0;
|
||||
|
||||
/// Return the value for the given \a path and \a fieldName. Returns the
|
||||
/// provided \a defaultValue value if none is set.
|
||||
template <class T>
|
||||
inline T GetAs(const SdfPath& path, const TfToken& fieldName,
|
||||
const T& defaultValue = T()) const;
|
||||
|
||||
/// @}
|
||||
|
||||
|
||||
/// \name Dict key access API
|
||||
/// @{
|
||||
|
||||
// Return true and set \p value (if non null) if the field identified by
|
||||
// \p path and \p fieldName is dictionary-valued, and if there is an element
|
||||
// at \p keyPath in that dictionary. Return false otherwise. If
|
||||
// \p keyPath names an entire sub-dictionary, set \p value to that entire
|
||||
// sub-dictionary and return true.
|
||||
SDF_API
|
||||
virtual bool HasDictKey(const SdfPath& path,
|
||||
const TfToken &fieldName,
|
||||
const TfToken &keyPath,
|
||||
SdfAbstractDataValue* value) const;
|
||||
SDF_API
|
||||
virtual bool HasDictKey(const SdfPath& path,
|
||||
const TfToken &fieldName,
|
||||
const TfToken &keyPath,
|
||||
VtValue *value = NULL) const;
|
||||
|
||||
// Same as HasDictKey but return empty VtValue on failure.
|
||||
SDF_API
|
||||
virtual VtValue GetDictValueByKey(const SdfPath& path,
|
||||
const TfToken &fieldName,
|
||||
const TfToken &keyPath) const;
|
||||
|
||||
// Set the element at \p keyPath in the dictionary-valued field identified
|
||||
// by \p path and \p fieldName. If the field itself is not
|
||||
// dictionary-valued, replace the field with a new dictionary and set the
|
||||
// element at \p keyPath in it. If \p value is empty, invoke
|
||||
// EraseDictValueByKey instead.
|
||||
SDF_API
|
||||
virtual void SetDictValueByKey(const SdfPath& path,
|
||||
const TfToken &fieldName,
|
||||
const TfToken &keyPath,
|
||||
const VtValue &value);
|
||||
SDF_API
|
||||
virtual void SetDictValueByKey(const SdfPath& path,
|
||||
const TfToken &fieldName,
|
||||
const TfToken &keyPath,
|
||||
const SdfAbstractDataConstValue& value);
|
||||
|
||||
// If \p path and \p fieldName identify a dictionary-valued field with an
|
||||
// element at \p keyPath, remove that element from the dictionary. If this
|
||||
// leaves the dictionary empty, Erase() the entire field.
|
||||
SDF_API
|
||||
virtual void EraseDictValueByKey(const SdfPath& path,
|
||||
const TfToken &fieldName,
|
||||
const TfToken &keyPath);
|
||||
|
||||
// If \p path, \p fieldName, and \p keyPath identify a (sub) dictionary,
|
||||
// return a vector of the keys in that dictionary, otherwise return an empty
|
||||
// vector.
|
||||
SDF_API
|
||||
virtual std::vector<TfToken> ListDictKeys(const SdfPath& path,
|
||||
const TfToken &fieldName,
|
||||
const TfToken &keyPath) const;
|
||||
|
||||
|
||||
/// @}
|
||||
|
||||
|
||||
/// \name Time-sample API
|
||||
///
|
||||
/// This API supports narrowly-targeted queries against the
|
||||
/// "timeSamples" key of properties. In particular, it enables
|
||||
/// asking for single time samples without pulling on the entire
|
||||
/// set of time samples, as well as asking about the set of sample
|
||||
/// times without pulling on the actual values at those times.
|
||||
///
|
||||
/// @{
|
||||
|
||||
SDF_API
|
||||
virtual std::set<double>
|
||||
ListAllTimeSamples() const = 0;
|
||||
|
||||
SDF_API
|
||||
virtual std::set<double>
|
||||
ListTimeSamplesForPath(const SdfPath& path) const = 0;
|
||||
|
||||
SDF_API
|
||||
virtual bool
|
||||
GetBracketingTimeSamples(double time, double* tLower, double* tUpper) const = 0;
|
||||
|
||||
SDF_API
|
||||
virtual size_t
|
||||
GetNumTimeSamplesForPath(const SdfPath& path) const = 0;
|
||||
|
||||
SDF_API
|
||||
virtual bool
|
||||
GetBracketingTimeSamplesForPath(const SdfPath& path,
|
||||
double time,
|
||||
double* tLower, double* tUpper) const = 0;
|
||||
|
||||
SDF_API
|
||||
virtual bool
|
||||
QueryTimeSample(const SdfPath& path, double time,
|
||||
VtValue *optionalValue = NULL) const = 0;
|
||||
SDF_API
|
||||
virtual bool
|
||||
QueryTimeSample(const SdfPath& path, double time,
|
||||
SdfAbstractDataValue *optionalValue) const = 0;
|
||||
|
||||
SDF_API
|
||||
virtual void
|
||||
SetTimeSample(const SdfPath& path, double time,
|
||||
const VtValue & value) = 0;
|
||||
|
||||
SDF_API
|
||||
virtual void
|
||||
EraseTimeSample(const SdfPath& path, double time) = 0;
|
||||
|
||||
/// @}
|
||||
|
||||
protected:
|
||||
/// Visits every spec in this SdfAbstractData object with the given
|
||||
/// \p visitor. The order in which specs are visited is undefined.
|
||||
/// The visitor may not modify the SdfAbstractData object it is visiting.
|
||||
/// This method should \b not call \c Done() on the visitor.
|
||||
/// \sa SdfAbstractDataSpecVisitor
|
||||
SDF_API
|
||||
virtual void _VisitSpecs(SdfAbstractDataSpecVisitor* visitor) const = 0;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline T SdfAbstractData::GetAs(
|
||||
const SdfPath& path,
|
||||
const TfToken& field, const T& defaultVal) const
|
||||
{
|
||||
VtValue val = Get(path, field);
|
||||
if (val.IsHolding<T>()) {
|
||||
return val.UncheckedGet<T>();
|
||||
}
|
||||
return defaultVal;
|
||||
}
|
||||
|
||||
/// \class SdfAbstractDataValue
|
||||
///
|
||||
/// A type-erased container for a field value in an SdfAbstractData.
|
||||
///
|
||||
/// \sa SdfAbstractDataTypedValue
|
||||
class SdfAbstractDataValue
|
||||
{
|
||||
public:
|
||||
virtual bool StoreValue(const VtValue& value) = 0;
|
||||
|
||||
template <class T>
|
||||
bool StoreValue(const T& v)
|
||||
{
|
||||
if (TfSafeTypeCompare(typeid(T), valueType)) {
|
||||
*static_cast<T*>(value) = v;
|
||||
return true;
|
||||
}
|
||||
typeMismatch = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool StoreValue(const SdfValueBlock& block)
|
||||
{
|
||||
isValueBlock = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void* value;
|
||||
const std::type_info& valueType;
|
||||
bool isValueBlock;
|
||||
bool typeMismatch;
|
||||
|
||||
protected:
|
||||
SdfAbstractDataValue(void* value_, const std::type_info& valueType_)
|
||||
: value(value_)
|
||||
, valueType(valueType_)
|
||||
, isValueBlock(false)
|
||||
, typeMismatch(false)
|
||||
{ }
|
||||
};
|
||||
|
||||
/// \class SdfAbstractDataTypedValue
|
||||
///
|
||||
/// The fully-typed container for a field value in an \c SdfAbstractData.
|
||||
/// An \c SdfAbstractDataTypedValue allows a consumer to pass a pointer to
|
||||
/// an object through the virtual \c SdfAbstractData interface along with
|
||||
/// information about that object's type. That information may allow
|
||||
/// implementations of \c SdfAbstractData to populate the contained object
|
||||
/// in a more efficient way, avoiding unnecessary boxing/unboxing of data.
|
||||
///
|
||||
/// SdfAbstractDataTypedValue objects are intended to be transient; they
|
||||
/// are solely used to get pointer information into and out of an
|
||||
/// SdfAbstractData container.
|
||||
///
|
||||
template <class T>
|
||||
class SdfAbstractDataTypedValue : public SdfAbstractDataValue
|
||||
{
|
||||
public:
|
||||
SdfAbstractDataTypedValue(T* value)
|
||||
: SdfAbstractDataValue(value, typeid(T))
|
||||
{ }
|
||||
|
||||
virtual bool StoreValue(const VtValue& v)
|
||||
{
|
||||
if (ARCH_LIKELY(v.IsHolding<T>())) {
|
||||
*static_cast<T*>(value) = v.UncheckedGet<T>();
|
||||
if (std::is_same<T, SdfValueBlock>::value) {
|
||||
isValueBlock = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (v.IsHolding<SdfValueBlock>()) {
|
||||
isValueBlock = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
typeMismatch = true;
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/// \class SdfAbstractDataConstValue
|
||||
///
|
||||
/// A type-erased container for a const field value in an SdfAbstractData.
|
||||
///
|
||||
/// \sa SdfAbstractDataConstTypedValue
|
||||
class SdfAbstractDataConstValue
|
||||
{
|
||||
public:
|
||||
virtual bool GetValue(VtValue* value) const = 0;
|
||||
|
||||
template <class T> bool GetValue(T* v) const
|
||||
{
|
||||
if (TfSafeTypeCompare(typeid(T), valueType)) {
|
||||
*v = *static_cast<const T*>(value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool IsEqual(const VtValue& value) const = 0;
|
||||
|
||||
const void* value;
|
||||
const std::type_info& valueType;
|
||||
|
||||
protected:
|
||||
SdfAbstractDataConstValue(const void* value_,
|
||||
const std::type_info& valueType_)
|
||||
: value(value_)
|
||||
, valueType(valueType_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/// \class SdfAbstractDataConstTypedValue
|
||||
///
|
||||
/// The fully-typed container for a field value in an \c SdfAbstractData.
|
||||
/// An \c SdfAbstractDataConstTypedValue allows a consumer to pass a pointer to
|
||||
/// an object through the virtual \c SdfAbstractData interface along with
|
||||
/// information about that object's type. That information may allow
|
||||
/// implementations of \c SdfAbstractData to store the contained object
|
||||
/// in a more efficient way, avoiding unnecessary boxing/unboxing of data.
|
||||
///
|
||||
/// SdfAbstractDataConstTypedValue objects are intended to be transient; they
|
||||
/// are solely used to get pointer information into an SdfAbstractData
|
||||
/// container.
|
||||
///
|
||||
template <class T>
|
||||
class SdfAbstractDataConstTypedValue : public SdfAbstractDataConstValue
|
||||
{
|
||||
public:
|
||||
SdfAbstractDataConstTypedValue(const T* value)
|
||||
: SdfAbstractDataConstValue(value, typeid(T))
|
||||
{ }
|
||||
|
||||
virtual bool GetValue(VtValue* v) const
|
||||
{
|
||||
*v = _GetValue();
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool IsEqual(const VtValue& v) const
|
||||
{
|
||||
return (v.IsHolding<T>() && v.UncheckedGet<T>() == _GetValue());
|
||||
}
|
||||
|
||||
private:
|
||||
const T& _GetValue() const
|
||||
{
|
||||
return *static_cast<const T*>(value);
|
||||
}
|
||||
};
|
||||
|
||||
// Specialization of SdAbstractDataConstTypedValue that converts character
|
||||
// arrays to std::string.
|
||||
template <int N>
|
||||
class SdfAbstractDataConstTypedValue<char[N]>
|
||||
: public SdfAbstractDataConstTypedValue<std::string>
|
||||
{
|
||||
public:
|
||||
typedef char CharArray[N];
|
||||
SdfAbstractDataConstTypedValue(const CharArray* value)
|
||||
: SdfAbstractDataConstTypedValue<std::string>(&_str)
|
||||
, _str(*value)
|
||||
{ }
|
||||
|
||||
private:
|
||||
std::string _str;
|
||||
};
|
||||
|
||||
/// \class SdfAbstractDataSpecVisitor
|
||||
///
|
||||
/// Base class for objects used to visit specs in an SdfAbstractData object.
|
||||
///
|
||||
/// \sa SdfAbstractData::VisitSpecs.
|
||||
class SdfAbstractDataSpecVisitor
|
||||
{
|
||||
public:
|
||||
SDF_API
|
||||
virtual ~SdfAbstractDataSpecVisitor();
|
||||
|
||||
/// \c SdfAbstractData::VisitSpecs calls this function for every entry it
|
||||
/// contains, passing itself as \p data and the entry's \p path. Return
|
||||
/// false to stop iteration early, true to continue.
|
||||
SDF_API
|
||||
virtual bool VisitSpec(const SdfAbstractData& data,
|
||||
const SdfPath& path) = 0;
|
||||
|
||||
/// \c SdfAbstractData::VisitSpecs will call this after visitation is
|
||||
/// complete, even if some \c VisitSpec() returned \c false.
|
||||
SDF_API
|
||||
virtual void Done(const SdfAbstractData& data) = 0;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_ABSTRACT_DATA_H
|
||||
@@ -0,0 +1,257 @@
|
||||
//
|
||||
// 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_SDF_ACCESSOR_HELPERS_H
|
||||
#define PXR_USD_SDF_ACCESSOR_HELPERS_H
|
||||
|
||||
/// \file sdf/accessorHelpers.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/schema.h"
|
||||
#include "pxr/usd/sdf/spec.h"
|
||||
#include "pxr/usd/sdf/types.h"
|
||||
|
||||
// This file defines macros intended to reduce the amount of boilerplate code
|
||||
// associated with adding new metadata to SdfSpec subclasses. There's still a
|
||||
// lot of files to touch, but these at least reduce the copy/paste/edit load.
|
||||
//
|
||||
// Prior to using these macros in the SdfSpec implementation file, define the
|
||||
// following symbols:
|
||||
//
|
||||
// #define SDF_ACCESSOR_CLASS SdfSomeSpec
|
||||
// #define SDF_ACCESSOR_READ_PREDICATE(key_) _CanRead(key_)
|
||||
// #define SDF_ACCESSOR_WRITE_PREDICATE(key_) _CanWrite(key_)
|
||||
//
|
||||
// ...where _CanRead and _CanWrite are member functions of the specified class,
|
||||
// with the signature 'bool _fn_(const TfToken&)'. If either accessor predicate
|
||||
// is unnecessary, #define the corresponding symbol to 'SDF_NO_PREDICATE'.
|
||||
//
|
||||
// Also, please observe good form and #undef the symbols after instancing the
|
||||
// accessor macros.
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
// "Helper" macros
|
||||
#define _GET_KEY_(key_) key_
|
||||
#define SDF_NO_PREDICATE true
|
||||
|
||||
#define _GET_WITH_FALLBACK(key_, heldType_) \
|
||||
{ \
|
||||
typedef Sdf_AccessorHelpers<SDF_ACCESSOR_CLASS> _Helper; \
|
||||
const VtValue& value = _Helper::GetField(this, key_); \
|
||||
if (value.IsEmpty() || !value.IsHolding<heldType_>()) { \
|
||||
const SdfSchemaBase& schema = _Helper::GetSchema(this); \
|
||||
return schema.GetFallback(_GET_KEY_(key_)).Get<heldType_>(); \
|
||||
} \
|
||||
else { \
|
||||
return value.Get<heldType_>(); \
|
||||
} \
|
||||
}
|
||||
|
||||
// Accessor methods for "simple type" values: Get, Is, Set, Has, Clear
|
||||
// Usually the client will utilize one of the combination macros (below).
|
||||
|
||||
#define SDF_DEFINE_GET(name_, key_, heldType_) \
|
||||
heldType_ \
|
||||
SDF_ACCESSOR_CLASS::Get ## name_() const \
|
||||
{ \
|
||||
if (SDF_ACCESSOR_READ_PREDICATE(_GET_KEY_(key_))) { \
|
||||
/* Empty clause needed to prevent compiler complaints */ \
|
||||
} \
|
||||
\
|
||||
_GET_WITH_FALLBACK(key_, heldType_); \
|
||||
}
|
||||
|
||||
#define SDF_DEFINE_IS(name_, key_) \
|
||||
bool \
|
||||
SDF_ACCESSOR_CLASS::Is ## name_() const \
|
||||
{ \
|
||||
if (!SDF_ACCESSOR_READ_PREDICATE(_GET_KEY_(key_))) { \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
_GET_WITH_FALLBACK(key_, bool); \
|
||||
}
|
||||
|
||||
#define SDF_DEFINE_SET(name_, key_, argType_) \
|
||||
void \
|
||||
SDF_ACCESSOR_CLASS::Set ## name_(argType_ value) \
|
||||
{ \
|
||||
if (SDF_ACCESSOR_WRITE_PREDICATE(_GET_KEY_(key_))) { \
|
||||
typedef Sdf_AccessorHelpers<SDF_ACCESSOR_CLASS> _Helper; \
|
||||
_Helper::SetField(this, _GET_KEY_(key_), value); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define SDF_DEFINE_HAS(name_, key_) \
|
||||
bool \
|
||||
SDF_ACCESSOR_CLASS::Has ## name_() const \
|
||||
{ \
|
||||
typedef Sdf_AccessorHelpers<SDF_ACCESSOR_CLASS> _Helper; \
|
||||
return SDF_ACCESSOR_READ_PREDICATE(_GET_KEY_(key_)) ? \
|
||||
_Helper::HasField(this, _GET_KEY_(key_)) : false; \
|
||||
}
|
||||
|
||||
#define SDF_DEFINE_CLEAR(name_, key_) \
|
||||
void \
|
||||
SDF_ACCESSOR_CLASS::Clear ## name_() \
|
||||
{ \
|
||||
typedef Sdf_AccessorHelpers<SDF_ACCESSOR_CLASS> _Helper; \
|
||||
if (SDF_ACCESSOR_WRITE_PREDICATE(_GET_KEY_(key_))) { \
|
||||
_Helper::ClearField(this, _GET_KEY_(key_)); \
|
||||
} \
|
||||
}
|
||||
|
||||
// Accessor methods similar to the above, but intended for private use in
|
||||
// the SdSpec classes.
|
||||
|
||||
#define SDF_DEFINE_GET_PRIVATE(name_, key_, heldType_) \
|
||||
heldType_ \
|
||||
SDF_ACCESSOR_CLASS::_Get ## name_() const \
|
||||
{ \
|
||||
if (SDF_ACCESSOR_READ_PREDICATE(_GET_KEY_(key_))) { \
|
||||
/* Empty clause needed to prevent compiler complaints */ \
|
||||
} \
|
||||
\
|
||||
_GET_WITH_FALLBACK(key_, heldType_); \
|
||||
}
|
||||
|
||||
// Accessor methods for VtDictionary types, utilizing SdDictionaryProxy for the
|
||||
// 'Get' accessors. Due to unusual naming in the original SdSpec API, these
|
||||
// macros accept/require explicit accessor method names. Dammit.
|
||||
#define SDF_DEFINE_DICTIONARY_GET(name_, key_) \
|
||||
SdfDictionaryProxy \
|
||||
SDF_ACCESSOR_CLASS::name_() const \
|
||||
{ \
|
||||
typedef Sdf_AccessorHelpers<SDF_ACCESSOR_CLASS> _Helper; \
|
||||
return SDF_ACCESSOR_READ_PREDICATE(_GET_KEY_(key_)) ? \
|
||||
SdfDictionaryProxy(_Helper::GetSpecHandle(this), _GET_KEY_(key_)) : \
|
||||
SdfDictionaryProxy(); \
|
||||
}
|
||||
|
||||
#define SDF_DEFINE_DICTIONARY_SET(name_, key_) \
|
||||
void \
|
||||
SDF_ACCESSOR_CLASS::name_( \
|
||||
const std::string& name, \
|
||||
const VtValue& value) \
|
||||
{ \
|
||||
typedef Sdf_AccessorHelpers<SDF_ACCESSOR_CLASS> _Helper; \
|
||||
if (SDF_ACCESSOR_WRITE_PREDICATE(_GET_KEY_(key_))) { \
|
||||
SdfDictionaryProxy proxy( \
|
||||
_Helper::GetSpecHandle(this), _GET_KEY_(key_)); \
|
||||
if (value.IsEmpty()) { \
|
||||
proxy.erase(name); \
|
||||
} \
|
||||
else { \
|
||||
proxy[name] = value; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
// Convenience macros to provide common combinations of value accessors
|
||||
|
||||
#define SDF_DEFINE_TYPED_GET_SET(name_, key_, getType_, setType_) \
|
||||
SDF_DEFINE_GET(name_, key_, getType_) \
|
||||
SDF_DEFINE_SET(name_, key_, setType_)
|
||||
|
||||
#define SDF_DEFINE_TYPED_GET_SET_HAS_CLEAR(name_, key_, getType_, setType_) \
|
||||
SDF_DEFINE_TYPED_GET_SET(name_, key_, getType_, setType_) \
|
||||
SDF_DEFINE_HAS(name_, key_) \
|
||||
SDF_DEFINE_CLEAR(name_, key_)
|
||||
|
||||
#define SDF_DEFINE_GET_SET(name_, key_, type_) \
|
||||
SDF_DEFINE_TYPED_GET_SET(name_, key_, type_, \
|
||||
boost::call_traits<type_>::param_type)
|
||||
|
||||
#define SDF_DEFINE_GET_SET_HAS_CLEAR(name_, key_, type_) \
|
||||
SDF_DEFINE_TYPED_GET_SET_HAS_CLEAR(name_, key_, type_, \
|
||||
boost::call_traits<type_>::param_type)
|
||||
|
||||
#define SDF_DEFINE_IS_SET(name_, key_) \
|
||||
SDF_DEFINE_IS(name_, key_) \
|
||||
SDF_DEFINE_SET(name_, key_, bool)
|
||||
|
||||
#define SDF_DEFINE_DICTIONARY_GET_SET(getName_, setName_, key_) \
|
||||
SDF_DEFINE_DICTIONARY_GET(getName_, key_) \
|
||||
SDF_DEFINE_DICTIONARY_SET(setName_, key_)
|
||||
|
||||
// Implementation details
|
||||
// The helper macros above can be used in the implementation of a spec
|
||||
// class or a spec API class (see declareSpec.h for details). Both cases
|
||||
// access data in a different way -- spec classes can query their data
|
||||
// members directly, while spec API classes need to query their associated
|
||||
// spec. These templates capture those differences.
|
||||
|
||||
template <class T,
|
||||
bool IsForSpec = boost::is_base_of<SdfSpec, T>::value>
|
||||
struct Sdf_AccessorHelpers;
|
||||
|
||||
template <class T>
|
||||
struct Sdf_AccessorHelpers<T, true>
|
||||
{
|
||||
static const SdfSchemaBase& GetSchema(const T* spec)
|
||||
{ return spec->GetSchema(); }
|
||||
|
||||
static VtValue GetField(const T* spec, const TfToken& key)
|
||||
{ return spec->GetField(key); }
|
||||
|
||||
template <class V>
|
||||
static bool SetField(T* spec, const TfToken& key, const V& value)
|
||||
{ return spec->SetField(key, value); }
|
||||
|
||||
static bool HasField(const T* spec, const TfToken& key)
|
||||
{ return spec->HasField(key); }
|
||||
|
||||
static void ClearField(T* spec, const TfToken& key)
|
||||
{ spec->ClearField(key); }
|
||||
|
||||
static SdfSpecHandle GetSpecHandle(const T* spec)
|
||||
{ return SdfCreateNonConstHandle(spec); }
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct Sdf_AccessorHelpers<T, false>
|
||||
{
|
||||
static const SdfSchemaBase& GetSchema(const T* spec)
|
||||
{ return spec->_GetSpec().GetSchema(); }
|
||||
|
||||
static VtValue GetField(const T* spec, const TfToken& key)
|
||||
{ return spec->_GetSpec().GetField(key); }
|
||||
|
||||
template <class V>
|
||||
static bool SetField(T* spec, const TfToken& key, const V& value)
|
||||
{ return spec->_GetSpec().SetField(key, value); }
|
||||
|
||||
static bool HasField(const T* spec, const TfToken& key)
|
||||
{ return spec->_GetSpec().HasField(key); }
|
||||
|
||||
static void ClearField(T* spec, const TfToken& key)
|
||||
{ spec->_GetSpec().ClearField(key); }
|
||||
|
||||
static SdfSpecHandle GetSpecHandle(const T* spec)
|
||||
{ return SdfCreateNonConstHandle(&(spec->_GetSpec())); }
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // #ifndef PXR_USD_SDF_ACCESSOR_HELPERS_H
|
||||
@@ -0,0 +1,122 @@
|
||||
//
|
||||
// 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_SDF_ALLOWED_H
|
||||
#define PXR_USD_SDF_ALLOWED_H
|
||||
|
||||
/// \file sdf/allowed.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
#include "pxr/base/tf/diagnostic.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <boost/operators.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class SdfAllowed
|
||||
///
|
||||
/// Indicates if an operation is allowed and, if not, why not.
|
||||
///
|
||||
/// A \c SdfAllowed either evaluates to \c true in a boolean context
|
||||
/// or evaluates to \c false and has a string annotation.
|
||||
///
|
||||
class SdfAllowed : private boost::equality_comparable<SdfAllowed> {
|
||||
private:
|
||||
typedef boost::optional<std::string> _State;
|
||||
|
||||
public:
|
||||
typedef std::pair<bool, std::string> Pair;
|
||||
|
||||
/// Construct \c true.
|
||||
SdfAllowed() { }
|
||||
/// Construct \c true.
|
||||
SdfAllowed(bool x) { TF_AXIOM(x); }
|
||||
/// Construct \c false with annotation \p whyNot.
|
||||
SdfAllowed(const char* whyNot) : _state(std::string(whyNot)) { }
|
||||
/// Construct \c false with annotation \p whyNot.
|
||||
SdfAllowed(const std::string& whyNot) : _state(whyNot) { }
|
||||
/// Construct in \p condition with annotation \p whyNot if \c false.
|
||||
SdfAllowed(bool condition, const char* whyNot) :
|
||||
_state(!condition, std::string(whyNot)) { }
|
||||
/// Construct in \p condition with annotation \p whyNot if \c false.
|
||||
SdfAllowed(bool condition, const std::string& whyNot) :
|
||||
_state(!condition, whyNot) { }
|
||||
/// Construct from bool,string pair \p x.
|
||||
SdfAllowed(const Pair& x) : _state(!x.first, x.second) { }
|
||||
~SdfAllowed() { }
|
||||
|
||||
#if !defined(doxygen)
|
||||
typedef _State SdfAllowed::*UnspecifiedBoolType;
|
||||
#endif
|
||||
|
||||
/// Returns \c true in a boolean context if allowed, \c false otherwise.
|
||||
operator UnspecifiedBoolType() const
|
||||
{
|
||||
return _state ? NULL : &SdfAllowed::_state;
|
||||
}
|
||||
|
||||
/// Returns \c false in a boolean context if allowed, \c true otherwise.
|
||||
bool operator!() const
|
||||
{
|
||||
return static_cast<bool>(_state);
|
||||
}
|
||||
|
||||
/// Returns the reason why the operation is not allowed. If the
|
||||
/// operation is allowed this returns the empty string.
|
||||
operator const std::string&() const
|
||||
{
|
||||
return GetWhyNot();
|
||||
}
|
||||
|
||||
/// Returns the reason why the operation is not allowed. If the
|
||||
/// operation is allowed this returns the empty string.
|
||||
SDF_API const std::string& GetWhyNot() const;
|
||||
|
||||
/// Returns \c true if allowed, otherwise fills \p whyNot if not \c NULL
|
||||
/// and returns \c false.
|
||||
bool IsAllowed(std::string* whyNot) const
|
||||
{
|
||||
if (whyNot && _state) {
|
||||
*whyNot = *_state;
|
||||
}
|
||||
return !_state;
|
||||
}
|
||||
|
||||
/// Compare to \p other. Returns \c true if both are \c true or
|
||||
/// both are \c false and reasons why not are identical.
|
||||
bool operator==(const SdfAllowed& other) const
|
||||
{
|
||||
return _state == other._state;
|
||||
}
|
||||
|
||||
private:
|
||||
_State _state;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_ALLOWED_H
|
||||
@@ -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_SDF_API_H
|
||||
#define PXR_USD_SDF_API_H
|
||||
|
||||
#include "pxr/base/arch/export.h"
|
||||
|
||||
#if defined(PXR_STATIC)
|
||||
# define SDF_API
|
||||
# define SDF_API_TEMPLATE_CLASS(...)
|
||||
# define SDF_API_TEMPLATE_STRUCT(...)
|
||||
# define SDF_LOCAL
|
||||
#else
|
||||
# if defined(SDF_EXPORTS)
|
||||
# define SDF_API ARCH_EXPORT
|
||||
# define SDF_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define SDF_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# else
|
||||
# define SDF_API ARCH_IMPORT
|
||||
# define SDF_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define SDF_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# endif
|
||||
# define SDF_LOCAL ARCH_HIDDEN
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,138 @@
|
||||
//
|
||||
// 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_SDF_ASSET_PATH_H
|
||||
#define PXR_USD_SDF_ASSET_PATH_H
|
||||
|
||||
/// \file sdf/assetPath.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <boost/operators.hpp>
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class SdfAssetPath
|
||||
///
|
||||
/// Contains an asset path and an optional resolved path.
|
||||
///
|
||||
class SdfAssetPath:
|
||||
public boost::totally_ordered<SdfAssetPath>
|
||||
{
|
||||
public:
|
||||
/// \name Constructors
|
||||
/// @{
|
||||
///
|
||||
|
||||
/// Construct an empty asset path.
|
||||
SDF_API SdfAssetPath();
|
||||
|
||||
/// Construct asset path with no associated resolved path.
|
||||
SDF_API explicit SdfAssetPath(const std::string &path);
|
||||
|
||||
/// Construct an asset path with an associated resolved path.
|
||||
SDF_API SdfAssetPath(const std::string &path, const std::string &resolvedPath);
|
||||
|
||||
/// @}
|
||||
|
||||
///\name Operators
|
||||
/// @{
|
||||
|
||||
/// Equality, including the resolved path.
|
||||
bool operator==(const SdfAssetPath &rhs) const {
|
||||
return _assetPath == rhs._assetPath &&
|
||||
_resolvedPath == rhs._resolvedPath;
|
||||
}
|
||||
|
||||
/// Ordering first by asset path, then by resolved path.
|
||||
SDF_API bool operator<(const SdfAssetPath &rhs) const;
|
||||
|
||||
/// Hash function
|
||||
size_t GetHash() const {
|
||||
size_t hash = 0;
|
||||
boost::hash_combine(hash, _assetPath);
|
||||
boost::hash_combine(hash, _resolvedPath);
|
||||
return hash;
|
||||
}
|
||||
|
||||
/// \class Hash
|
||||
struct Hash
|
||||
{
|
||||
size_t operator()(const SdfAssetPath &ap) const {
|
||||
return ap.GetHash();
|
||||
}
|
||||
};
|
||||
|
||||
friend size_t hash_value(const SdfAssetPath &ap) { return ap.GetHash(); }
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name Accessors
|
||||
/// @{
|
||||
|
||||
/// Return the asset path.
|
||||
const std::string &GetAssetPath() const {
|
||||
return _assetPath;
|
||||
}
|
||||
|
||||
/// Return the resolved asset path, if any.
|
||||
///
|
||||
/// Note that SdfAssetPath only carries a resolved path if the creator of
|
||||
/// an instance supplied one to the constructor. SdfAssetPath will never
|
||||
/// perform any resolution itself.
|
||||
const std::string &GetResolvedPath() const {
|
||||
return _resolvedPath;
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
private:
|
||||
friend inline void swap(SdfAssetPath &lhs, SdfAssetPath &rhs) {
|
||||
lhs._assetPath.swap(rhs._assetPath);
|
||||
lhs._resolvedPath.swap(rhs._resolvedPath);
|
||||
}
|
||||
|
||||
std::string _assetPath;
|
||||
std::string _resolvedPath;
|
||||
};
|
||||
|
||||
/// \name Related
|
||||
/// @{
|
||||
|
||||
/// Stream insertion operator for the string representation of this assetPath.
|
||||
///
|
||||
/// \note This always encodes only the result of GetAssetPath(). The resolved
|
||||
/// path is ignored for the purpose of this operator. This means that
|
||||
/// two SdfAssetPath that do not compare equal may produce
|
||||
/// indistinguishable ostream output.
|
||||
SDF_API std::ostream& operator<<(std::ostream& out, const SdfAssetPath& ap);
|
||||
|
||||
/// @}
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_ASSET_PATH_H
|
||||
@@ -0,0 +1,191 @@
|
||||
//
|
||||
// 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_SDF_ATTRIBUTE_SPEC_H
|
||||
#define PXR_USD_SDF_ATTRIBUTE_SPEC_H
|
||||
|
||||
/// \file sdf/attributeSpec.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
#include "pxr/usd/sdf/declareSpec.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/usd/sdf/propertySpec.h"
|
||||
#include "pxr/usd/sdf/types.h"
|
||||
#include "pxr/base/tf/enum.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class SdfAttributeSpec
|
||||
///
|
||||
/// A subclass of SdfPropertySpec that holds typed data.
|
||||
///
|
||||
/// Attributes are typed data containers that can optionally hold any
|
||||
/// and all of the following:
|
||||
/// \li A single default value.
|
||||
/// \li An array of knot values describing how the value varies over time.
|
||||
/// \li A dictionary of posed values, indexed by name.
|
||||
///
|
||||
/// The values contained in an attribute must all be of the same type. In the
|
||||
/// Python API the \c typeName property holds the attribute type. In the C++
|
||||
/// API, you can get the attribute type using the GetTypeName() method. In
|
||||
/// addition, all values, including all knot values, must be the same shape.
|
||||
/// For information on shapes, see the VtShape class reference in the C++
|
||||
/// documentation.
|
||||
///
|
||||
class SdfAttributeSpec : public SdfPropertySpec
|
||||
{
|
||||
SDF_DECLARE_SPEC(SdfAttributeSpec, SdfPropertySpec);
|
||||
|
||||
public:
|
||||
typedef SdfAttributeSpec This;
|
||||
typedef SdfPropertySpec Parent;
|
||||
|
||||
///
|
||||
/// \name Spec construction
|
||||
/// @{
|
||||
|
||||
/// Constructs a new prim attribute instance.
|
||||
///
|
||||
/// Creates and returns a new attribute for the given prim.
|
||||
/// The \p owner will own the newly created attribute.
|
||||
SDF_API
|
||||
static SdfAttributeSpecHandle
|
||||
New(const SdfPrimSpecHandle& owner,
|
||||
const std::string& name, const SdfValueTypeName& typeName,
|
||||
SdfVariability variability = SdfVariabilityVarying,
|
||||
bool custom = false);
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name Connections
|
||||
/// @{
|
||||
|
||||
/// Returns a proxy for editing the attribute's connection paths.
|
||||
///
|
||||
/// The returned proxy, which is an SdfListEditorProxy, modifies the
|
||||
/// SdfListOp that represents this attribute's connections.
|
||||
SDF_API
|
||||
SdfConnectionsProxy GetConnectionPathList() const;
|
||||
|
||||
/// Returns \c true if any connection paths are set on this attribute.
|
||||
SDF_API
|
||||
bool HasConnectionPaths() const;
|
||||
|
||||
/// Clears the connection paths for this attribute.
|
||||
SDF_API
|
||||
void ClearConnectionPaths();
|
||||
|
||||
/// @}
|
||||
/// \name Attribute value API
|
||||
/// @{
|
||||
|
||||
/// Returns the allowed tokens metadata for this attribute.
|
||||
/// Consumers may use this metadata to define a set of predefined
|
||||
/// options for this attribute's value. However, this metadata is
|
||||
/// purely advisory. It is up to the consumer to perform any
|
||||
/// validation against this set of tokens, if desired.
|
||||
SDF_API
|
||||
VtTokenArray GetAllowedTokens() const;
|
||||
|
||||
/// Sets the allowed tokens metadata for this attribute.
|
||||
SDF_API
|
||||
void SetAllowedTokens(const VtTokenArray& allowedTokens);
|
||||
|
||||
/// Returns true if allowed tokens metadata is set for this attribute.
|
||||
SDF_API
|
||||
bool HasAllowedTokens() const;
|
||||
|
||||
/// Clears the allowed tokens metadata for this attribute.
|
||||
SDF_API
|
||||
void ClearAllowedTokens();
|
||||
|
||||
/// Returns the display unit of the attribute.
|
||||
SDF_API
|
||||
TfEnum GetDisplayUnit() const;
|
||||
|
||||
/// Sets the display unit of the attribute.
|
||||
SDF_API
|
||||
void SetDisplayUnit(const TfEnum& displayUnit);
|
||||
|
||||
/// Returns true if a display unit is set for this attribute.
|
||||
SDF_API
|
||||
bool HasDisplayUnit() const;
|
||||
|
||||
/// Clears the display unit of the attribute.
|
||||
SDF_API
|
||||
void ClearDisplayUnit();
|
||||
|
||||
/// Returns the color-space in which a color or texture valued attribute
|
||||
/// is authored.
|
||||
SDF_API
|
||||
TfToken GetColorSpace() const;
|
||||
|
||||
/// Sets the color-space in which a color or texture valued attribute is
|
||||
/// authored.
|
||||
SDF_API
|
||||
void SetColorSpace(const TfToken &colorSpace);
|
||||
|
||||
/// Returns true if this attribute has a colorSpace value authored.
|
||||
SDF_API
|
||||
bool HasColorSpace() const;
|
||||
|
||||
/// Clears the colorSpace metadata value set on this attribute.
|
||||
SDF_API
|
||||
void ClearColorSpace();
|
||||
|
||||
/// @}
|
||||
/// \name Spec properties
|
||||
/// @{
|
||||
|
||||
/// Returns the roleName for this attribute's typeName.
|
||||
///
|
||||
/// If the typeName has no roleName, return empty token.
|
||||
SDF_API
|
||||
TfToken GetRoleName() const;
|
||||
|
||||
/// @}
|
||||
};
|
||||
|
||||
/// Convenience function to create an attributeSpec on a primSpec at the given
|
||||
/// path, and any necessary parent primSpecs, in the given layer.
|
||||
///
|
||||
/// If an attributeSpec already exists at the given path, just author typeName,
|
||||
/// variability, and custom according to passed arguments and return true.
|
||||
///
|
||||
/// Any newly created prim specs have SdfSpecifierOver and an empty type (as if
|
||||
/// created by SdfJustCreatePrimInLayer()). attrPath must be a valid prim
|
||||
/// property path (see SdfPath::IsPrimPropertyPath()). Return false and issue
|
||||
/// an error if we fail to author the required scene description.
|
||||
SDF_API
|
||||
bool
|
||||
SdfJustCreatePrimAttributeInLayer(
|
||||
const SdfLayerHandle &layer,
|
||||
const SdfPath &attrPath,
|
||||
const SdfValueTypeName &typeName,
|
||||
SdfVariability variability = SdfVariabilityVarying,
|
||||
bool isCustom = false);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_ATTRIBUTE_SPEC_H
|
||||
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// 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_SDF_CHANGE_BLOCK_H
|
||||
#define PXR_USD_SDF_CHANGE_BLOCK_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class SdfChangeBlock
|
||||
///
|
||||
/// <b>DANGER DANGER DANGER</b>
|
||||
///
|
||||
/// Please make sure you have read and fully understand the
|
||||
/// issues below before using a changeblock! They are very
|
||||
/// easy to use in an unsafe way that could make the system
|
||||
/// crash or corrupt data. If you have any questions, please
|
||||
/// contact the USD team, who would be happy to help!
|
||||
///
|
||||
/// SdfChangeBlock provides a way to group a round of related changes to
|
||||
/// scene description in order to process them more efficiently.
|
||||
///
|
||||
/// Normally, Sdf sends notification immediately as changes are made so
|
||||
/// that downstream representations in Csd and Mf can update accordingly.
|
||||
///
|
||||
/// However, sometimes it can be advantageous to group a series of Sdf
|
||||
/// changes into a batch so that they can be processed more efficiently,
|
||||
/// with a single round of change processing. An example might be when
|
||||
/// setting many avar values on a model at the same time.
|
||||
///
|
||||
/// Opening a changeblock tells Sdf to delay sending notification about
|
||||
/// changes until the outermost changeblock is exited. Until then,
|
||||
/// Sdf internally queues up the notification it needs to send.
|
||||
///
|
||||
/// \note It is *not* safe to use Csd, Mf, or other downstream API
|
||||
/// while a changeblock is open!!111 This is because those derived
|
||||
/// representations will not have had a chance to update while the
|
||||
/// changeblock is open. Not only will their view of the world be
|
||||
/// stale, it could be unsafe to even make queries from, since they
|
||||
/// may be holding onto expired handles to Sdf objects that no longer
|
||||
/// exist.
|
||||
///
|
||||
/// If you need to make a bunch of changes to scene description,
|
||||
/// the best approach is to build a list of necessary changes that
|
||||
/// can be performed directly via the Sdf API, then submit those all
|
||||
/// inside a changeblock without talking to any downstream libraries.
|
||||
/// For example, this is how Csd performs namespace edits.
|
||||
///
|
||||
|
||||
class SdfChangeBlock {
|
||||
public:
|
||||
SDF_API
|
||||
SdfChangeBlock();
|
||||
SDF_API
|
||||
~SdfChangeBlock();
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_CHANGE_BLOCK_H
|
||||
@@ -0,0 +1,266 @@
|
||||
//
|
||||
// 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_SDF_CHANGE_LIST_H
|
||||
#define PXR_USD_SDF_CHANGE_LIST_H
|
||||
|
||||
/// \file sdf/changeList.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/usd/sdf/types.h"
|
||||
#include "pxr/base/tf/smallVector.h"
|
||||
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <iosfwd>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class SdfChangeList;
|
||||
typedef std::vector<
|
||||
std::pair<SdfLayerHandle, SdfChangeList>
|
||||
> SdfLayerChangeListVec;
|
||||
|
||||
/// \class SdfChangeList
|
||||
///
|
||||
/// A list of scene description modifications, organized by the namespace
|
||||
/// paths where the changes occur.
|
||||
///
|
||||
class SdfChangeList
|
||||
{
|
||||
public:
|
||||
|
||||
SdfChangeList() = default;
|
||||
SDF_API SdfChangeList(SdfChangeList const &);
|
||||
SdfChangeList(SdfChangeList &&) = default;
|
||||
SDF_API SdfChangeList &operator=(SdfChangeList const &);
|
||||
SdfChangeList &operator=(SdfChangeList &&) = default;
|
||||
|
||||
enum SubLayerChangeType {
|
||||
SubLayerAdded,
|
||||
SubLayerRemoved,
|
||||
SubLayerOffset
|
||||
};
|
||||
|
||||
void DidReplaceLayerContent();
|
||||
void DidReloadLayerContent();
|
||||
void DidChangeLayerResolvedPath();
|
||||
void DidChangeLayerIdentifier(const std::string &oldIdentifier);
|
||||
void DidChangeSublayerPaths(const std::string &subLayerPath,
|
||||
SubLayerChangeType changeType);
|
||||
|
||||
void DidAddPrim(const SdfPath &primPath, bool inert);
|
||||
void DidRemovePrim(const SdfPath &primPath, bool inert);
|
||||
void DidReorderPrims(const SdfPath &parentPath);
|
||||
void DidChangePrimName(const SdfPath &oldPath, const SdfPath &newPath);
|
||||
void DidChangePrimVariantSets(const SdfPath &primPath);
|
||||
void DidChangePrimInheritPaths(const SdfPath &primPath);
|
||||
void DidChangePrimReferences(const SdfPath &primPath);
|
||||
void DidChangePrimSpecializes(const SdfPath &primPath);
|
||||
|
||||
void DidAddProperty(const SdfPath &propPath, bool hasOnlyRequiredFields);
|
||||
void DidRemoveProperty(const SdfPath &propPath, bool hasOnlyRequiredFields);
|
||||
void DidReorderProperties(const SdfPath &propPath);
|
||||
void DidChangePropertyName(const SdfPath &oldPath, const SdfPath &newPath);
|
||||
|
||||
void DidChangeAttributeTimeSamples(const SdfPath &attrPath);
|
||||
void DidChangeAttributeConnection(const SdfPath &attrPath);
|
||||
void DidChangeRelationshipTargets(const SdfPath &relPath);
|
||||
void DidAddTarget(const SdfPath &targetPath);
|
||||
void DidRemoveTarget(const SdfPath &targetPath);
|
||||
|
||||
void DidChangeInfo(const SdfPath &path, const TfToken &key,
|
||||
const VtValue &oldValue, const VtValue &newValue);
|
||||
|
||||
/// \struct Entry
|
||||
///
|
||||
/// Entry of changes at a single path in namespace.
|
||||
///
|
||||
/// If the path is SdfPath::AbsoluteRootPath(), that indicates a change
|
||||
/// to the root of namespace (that is, a layer or stage).
|
||||
///
|
||||
/// Note: Our language for invalidation used to be more precise
|
||||
/// about items added, removed, or reordered. It might seem that
|
||||
/// this would afford more opportunities for efficient updates,
|
||||
/// but in practice it does not. Because our derived data typically
|
||||
/// must recompose or reinstantiate based on the underlying data,
|
||||
/// the particular delta might be ignored, overridden, or invalid.
|
||||
/// It is simpler to treat all changes identically, and focus on
|
||||
/// making the common base case fast, rather than have complicated
|
||||
/// differential update logic. It also vastly simplifies the
|
||||
/// language of invalidation.
|
||||
///
|
||||
struct Entry {
|
||||
// Map of info keys that have changed to (old, new) value pairs.
|
||||
typedef std::pair<VtValue, VtValue> InfoChange;
|
||||
// We usually change just a few fields on a spec in one go, so we store
|
||||
// up to three locally (e.g. typeName, variability, default).
|
||||
typedef TfSmallVector<std::pair<TfToken, InfoChange>, 3> InfoChangeVec;
|
||||
InfoChangeVec infoChanged;
|
||||
|
||||
/// Return the iterator in infoChanged whose first element is \p key, or
|
||||
/// infoChanged.end() if there is no such element.
|
||||
InfoChangeVec::const_iterator
|
||||
FindInfoChange(TfToken const &key) const {
|
||||
InfoChangeVec::const_iterator iter = infoChanged.begin();
|
||||
for (InfoChangeVec::const_iterator end = infoChanged.end();
|
||||
iter != end; ++iter) {
|
||||
if (iter->first == key) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return iter;
|
||||
}
|
||||
|
||||
/// Return true if this entry has an info change for \p key, false
|
||||
/// otherwise.
|
||||
bool HasInfoChange(TfToken const &key) const {
|
||||
return FindInfoChange(key) != infoChanged.end();
|
||||
}
|
||||
|
||||
typedef std::pair<std::string, SubLayerChangeType> SubLayerChange;
|
||||
std::vector<SubLayerChange> subLayerChanges;
|
||||
|
||||
// Empty if didRename is not set
|
||||
SdfPath oldPath;
|
||||
|
||||
// Empty if didChangeIdentifier is not set
|
||||
std::string oldIdentifier;
|
||||
|
||||
// Most changes are stored as simple bits.
|
||||
struct _Flags {
|
||||
_Flags() {
|
||||
memset(this, 0, sizeof(*this));
|
||||
}
|
||||
|
||||
// SdfLayer
|
||||
bool didChangeIdentifier:1;
|
||||
bool didChangeResolvedPath:1;
|
||||
bool didReplaceContent:1;
|
||||
bool didReloadContent:1;
|
||||
|
||||
// SdfLayer, SdfPrimSpec, SdfRelationshipTarget.
|
||||
bool didReorderChildren:1;
|
||||
bool didReorderProperties:1;
|
||||
|
||||
// SdfPrimSpec, SdfPropertySpec
|
||||
bool didRename:1;
|
||||
|
||||
// SdfPrimSpec
|
||||
bool didChangePrimVariantSets:1;
|
||||
bool didChangePrimInheritPaths:1;
|
||||
bool didChangePrimSpecializes:1;
|
||||
bool didChangePrimReferences:1;
|
||||
|
||||
// SdfPropertySpec
|
||||
bool didChangeAttributeTimeSamples:1;
|
||||
bool didChangeAttributeConnection:1;
|
||||
bool didChangeRelationshipTargets:1;
|
||||
bool didAddTarget:1;
|
||||
bool didRemoveTarget:1;
|
||||
|
||||
// SdfPrimSpec add/remove
|
||||
bool didAddInertPrim:1;
|
||||
bool didAddNonInertPrim:1;
|
||||
bool didRemoveInertPrim:1;
|
||||
bool didRemoveNonInertPrim:1;
|
||||
|
||||
// Property add/remove
|
||||
bool didAddPropertyWithOnlyRequiredFields:1;
|
||||
bool didAddProperty:1;
|
||||
bool didRemovePropertyWithOnlyRequiredFields:1;
|
||||
bool didRemoveProperty:1;
|
||||
};
|
||||
|
||||
_Flags flags;
|
||||
};
|
||||
|
||||
/// Map of change entries at various paths in a layer. We store one entry
|
||||
/// in local space, since it's very common to edit just a single spec in a
|
||||
/// single round of changes.
|
||||
using EntryList = TfSmallVector<std::pair<SdfPath, Entry>, 1>;
|
||||
|
||||
public:
|
||||
const EntryList & GetEntryList() const { return _entries; }
|
||||
|
||||
// Change accessors/mutators
|
||||
SDF_API
|
||||
Entry const &GetEntry( const SdfPath & ) const;
|
||||
|
||||
using const_iterator = EntryList::const_iterator;
|
||||
|
||||
SDF_API
|
||||
const_iterator FindEntry(SdfPath const &) const;
|
||||
|
||||
const_iterator begin() const {
|
||||
return _entries.begin();
|
||||
}
|
||||
|
||||
const_iterator cbegin() const {
|
||||
return _entries.cbegin();
|
||||
}
|
||||
|
||||
const_iterator end() const {
|
||||
return _entries.end();
|
||||
}
|
||||
|
||||
const_iterator cend() const {
|
||||
return _entries.cend();
|
||||
}
|
||||
|
||||
private:
|
||||
friend void swap(SdfChangeList &a, SdfChangeList &b) {
|
||||
a._entries.swap(b._entries);
|
||||
a._entriesAccel.swap(b._entriesAccel);
|
||||
}
|
||||
|
||||
Entry &_GetEntry(SdfPath const &);
|
||||
|
||||
// If no entry with `newPath` exists, create one. If an entry with
|
||||
// `oldPath` exists, move its contents over `newPath`'s and erase it.
|
||||
// Return a reference to `newPath`'s entry.
|
||||
Entry &_MoveEntry(SdfPath const &oldPath, SdfPath const &newPath);
|
||||
|
||||
EntryList::iterator _MakeNonConstIterator(EntryList::const_iterator i);
|
||||
|
||||
Entry &_AddNewEntry(SdfPath const &path);
|
||||
|
||||
void _EraseEntry(SdfPath const &);
|
||||
|
||||
void _RebuildAccel();
|
||||
|
||||
EntryList _entries;
|
||||
using _AccelTable = std::unordered_map<SdfPath, size_t, SdfPath::Hash>;
|
||||
std::unique_ptr<_AccelTable> _entriesAccel;
|
||||
static constexpr size_t _AccelThreshold = 64;
|
||||
};
|
||||
|
||||
// Stream-output operator
|
||||
SDF_API std::ostream& operator<<(std::ostream&, const SdfChangeList &);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_CHANGE_LIST_H
|
||||
@@ -0,0 +1,123 @@
|
||||
//
|
||||
// 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_SDF_CHILDREN_H
|
||||
#define PXR_USD_SDF_CHILDREN_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
SDF_DECLARE_HANDLES(SdfLayer);
|
||||
class SdfSpec;
|
||||
|
||||
/// \class Sdf_Children
|
||||
///
|
||||
/// Sdf_Children generically represents the children of an object. For
|
||||
/// instance, it might be used for the name children of a prim or the
|
||||
/// relationship targets of a relationship.
|
||||
///
|
||||
/// The provided ChildPolicy class determines how this object behaves.
|
||||
/// It primarily specifies how to map between keys (such as the name of
|
||||
/// an object) and values (such as SpecHandles for those objects).
|
||||
///
|
||||
template<class ChildPolicy>
|
||||
class Sdf_Children
|
||||
{
|
||||
public:
|
||||
typedef typename ChildPolicy::KeyPolicy KeyPolicy;
|
||||
typedef typename ChildPolicy::KeyType KeyType;
|
||||
typedef typename ChildPolicy::ValueType ValueType;
|
||||
typedef typename ChildPolicy::FieldType FieldType;
|
||||
typedef Sdf_Children<ChildPolicy> This;
|
||||
|
||||
SDF_API
|
||||
Sdf_Children();
|
||||
|
||||
SDF_API
|
||||
Sdf_Children(const Sdf_Children<ChildPolicy> &other);
|
||||
|
||||
SDF_API
|
||||
Sdf_Children(const SdfLayerHandle &layer,
|
||||
const SdfPath &parentPath, const TfToken &childrenKey,
|
||||
const KeyPolicy& keyPolicy = KeyPolicy());
|
||||
|
||||
/// Return whether this object is valid.
|
||||
SDF_API
|
||||
bool IsValid() const;
|
||||
|
||||
/// Return the number of children that this object contains.
|
||||
SDF_API
|
||||
size_t GetSize() const;
|
||||
|
||||
/// Return the child at the specified index.
|
||||
SDF_API
|
||||
ValueType GetChild(size_t index) const;
|
||||
|
||||
/// Find the index of the specified key, or return the size if it's not found.
|
||||
SDF_API
|
||||
size_t Find(const KeyType &key) const;
|
||||
|
||||
/// Find the key that corresponds to \a value, or return a default
|
||||
/// constructed key if it's not found.
|
||||
SDF_API
|
||||
KeyType FindKey(const ValueType &value) const;
|
||||
|
||||
/// Return true if this object and \a other are equivalent.
|
||||
SDF_API
|
||||
bool IsEqualTo(const This &other) const;
|
||||
|
||||
/// Replace this object's children with the ones in \a values.
|
||||
SDF_API
|
||||
bool Copy(const std::vector<ValueType> & values, const std::string &type);
|
||||
|
||||
/// Insert a new child at the specified \a index.
|
||||
SDF_API
|
||||
bool Insert(const ValueType& value, size_t index, const std::string &type);
|
||||
|
||||
/// Erase the child with the specified key.
|
||||
SDF_API
|
||||
bool Erase(const KeyType& key, const std::string &type);
|
||||
|
||||
private:
|
||||
void _UpdateChildNames() const;
|
||||
|
||||
private:
|
||||
SdfLayerHandle _layer;
|
||||
SdfPath _parentPath;
|
||||
TfToken _childrenKey;
|
||||
KeyPolicy _keyPolicy;
|
||||
|
||||
mutable std::vector<FieldType> _childNames;
|
||||
mutable bool _childNamesValid;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_CHILDREN_H
|
||||
@@ -0,0 +1,293 @@
|
||||
//
|
||||
// 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_SDF_CHILDREN_POLICIES_H
|
||||
#define PXR_USD_SDF_CHILDREN_POLICIES_H
|
||||
|
||||
// These policies are used as template arguments to SdfChildrenView to
|
||||
// determine how the view maps between keys (the child's name or path) and
|
||||
// values (the child's SpecHandle).
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/usd/sdf/types.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/usd/sdf/proxyPolicies.h"
|
||||
#include "pxr/usd/sdf/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
SDF_DECLARE_HANDLES(SdfAttributeSpec);
|
||||
SDF_DECLARE_HANDLES(SdfPrimSpec);
|
||||
SDF_DECLARE_HANDLES(SdfPropertySpec);
|
||||
SDF_DECLARE_HANDLES(SdfRelationshipSpec);
|
||||
SDF_DECLARE_HANDLES(SdfVariantSpec);
|
||||
SDF_DECLARE_HANDLES(SdfVariantSetSpec);
|
||||
|
||||
//
|
||||
// Token Child Policies
|
||||
//
|
||||
|
||||
template <class SpecType>
|
||||
class Sdf_TokenChildPolicy {
|
||||
public:
|
||||
typedef SdfNameKeyPolicy KeyPolicy;
|
||||
typedef KeyPolicy::value_type KeyType;
|
||||
typedef TfToken FieldType;
|
||||
typedef SpecType ValueType;
|
||||
|
||||
static KeyType GetKey(const ValueType &spec) {
|
||||
return spec->GetPath().GetName();
|
||||
}
|
||||
|
||||
static SdfPath GetParentPath(const SdfPath &childPath) {
|
||||
return childPath.GetParentPath();
|
||||
}
|
||||
|
||||
static FieldType GetFieldValue(const SdfPath &childPath) {
|
||||
return childPath.GetNameToken();
|
||||
}
|
||||
|
||||
static bool IsValidIdentifier(const std::string &name) {
|
||||
return SdfSchema::IsValidIdentifier(name);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class Sdf_PrimChildPolicy :
|
||||
public Sdf_TokenChildPolicy<SdfPrimSpecHandle>
|
||||
{
|
||||
public:
|
||||
|
||||
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
|
||||
return parentPath.AppendChild(key);
|
||||
}
|
||||
|
||||
static TfToken GetChildrenToken(const SdfPath& parentPath) {
|
||||
return SdfChildrenKeys->PrimChildren;
|
||||
}
|
||||
};
|
||||
|
||||
class Sdf_PropertyChildPolicy :
|
||||
public Sdf_TokenChildPolicy<SdfPropertySpecHandle>
|
||||
{
|
||||
public:
|
||||
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
|
||||
if (parentPath.IsTargetPath()) {
|
||||
return parentPath.AppendRelationalAttribute(key);
|
||||
}
|
||||
else {
|
||||
return parentPath.AppendProperty(key);
|
||||
}
|
||||
}
|
||||
|
||||
static TfToken GetChildrenToken(const SdfPath& parentPath) {
|
||||
return SdfChildrenKeys->PropertyChildren;
|
||||
}
|
||||
|
||||
static bool IsValidIdentifier(const std::string &name) {
|
||||
return SdfSchema::IsValidNamespacedIdentifier(name);
|
||||
}
|
||||
};
|
||||
|
||||
class Sdf_AttributeChildPolicy :
|
||||
public Sdf_TokenChildPolicy<SdfAttributeSpecHandle>
|
||||
{
|
||||
public:
|
||||
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
|
||||
if (parentPath.IsTargetPath()) {
|
||||
return parentPath.AppendRelationalAttribute(key);
|
||||
}
|
||||
else {
|
||||
return parentPath.AppendProperty(key);
|
||||
}
|
||||
}
|
||||
|
||||
static TfToken GetChildrenToken(const SdfPath& parentPath) {
|
||||
return SdfChildrenKeys->PropertyChildren;
|
||||
}
|
||||
|
||||
static bool IsValidIdentifier(const std::string &name) {
|
||||
return SdfSchema::IsValidNamespacedIdentifier(name);
|
||||
}
|
||||
};
|
||||
|
||||
class Sdf_RelationshipChildPolicy :
|
||||
public Sdf_TokenChildPolicy<SdfRelationshipSpecHandle>
|
||||
{
|
||||
public:
|
||||
|
||||
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
|
||||
return parentPath.AppendProperty(key);
|
||||
}
|
||||
|
||||
static TfToken GetChildrenToken(const SdfPath& parentPath) {
|
||||
return SdfChildrenKeys->PropertyChildren;
|
||||
}
|
||||
|
||||
static bool IsValidIdentifier(const std::string &name) {
|
||||
return SdfSchema::IsValidNamespacedIdentifier(name);
|
||||
}
|
||||
};
|
||||
|
||||
class Sdf_MapperArgChildPolicy :
|
||||
public Sdf_TokenChildPolicy<SdfSpecHandle>
|
||||
{
|
||||
public:
|
||||
|
||||
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
|
||||
return parentPath.AppendMapperArg(key);
|
||||
}
|
||||
|
||||
static TfToken GetChildrenToken(const SdfPath& parentPath) {
|
||||
return SdfChildrenKeys->MapperArgChildren;
|
||||
}
|
||||
};
|
||||
|
||||
class Sdf_ExpressionChildPolicy :
|
||||
public Sdf_TokenChildPolicy<SdfSpecHandle>
|
||||
{
|
||||
public:
|
||||
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
|
||||
return parentPath.AppendExpression();
|
||||
}
|
||||
|
||||
static TfToken GetChildrenToken(const SdfPath& parentPath) {
|
||||
return SdfChildrenKeys->ExpressionChildren;
|
||||
}
|
||||
};
|
||||
|
||||
class Sdf_VariantChildPolicy :
|
||||
public Sdf_TokenChildPolicy<SdfVariantSpecHandle>
|
||||
{
|
||||
public:
|
||||
|
||||
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
|
||||
std::string variantSet = parentPath.GetVariantSelection().first;
|
||||
return parentPath.GetParentPath().AppendVariantSelection(
|
||||
TfToken(variantSet), key);
|
||||
}
|
||||
|
||||
static SdfPath GetParentPath(const SdfPath &childPath) {
|
||||
// Construct a path with the same variant set but an empty variant
|
||||
std::string variantSet = childPath.GetVariantSelection().first;
|
||||
return childPath.GetParentPath().AppendVariantSelection(variantSet, "");
|
||||
}
|
||||
|
||||
static TfToken GetChildrenToken(const SdfPath& parentPath) {
|
||||
return SdfChildrenKeys->VariantChildren;
|
||||
}
|
||||
};
|
||||
|
||||
class Sdf_VariantSetChildPolicy :
|
||||
public Sdf_TokenChildPolicy<SdfVariantSetSpecHandle>
|
||||
{
|
||||
public:
|
||||
|
||||
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
|
||||
return parentPath.AppendVariantSelection(key, "");
|
||||
}
|
||||
|
||||
static TfToken GetChildrenToken(const SdfPath& parentPath) {
|
||||
return SdfChildrenKeys->VariantSetChildren;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Path Child Policies
|
||||
//
|
||||
|
||||
template <class SpecType>
|
||||
class Sdf_PathChildPolicy
|
||||
{
|
||||
public:
|
||||
typedef SdfPathKeyPolicy KeyPolicy;
|
||||
typedef KeyPolicy::value_type KeyType;
|
||||
typedef SpecType ValueType;
|
||||
typedef SdfPath FieldType;
|
||||
|
||||
static SdfPath GetParentPath(const SdfPath &childPath) {
|
||||
return childPath.GetParentPath();
|
||||
}
|
||||
|
||||
static KeyType GetKey(const ValueType &value) {
|
||||
return value->GetPath().GetTargetPath();
|
||||
}
|
||||
|
||||
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
|
||||
return parentPath.AppendTarget(key);
|
||||
}
|
||||
|
||||
static FieldType GetFieldValue(const SdfPath &childPath) {
|
||||
return childPath.GetTargetPath();
|
||||
}
|
||||
|
||||
static bool IsValidIdentifier(const FieldType &path) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool IsValidIdentifier(const std::string &path) {
|
||||
return SdfPath::IsValidPathString(path);
|
||||
}
|
||||
};
|
||||
|
||||
class Sdf_MapperChildPolicy :
|
||||
public Sdf_PathChildPolicy<SdfSpecHandle>
|
||||
{
|
||||
public:
|
||||
static SdfPath GetChildPath(const SdfPath &parentPath, const FieldType &key) {
|
||||
SdfPath targetPath = key.MakeAbsolutePath(parentPath.GetPrimPath());
|
||||
return parentPath.AppendMapper(targetPath);
|
||||
}
|
||||
|
||||
static FieldType GetFieldValue(const SdfPath &childPath) {
|
||||
SdfPath targetPath = childPath.GetTargetPath();
|
||||
return targetPath.MakeAbsolutePath(childPath.GetPrimPath());
|
||||
}
|
||||
|
||||
static TfToken GetChildrenToken(const SdfPath& parentPath) {
|
||||
return SdfChildrenKeys->MapperChildren;
|
||||
}
|
||||
};
|
||||
|
||||
class Sdf_AttributeConnectionChildPolicy :
|
||||
public Sdf_PathChildPolicy<SdfSpecHandle> {
|
||||
public:
|
||||
static TfToken GetChildrenToken(const SdfPath& parentPath) {
|
||||
return SdfChildrenKeys->ConnectionChildren;
|
||||
}
|
||||
};
|
||||
|
||||
class Sdf_RelationshipTargetChildPolicy :
|
||||
public Sdf_PathChildPolicy<SdfSpecHandle> {
|
||||
|
||||
public:
|
||||
static TfToken GetChildrenToken(const SdfPath& parentPath) {
|
||||
return SdfChildrenKeys->RelationshipTargetChildren;
|
||||
}
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_CHILDREN_POLICIES_H
|
||||
@@ -0,0 +1,478 @@
|
||||
//
|
||||
// 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_SDF_CHILDREN_PROXY_H
|
||||
#define PXR_USD_SDF_CHILDREN_PROXY_H
|
||||
|
||||
/// \file sdf/childrenProxy.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
#include "pxr/usd/sdf/changeBlock.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
#include "pxr/base/tf/diagnostic.h"
|
||||
#include "pxr/base/tf/iterator.h"
|
||||
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
#include <boost/iterator/reverse_iterator.hpp>
|
||||
#include <boost/operators.hpp>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
template <class _View>
|
||||
class SdfChildrenProxy : boost::equality_comparable<SdfChildrenProxy<_View> > {
|
||||
public:
|
||||
typedef _View View;
|
||||
typedef typename View::Adapter Adapter;
|
||||
typedef typename View::ChildPolicy ChildPolicy;
|
||||
typedef typename View::key_type key_type;
|
||||
typedef typename View::value_type mapped_type;
|
||||
typedef std::vector<mapped_type> mapped_vector_type;
|
||||
typedef std::pair<const key_type, mapped_type> value_type;
|
||||
typedef std::map<key_type, mapped_type> map_type;
|
||||
typedef typename View::size_type size_type;
|
||||
typedef SdfChildrenProxy<View> This;
|
||||
|
||||
private:
|
||||
typedef typename View::const_iterator _inner_iterator;
|
||||
|
||||
class _ValueProxy {
|
||||
public:
|
||||
_ValueProxy() : _owner(NULL) { }
|
||||
_ValueProxy(This* owner, _inner_iterator i) : _owner(owner), _pos(i)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
operator mapped_type() const
|
||||
{
|
||||
return *_pos;
|
||||
}
|
||||
|
||||
template <class U>
|
||||
_ValueProxy& operator=(const U& x)
|
||||
{
|
||||
_owner->_Set(*_pos, x);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const mapped_type& other) const
|
||||
{
|
||||
return *_pos == other;
|
||||
}
|
||||
|
||||
private:
|
||||
This* _owner;
|
||||
_inner_iterator _pos;
|
||||
};
|
||||
|
||||
class _PairProxy {
|
||||
public:
|
||||
explicit _PairProxy(This* owner, _inner_iterator i) :
|
||||
first(owner->_view.key(i)), second(owner, i) { }
|
||||
|
||||
const key_type first;
|
||||
_ValueProxy second;
|
||||
|
||||
operator value_type() const
|
||||
{
|
||||
return value_type(first, second);
|
||||
}
|
||||
};
|
||||
friend class _PairProxy;
|
||||
|
||||
class _Traits {
|
||||
public:
|
||||
static value_type Dereference(const This* owner, _inner_iterator i)
|
||||
{
|
||||
return value_type(owner->_view.key(i), *i);
|
||||
}
|
||||
|
||||
static _PairProxy Dereference(This* owner, _inner_iterator i)
|
||||
{
|
||||
return _PairProxy(owner, i);
|
||||
}
|
||||
};
|
||||
|
||||
template <class _Owner, class _Iter, class _Value>
|
||||
class _Iterator :
|
||||
public boost::iterator_facade<
|
||||
_Iterator<_Owner, _Iter, _Value>,
|
||||
_Value,
|
||||
std::bidirectional_iterator_tag,
|
||||
_Value> {
|
||||
public:
|
||||
_Iterator() { }
|
||||
_Iterator(_Owner owner, _inner_iterator i) : _owner(owner), _pos(i) { }
|
||||
template <class O2, class I2, class V2>
|
||||
_Iterator(const _Iterator<O2, I2, V2>& other) :
|
||||
_owner(other._owner), _pos(other._pos) { }
|
||||
|
||||
private:
|
||||
friend class boost::iterator_core_access;
|
||||
|
||||
_Value dereference() const
|
||||
{
|
||||
return _Traits::Dereference(_owner, _pos);
|
||||
}
|
||||
|
||||
template <class O2, class I2, class V2>
|
||||
bool equal(const _Iterator<O2, I2, V2>& other) const
|
||||
{
|
||||
return _pos == other._pos;
|
||||
}
|
||||
|
||||
void increment() {
|
||||
++_pos;
|
||||
}
|
||||
|
||||
void decrement() {
|
||||
--_pos;
|
||||
}
|
||||
|
||||
private:
|
||||
_Owner _owner;
|
||||
_inner_iterator _pos;
|
||||
|
||||
template <class O2, class I2, class V2>
|
||||
friend class _Iterator;
|
||||
};
|
||||
|
||||
public:
|
||||
typedef _ValueProxy reference;
|
||||
typedef _Iterator<This*, _inner_iterator, _PairProxy> iterator;
|
||||
typedef boost::reverse_iterator<iterator> reverse_iterator;
|
||||
typedef _Iterator<const This*, _inner_iterator, value_type> const_iterator;
|
||||
typedef boost::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
|
||||
static const int CanSet = 1;
|
||||
static const int CanInsert = 2;
|
||||
static const int CanErase = 4;
|
||||
|
||||
SdfChildrenProxy(const View& view, const std::string& type,
|
||||
int permission = CanSet | CanInsert | CanErase) :
|
||||
_view(view), _type(type), _permission(permission)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
template <class U>
|
||||
SdfChildrenProxy(const SdfChildrenProxy<U>& other) :
|
||||
_view(other._view), _type(other._type), _permission(other._permission)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
This& operator=(const This& other)
|
||||
{
|
||||
if (other._Validate()) {
|
||||
_Copy(other._view.values());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class U>
|
||||
This& operator=(const SdfChildrenProxy<U>& other)
|
||||
{
|
||||
if (other._Validate()) {
|
||||
_Copy(other._view.values());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
This& operator=(const mapped_vector_type& values)
|
||||
{
|
||||
_Copy(values);
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator mapped_vector_type() const
|
||||
{
|
||||
return _Validate() ? _view.values() : mapped_vector_type();
|
||||
}
|
||||
|
||||
map_type items() const
|
||||
{
|
||||
return _Validate() ? _view.template items_as<map_type>() :map_type();
|
||||
}
|
||||
|
||||
iterator begin()
|
||||
{
|
||||
return iterator(_GetThis(), _view.begin());
|
||||
}
|
||||
iterator end()
|
||||
{
|
||||
return iterator(_GetThis(), _view.end());
|
||||
}
|
||||
const_iterator begin() const
|
||||
{
|
||||
return const_iterator(_GetThis(), _view.begin());
|
||||
}
|
||||
const_iterator end() const
|
||||
{
|
||||
return const_iterator(_GetThis(), _view.end());
|
||||
}
|
||||
|
||||
reverse_iterator rbegin()
|
||||
{
|
||||
return reverse_iterator(end());
|
||||
}
|
||||
reverse_iterator rend()
|
||||
{
|
||||
return reverse_iterator(begin());
|
||||
}
|
||||
const_reverse_iterator rbegin() const
|
||||
{
|
||||
return reverse_iterator(end());
|
||||
}
|
||||
const_reverse_iterator rend() const
|
||||
{
|
||||
return reverse_iterator(begin());
|
||||
}
|
||||
|
||||
size_type size() const
|
||||
{
|
||||
return _Validate() ? _view.size() : 0;
|
||||
}
|
||||
|
||||
size_type max_size() const
|
||||
{
|
||||
return _view.max_size();
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return _Validate() ? _view.empty() : true;
|
||||
}
|
||||
|
||||
std::pair<iterator, bool> insert(const mapped_type& value)
|
||||
{
|
||||
if (_Validate(CanInsert)) {
|
||||
iterator i = find(_view.key(value));
|
||||
if (i == end()) {
|
||||
if (_PrimInsert(value, size())) {
|
||||
return std::make_pair(find(_view.key(value)), true);
|
||||
}
|
||||
else {
|
||||
return std::make_pair(end(), false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return std::make_pair(i, false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return std::make_pair(iterator(), false);
|
||||
}
|
||||
}
|
||||
|
||||
iterator insert(iterator pos, const mapped_type& value)
|
||||
{
|
||||
return insert(value).first;
|
||||
}
|
||||
|
||||
template <class InputIterator>
|
||||
void insert(InputIterator first, InputIterator last)
|
||||
{
|
||||
if (_Validate(CanInsert)) {
|
||||
SdfChangeBlock block;
|
||||
for (; first != last; ++first) {
|
||||
_PrimInsert(*first, size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void erase(iterator pos)
|
||||
{
|
||||
_Erase(pos->first);
|
||||
}
|
||||
|
||||
size_type erase(const key_type& key)
|
||||
{
|
||||
return _Erase(key) ? 1 : 0;
|
||||
}
|
||||
|
||||
void erase(iterator first, iterator last)
|
||||
{
|
||||
if (_Validate(CanErase)) {
|
||||
SdfChangeBlock block;
|
||||
while (first != last) {
|
||||
const key_type& key = first->first;
|
||||
++first;
|
||||
_PrimErase(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
_Copy(mapped_vector_type());
|
||||
}
|
||||
|
||||
iterator find(const key_type& key)
|
||||
{
|
||||
return _Validate() ? iterator(this, _view.find(key)) : iterator();
|
||||
}
|
||||
|
||||
const_iterator find(const key_type& key) const
|
||||
{
|
||||
return _Validate() ? const_iterator(this, _view.find(key)) :
|
||||
const_iterator();
|
||||
}
|
||||
|
||||
size_type count(const key_type& key) const
|
||||
{
|
||||
return _Validate() ? _view.count(key) : 0;
|
||||
}
|
||||
|
||||
bool operator==(const This& other) const
|
||||
{
|
||||
return _view == other._view;
|
||||
}
|
||||
|
||||
/// Explicit bool conversion operator. The proxy object converts to
|
||||
/// \c true if it is valid, \c false otherwise.
|
||||
explicit operator bool() const
|
||||
{
|
||||
return _view.IsValid();
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string& _GetType() const
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
int _GetPermission() const
|
||||
{
|
||||
return _permission;
|
||||
}
|
||||
|
||||
This* _GetThis()
|
||||
{
|
||||
return _Validate() ? this : NULL;
|
||||
}
|
||||
|
||||
const This* _GetThis() const
|
||||
{
|
||||
return _Validate() ? this : NULL;
|
||||
}
|
||||
|
||||
bool _Validate() const
|
||||
{
|
||||
if (_view.IsValid()) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
TF_CODING_ERROR("Accessing expired %s", _type.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool _Validate(int permission)
|
||||
{
|
||||
if (!_Validate()) {
|
||||
return false;
|
||||
}
|
||||
if ((_permission & permission) == permission) {
|
||||
return true;
|
||||
}
|
||||
const char* op = "edit";
|
||||
if (~_permission & permission & CanSet) {
|
||||
op = "replace";
|
||||
}
|
||||
else if (~_permission & permission & CanInsert) {
|
||||
op = "insert";
|
||||
}
|
||||
else if (~_permission & permission & CanErase) {
|
||||
op = "remove";
|
||||
}
|
||||
TF_CODING_ERROR("Cannot %s %s", op, _type.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
bool _Copy(const mapped_vector_type& values)
|
||||
{
|
||||
return _Validate(CanSet) ? _PrimCopy(values) : false;
|
||||
}
|
||||
|
||||
bool _Insert(const mapped_type& value, size_t index)
|
||||
{
|
||||
return _Validate(CanInsert) ? _PrimInsert(value, index) : false;
|
||||
}
|
||||
|
||||
bool _Erase(const key_type& key)
|
||||
{
|
||||
return _Validate(CanErase) ? _PrimErase(key) : false;
|
||||
}
|
||||
|
||||
bool _PrimCopy(const mapped_vector_type& values)
|
||||
{
|
||||
typedef std::vector<typename ChildPolicy::ValueType>
|
||||
ChildrenValueVector;
|
||||
|
||||
ChildrenValueVector v;
|
||||
for (size_t i = 0; i < values.size(); ++i)
|
||||
v.push_back(Adapter::Convert(values[i]));
|
||||
|
||||
return _view.GetChildren().Copy(v, _type);
|
||||
}
|
||||
|
||||
bool _PrimInsert(const mapped_type& value, size_t index)
|
||||
{
|
||||
return _view.GetChildren().Insert(
|
||||
Adapter::Convert(value), index, _type);
|
||||
}
|
||||
|
||||
bool _PrimErase(const key_type& key)
|
||||
{
|
||||
return _view.GetChildren().Erase(key, _type);
|
||||
}
|
||||
|
||||
private:
|
||||
View _view;
|
||||
std::string _type;
|
||||
int _permission;
|
||||
|
||||
template <class V> friend class SdfChildrenProxy;
|
||||
template <class V> friend class SdfPyChildrenProxy;
|
||||
};
|
||||
|
||||
// Allow TfIteration over children proxies.
|
||||
template <typename _View>
|
||||
struct Tf_ShouldIterateOverCopy<SdfChildrenProxy<_View> > : boost::true_type
|
||||
{
|
||||
};
|
||||
|
||||
// Cannot get from a VtValue except as the correct type.
|
||||
template <class _View>
|
||||
struct Vt_DefaultValueFactory<SdfChildrenProxy<_View> > {
|
||||
static Vt_DefaultValueHolder Invoke() = delete;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_CHILDREN_PROXY_H
|
||||
@@ -0,0 +1,177 @@
|
||||
//
|
||||
// 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_SDF_CHILDREN_UTILS_H
|
||||
#define PXR_USD_SDF_CHILDREN_UTILS_H
|
||||
|
||||
/// \file sdf/childrenUtils.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
#include "pxr/usd/sdf/allowed.h"
|
||||
#include "pxr/usd/sdf/types.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class Sdf_ChildrenUtils
|
||||
///
|
||||
/// Helper functions for creating and manipulating the children
|
||||
/// of a spec. A ChildPolicy must be provided that specifies which type
|
||||
/// of children to edit. (See childrenPolicies.h for details).
|
||||
///
|
||||
template<class ChildPolicy>
|
||||
class Sdf_ChildrenUtils
|
||||
{
|
||||
public:
|
||||
/// The type of the key that identifies a child. This is usually
|
||||
/// a std::string or an SdfPath.
|
||||
typedef typename ChildPolicy::KeyType KeyType;
|
||||
|
||||
/// The type of the child identifier as it's stored in the layer's data.
|
||||
/// This is usually a TfToken.
|
||||
typedef typename ChildPolicy::FieldType FieldType;
|
||||
|
||||
/// Create a new spec in \a layer at \childPath and add it to its parent's
|
||||
/// field named \childrenKey. Emit an error and return false if the new spec
|
||||
/// couldn't be created.
|
||||
static bool CreateSpec(
|
||||
const SdfLayerHandle &layer,
|
||||
const SdfPath &childPath,
|
||||
SdfSpecType specType,
|
||||
bool inert=true) {
|
||||
return CreateSpec(get_pointer(layer), childPath, specType, inert);
|
||||
}
|
||||
|
||||
// This overload is intended primarily for internal use.
|
||||
SDF_API
|
||||
static bool CreateSpec(
|
||||
SdfLayer *layer,
|
||||
const SdfPath &childPath,
|
||||
SdfSpecType specType,
|
||||
bool inert=true);
|
||||
|
||||
/// \name Rename API
|
||||
/// @{
|
||||
|
||||
/// Return whether \a newName is a valid name for a child.
|
||||
SDF_API
|
||||
static bool IsValidName(const FieldType &newName);
|
||||
|
||||
/// Return whether \a newName is a valid name for a child.
|
||||
SDF_API
|
||||
static bool IsValidName(const std::string &newName);
|
||||
|
||||
/// Return whether \a spec can be renamed to \a newName.
|
||||
static SdfAllowed CanRename(
|
||||
const SdfSpec &spec,
|
||||
const FieldType &newName);
|
||||
|
||||
/// Rename \a spec to \a newName. If \a fixPrimListEdits is true,
|
||||
/// then also fix up the name children order. It's an error for
|
||||
/// \a fixPrimListEdits to be true if spec is not a PrimSpec.
|
||||
SDF_API
|
||||
static bool Rename(
|
||||
const SdfSpec &spec,
|
||||
const FieldType &newName);
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name Children List API
|
||||
/// @{
|
||||
|
||||
/// Replace the children of the spec at \a path with the specs in \a
|
||||
/// values. This will delete existing children that aren't in \a values and
|
||||
/// reparent children from other locations in the layer.
|
||||
SDF_API
|
||||
static bool SetChildren(
|
||||
const SdfLayerHandle &layer,
|
||||
const SdfPath &path,
|
||||
const std::vector<typename ChildPolicy::ValueType> &values);
|
||||
|
||||
/// Insert \a value as a child of \a path at the specified index.
|
||||
SDF_API
|
||||
static bool InsertChild(
|
||||
const SdfLayerHandle &layer,
|
||||
const SdfPath &path,
|
||||
const typename ChildPolicy::ValueType& value,
|
||||
int index);
|
||||
|
||||
/// Remove the child identified by \a key.
|
||||
SDF_API
|
||||
static bool RemoveChild(
|
||||
const SdfLayerHandle &layer,
|
||||
const SdfPath &path,
|
||||
const typename ChildPolicy::KeyType& key);
|
||||
|
||||
/// @}
|
||||
/// \name Batch editing API
|
||||
/// @{
|
||||
|
||||
|
||||
/// Insert \a value as a child of \a path at the specified index with
|
||||
/// the new name \p newName.
|
||||
SDF_API
|
||||
static bool MoveChildForBatchNamespaceEdit(
|
||||
const SdfLayerHandle &layer,
|
||||
const SdfPath &path,
|
||||
const typename ChildPolicy::ValueType& value,
|
||||
const typename ChildPolicy::FieldType& newName,
|
||||
int index);
|
||||
|
||||
/// Remove the child identified by \a key.
|
||||
SDF_API
|
||||
static bool RemoveChildForBatchNamespaceEdit(
|
||||
const SdfLayerHandle &layer,
|
||||
const SdfPath &path,
|
||||
const typename ChildPolicy::KeyType& key)
|
||||
{
|
||||
return RemoveChild(layer, path, key);
|
||||
}
|
||||
|
||||
/// Returns \c true if \p value can be inserted as a child of \p path
|
||||
/// with the new name \p newName at the index \p index, otherwise
|
||||
/// returns \c false and sets \p whyNot.
|
||||
SDF_API
|
||||
static bool CanMoveChildForBatchNamespaceEdit(
|
||||
const SdfLayerHandle &layer,
|
||||
const SdfPath &path,
|
||||
const typename ChildPolicy::ValueType& value,
|
||||
const typename ChildPolicy::FieldType& newName,
|
||||
int index,
|
||||
std::string* whyNot);
|
||||
|
||||
/// Returns \c true if the child of \p path identified by \p key can
|
||||
/// be removed, otherwise returns \c false and sets \p whyNot.
|
||||
SDF_API
|
||||
static bool CanRemoveChildForBatchNamespaceEdit(
|
||||
const SdfLayerHandle &layer,
|
||||
const SdfPath &path,
|
||||
const typename ChildPolicy::FieldType& key,
|
||||
std::string* whyNot);
|
||||
|
||||
/// @}
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_CHILDREN_UTILS_H
|
||||
@@ -0,0 +1,537 @@
|
||||
//
|
||||
// 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_SDF_CHILDREN_VIEW_H
|
||||
#define PXR_USD_SDF_CHILDREN_VIEW_H
|
||||
|
||||
/// \file sdf/childrenView.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
#include "pxr/usd/sdf/children.h"
|
||||
#include "pxr/base/tf/iterator.h"
|
||||
|
||||
#include <boost/compressed_pair.hpp>
|
||||
#include <boost/iterator/filter_iterator.hpp>
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
#include <boost/iterator/reverse_iterator.hpp>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class SdfChildrenViewTrivialPredicate
|
||||
///
|
||||
/// Special case predicate that always passes.
|
||||
///
|
||||
/// \c T is the type exposed by the value traits.
|
||||
///
|
||||
/// This predicate is compiled out.
|
||||
///
|
||||
template <class T>
|
||||
class SdfChildrenViewTrivialPredicate {
|
||||
public:
|
||||
bool operator()(const T& x) const { return true; }
|
||||
};
|
||||
|
||||
/// \class SdfChildrenViewTrivialAdapter
|
||||
///
|
||||
/// Special case adapter that does no conversions.
|
||||
///
|
||||
template <class T>
|
||||
class SdfChildrenViewTrivialAdapter {
|
||||
public:
|
||||
typedef T PrivateType;
|
||||
typedef T PublicType;
|
||||
static const PublicType& Convert(const PrivateType& t) { return t; }
|
||||
};
|
||||
|
||||
/// \class Sdf_ChildrenViewTraits
|
||||
/// This traits class defines the iterator for a particular ChildrenView
|
||||
/// along with conversions to and from the view's internal un-filtered iterator.
|
||||
///
|
||||
/// A specialization of the traits for trivial predicates allows the
|
||||
/// internal iterator to be used directly.
|
||||
///
|
||||
template <typename _Owner, typename _InnerIterator, typename _DummyPredicate>
|
||||
class Sdf_ChildrenViewTraits {
|
||||
private:
|
||||
|
||||
// Internal predicate object which will be passed to the filter
|
||||
// iterator. This just calls through to the owner's predicate.
|
||||
class _Predicate {
|
||||
public:
|
||||
typedef typename _Owner::value_type value_type;
|
||||
|
||||
_Predicate() : _owner(NULL) { }
|
||||
_Predicate(const _Owner* owner) : _owner(owner) { }
|
||||
|
||||
bool operator()(const value_type& x) const
|
||||
{
|
||||
return _owner->GetPredicate()(
|
||||
_Owner::Adapter::Convert(x));
|
||||
}
|
||||
|
||||
private:
|
||||
const _Owner* _owner;
|
||||
};
|
||||
|
||||
public:
|
||||
typedef boost::filter_iterator<_Predicate, _InnerIterator> const_iterator;
|
||||
|
||||
// Convert from a private _InnerIterator to a public const_iterator.
|
||||
// filter_iterator requires an end iterator, which is constructed using
|
||||
// size.
|
||||
static const_iterator GetIterator(const _Owner* owner,
|
||||
const _InnerIterator& i,
|
||||
size_t size)
|
||||
{
|
||||
_InnerIterator end(owner,size);
|
||||
return const_iterator(_Predicate(owner), i, end);
|
||||
}
|
||||
|
||||
// Convert from a public const_iterator to a private _InnerIterator.
|
||||
static const _InnerIterator& GetBase(const const_iterator& i)
|
||||
{
|
||||
return i.base();
|
||||
}
|
||||
};
|
||||
|
||||
// Children view traits specialization for trivial predicates. This
|
||||
// eliminates the predicate altogether and defines the public iterator type
|
||||
// to be the same as the inner iterator type.
|
||||
template <typename _Owner, typename _InnerIterator>
|
||||
class Sdf_ChildrenViewTraits<_Owner, _InnerIterator,
|
||||
SdfChildrenViewTrivialPredicate<typename _Owner::ChildPolicy::ValueType> > {
|
||||
private:
|
||||
|
||||
public:
|
||||
typedef _InnerIterator const_iterator;
|
||||
|
||||
static const const_iterator& GetIterator(const _Owner*,
|
||||
const _InnerIterator& i, size_t size)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
||||
static const _InnerIterator& GetBase(const const_iterator& i)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
};
|
||||
|
||||
/// \class SdfChildrenView
|
||||
///
|
||||
/// Provides a view onto an object's children.
|
||||
///
|
||||
/// The \c _ChildPolicy dictates the type of children being viewed by this
|
||||
/// object. This policy defines the key type by which children are referenced
|
||||
/// (e.g. a TfToken, or an SdfPath) and the value type of the children objects.
|
||||
///
|
||||
/// The \c _Predicate takes a value type argument and returns \c true if the
|
||||
/// object should be included in the view and \c false otherwise.
|
||||
///
|
||||
/// The \c _Adapter allows the view to present the children objects as a
|
||||
/// different type. The _Adapter class must provide functions to convert the
|
||||
/// children object type defined by \c _ChildPolicy to the desired public
|
||||
/// type and vice-versa. See SdfChildrenViewTrivialAdapter for an example.
|
||||
/// By default, the view presents children objects as the value type defined
|
||||
/// in \c _ChildPolicy.
|
||||
///
|
||||
/// Note that all methods are const, i.e. the children cannot be changed
|
||||
/// through a view.
|
||||
///
|
||||
template <typename _ChildPolicy,
|
||||
typename _Predicate =
|
||||
SdfChildrenViewTrivialPredicate<
|
||||
typename _ChildPolicy::ValueType>,
|
||||
typename _Adapter =
|
||||
SdfChildrenViewTrivialAdapter<
|
||||
typename _ChildPolicy::ValueType> >
|
||||
class SdfChildrenView {
|
||||
public:
|
||||
typedef SdfChildrenView<_ChildPolicy, _Predicate, _Adapter> This;
|
||||
|
||||
typedef _Adapter Adapter;
|
||||
typedef _Predicate Predicate;
|
||||
typedef _ChildPolicy ChildPolicy;
|
||||
typedef typename ChildPolicy::KeyPolicy KeyPolicy;
|
||||
typedef Sdf_Children<ChildPolicy> ChildrenType;
|
||||
|
||||
typedef typename ChildPolicy::KeyType key_type;
|
||||
typedef typename Adapter::PublicType value_type;
|
||||
|
||||
private:
|
||||
|
||||
// An iterator type for the internal unfiltered data storage. This
|
||||
// iterator holds a pointer to its owning object and an index into
|
||||
// the owner's storage. That allows the iterator to operate without
|
||||
// knowing anything about the specific data storage that's used,
|
||||
// which is important for providing both Gd and Lsd backed storage.
|
||||
class _InnerIterator :
|
||||
public boost::iterator_facade<_InnerIterator,
|
||||
value_type,
|
||||
std::random_access_iterator_tag,
|
||||
value_type> {
|
||||
public:
|
||||
typedef value_type reference;
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
|
||||
_InnerIterator() :
|
||||
_owner(NULL), _pos(0) { }
|
||||
_InnerIterator(const This* owner, const size_t& pos) :
|
||||
_owner(owner), _pos(pos) { }
|
||||
|
||||
private:
|
||||
friend class boost::iterator_core_access;
|
||||
|
||||
reference dereference() const
|
||||
{
|
||||
return _owner->_Get(_pos);
|
||||
}
|
||||
|
||||
bool equal(const _InnerIterator& other) const
|
||||
{
|
||||
return _pos == other._pos;
|
||||
}
|
||||
|
||||
void increment() {
|
||||
++_pos;
|
||||
}
|
||||
|
||||
void decrement() {
|
||||
--_pos;
|
||||
}
|
||||
|
||||
void advance(difference_type n) {
|
||||
_pos += n;
|
||||
}
|
||||
|
||||
difference_type distance_to(const _InnerIterator& other) const {
|
||||
return other._pos-_pos;
|
||||
}
|
||||
|
||||
private:
|
||||
const This* _owner;
|
||||
size_t _pos;
|
||||
};
|
||||
|
||||
public:
|
||||
typedef Sdf_ChildrenViewTraits<This, _InnerIterator, Predicate> _Traits;
|
||||
typedef typename _Traits::const_iterator const_iterator;
|
||||
typedef boost::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
|
||||
SdfChildrenView()
|
||||
{
|
||||
}
|
||||
|
||||
SdfChildrenView(const SdfLayerHandle &layer, const SdfPath &path,
|
||||
const TfToken &childrenKey,
|
||||
const KeyPolicy& keyPolicy = KeyPolicy()) :
|
||||
_children(layer, path, childrenKey, keyPolicy)
|
||||
{
|
||||
}
|
||||
|
||||
SdfChildrenView(const SdfLayerHandle &layer, const SdfPath &path,
|
||||
const TfToken &childrenKey,
|
||||
const Predicate& predicate,
|
||||
const KeyPolicy& keyPolicy = KeyPolicy()) :
|
||||
_children(layer, path, childrenKey, keyPolicy),
|
||||
_predicate(predicate)
|
||||
{
|
||||
}
|
||||
|
||||
SdfChildrenView(const SdfChildrenView &other) :
|
||||
_children(other._children),
|
||||
_predicate(other._predicate)
|
||||
{
|
||||
}
|
||||
|
||||
template <class OtherAdapter>
|
||||
SdfChildrenView(const SdfChildrenView<ChildPolicy, Predicate,
|
||||
OtherAdapter> &other) :
|
||||
_children(other._children),
|
||||
_predicate(other._predicate)
|
||||
{
|
||||
}
|
||||
|
||||
~SdfChildrenView()
|
||||
{
|
||||
}
|
||||
|
||||
SdfChildrenView& operator=(const SdfChildrenView &other)
|
||||
{
|
||||
_children= other._children;
|
||||
_predicate = other._predicate;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Returns an const_iterator pointing to the beginning of the vector.
|
||||
const_iterator begin() const {
|
||||
_InnerIterator i(this,0);
|
||||
return _Traits::GetIterator(this, i, _GetSize());
|
||||
}
|
||||
|
||||
/// Returns an const_iterator pointing to the end of the vector.
|
||||
const_iterator end() const {
|
||||
_InnerIterator i(this,_GetSize());
|
||||
return _Traits::GetIterator(this, i, _GetSize());
|
||||
}
|
||||
|
||||
/// Returns an const_reverse_iterator pointing to the beginning of the
|
||||
/// reversed vector.
|
||||
const_reverse_iterator rbegin() const {
|
||||
return const_reverse_iterator(end());
|
||||
}
|
||||
|
||||
/// Returns an const_reverse_iterator pointing to the end of the
|
||||
/// reversed vector.
|
||||
const_reverse_iterator rend() const {
|
||||
return const_reverse_iterator(begin());
|
||||
}
|
||||
|
||||
/// Returns the size of the vector.
|
||||
size_type size() const {
|
||||
return std::distance(begin(), end());
|
||||
}
|
||||
|
||||
/// Returns \c true if the vector is empty.
|
||||
bool empty() const {
|
||||
return begin() == end();
|
||||
}
|
||||
|
||||
/// Returns the \p n'th element.
|
||||
value_type operator[](size_type n) const {
|
||||
const_iterator i = begin();
|
||||
std::advance(i, n);
|
||||
return *i;
|
||||
}
|
||||
|
||||
/// Returns the first element.
|
||||
value_type front() const {
|
||||
return *begin();
|
||||
}
|
||||
|
||||
/// Returns the last element.
|
||||
value_type back() const {
|
||||
return *rbegin();
|
||||
}
|
||||
|
||||
/// Finds the element with key \p x.
|
||||
const_iterator find(const key_type& x) const {
|
||||
_InnerIterator inner(this, _children.Find(x));
|
||||
const_iterator iter = _Traits::GetIterator(this, inner, _GetSize());
|
||||
|
||||
// _Traits::GetIterator may return a filtered iterator. We need to
|
||||
// check that that iterator actually corresponds to the desired item.
|
||||
// This ensures that we return end() in the case where the element being
|
||||
// searched for is present in the children but filtered out by the
|
||||
// view's predicate.
|
||||
return _Traits::GetBase(iter) == inner ? iter : end();
|
||||
}
|
||||
|
||||
/// Finds element \p x, if present in this view.
|
||||
const_iterator find(const value_type& x) const {
|
||||
const_iterator i = find(key(x));
|
||||
return (i != end() && *i == x) ? i : end();
|
||||
}
|
||||
|
||||
/// Returns the key for an element.
|
||||
key_type key(const const_iterator& x) const {
|
||||
return key(*x);
|
||||
}
|
||||
|
||||
/// Returns the key for a value.
|
||||
key_type key(const value_type& x) const {
|
||||
return _children.FindKey(Adapter::Convert(x));
|
||||
}
|
||||
|
||||
/// Returns the elements, in order.
|
||||
std::vector<value_type> values() const {
|
||||
return std::vector<value_type>(begin(), end());
|
||||
}
|
||||
|
||||
/// Returns the elements, in order.
|
||||
template <typename V>
|
||||
V values_as() const {
|
||||
V x;
|
||||
std::copy(begin(), end(), std::inserter(x, x.begin()));
|
||||
return x;
|
||||
}
|
||||
|
||||
/// Returns the keys for all elements, in order.
|
||||
std::vector<key_type> keys() const {
|
||||
std::vector<key_type> result;
|
||||
result.reserve(size());
|
||||
for (const_iterator i = begin(), n = end(); i != n; ++i) {
|
||||
result.push_back(key(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Returns the keys for all elements, in order.
|
||||
template <typename V>
|
||||
V keys_as() const {
|
||||
std::vector<key_type> k = keys();
|
||||
return V(k.begin(), k.end());
|
||||
}
|
||||
|
||||
/// Returns the elements as a dictionary.
|
||||
template <typename Dict>
|
||||
Dict items_as() const {
|
||||
Dict result;
|
||||
for (const_iterator i = begin(), n = end(); i != n; ++i) {
|
||||
result.insert(std::make_pair(key(i), *i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Returns true if an element with key \p x is in the container.
|
||||
bool has(const key_type& x) const {
|
||||
return (_children.Find(x) != _GetSize());
|
||||
}
|
||||
|
||||
/// Returns true if an element with the same key as \p x is in
|
||||
/// the container.
|
||||
bool has(const value_type& x) const {
|
||||
return has(key(Adapter::Convert(x)));
|
||||
}
|
||||
|
||||
/// Returns the number of elements with key \p x in the container.
|
||||
size_type count(const key_type& x) const {
|
||||
return has(x);
|
||||
}
|
||||
|
||||
/// Returns the element with key \p x or a default constructed value
|
||||
/// if no such element exists.
|
||||
value_type get(const key_type& x) const {
|
||||
size_t index = _children.Find(x);
|
||||
if (index == _GetSize()) {
|
||||
return value_type();
|
||||
}
|
||||
return _Get(index);
|
||||
}
|
||||
|
||||
/// Returns the element with key \p x or the fallback if no such
|
||||
/// element exists.
|
||||
value_type get(const key_type& x, const value_type& fallback) const {
|
||||
size_t index = _children.Find(x);
|
||||
if (index == _GetSize()) {
|
||||
return fallback;
|
||||
}
|
||||
return _Get(index);
|
||||
}
|
||||
|
||||
/// Returns the element with key \p x or a default constructed value
|
||||
/// if no such element exists.
|
||||
value_type operator[](const key_type& x) const {
|
||||
return get(x);
|
||||
}
|
||||
|
||||
/// Compares children for equality. Children are equal if the
|
||||
/// list edits are identical and the keys contain the same elements.
|
||||
bool operator==(const This& other) const {
|
||||
return _children.IsEqualTo(other._children);
|
||||
}
|
||||
|
||||
/// Compares children for inequality. Children are not equal if
|
||||
/// list edits are not identical or the keys don't contain the same
|
||||
/// elements.
|
||||
bool operator!=(const This& other) const {
|
||||
return !_children.IsEqualTo(other._children);
|
||||
}
|
||||
|
||||
// Return true if this object is valid
|
||||
bool IsValid() const {
|
||||
return _children.IsValid();
|
||||
}
|
||||
|
||||
// Return the Sd_Children object that this view is holding.
|
||||
ChildrenType &GetChildren() {
|
||||
return _children;
|
||||
}
|
||||
|
||||
// Return this view's predicate.
|
||||
const Predicate& GetPredicate() const {
|
||||
return _predicate;
|
||||
}
|
||||
|
||||
private:
|
||||
// Return the value that corresponds to the provided index.
|
||||
value_type _Get(size_type index) const {
|
||||
return Adapter::Convert(_children.GetChild(index));
|
||||
}
|
||||
|
||||
// Return the number of elements
|
||||
size_t _GetSize() const {
|
||||
return _children.GetSize();
|
||||
}
|
||||
|
||||
private:
|
||||
template <class V, class P, class A> friend class SdfChildrenView;
|
||||
ChildrenType _children;
|
||||
Predicate _predicate;
|
||||
};
|
||||
|
||||
/// Helper class to convert a given view of type \c _View to an
|
||||
/// adapted view using \c _Adapter as the adapter class.
|
||||
template <class _View, class _Adapter>
|
||||
struct SdfAdaptedChildrenViewCreator
|
||||
{
|
||||
typedef _View OriginalView;
|
||||
typedef SdfChildrenView<typename _View::ChildPolicy,
|
||||
typename _View::Predicate,
|
||||
_Adapter> AdaptedView;
|
||||
|
||||
static AdaptedView Create(const OriginalView& view)
|
||||
{
|
||||
return AdaptedView(view);
|
||||
}
|
||||
};
|
||||
|
||||
// Allow TfIteration over children views.
|
||||
template <typename C, typename P, typename A>
|
||||
struct Tf_ShouldIterateOverCopy<SdfChildrenView<C, P, A> > : boost::true_type
|
||||
{
|
||||
};
|
||||
template <typename C, typename P, typename A>
|
||||
struct Tf_IteratorInterface<SdfChildrenView<C, P, A>, false> {
|
||||
typedef SdfChildrenView<C, P, A> Type;
|
||||
typedef typename Type::const_iterator IteratorType;
|
||||
static IteratorType Begin(Type const &c) { return c.begin(); }
|
||||
static IteratorType End(Type const &c) { return c.end(); }
|
||||
};
|
||||
template <typename C, typename P, typename A>
|
||||
struct Tf_IteratorInterface<SdfChildrenView<C, P, A>, true> {
|
||||
typedef SdfChildrenView<C, P, A> Type;
|
||||
typedef typename Type::const_reverse_iterator IteratorType;
|
||||
static IteratorType Begin(Type const &c) { return c.rbegin(); }
|
||||
static IteratorType End(Type const &c) { return c.rend(); }
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_CHILDREN_VIEW_H
|
||||
@@ -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_SDF_CLEANUP_ENABLER_H
|
||||
#define PXR_USD_SDF_CLEANUP_ENABLER_H
|
||||
|
||||
/// \file sdf/cleanupEnabler.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
#include "pxr/base/tf/stacked.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class SdfCleanupEnabler
|
||||
///
|
||||
/// An RAII class which, when an instance is alive, enables scheduling of
|
||||
/// automatic cleanup of SdfLayers.
|
||||
///
|
||||
/// Any affected specs which no longer contribute to the scene will be removed
|
||||
/// when the last SdfCleanupEnabler instance goes out of scope. Note that for
|
||||
/// this purpose, SdfPropertySpecs are removed if they have only required fields
|
||||
/// (see SdfPropertySpecs::HasOnlyRequiredFields), but only if the property spec
|
||||
/// itself was affected by an edit that left it with only required fields. This
|
||||
/// will have the effect of uninstantiating on-demand attributes. For example,
|
||||
/// if its parent prim was affected by an edit that left it otherwise inert, it
|
||||
/// will not be removed if it contains an SdfPropertySpec with only required
|
||||
/// fields, but if the property spec itself is edited leaving it with only
|
||||
/// required fields, it will be removed, potentially uninstantiating it if it's
|
||||
/// an on-demand property.
|
||||
///
|
||||
/// SdfCleanupEnablers are accessible in both C++ and Python.
|
||||
///
|
||||
/// /// SdfCleanupEnabler can be used in the following manner:
|
||||
/// \code
|
||||
/// {
|
||||
/// SdfCleanupEnabler enabler;
|
||||
///
|
||||
/// // Perform any action that might otherwise leave inert specs around,
|
||||
/// // such as removing info from properties or prims, or removing name
|
||||
/// // children. i.e:
|
||||
/// primSpec->ClearInfo(SdfFieldKeys->Default);
|
||||
///
|
||||
/// // When enabler goes out of scope on the next line, primSpec will
|
||||
/// // be removed if it has been left as an empty over.
|
||||
/// }
|
||||
/// \endcode
|
||||
///
|
||||
TF_DEFINE_STACKED(SdfCleanupEnabler, false, SDF_API)
|
||||
{
|
||||
public:
|
||||
|
||||
SDF_API SdfCleanupEnabler();
|
||||
|
||||
SDF_API ~SdfCleanupEnabler();
|
||||
|
||||
/// Returns whether cleanup is currently being scheduled.
|
||||
SDF_API static bool IsCleanupEnabled();
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // #ifndef PXR_USD_SDF_CLEANUP_ENABLER_H
|
||||
@@ -0,0 +1,228 @@
|
||||
//
|
||||
// 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_SDF_COPY_UTILS_H
|
||||
#define PXR_USD_SDF_COPY_UTILS_H
|
||||
|
||||
/// \file sdf/copyUtils.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/usd/sdf/types.h"
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <functional>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class SdfPath;
|
||||
class TfToken;
|
||||
class VtValue;
|
||||
SDF_DECLARE_HANDLES(SdfLayer);
|
||||
|
||||
/// \name Simple Spec Copying API
|
||||
/// @{
|
||||
|
||||
/// Utility function for copying spec data at \p srcPath in \p srcLayer to
|
||||
/// \p destPath in \p destLayer.
|
||||
///
|
||||
/// Copying is performed recursively: all child specs are copied as well.
|
||||
/// Any destination specs that already exist will be overwritten.
|
||||
///
|
||||
/// Parent specs of the destination are not created, and must exist before
|
||||
/// SdfCopySpec is called, or a coding error will result. For prim parents,
|
||||
/// clients may find it convenient to call SdfCreatePrimInLayer before
|
||||
/// SdfCopySpec.
|
||||
///
|
||||
/// As a special case, if the top-level object to be copied is a relationship
|
||||
/// target or a connection, the destination spec must already exist. That is
|
||||
/// because we don't want SdfCopySpec to impose any policy on how list edits are
|
||||
/// made; client code should arrange for relationship targets and connections to
|
||||
/// be specified as prepended, appended, deleted, and/or ordered, as needed.
|
||||
///
|
||||
/// Variant specs may be copied to prim paths and vice versa. When copying a
|
||||
/// variant to a prim, the specifier and typename from the variant's parent
|
||||
/// prim will be used.
|
||||
///
|
||||
/// Attribute connections, relationship targets, inherit and specializes paths,
|
||||
/// and internal sub-root references that target an object beneath \p srcPath
|
||||
/// will be remapped to target objects beneath \p dstPath.
|
||||
///
|
||||
SDF_API
|
||||
bool
|
||||
SdfCopySpec(
|
||||
const SdfLayerHandle& srcLayer, const SdfPath& srcPath,
|
||||
const SdfLayerHandle& dstLayer, const SdfPath& dstPath);
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name Advanced Spec Copying API
|
||||
/// @{
|
||||
|
||||
/// Return true if \p field should be copied from the spec at \p srcPath in
|
||||
/// \p srcLayer to the spec at \p dstPath in \p dstLayer. \p fieldInSrc and
|
||||
/// \p fieldInDst indicates whether the field has values at the source and
|
||||
/// destination specs. Return false otherwise.
|
||||
///
|
||||
/// This function may modify the value that is copied by filling in
|
||||
/// \p valueToCopy with the desired value. \p valueToCopy may also be a
|
||||
/// SdfCopySpecsValueEdit that specifies an editing operation for this field.
|
||||
/// If \p valueToCopy is not set, the field value from the source spec will be
|
||||
/// used as-is. Setting \p valueToCopy to an empty VtValue indicates that the
|
||||
/// field should be removed from the destination spec, if it already exists.
|
||||
///
|
||||
/// Note that if this function returns true and the source spec has no value
|
||||
/// for \p field (e.g., fieldInSrc == false), the field in the destination
|
||||
/// spec will also be set to no value.
|
||||
using SdfShouldCopyValueFn = std::function<
|
||||
bool(SdfSpecType specType, const TfToken& field,
|
||||
const SdfLayerHandle& srcLayer, const SdfPath& srcPath, bool fieldInSrc,
|
||||
const SdfLayerHandle& dstLayer, const SdfPath& dstPath, bool fieldInDst,
|
||||
boost::optional<VtValue>* valueToCopy)>;
|
||||
|
||||
/// \class SdfCopySpecsValueEdit
|
||||
/// Value containing an editing operation for SdfCopySpecs.
|
||||
///
|
||||
/// The SdfShouldCopyValueFn callback allows users to return a value to copy
|
||||
/// into the destination spec via the \p valueToCopy parameter. However, there
|
||||
/// may be cases where it would be more efficient to perform incremental edits
|
||||
/// using specific SdfLayer API instead.
|
||||
///
|
||||
/// To accommodate this, consumers may provide a callback that applies a
|
||||
/// scene description edit in \p valueToCopy via an SdfCopySpecsValueEdit
|
||||
/// object.
|
||||
class SdfCopySpecsValueEdit
|
||||
{
|
||||
public:
|
||||
/// Callback to apply a scene description edit to the specified layer and
|
||||
/// spec path.
|
||||
using EditFunction =
|
||||
std::function<void(const SdfLayerHandle&, const SdfPath&)>;
|
||||
|
||||
explicit SdfCopySpecsValueEdit(const EditFunction& edit) : _edit(edit) { }
|
||||
const EditFunction& GetEditFunction() const { return _edit; }
|
||||
|
||||
/// SdfCopySpecsValueEdit objects are not comparable, but must provide
|
||||
/// operator== to be stored in a VtValue.
|
||||
bool operator==(const SdfCopySpecsValueEdit& rhs) const { return false; }
|
||||
bool operator!=(const SdfCopySpecsValueEdit& rhs) const { return true; }
|
||||
|
||||
private:
|
||||
EditFunction _edit;
|
||||
};
|
||||
|
||||
/// Return true if \p childrenField and the child objects the field represents
|
||||
/// should be copied from the spec at \p srcPath in \p srcLayer to the spec at
|
||||
/// \p dstPath in \p dstLayer. \p fieldInSrc and \p fieldInDst indicates
|
||||
/// whether that field has values at the source and destination specs.
|
||||
/// Return false otherwise.
|
||||
///
|
||||
/// This function may modify which children are copied by filling in
|
||||
/// \p srcChildren and \p dstChildren will the children to copy and their
|
||||
/// destination. Both of these values must be set, and must contain the same
|
||||
/// number of children.
|
||||
///
|
||||
/// Note that if this function returns true and the source spec has no value
|
||||
/// for \p childrenField (e.g., fieldInSrc == false), the field in the
|
||||
/// destination spec will also be set to no value, causing any existing children
|
||||
/// to be removed.
|
||||
using SdfShouldCopyChildrenFn = std::function<
|
||||
bool(const TfToken& childrenField,
|
||||
const SdfLayerHandle& srcLayer, const SdfPath& srcPath, bool fieldInSrc,
|
||||
const SdfLayerHandle& dstLayer, const SdfPath& dstPath, bool fieldInDst,
|
||||
boost::optional<VtValue>* srcChildren,
|
||||
boost::optional<VtValue>* dstChildren)>;
|
||||
|
||||
/// SdfShouldCopyValueFn used by the simple version of SdfCopySpec.
|
||||
///
|
||||
/// Copies all values from the source, transforming path-valued fields prefixed
|
||||
/// with \p srcRootPath to have the prefix \p dstRootPath.
|
||||
///
|
||||
/// Existing values in the destination will be overwritten by values in the
|
||||
/// source. Any fields in the destination that aren't in the source will be
|
||||
/// cleared.
|
||||
SDF_API
|
||||
bool
|
||||
SdfShouldCopyValue(
|
||||
const SdfPath& srcRootPath, const SdfPath& dstRootPath,
|
||||
SdfSpecType specType, const TfToken& field,
|
||||
const SdfLayerHandle& srcLayer, const SdfPath& srcPath, bool fieldInSrc,
|
||||
const SdfLayerHandle& dstLayer, const SdfPath& dstPath, bool fieldInDst,
|
||||
boost::optional<VtValue>* valueToCopy);
|
||||
|
||||
/// SdfShouldCopyChildrenFn used by the simple version of SdfCopySpec.
|
||||
///
|
||||
/// Copies all child values from the source, transforming path-valued fields
|
||||
/// prefixed with \p srcRootPath to have the prefix \p dstRootPath.
|
||||
///
|
||||
/// Existing values in the destination will be overwritten by values in the
|
||||
/// source. Any fields in the destination that aren't in the source will be
|
||||
/// cleared.
|
||||
SDF_API
|
||||
bool
|
||||
SdfShouldCopyChildren(
|
||||
const SdfPath& srcRootPath, const SdfPath& dstRootPath,
|
||||
const TfToken& childrenField,
|
||||
const SdfLayerHandle& srcLayer, const SdfPath& srcPath, bool fieldInSrc,
|
||||
const SdfLayerHandle& dstLayer, const SdfPath& dstPath, bool fieldInDst,
|
||||
boost::optional<VtValue>* srcChildren,
|
||||
boost::optional<VtValue>* dstChildren);
|
||||
|
||||
/// Utility function for copying spec data at \p srcPath in \p srcLayer to
|
||||
/// \p destPath in \p destLayer. Various behaviors (such as which parts of the
|
||||
/// spec to copy) are controlled by the supplied \p shouldCopyValueFn and
|
||||
/// \p shouldCopyChildrenFn.
|
||||
///
|
||||
/// Copying is performed recursively: all child specs are copied as well, except
|
||||
/// where prevented by \p shouldCopyChildrenFn.
|
||||
///
|
||||
/// Parent specs of the destination are not created, and must exist before
|
||||
/// SdfCopySpec is called, or a coding error will result. For prim parents,
|
||||
/// clients may find it convenient to call SdfCreatePrimInLayer before
|
||||
/// SdfCopySpec.
|
||||
///
|
||||
/// Variant specs may be copied to prim paths and vice versa. When copying a
|
||||
/// variant to a prim, the specifier and typename from the variant's parent
|
||||
/// prim will be used.
|
||||
///
|
||||
/// As a special case, if the top-level object to be copied is a relationship
|
||||
/// target or a connection, the destination spec must already exist. That is
|
||||
/// because we don't want SdfCopySpec to impose any policy on how list edits are
|
||||
/// made; client code should arrange for relationship targets and connections to
|
||||
/// be specified as prepended, appended, deleted, and/or ordered, as needed.
|
||||
///
|
||||
SDF_API
|
||||
bool
|
||||
SdfCopySpec(
|
||||
const SdfLayerHandle& srcLayer, const SdfPath& srcPath,
|
||||
const SdfLayerHandle& dstLayer, const SdfPath& dstPath,
|
||||
const SdfShouldCopyValueFn& shouldCopyValueFn,
|
||||
const SdfShouldCopyChildrenFn& shouldCopyChildrenFn);
|
||||
|
||||
/// @}
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_COPY_UTILS_H
|
||||
@@ -0,0 +1,184 @@
|
||||
//
|
||||
// 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_SDF_DATA_H
|
||||
#define PXR_USD_SDF_DATA_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
#include "pxr/usd/sdf/abstractData.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
#include "pxr/base/tf/hashmap.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(SdfData);
|
||||
|
||||
/// \class SdfData
|
||||
///
|
||||
/// SdfData provides concrete scene description data storage.
|
||||
///
|
||||
/// An SdfData is an implementation of SdfAbstractData that simply
|
||||
/// stores specs and fields in a map keyed by path.
|
||||
///
|
||||
class SdfData : public SdfAbstractData
|
||||
{
|
||||
public:
|
||||
SdfData() {}
|
||||
SDF_API
|
||||
virtual ~SdfData();
|
||||
|
||||
/// SdfAbstractData overrides
|
||||
|
||||
SDF_API
|
||||
virtual bool StreamsData() const;
|
||||
|
||||
SDF_API
|
||||
virtual void CreateSpec(const SdfPath& path,
|
||||
SdfSpecType specType);
|
||||
SDF_API
|
||||
virtual bool HasSpec(const SdfPath& path) const;
|
||||
SDF_API
|
||||
virtual void EraseSpec(const SdfPath& path);
|
||||
SDF_API
|
||||
virtual void MoveSpec(const SdfPath& oldPath,
|
||||
const SdfPath& newPath);
|
||||
SDF_API
|
||||
virtual SdfSpecType GetSpecType(const SdfPath& path) const;
|
||||
|
||||
SDF_API
|
||||
virtual bool Has(const SdfPath& path, const TfToken &fieldName,
|
||||
SdfAbstractDataValue* value) const;
|
||||
SDF_API
|
||||
virtual bool Has(const SdfPath& path, const TfToken& fieldName,
|
||||
VtValue *value = NULL) const;
|
||||
SDF_API
|
||||
virtual bool
|
||||
HasSpecAndField(const SdfPath &path, const TfToken &fieldName,
|
||||
SdfAbstractDataValue *value, SdfSpecType *specType) const;
|
||||
|
||||
SDF_API
|
||||
virtual bool
|
||||
HasSpecAndField(const SdfPath &path, const TfToken &fieldName,
|
||||
VtValue *value, SdfSpecType *specType) const;
|
||||
|
||||
SDF_API
|
||||
virtual VtValue Get(const SdfPath& path,
|
||||
const TfToken& fieldName) const;
|
||||
SDF_API
|
||||
virtual void Set(const SdfPath& path, const TfToken& fieldName,
|
||||
const VtValue & value);
|
||||
SDF_API
|
||||
virtual void Set(const SdfPath& path, const TfToken& fieldName,
|
||||
const SdfAbstractDataConstValue& value);
|
||||
SDF_API
|
||||
virtual void Erase(const SdfPath& path,
|
||||
const TfToken& fieldName);
|
||||
SDF_API
|
||||
virtual std::vector<TfToken> List(const SdfPath& path) const;
|
||||
|
||||
SDF_API
|
||||
virtual std::set<double>
|
||||
ListAllTimeSamples() const;
|
||||
|
||||
SDF_API
|
||||
virtual std::set<double>
|
||||
ListTimeSamplesForPath(const SdfPath& path) const;
|
||||
|
||||
SDF_API
|
||||
virtual bool
|
||||
GetBracketingTimeSamples(double time, double* tLower, double* tUpper) const;
|
||||
|
||||
SDF_API
|
||||
virtual size_t
|
||||
GetNumTimeSamplesForPath(const SdfPath& path) const;
|
||||
|
||||
SDF_API
|
||||
virtual bool
|
||||
GetBracketingTimeSamplesForPath(const SdfPath& path,
|
||||
double time,
|
||||
double* tLower, double* tUpper) const;
|
||||
|
||||
SDF_API
|
||||
virtual bool
|
||||
QueryTimeSample(const SdfPath& path, double time,
|
||||
SdfAbstractDataValue *optionalValue) const;
|
||||
SDF_API
|
||||
virtual bool
|
||||
QueryTimeSample(const SdfPath& path, double time,
|
||||
VtValue *value) const;
|
||||
|
||||
SDF_API
|
||||
virtual void
|
||||
SetTimeSample(const SdfPath& path, double time,
|
||||
const VtValue & value);
|
||||
|
||||
SDF_API
|
||||
virtual void
|
||||
EraseTimeSample(const SdfPath& path, double time);
|
||||
|
||||
protected:
|
||||
// SdfAbstractData overrides
|
||||
SDF_API
|
||||
virtual void _VisitSpecs(SdfAbstractDataSpecVisitor* visitor) const;
|
||||
|
||||
private:
|
||||
const VtValue* _GetSpecTypeAndFieldValue(const SdfPath& path,
|
||||
const TfToken& field,
|
||||
SdfSpecType* specType) const;
|
||||
|
||||
const VtValue* _GetFieldValue(const SdfPath& path,
|
||||
const TfToken& field) const;
|
||||
|
||||
VtValue* _GetMutableFieldValue(const SdfPath& path,
|
||||
const TfToken& field);
|
||||
|
||||
VtValue* _GetOrCreateFieldValue(const SdfPath& path,
|
||||
const TfToken& field);
|
||||
|
||||
private:
|
||||
// Backing storage for a single "spec" -- prim, property, etc.
|
||||
typedef std::pair<TfToken, VtValue> _FieldValuePair;
|
||||
struct _SpecData {
|
||||
_SpecData() : specType(SdfSpecTypeUnknown) {}
|
||||
|
||||
SdfSpecType specType;
|
||||
std::vector<_FieldValuePair> fields;
|
||||
};
|
||||
|
||||
// Hashtable storing _SpecData.
|
||||
typedef SdfPath _Key;
|
||||
typedef SdfPath::Hash _KeyHash;
|
||||
typedef TfHashMap<_Key, _SpecData, _KeyHash> _HashTable;
|
||||
|
||||
_HashTable _data;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_DATA_H
|
||||
@@ -0,0 +1,340 @@
|
||||
//
|
||||
// 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_SDF_DECLARE_HANDLES_H
|
||||
#define PXR_USD_SDF_DECLARE_HANDLES_H
|
||||
|
||||
/// \file sdf/declareHandles.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
#include "pxr/base/arch/demangle.h"
|
||||
#include "pxr/base/arch/hints.h"
|
||||
#include "pxr/base/tf/diagnostic.h"
|
||||
#include "pxr/base/tf/weakPtrFacade.h"
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
|
||||
#include <set>
|
||||
#include <typeinfo>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include <boost/intrusive_ptr.hpp>
|
||||
#include <boost/operators.hpp>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class SdfLayer;
|
||||
class SdfSpec;
|
||||
template <class T> class TfRefPtr;
|
||||
class Sdf_Identity;
|
||||
|
||||
// Sdf_Identities are held via intrusive_ptr so that we can carefully
|
||||
// manage the ref-count to avoid race conditions -- see
|
||||
// Sdf_IdentityRegistry::Identify().
|
||||
typedef boost::intrusive_ptr<Sdf_Identity> Sdf_IdentityRefPtr;
|
||||
|
||||
/// \class SdfHandle
|
||||
///
|
||||
/// SdfHandle is a smart ptr that calls IsDormant() on the pointed-to
|
||||
/// object as an extra expiration check so that dormant objects appear to
|
||||
/// be expired.
|
||||
///
|
||||
template <class T>
|
||||
class SdfHandle : private boost::totally_ordered<SdfHandle<T> > {
|
||||
public:
|
||||
typedef SdfHandle<T> This;
|
||||
typedef T SpecType;
|
||||
|
||||
typedef typename std::remove_const<SpecType>::type NonConstSpecType;
|
||||
typedef SdfHandle<NonConstSpecType> NonConstThis;
|
||||
|
||||
SdfHandle() { }
|
||||
SdfHandle(TfNullPtrType) { }
|
||||
explicit SdfHandle(const Sdf_IdentityRefPtr& id) : _spec(id) { }
|
||||
SdfHandle(const SpecType& spec) : _spec(spec) { }
|
||||
|
||||
template <class U>
|
||||
SdfHandle(const SdfHandle<U>& x) : _spec(x._spec) { }
|
||||
|
||||
This& operator=(const This& x)
|
||||
{
|
||||
const_cast<NonConstSpecType&>(_spec) = x._spec;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class U>
|
||||
This& operator=(const SdfHandle<U>& x)
|
||||
{
|
||||
const_cast<NonConstSpecType&>(_spec) = x._spec;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Dereference. Raises a fatal error if the object is invalid or
|
||||
/// dormant.
|
||||
SpecType* operator->() const
|
||||
{
|
||||
if (ARCH_UNLIKELY(_spec.IsDormant())) {
|
||||
TF_FATAL_ERROR("Dereferenced an invalid %s",
|
||||
ArchGetDemangled(typeid(SpecType)).c_str());
|
||||
return 0;
|
||||
}
|
||||
return const_cast<SpecType*>(&_spec);
|
||||
}
|
||||
|
||||
const SpecType & GetSpec() const
|
||||
{
|
||||
return _spec;
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
const_cast<SpecType&>(_spec) = SpecType();
|
||||
}
|
||||
|
||||
#if !defined(doxygen)
|
||||
typedef SpecType This::*UnspecifiedBoolType;
|
||||
#endif
|
||||
|
||||
/// Returns \c true in a boolean context if the object is valid,
|
||||
/// \c false otherwise.
|
||||
operator UnspecifiedBoolType() const
|
||||
{
|
||||
return _spec.IsDormant() ? 0 : &This::_spec;
|
||||
}
|
||||
/// Returns \c false in a boolean context if the object is valid,
|
||||
/// \c true otherwise.
|
||||
bool operator!() const
|
||||
{
|
||||
return _spec.IsDormant();
|
||||
}
|
||||
|
||||
/// Compares handles for equality.
|
||||
template <class U>
|
||||
bool operator==(const SdfHandle<U>& other) const
|
||||
{
|
||||
return _spec == other._spec;
|
||||
}
|
||||
|
||||
/// Arranges handles in an arbitrary strict weak ordering. Note that
|
||||
/// this ordering is stable across path changes.
|
||||
template <class U>
|
||||
bool operator<(const SdfHandle<U>& other) const
|
||||
{
|
||||
return _spec < other._spec;
|
||||
}
|
||||
|
||||
/// Hash.
|
||||
friend size_t hash_value(const This &x) {
|
||||
return hash_value(x._spec);
|
||||
}
|
||||
|
||||
private:
|
||||
friend
|
||||
inline SpecType *get_pointer(const SdfHandle &x) {
|
||||
return ARCH_UNLIKELY(x._spec.IsDormant()) ?
|
||||
nullptr : const_cast<SpecType*>(&x._spec);
|
||||
}
|
||||
|
||||
SpecType _spec;
|
||||
|
||||
template <class U> friend class SdfHandle;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
namespace boost {
|
||||
|
||||
using PXR_NS::get_pointer;
|
||||
|
||||
}
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
template <class T>
|
||||
struct SdfHandleTo {
|
||||
typedef SdfHandle<T> Handle;
|
||||
typedef SdfHandle<const T> ConstHandle;
|
||||
typedef std::vector<Handle> Vector;
|
||||
typedef std::vector<ConstHandle> ConstVector;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct SdfHandleTo<SdfLayer> {
|
||||
typedef TfWeakPtr<SdfLayer> Handle;
|
||||
typedef TfWeakPtr<const SdfLayer> ConstHandle;
|
||||
typedef std::vector<Handle> Vector;
|
||||
typedef std::vector<ConstHandle> ConstVector;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
typename SdfHandleTo<T>::Handle
|
||||
SdfCreateHandle(T *p)
|
||||
{
|
||||
return typename SdfHandleTo<T>::Handle(p ? *p : T());
|
||||
}
|
||||
|
||||
template <>
|
||||
SDF_API SdfHandleTo<SdfLayer>::Handle
|
||||
SdfCreateHandle(SdfLayer *p);
|
||||
|
||||
template <typename T>
|
||||
typename SdfHandleTo<T>::Handle
|
||||
SdfCreateNonConstHandle(T const *p)
|
||||
{
|
||||
return SdfCreateHandle(const_cast<T *>(p));
|
||||
}
|
||||
|
||||
struct Sdf_CastAccess {
|
||||
template<class DST, class SRC>
|
||||
static DST CastSpec(const SRC& spec) {
|
||||
return DST(spec);
|
||||
}
|
||||
};
|
||||
|
||||
SDF_API bool
|
||||
Sdf_CanCastToType(
|
||||
const SdfSpec& srcSpec, const std::type_info& destType);
|
||||
|
||||
SDF_API bool
|
||||
Sdf_CanCastToTypeCheckSchema(
|
||||
const SdfSpec& srcSpec, const std::type_info& destType);
|
||||
|
||||
template <class DST, class SRC>
|
||||
struct Sdf_SpecTypesAreDirectlyRelated
|
||||
: std::integral_constant<bool,
|
||||
std::is_base_of<DST, SRC>::value ||
|
||||
std::is_base_of<SRC, DST>::value>
|
||||
{ };
|
||||
|
||||
/// Convert SdfHandle<SRC> \p x to an SdfHandle<DST>. This function
|
||||
/// behaves similar to a dynamic_cast. If class DST cannot represent
|
||||
/// the spec pointed to be \p x, or if the classes DST and SRC are
|
||||
/// not directly related to each other in the C++ type hierarchy,
|
||||
/// the conversion fails and an invalid handle is returned.
|
||||
///
|
||||
/// XXX: The second condition in the above statement is currently untrue.
|
||||
/// This function will allow casting between spec classes even if
|
||||
/// they are not directly related. Doing so could lead to schema
|
||||
/// mismatches and other buggy behavior.
|
||||
template <typename DST, typename SRC>
|
||||
inline
|
||||
SdfHandle<typename DST::SpecType>
|
||||
TfDynamic_cast(const SdfHandle<SRC>& x)
|
||||
{
|
||||
typedef typename DST::SpecType Spec;
|
||||
typedef SdfHandle<Spec> Handle;
|
||||
|
||||
if (Sdf_CanCastToType(x.GetSpec(), typeid(Spec))) {
|
||||
return Handle(Sdf_CastAccess::CastSpec<Spec,SRC>(x.GetSpec()));
|
||||
}
|
||||
|
||||
return Handle();
|
||||
}
|
||||
|
||||
template <typename DST, typename SRC>
|
||||
inline
|
||||
SdfHandle<typename DST::SpecType>
|
||||
TfSafeDynamic_cast(const SdfHandle<SRC>& x)
|
||||
{
|
||||
return TfDynamic_cast(x);
|
||||
}
|
||||
|
||||
/// Convert SdfHandle<SRC> \p x to an SdfHandle<DST>. This function
|
||||
/// behaves similar to a static_cast. No runtime checks are performed
|
||||
/// to ensure the conversion is valid; it is up to the consumer to
|
||||
/// ensure this.
|
||||
template <typename DST, typename SRC>
|
||||
inline
|
||||
SdfHandle<typename DST::SpecType>
|
||||
TfStatic_cast(const SdfHandle<SRC>& x)
|
||||
{
|
||||
typedef typename DST::SpecType Spec;
|
||||
typedef SdfHandle<Spec> Handle;
|
||||
static_assert(Sdf_SpecTypesAreDirectlyRelated<Spec, SRC>::value,
|
||||
"Spec and SRC must be directly related.");
|
||||
|
||||
return Handle(Sdf_CastAccess::CastSpec<Spec,SRC>(x.GetSpec()));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline
|
||||
SdfHandle<typename T::SpecType>
|
||||
TfConst_cast(const SdfHandle<const typename T::SpecType>& x)
|
||||
{
|
||||
return TfStatic_cast<T>(x);
|
||||
}
|
||||
|
||||
/// Convert SdfHandle<SRC> \p x to an SdfHandle<DST>. This function is
|
||||
/// similar to TfDynamic_cast, but it allows the SRC and DST spec to be
|
||||
/// indirectly related, so long as the schema associated with the DST
|
||||
/// spec type is a subclass of the schema associated with \p x.
|
||||
template <typename DST, typename SRC>
|
||||
inline
|
||||
SdfHandle<typename DST::SpecType>
|
||||
SdfSpecDynamic_cast(const SdfHandle<SRC>& x)
|
||||
{
|
||||
typedef typename DST::SpecType Spec;
|
||||
typedef SdfHandle<Spec> Handle;
|
||||
|
||||
if (Sdf_CanCastToTypeCheckSchema(x.GetSpec(), typeid(Spec))) {
|
||||
return Handle(Sdf_CastAccess::CastSpec<Spec,SRC>(x.GetSpec()));
|
||||
}
|
||||
|
||||
return Handle();
|
||||
}
|
||||
|
||||
/// Convert SdfHandle<SRC> \p x to an SdfHandle<DST>. This function is
|
||||
/// similar to TfStatic_cast, but it allows the SRC and DST spec to be
|
||||
/// indirectly related.
|
||||
template <typename DST, typename SRC>
|
||||
inline
|
||||
SdfHandle<typename DST::SpecType>
|
||||
SdfSpecStatic_cast(const SdfHandle<SRC>& x)
|
||||
{
|
||||
typedef typename DST::SpecType Spec;
|
||||
typedef SdfHandle<Spec> Handle;
|
||||
return Handle(Sdf_CastAccess::CastSpec<Spec,SRC>(x.GetSpec()));
|
||||
}
|
||||
|
||||
/// Convert SRC_SPEC to a DST_SPEC.
|
||||
template <typename DST_SPEC, typename SRC_SPEC>
|
||||
inline
|
||||
DST_SPEC
|
||||
SdfSpecStatic_cast(const SRC_SPEC& x)
|
||||
{
|
||||
return Sdf_CastAccess::CastSpec<DST_SPEC,SRC_SPEC>(x);
|
||||
}
|
||||
|
||||
typedef TfRefPtr<SdfLayer> SdfLayerRefPtr;
|
||||
typedef std::vector<TfRefPtr<SdfLayer> > SdfLayerRefPtrVector;
|
||||
typedef std::set<SdfHandleTo<SdfLayer>::Handle> SdfLayerHandleSet;
|
||||
|
||||
#define SDF_DECLARE_HANDLES(cls) \
|
||||
typedef SdfHandleTo<class cls>::Handle cls##Handle; \
|
||||
typedef SdfHandleTo<class cls>::ConstHandle cls##ConstHandle; \
|
||||
typedef SdfHandleTo<class cls>::Vector cls##HandleVector; \
|
||||
typedef SdfHandleTo<class cls>::ConstVector cls##ConstHandleVector
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_DECLARE_HANDLES_H
|
||||
@@ -0,0 +1,118 @@
|
||||
//
|
||||
// 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_SDF_DECLARE_SPEC_H
|
||||
#define PXR_USD_SDF_DECLARE_SPEC_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/usd/sdf/specType.h"
|
||||
#include "pxr/base/tf/registryManager.h"
|
||||
#include "pxr/base/tf/type.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class SdfSpec;
|
||||
|
||||
/// Helper macros for implementing C++ spec classes corresponding to
|
||||
/// the various scene description spec types defined by Sdf. There are
|
||||
/// two macros that each C++ spec class must invoke, one in the class
|
||||
/// definition and one in the implementation .cpp file. For example:
|
||||
///
|
||||
/// <in MySpecType.h>
|
||||
/// class MySpecType : public MyBaseSpecType {
|
||||
/// SDF_DECLARE_SPEC(MySpecType, MyBaseSpecType);
|
||||
/// ...
|
||||
/// };
|
||||
///
|
||||
/// <in MySpecType.cpp>
|
||||
/// SDF_DEFINE_SPEC(MySchemaType, <SdfSpecType enum value>, MySpecType,
|
||||
/// MyBaseSpecType);
|
||||
///
|
||||
/// There are two sets of these macros, one for concrete spec types
|
||||
/// and one for 'abstract' spec types that only serve as a base class
|
||||
/// for concrete specs.
|
||||
///
|
||||
#define SDF_DECLARE_ABSTRACT_SPEC(SpecType, BaseSpecType) \
|
||||
public: \
|
||||
SpecType() { } \
|
||||
SpecType(const SpecType& spec) \
|
||||
: BaseSpecType(spec) { } \
|
||||
explicit SpecType(const Sdf_IdentityRefPtr& identity) \
|
||||
: BaseSpecType(identity) { } \
|
||||
protected: \
|
||||
friend struct Sdf_CastAccess; \
|
||||
explicit SpecType(const SdfSpec& spec) \
|
||||
: BaseSpecType(spec) { } \
|
||||
|
||||
#define SDF_DEFINE_ABSTRACT_SPEC(SchemaType, SpecType, BaseSpecType) \
|
||||
TF_REGISTRY_FUNCTION_WITH_TAG(TfType, Type) \
|
||||
{ \
|
||||
TfType::Define<SpecType, TfType::Bases<BaseSpecType> >(); \
|
||||
} \
|
||||
TF_REGISTRY_FUNCTION_WITH_TAG(SdfSpecTypeRegistration, Registration) \
|
||||
{ \
|
||||
SdfSpecTypeRegistration::RegisterAbstractSpecType< \
|
||||
SchemaType, SpecType>(); \
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------
|
||||
|
||||
#define SDF_DECLARE_SPEC(SpecType, BaseSpecType) \
|
||||
SDF_DECLARE_ABSTRACT_SPEC(SpecType, BaseSpecType) \
|
||||
|
||||
#define SDF_DEFINE_SPEC(SchemaType, SpecTypeEnum, SpecType, BaseSpecType) \
|
||||
TF_REGISTRY_FUNCTION_WITH_TAG(TfType, Type) \
|
||||
{ \
|
||||
TfType::Define<SpecType, TfType::Bases<BaseSpecType> >(); \
|
||||
} \
|
||||
TF_REGISTRY_FUNCTION_WITH_TAG(SdfSpecTypeRegistration, Registration) \
|
||||
{ \
|
||||
SdfSpecTypeRegistration::RegisterSpecType<SchemaType, SpecType> \
|
||||
(SpecTypeEnum); \
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// Special set of macros for SdfSpec only.
|
||||
|
||||
#define SDF_DECLARE_BASE_SPEC(SpecType) \
|
||||
public: \
|
||||
SpecType() { } \
|
||||
SpecType(const SpecType& spec) : _id(spec._id) { } \
|
||||
explicit SpecType(const Sdf_IdentityRefPtr& id) : _id(id) { } \
|
||||
|
||||
#define SDF_DEFINE_BASE_SPEC(SchemaType, SpecType) \
|
||||
TF_REGISTRY_FUNCTION_WITH_TAG(TfType, Type) \
|
||||
{ \
|
||||
TfType::Define<SpecType>(); \
|
||||
} \
|
||||
TF_REGISTRY_FUNCTION_WITH_TAG(SdfSpecTypeRegistration, Registration) \
|
||||
{ \
|
||||
SdfSpecTypeRegistration::RegisterAbstractSpecType< \
|
||||
SchemaType, SpecType>(); \
|
||||
}
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_DECLARE_SPEC_H
|
||||
@@ -0,0 +1,492 @@
|
||||
//
|
||||
// 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_SDF_FILE_FORMAT_H
|
||||
#define PXR_USD_SDF_FILE_FORMAT_H
|
||||
|
||||
/// \file sdf/fileFormat.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
#include "pxr/base/tf/refBase.h"
|
||||
#include "pxr/base/tf/staticTokens.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/tf/type.h"
|
||||
#include "pxr/base/tf/weakBase.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class ArAssetInfo;
|
||||
class SdfSchemaBase;
|
||||
class SdfLayerHints;
|
||||
|
||||
SDF_DECLARE_HANDLES(SdfLayer);
|
||||
SDF_DECLARE_HANDLES(SdfSpec);
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(SdfAbstractData);
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(SdfFileFormat);
|
||||
|
||||
#define SDF_FILE_FORMAT_TOKENS \
|
||||
((TargetArg, "target"))
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(SdfFileFormatTokens, SDF_API, SDF_FILE_FORMAT_TOKENS);
|
||||
|
||||
/// \class SdfFileFormat
|
||||
///
|
||||
/// Base class for file format implementations.
|
||||
///
|
||||
class SdfFileFormat
|
||||
: public TfRefBase
|
||||
, public TfWeakBase
|
||||
{
|
||||
public:
|
||||
SdfFileFormat(const SdfFileFormat&) = delete;
|
||||
SdfFileFormat& operator=(const SdfFileFormat&) = delete;
|
||||
|
||||
/// Returns the schema for this format.
|
||||
SDF_API const SdfSchemaBase& GetSchema() const;
|
||||
|
||||
/// Returns the format identifier.
|
||||
SDF_API const TfToken& GetFormatId() const;
|
||||
|
||||
/// Returns the target for this file format.
|
||||
SDF_API const TfToken& GetTarget() const;
|
||||
|
||||
/// Returns the cookie to be used when writing files with this format.
|
||||
SDF_API const std::string& GetFileCookie() const;
|
||||
|
||||
/// Returns the current version of this file format.
|
||||
SDF_API const TfToken& GetVersionString() const;
|
||||
|
||||
/// Returns true if this file format is the primary format for the
|
||||
/// extensions it handles.
|
||||
SDF_API bool IsPrimaryFormatForExtensions() const;
|
||||
|
||||
/// Returns a list of extensions that this format supports.
|
||||
SDF_API const std::vector<std::string>& GetFileExtensions() const;
|
||||
|
||||
/// Returns the primary file extension for this format. This is the
|
||||
/// extension that is reported for layers using this file format.
|
||||
SDF_API const std::string& GetPrimaryFileExtension() const;
|
||||
|
||||
/// Returns true if \p extension matches one of the extensions returned by
|
||||
/// GetFileExtensions.
|
||||
SDF_API bool IsSupportedExtension(const std::string& extension) const;
|
||||
|
||||
/// Returns true if this file format is a package containing other
|
||||
/// assets.
|
||||
SDF_API
|
||||
virtual bool IsPackage() const;
|
||||
|
||||
/// Returns the path of the "root" layer contained in the package
|
||||
/// layer at \p resolvedPath produced by this file format. If this
|
||||
/// file format is not a package, returns the empty string.
|
||||
///
|
||||
/// The package root layer is the layer in the package layer that
|
||||
/// is used when that package is opened via SdfLayer.
|
||||
SDF_API
|
||||
virtual std::string GetPackageRootLayerPath(
|
||||
const std::string& resolvedPath) const;
|
||||
|
||||
/// Type for specifying additional file format-specific arguments
|
||||
/// to the various API below.
|
||||
typedef std::map<std::string, std::string> FileFormatArguments;
|
||||
|
||||
/// Returns the FileFormatArguments that correspond to the default behavior
|
||||
/// of this file format when no FileFormatArguments are passed to NewLayer
|
||||
/// or InitData.
|
||||
SDF_API
|
||||
virtual FileFormatArguments GetDefaultFileFormatArguments() const;
|
||||
|
||||
/// This method allows the file format to bind to whatever data container is
|
||||
/// appropriate.
|
||||
///
|
||||
/// Returns a shared pointer to an SdfAbstractData implementation.
|
||||
SDF_API
|
||||
virtual SdfAbstractDataRefPtr
|
||||
InitData(const FileFormatArguments& args) const;
|
||||
|
||||
/// Instantiate a layer.
|
||||
SDF_API
|
||||
SdfLayerRefPtr NewLayer(const SdfFileFormatConstPtr &fileFormat,
|
||||
const std::string &identifier,
|
||||
const std::string &realPath,
|
||||
const ArAssetInfo& assetInfo,
|
||||
const FileFormatArguments &args) const;
|
||||
|
||||
/// Return true if this file format prefers to skip reloading anonymous
|
||||
/// layers.
|
||||
SDF_API bool ShouldSkipAnonymousReload() const;
|
||||
|
||||
/// Return true if layers produced by this file format are based
|
||||
/// on physical files on disk. If so, this file format requires
|
||||
/// layers to be serialized to and read from files on disk.
|
||||
///
|
||||
/// For file formats where this function returns true, when
|
||||
/// opening a layer Sdf will fetch layers to the filesystem
|
||||
/// via calls to ArResolver::FetchToLocalResolvedPath prior
|
||||
/// to calling ReadFromFile.
|
||||
///
|
||||
/// This allows asset systems that do not store layers as individual
|
||||
/// files to operate with file formats that require these files.
|
||||
///
|
||||
/// \sa ArResolver::Resolve
|
||||
/// \sa ArResolver::FetchToLocalResolvedPath
|
||||
SDF_API bool LayersAreFileBased() const;
|
||||
|
||||
/// Returns true if \p file can be read by this format.
|
||||
SDF_API
|
||||
virtual bool CanRead(
|
||||
const std::string& file) const = 0;
|
||||
|
||||
/// Reads scene description from the asset specified by \p resolvedPath
|
||||
/// into the layer \p layer.
|
||||
///
|
||||
/// \p metadataOnly is a flag that asks for only the layer metadata
|
||||
/// to be read in, which can be much faster if that is all that is
|
||||
/// required. Note that this is just a hint: some FileFormat readers
|
||||
/// may disregard this flag and still fully populate the layer contents.
|
||||
///
|
||||
/// Returns true if the asset is successfully read into \p layer,
|
||||
/// false otherwise.
|
||||
SDF_API
|
||||
virtual bool Read(
|
||||
SdfLayer* layer,
|
||||
const std::string& resolvedPath,
|
||||
bool metadataOnly) const = 0;
|
||||
|
||||
/// Writes the content in \p layer into the file at \p filePath. If the
|
||||
/// content is successfully written, this method returns true. Otherwise,
|
||||
/// false is returned and errors are posted. The default implementation
|
||||
/// returns false.
|
||||
SDF_API
|
||||
virtual bool WriteToFile(
|
||||
const SdfLayer& layer,
|
||||
const std::string& filePath,
|
||||
const std::string& comment = std::string(),
|
||||
const FileFormatArguments& args = FileFormatArguments()) const;
|
||||
|
||||
/// Reads data in the string \p str into the layer \p layer. If
|
||||
/// the file is successfully read, this method returns true. Otherwise,
|
||||
/// false is returned and errors are posted.
|
||||
SDF_API
|
||||
virtual bool ReadFromString(
|
||||
SdfLayer* layer,
|
||||
const std::string& str) const;
|
||||
|
||||
/// Write the provided \p spec to \p out indented \p indent levels.
|
||||
SDF_API
|
||||
virtual bool WriteToStream(
|
||||
const SdfSpecHandle &spec,
|
||||
std::ostream& out,
|
||||
size_t indent) const;
|
||||
|
||||
/// Writes the content in \p layer to the string \p str. This function
|
||||
/// should write a textual representation of \p layer to the stream
|
||||
/// that can be read back in via ReadFromString.
|
||||
SDF_API
|
||||
virtual bool WriteToString(
|
||||
const SdfLayer& layer,
|
||||
std::string* str,
|
||||
const std::string& comment = std::string()) const;
|
||||
|
||||
/// Returns the set of resolved paths to external asset file dependencies
|
||||
/// for the given \p layer. These are additional dependencies, specific to
|
||||
/// the file format, that are needed when generating the layer's contents
|
||||
/// and would not otherwise be discoverable through composition dependencies
|
||||
/// (i.e. sublayers, references, and payloads).
|
||||
///
|
||||
/// The default implementation returns an empty set. Derived file formats
|
||||
/// that depend on external assets to read and generate layer content
|
||||
/// should implement this function to return the external asset paths.
|
||||
///
|
||||
/// \sa SdfLayer::GetExternalAssetDependencies
|
||||
/// \sa SdfLayer::Reload
|
||||
SDF_API
|
||||
virtual std::set<std::string> GetExternalAssetDependencies(
|
||||
const SdfLayer& layer) const;
|
||||
|
||||
/// Returns the file extension for path or file name \p s, without the
|
||||
/// leading dot character.
|
||||
SDF_API static std::string GetFileExtension(const std::string& s);
|
||||
|
||||
/// Returns a set containing the extension(s) corresponding to
|
||||
/// all registered file formats.
|
||||
SDF_API static std::set<std::string> FindAllFileFormatExtensions();
|
||||
|
||||
/// Returns the file format instance with the specified \p formatId
|
||||
/// identifier. If a format with a matching identifier is not found, this
|
||||
/// returns a null file format pointer.
|
||||
SDF_API
|
||||
static SdfFileFormatConstPtr FindById(
|
||||
const TfToken& formatId);
|
||||
|
||||
/// Returns the file format instance that supports the extension for
|
||||
/// \p path. If a format with a matching extension is not found, this
|
||||
/// returns a null file format pointer.
|
||||
///
|
||||
/// An extension may be handled by multiple file formats, but each
|
||||
/// with a different target. In such cases, if no \p target is specified,
|
||||
/// the file format that is registered as the primary plugin will be
|
||||
/// returned. Otherwise, the file format whose target matches \p target
|
||||
/// will be returned.
|
||||
SDF_API
|
||||
static SdfFileFormatConstPtr FindByExtension(
|
||||
const std::string& path,
|
||||
const std::string& target = std::string());
|
||||
|
||||
/// Returns a file format instance that supports the extension for \p
|
||||
/// path and whose target matches one of those specified by the given
|
||||
/// \p args. If the \p args specify no target, then the file format that is
|
||||
/// registered as the primary plugin will be returned. If a format with a
|
||||
/// matching extension is not found, this returns a null file format
|
||||
/// pointer.
|
||||
SDF_API
|
||||
static SdfFileFormatConstPtr FindByExtension(
|
||||
const std::string& path,
|
||||
const FileFormatArguments& args);
|
||||
|
||||
protected:
|
||||
/// Constructor.
|
||||
SDF_API SdfFileFormat(
|
||||
const TfToken& formatId,
|
||||
const TfToken& versionString,
|
||||
const TfToken& target,
|
||||
const std::string& extension);
|
||||
|
||||
/// Constructor.
|
||||
/// \p schema must remain valid for the lifetime of this file format.
|
||||
SDF_API SdfFileFormat(
|
||||
const TfToken& formatId,
|
||||
const TfToken& versionString,
|
||||
const TfToken& target,
|
||||
const std::string& extension,
|
||||
const SdfSchemaBase& schema);
|
||||
|
||||
/// Disallow temporary SdfSchemaBase objects being passed to the c'tor.
|
||||
SdfFileFormat(
|
||||
const TfToken& formatId,
|
||||
const TfToken& versionString,
|
||||
const TfToken& target,
|
||||
const std::string& extension,
|
||||
const SdfSchemaBase&& schema) = delete;
|
||||
|
||||
/// Constructor.
|
||||
SDF_API SdfFileFormat(
|
||||
const TfToken& formatId,
|
||||
const TfToken& versionString,
|
||||
const TfToken& target,
|
||||
const std::vector<std::string> &extensions);
|
||||
|
||||
/// Constructor.
|
||||
/// \p schema must remain valid for the lifetime of this file format.
|
||||
SDF_API SdfFileFormat(
|
||||
const TfToken& formatId,
|
||||
const TfToken& versionString,
|
||||
const TfToken& target,
|
||||
const std::vector<std::string> &extensions,
|
||||
const SdfSchemaBase& schema);
|
||||
|
||||
/// Disallow temporary SdfSchemaBase objects being passed to the c'tor.
|
||||
SdfFileFormat(
|
||||
const TfToken& formatId,
|
||||
const TfToken& versionString,
|
||||
const TfToken& target,
|
||||
const std::vector<std::string> &extensions,
|
||||
const SdfSchemaBase&& schema) = delete;
|
||||
|
||||
/// Destructor.
|
||||
SDF_API virtual ~SdfFileFormat();
|
||||
|
||||
//
|
||||
// Minimally break layer encapsulation with the following methods. These
|
||||
// methods are also intended to limit the need for SdfLayer friendship with
|
||||
// SdfFileFormat child classes.
|
||||
//
|
||||
|
||||
/// Set the internal data for \p layer to \p data, possibly transferring
|
||||
/// ownership of \p data.
|
||||
///
|
||||
/// Existing layer hints are reset to the default hints.
|
||||
SDF_API
|
||||
static void _SetLayerData(
|
||||
SdfLayer* layer, SdfAbstractDataRefPtr& data);
|
||||
|
||||
/// Set the internal data for \p layer to \p data, possibly transferring
|
||||
/// ownership of \p data.
|
||||
///
|
||||
/// Existing layer hints are replaced with \p hints.
|
||||
SDF_API
|
||||
static void _SetLayerData(
|
||||
SdfLayer* layer, SdfAbstractDataRefPtr& data,
|
||||
SdfLayerHints hints);
|
||||
|
||||
/// Get the internal data for \p layer.
|
||||
SDF_API
|
||||
static SdfAbstractDataConstPtr _GetLayerData(const SdfLayer& layer);
|
||||
|
||||
private:
|
||||
SDF_API
|
||||
virtual SdfLayer *_InstantiateNewLayer(
|
||||
const SdfFileFormatConstPtr &fileFormat,
|
||||
const std::string &identifier,
|
||||
const std::string &realPath,
|
||||
const ArAssetInfo& assetInfo,
|
||||
const FileFormatArguments &args) const;
|
||||
|
||||
// File format subclasses may override this if they prefer not to skip
|
||||
// reloading anonymous layers. Default implementation returns true.
|
||||
SDF_API
|
||||
virtual bool _ShouldSkipAnonymousReload() const;
|
||||
|
||||
/// File format subclasses may override this to specify whether
|
||||
/// their layers are backed by physical files on disk.
|
||||
/// Default implementation returns true.
|
||||
SDF_API
|
||||
virtual bool _LayersAreFileBased() const;
|
||||
|
||||
const SdfSchemaBase& _schema;
|
||||
const TfToken _formatId;
|
||||
const TfToken _target;
|
||||
const std::string _cookie;
|
||||
const TfToken _versionString;
|
||||
const std::vector<std::string> _extensions;
|
||||
const bool _isPrimaryFormat;
|
||||
};
|
||||
|
||||
// Base file format factory.
|
||||
class Sdf_FileFormatFactoryBase : public TfType::FactoryBase {
|
||||
public:
|
||||
virtual SdfFileFormatRefPtr New() const = 0;
|
||||
};
|
||||
|
||||
// Default file format factory.
|
||||
template <typename T>
|
||||
class Sdf_FileFormatFactory : public Sdf_FileFormatFactoryBase {
|
||||
public:
|
||||
virtual SdfFileFormatRefPtr New() const
|
||||
{
|
||||
return TfCreateRefPtr(new T);
|
||||
}
|
||||
};
|
||||
|
||||
/// \def SDF_DEFINE_FILE_FORMAT
|
||||
///
|
||||
/// Performs registrations needed for the specified file format class to be
|
||||
/// discovered by Sdf. This typically would be invoked in a TF_REGISTRY_FUNCTION
|
||||
/// in the source file defining the file format.
|
||||
///
|
||||
/// The first argument is the name of the file format class being registered.
|
||||
/// Subsequent arguments list the base classes of the file format. Since all
|
||||
/// file formats must ultimately derive from SdfFileFormat, there should be
|
||||
/// at least one base class specified.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// \code
|
||||
/// // in MyFileFormat.cpp
|
||||
/// TF_REGISTRY_FUNCTION(TfType)
|
||||
/// {
|
||||
/// SDF_DEFINE_FILE_FORMAT(MyFileFormat, SdfFileFormat);
|
||||
/// }
|
||||
/// \endcode
|
||||
///
|
||||
#ifdef doxygen
|
||||
#define SDF_DEFINE_FILE_FORMAT(FileFormatClass, BaseClass1, ...)
|
||||
#else
|
||||
#define SDF_DEFINE_FILE_FORMAT(...) SdfDefineFileFormat<__VA_ARGS__>()
|
||||
|
||||
template <class FileFormat, class ...BaseFormats>
|
||||
void SdfDefineFileFormat()
|
||||
{
|
||||
TfType::Define<FileFormat, TfType::Bases<BaseFormats...>>()
|
||||
.template SetFactory<Sdf_FileFormatFactory<FileFormat>>();
|
||||
}
|
||||
#endif // doxygen
|
||||
|
||||
/// \def SDF_DEFINE_ABSTRACT_FILE_FORMAT
|
||||
///
|
||||
/// Performs registrations needed for the specified abstract file format
|
||||
/// class. This is used to register types that serve as base classes
|
||||
/// for other concrete file format classes used by Sdf.
|
||||
///
|
||||
/// The first argument is the name of the file format class being registered.
|
||||
/// Subsequent arguments list the base classes of the file format. Since all
|
||||
/// file formats must ultimately derive from SdfFileFormat, there should be
|
||||
/// at least one base class specified.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// \code
|
||||
/// // in MyFileFormat.cpp
|
||||
/// TF_REGISTRY_FUNCTION(TfType)
|
||||
/// {
|
||||
/// SDF_DEFINE_ABSTRACT_FILE_FORMAT(MyFileFormat, SdfFileFormat);
|
||||
/// }
|
||||
/// \endcode
|
||||
///
|
||||
#ifdef doxygen
|
||||
#define SDF_DEFINE_ABSTRACT_FILE_FORMAT(FileFormatClass, BaseClass1, ...)
|
||||
#else
|
||||
#define SDF_DEFINE_ABSTRACT_FILE_FORMAT(...) \
|
||||
SdfDefineAbstractFileFormat<__VA_ARGS__>()
|
||||
|
||||
template <class FileFormat, class ...BaseFormats>
|
||||
void SdfDefineAbstractFileFormat()
|
||||
{
|
||||
TfType::Define<FileFormat, TfType::Bases<BaseFormats...>>();
|
||||
}
|
||||
#endif //doxygen
|
||||
|
||||
/// \def SDF_FILE_FORMAT_FACTORY_ACCESS
|
||||
///
|
||||
/// Provides access to allow file format classes to be instantiated
|
||||
/// from Sdf. This should be specified in the class definition for
|
||||
/// concrete file format classes.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// \code
|
||||
/// // in MyFileFormat.h
|
||||
/// class MyFileFormat : public SdfFileFormat
|
||||
/// {
|
||||
/// SDF_FILE_FORMAT_FACTORY_ACCESS;
|
||||
/// // ...
|
||||
/// };
|
||||
/// \endcode
|
||||
///
|
||||
#ifdef doxygen
|
||||
#define SDF_FILE_FORMAT_FACTORY_ACCESS
|
||||
#else
|
||||
#define SDF_FILE_FORMAT_FACTORY_ACCESS \
|
||||
template<typename T> friend class Sdf_FileFormatFactory
|
||||
#endif //doxygen
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,132 @@
|
||||
//
|
||||
// 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_SDF_IDENTITY_H
|
||||
#define PXR_USD_SDF_IDENTITY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/base/tf/hashmap.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include <boost/intrusive_ptr.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <tbb/spin_mutex.h>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class Sdf_IdentityRegistry;
|
||||
SDF_DECLARE_HANDLES(SdfLayer);
|
||||
|
||||
/// \class Sdf_Identity
|
||||
///
|
||||
/// Identifies the logical object behind an SdfSpec.
|
||||
///
|
||||
/// This is simply the layer the spec belongs to and the path to the spec.
|
||||
///
|
||||
class Sdf_Identity : public boost::noncopyable {
|
||||
public:
|
||||
/// Returns the layer that this identity refers to.
|
||||
SDF_API
|
||||
const SdfLayerHandle &GetLayer() const;
|
||||
|
||||
/// Returns the path that this identity refers to.
|
||||
const SdfPath &GetPath() const {
|
||||
return _path;
|
||||
}
|
||||
|
||||
private:
|
||||
// Ref-counting ops manage _refCount.
|
||||
friend void intrusive_ptr_add_ref(Sdf_Identity*);
|
||||
friend void intrusive_ptr_release(Sdf_Identity*);
|
||||
|
||||
friend class Sdf_IdentityRegistry;
|
||||
|
||||
SDF_API
|
||||
Sdf_Identity(Sdf_IdentityRegistry *registry, const SdfPath &path);
|
||||
SDF_API
|
||||
~Sdf_Identity();
|
||||
|
||||
void _Forget();
|
||||
|
||||
mutable std::atomic_int _refCount;
|
||||
Sdf_IdentityRegistry *_registry;
|
||||
SdfPath _path;
|
||||
};
|
||||
|
||||
// Specialize boost::intrusive_ptr operations.
|
||||
inline void intrusive_ptr_add_ref(PXR_NS::Sdf_Identity* p) {
|
||||
++p->_refCount;
|
||||
}
|
||||
inline void intrusive_ptr_release(PXR_NS::Sdf_Identity* p) {
|
||||
if (--p->_refCount == 0) {
|
||||
delete p;
|
||||
}
|
||||
}
|
||||
|
||||
class Sdf_IdentityRegistry : public boost::noncopyable {
|
||||
public:
|
||||
Sdf_IdentityRegistry(const SdfLayerHandle &layer);
|
||||
~Sdf_IdentityRegistry();
|
||||
|
||||
/// Returns the layer that owns this registry.
|
||||
const SdfLayerHandle &GetLayer() const {
|
||||
return _layer;
|
||||
}
|
||||
|
||||
/// Return the identity associated with \a path, issuing a new
|
||||
/// one if necessary. The registry will track the identity
|
||||
/// and update it if the logical object it represents moves
|
||||
/// in namespace.
|
||||
Sdf_IdentityRefPtr Identify(const SdfPath &path);
|
||||
|
||||
/// Update identity in response to a namespace edit.
|
||||
void MoveIdentity(const SdfPath &oldPath, const SdfPath &newPath);
|
||||
|
||||
private:
|
||||
// When an identity expires, it will remove itself from the registry.
|
||||
friend class Sdf_Identity;
|
||||
|
||||
// Remove the identity mapping for \a path to \a id from the registry.
|
||||
// This is only called by Sdf_Identity's destructor.
|
||||
void _Remove(const SdfPath &path, Sdf_Identity *id);
|
||||
|
||||
/// The layer that owns this registry, and on behalf of which
|
||||
/// this registry tracks identities.
|
||||
const SdfLayerHandle _layer;
|
||||
|
||||
/// The identities being managed by this registry
|
||||
typedef TfHashMap<SdfPath, Sdf_Identity*, SdfPath::Hash> _IdMap;
|
||||
_IdMap _ids;
|
||||
|
||||
/// Cache the last fetched identity, it's commonly re-fetched.
|
||||
Sdf_IdentityRefPtr _lastId;
|
||||
|
||||
// This mutex synchronizes access to _ids.
|
||||
tbb::spin_mutex _idsMutex;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_IDENTITY_H
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// 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_SDF_LAYER_HINTS_H
|
||||
#define PXR_USD_SDF_LAYER_HINTS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// Contains hints about layer contents that may be used to accelerate certain
|
||||
/// composition operations.
|
||||
class SdfLayerHints
|
||||
{
|
||||
public:
|
||||
/// Default constructed hints provide the most conservative set of values
|
||||
/// such that consumers of the hints will act correctly if not optimally.
|
||||
SdfLayerHints() = default;
|
||||
|
||||
/// Construct hints with specific values. Using this constructor requires
|
||||
/// that all hint fields be specified.
|
||||
explicit SdfLayerHints(bool mightHaveRelocates)
|
||||
: mightHaveRelocates(mightHaveRelocates)
|
||||
{}
|
||||
|
||||
/// If this field is false, the layer does not contain relocates. If
|
||||
/// true, relocates may be present but are not guaranteed to exist.
|
||||
bool mightHaveRelocates = true;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,165 @@
|
||||
//
|
||||
// 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_SDF_LAYER_OFFSET_H
|
||||
#define PXR_USD_SDF_LAYER_OFFSET_H
|
||||
|
||||
/// \file sdf/layerOffset.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
|
||||
#include <boost/operators.hpp>
|
||||
#include <iosfwd>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class SdfTimeCode;
|
||||
|
||||
/// \class SdfLayerOffset
|
||||
///
|
||||
/// Represents a time offset and scale between layers.
|
||||
///
|
||||
/// The SdfLayerOffset class is an affine transform, providing both a scale and
|
||||
/// a translate. It supports vector algebra semantics for composing
|
||||
/// SdfLayerOffsets together via multiplication. The SdfLayerOffset class is
|
||||
/// unitless: it does not refer to seconds or frames.
|
||||
///
|
||||
/// For example, suppose layer A uses layer B, with an offset of X:
|
||||
/// when bringing animation from B into A, you first apply the scale of X, and
|
||||
/// then the offset. Suppose you have a scale of 2 and an offset of 24:
|
||||
/// first multiply B's frame numbers by 2, and then add 24. The animation from
|
||||
/// B as seen in A will take twice as long and start 24 frames later.
|
||||
///
|
||||
/// Offsets are typically used in either sublayers or prim references. For more
|
||||
/// information, see the SetSubLayerOffset() method of the SdfLayer class (the
|
||||
/// subLayerOffsets property in Python), as well as the SetReference() and
|
||||
/// GetReferenceLayerOffset() methods (the latter is the referenceLayerOffset
|
||||
/// property in Python) of the SdfPrimSpec class.
|
||||
///
|
||||
class SdfLayerOffset : public boost::totally_ordered<SdfLayerOffset>
|
||||
{
|
||||
public:
|
||||
/// \name Constructors
|
||||
/// @{
|
||||
|
||||
/// Constructs a new SdfLayerOffset instance.
|
||||
SDF_API
|
||||
explicit SdfLayerOffset(double offset = 0.0, double scale = 1.0);
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name Accessors
|
||||
/// @{
|
||||
|
||||
/// Returns the time offset.
|
||||
double GetOffset() const { return _offset; }
|
||||
|
||||
/// Returns the time scale factor.
|
||||
double GetScale() const { return _scale; }
|
||||
|
||||
/// Sets the time offset.
|
||||
void SetOffset(double newOffset) { _offset = newOffset; }
|
||||
|
||||
/// Sets the time scale factor.
|
||||
void SetScale(double newScale) { _scale = newScale; }
|
||||
|
||||
/// Returns \c true if this is an identity transformation, with
|
||||
/// an offset of 0.0 and a scale of 1.0.
|
||||
SDF_API
|
||||
bool IsIdentity() const;
|
||||
|
||||
/// Returns \c true if this offset is valid, i.e. both the offset and
|
||||
/// scale are finite (not infinite or NaN). Note that a valid layer
|
||||
/// offset's inverse may be invalid.
|
||||
SDF_API
|
||||
bool IsValid() const;
|
||||
|
||||
/// Gets the inverse offset, which performs the opposite transformation.
|
||||
SDF_API
|
||||
SdfLayerOffset GetInverse() const;
|
||||
|
||||
/// \name Hashing
|
||||
/// @{
|
||||
|
||||
/// Returns hash for this offset.
|
||||
SDF_API
|
||||
size_t GetHash() const;
|
||||
|
||||
/// Hash functor for hash maps and sets.
|
||||
struct Hash {
|
||||
size_t operator()(const SdfLayerOffset &offset) const {
|
||||
return offset.GetHash();
|
||||
}
|
||||
};
|
||||
|
||||
friend inline size_t hash_value(const SdfLayerOffset &offset) {
|
||||
return offset.GetHash();
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name Operators
|
||||
/// @{
|
||||
|
||||
/// Returns whether the offsets are equal.
|
||||
SDF_API
|
||||
bool operator==(const SdfLayerOffset &rhs) const;
|
||||
|
||||
/// Returns whether this offset is less than another. The meaning
|
||||
/// of less than is somewhat arbitrary.
|
||||
SDF_API
|
||||
bool operator<(const SdfLayerOffset &rhs) const;
|
||||
|
||||
/// Composes this with the offset \e rhs, such that the resulting
|
||||
/// offset is equivalent to first applying \e rhs and then \e *this.
|
||||
SDF_API
|
||||
SdfLayerOffset operator*(const SdfLayerOffset &rhs) const;
|
||||
|
||||
/// Applies the offset to the given value.
|
||||
SDF_API
|
||||
double operator*(double rhs) const;
|
||||
|
||||
/// Applies the offset to the given value.
|
||||
SDF_API
|
||||
SdfTimeCode operator*(const SdfTimeCode &rhs) const;
|
||||
|
||||
/// @}
|
||||
|
||||
private:
|
||||
double _offset;
|
||||
double _scale;
|
||||
};
|
||||
|
||||
typedef std::vector<SdfLayerOffset> SdfLayerOffsetVector;
|
||||
|
||||
///
|
||||
/// Writes the string representation of \a SdfLayerOffset to \a out.
|
||||
SDF_API
|
||||
std::ostream & operator<<( std::ostream &out,
|
||||
const SdfLayerOffset &layerOffset );
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_LAYER_OFFSET_H
|
||||
@@ -0,0 +1,347 @@
|
||||
//
|
||||
// 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_SDF_LAYER_STATE_DELEGATE_H
|
||||
#define PXR_USD_SDF_LAYER_STATE_DELEGATE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/usd/sdf/types.h"
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
#include "pxr/base/tf/refBase.h"
|
||||
#include "pxr/base/tf/weakBase.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
SDF_DECLARE_HANDLES(SdfLayer);
|
||||
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(SdfLayerStateDelegateBase);
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(SdfSimpleLayerStateDelegate);
|
||||
TF_DECLARE_WEAK_PTRS(SdfAbstractData);
|
||||
|
||||
class SdfAbstractDataConstValue;
|
||||
class SdfPath;
|
||||
class TfToken;
|
||||
|
||||
/// \class SdfLayerStateDelegateBase
|
||||
///
|
||||
/// Maintains authoring state information for an associated layer.
|
||||
///
|
||||
/// For example, layers rely on a state delegate to determine whether or
|
||||
/// not they have been dirtied by authoring operations.
|
||||
///
|
||||
/// A layer's state delegate is invoked on every authoring operation on
|
||||
/// that layer. The delegate may keep track of these operations for various
|
||||
/// purposes.
|
||||
///
|
||||
class SdfLayerStateDelegateBase
|
||||
: public TfRefBase
|
||||
, public TfWeakBase
|
||||
{
|
||||
public:
|
||||
SDF_API
|
||||
virtual ~SdfLayerStateDelegateBase();
|
||||
|
||||
SDF_API
|
||||
bool IsDirty();
|
||||
|
||||
SDF_API
|
||||
void SetField(
|
||||
const SdfPath& path,
|
||||
const TfToken& field,
|
||||
const VtValue& value,
|
||||
const VtValue *oldValue=NULL);
|
||||
|
||||
SDF_API
|
||||
void SetField(
|
||||
const SdfPath& path,
|
||||
const TfToken& field,
|
||||
const SdfAbstractDataConstValue& value,
|
||||
const VtValue *oldValue=NULL);
|
||||
|
||||
SDF_API
|
||||
void SetFieldDictValueByKey(
|
||||
const SdfPath& path,
|
||||
const TfToken& field,
|
||||
const TfToken& keyPath,
|
||||
const VtValue& value,
|
||||
const VtValue *oldValue=NULL);
|
||||
|
||||
SDF_API
|
||||
void SetFieldDictValueByKey(
|
||||
const SdfPath& path,
|
||||
const TfToken& field,
|
||||
const TfToken& keyPath,
|
||||
const SdfAbstractDataConstValue& value,
|
||||
const VtValue *oldValue=NULL);
|
||||
|
||||
SDF_API
|
||||
void SetTimeSample(
|
||||
const SdfPath& path,
|
||||
double time,
|
||||
const VtValue& value);
|
||||
|
||||
SDF_API
|
||||
void SetTimeSample(
|
||||
const SdfPath& path,
|
||||
double time,
|
||||
const SdfAbstractDataConstValue& value);
|
||||
|
||||
SDF_API
|
||||
void CreateSpec(
|
||||
const SdfPath& path,
|
||||
SdfSpecType specType,
|
||||
bool inert);
|
||||
|
||||
SDF_API
|
||||
void DeleteSpec(
|
||||
const SdfPath& path,
|
||||
bool inert);
|
||||
|
||||
SDF_API
|
||||
void MoveSpec(
|
||||
const SdfPath& oldPath,
|
||||
const SdfPath& newPath);
|
||||
|
||||
SDF_API
|
||||
void PushChild(
|
||||
const SdfPath& parentPath,
|
||||
const TfToken& field,
|
||||
const TfToken& value);
|
||||
|
||||
SDF_API
|
||||
void PushChild(
|
||||
const SdfPath& parentPath,
|
||||
const TfToken& field,
|
||||
const SdfPath& value);
|
||||
|
||||
SDF_API
|
||||
void PopChild(
|
||||
const SdfPath& parentPath,
|
||||
const TfToken& field,
|
||||
const TfToken& oldValue);
|
||||
|
||||
SDF_API
|
||||
void PopChild(
|
||||
const SdfPath& parentPath,
|
||||
const TfToken& field,
|
||||
const SdfPath& oldValue);
|
||||
|
||||
protected:
|
||||
SDF_API
|
||||
SdfLayerStateDelegateBase();
|
||||
|
||||
/// Returns the layer associated with this state delegate.
|
||||
/// May be NULL if no layer is associated.
|
||||
SDF_API
|
||||
SdfLayerHandle _GetLayer() const;
|
||||
|
||||
/// Returns the underlying data object for the layer associated with
|
||||
/// this state delegate. May be NULL if no layer is associated.
|
||||
SDF_API
|
||||
SdfAbstractDataPtr _GetLayerData() const;
|
||||
|
||||
/// Returns true if the associated layer has been authored to since
|
||||
/// the last time the layer was marked clean, false otherwise.
|
||||
virtual bool _IsDirty() = 0;
|
||||
|
||||
/// Mark the current state of the layer as clean, i.e. unchanged from its
|
||||
/// persistent representation.
|
||||
virtual void _MarkCurrentStateAsClean() = 0;
|
||||
|
||||
/// Mark the current state of the layer as dirty, i.e. modified from its
|
||||
/// persistent representation.
|
||||
virtual void _MarkCurrentStateAsDirty() = 0;
|
||||
|
||||
/// Invoked when the state delegate is associated with layer \p layer.
|
||||
/// \p layer may be NULL if the state delegate is being removed.
|
||||
virtual void _OnSetLayer(
|
||||
const SdfLayerHandle& layer) = 0;
|
||||
|
||||
/// Invoked when a field is being changed on the associated layer.
|
||||
virtual void _OnSetField(
|
||||
const SdfPath& path,
|
||||
const TfToken& fieldName,
|
||||
const VtValue& value) = 0;
|
||||
virtual void _OnSetField(
|
||||
const SdfPath& path,
|
||||
const TfToken& fieldName,
|
||||
const SdfAbstractDataConstValue& value) = 0;
|
||||
|
||||
/// Invoked when a field dict key is being changed on the associated layer.
|
||||
virtual void _OnSetFieldDictValueByKey(
|
||||
const SdfPath& path,
|
||||
const TfToken& fieldName,
|
||||
const TfToken& keyPath,
|
||||
const VtValue& value) = 0;
|
||||
virtual void _OnSetFieldDictValueByKey(
|
||||
const SdfPath& path,
|
||||
const TfToken& fieldName,
|
||||
const TfToken& keyPath,
|
||||
const SdfAbstractDataConstValue& value) = 0;
|
||||
|
||||
/// Invoked when a time sample is being changed on the associated layer.
|
||||
virtual void _OnSetTimeSample(
|
||||
const SdfPath& path,
|
||||
double time,
|
||||
const VtValue& value) = 0;
|
||||
virtual void _OnSetTimeSample(
|
||||
const SdfPath& path,
|
||||
double time,
|
||||
const SdfAbstractDataConstValue& value) = 0;
|
||||
|
||||
/// Invoked when a new spec is created on the associated layer.
|
||||
virtual void _OnCreateSpec(
|
||||
const SdfPath& path,
|
||||
SdfSpecType specType,
|
||||
bool inert) = 0;
|
||||
|
||||
/// Invoked when a spec and its children are deleted from the associated
|
||||
/// layer.
|
||||
virtual void _OnDeleteSpec(
|
||||
const SdfPath& path,
|
||||
bool inert) = 0;
|
||||
|
||||
/// Invoked when a spec and its children are moved.
|
||||
virtual void _OnMoveSpec(
|
||||
const SdfPath& oldPath,
|
||||
const SdfPath& newPath) = 0;
|
||||
|
||||
/// Invoked when a child spec is pushed onto a parent's list of children.
|
||||
virtual void _OnPushChild(
|
||||
const SdfPath& parentPath,
|
||||
const TfToken& fieldName,
|
||||
const TfToken& value) = 0;
|
||||
|
||||
/// Invoked when a child spec is pushed onto a parent's list of children.
|
||||
virtual void _OnPushChild(
|
||||
const SdfPath& parentPath,
|
||||
const TfToken& fieldName,
|
||||
const SdfPath& value) = 0;
|
||||
|
||||
/// Invoked when a child spec is popped off a parent's list of children.
|
||||
virtual void _OnPopChild(
|
||||
const SdfPath& parentPath,
|
||||
const TfToken& fieldName,
|
||||
const TfToken& oldValue) = 0;
|
||||
|
||||
/// Invoked when a child spec is popped off a parent's list of children.
|
||||
virtual void _OnPopChild(
|
||||
const SdfPath& parentPath,
|
||||
const TfToken& fieldName,
|
||||
const SdfPath& oldValue) = 0;
|
||||
|
||||
private:
|
||||
friend class SdfLayer;
|
||||
SDF_API void _SetLayer(const SdfLayerHandle& layer);
|
||||
|
||||
private:
|
||||
SdfLayerHandle _layer;
|
||||
};
|
||||
|
||||
/// \class SdfSimpleLayerStateDelegate
|
||||
/// A layer state delegate that simply records whether any changes have
|
||||
/// been made to a layer.
|
||||
class SdfSimpleLayerStateDelegate
|
||||
: public SdfLayerStateDelegateBase
|
||||
{
|
||||
public:
|
||||
static SdfSimpleLayerStateDelegateRefPtr New();
|
||||
|
||||
protected:
|
||||
SdfSimpleLayerStateDelegate();
|
||||
|
||||
// SdfLayerStateDelegateBase overrides
|
||||
virtual bool _IsDirty() override;
|
||||
virtual void _MarkCurrentStateAsClean() override;
|
||||
virtual void _MarkCurrentStateAsDirty() override;
|
||||
|
||||
virtual void _OnSetLayer(
|
||||
const SdfLayerHandle& layer) override;
|
||||
|
||||
virtual void _OnSetField(
|
||||
const SdfPath& path,
|
||||
const TfToken& fieldName,
|
||||
const VtValue& value) override;
|
||||
virtual void _OnSetField(
|
||||
const SdfPath& path,
|
||||
const TfToken& fieldName,
|
||||
const SdfAbstractDataConstValue& value) override;
|
||||
virtual void _OnSetFieldDictValueByKey(
|
||||
const SdfPath& path,
|
||||
const TfToken& fieldName,
|
||||
const TfToken& keyPath,
|
||||
const VtValue& value) override;
|
||||
virtual void _OnSetFieldDictValueByKey(
|
||||
const SdfPath& path,
|
||||
const TfToken& fieldName,
|
||||
const TfToken& keyPath,
|
||||
const SdfAbstractDataConstValue& value) override;
|
||||
|
||||
virtual void _OnSetTimeSample(
|
||||
const SdfPath& path,
|
||||
double time,
|
||||
const VtValue& value) override;
|
||||
virtual void _OnSetTimeSample(
|
||||
const SdfPath& path,
|
||||
double time,
|
||||
const SdfAbstractDataConstValue& value) override;
|
||||
|
||||
virtual void _OnCreateSpec(
|
||||
const SdfPath& path,
|
||||
SdfSpecType specType,
|
||||
bool inert) override;
|
||||
|
||||
virtual void _OnDeleteSpec(
|
||||
const SdfPath& path,
|
||||
bool inert) override;
|
||||
|
||||
virtual void _OnMoveSpec(
|
||||
const SdfPath& oldPath,
|
||||
const SdfPath& newPath) override;
|
||||
|
||||
virtual void _OnPushChild(
|
||||
const SdfPath& path,
|
||||
const TfToken& fieldName,
|
||||
const TfToken& value) override;
|
||||
virtual void _OnPushChild(
|
||||
const SdfPath& path,
|
||||
const TfToken& fieldName,
|
||||
const SdfPath& value) override;
|
||||
virtual void _OnPopChild(
|
||||
const SdfPath& path,
|
||||
const TfToken& fieldName,
|
||||
const TfToken& oldValue) override;
|
||||
virtual void _OnPopChild(
|
||||
const SdfPath& path,
|
||||
const TfToken& fieldName,
|
||||
const SdfPath& oldValue) override;
|
||||
|
||||
private:
|
||||
bool _dirty;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_LAYER_STATE_DELEGATE_H
|
||||
@@ -0,0 +1,89 @@
|
||||
//
|
||||
// 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_SDF_LAYER_TREE_H
|
||||
#define PXR_USD_SDF_LAYER_TREE_H
|
||||
|
||||
/// \file sdf/layerTree.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/usd/sdf/layerOffset.h"
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
// Layer tree forward declarations.
|
||||
class SdfLayerTree;
|
||||
typedef TfRefPtr<SdfLayerTree> SdfLayerTreeHandle;
|
||||
typedef std::vector<SdfLayerTreeHandle> SdfLayerTreeHandleVector;
|
||||
|
||||
SDF_DECLARE_HANDLES(SdfLayer);
|
||||
|
||||
/// \class SdfLayerTree
|
||||
///
|
||||
/// A SdfLayerTree is an immutable tree structure representing a sublayer
|
||||
/// stack and its recursive structure.
|
||||
///
|
||||
/// Layers can have sublayers, which can in turn have sublayers of their
|
||||
/// own. Clients that want to represent that hierarchical structure in
|
||||
/// memory can build a SdfLayerTree for that purpose.
|
||||
///
|
||||
/// We use TfRefPtr<SdfLayerTree> as handles to LayerTrees, as a simple way
|
||||
/// to pass them around as immutable trees without worrying about lifetime.
|
||||
///
|
||||
class SdfLayerTree : public TfRefBase, public TfWeakBase, boost::noncopyable {
|
||||
public:
|
||||
/// Create a new layer tree node.
|
||||
SDF_API
|
||||
static SdfLayerTreeHandle
|
||||
New( const SdfLayerHandle & layer,
|
||||
const SdfLayerTreeHandleVector & childTrees,
|
||||
const SdfLayerOffset & cumulativeOffset = SdfLayerOffset() );
|
||||
|
||||
/// Returns the layer handle this tree node represents.
|
||||
SDF_API const SdfLayerHandle & GetLayer() const;
|
||||
|
||||
/// Returns the cumulative layer offset from the root of the tree.
|
||||
SDF_API const SdfLayerOffset & GetOffset() const;
|
||||
|
||||
/// Returns the children of this tree node.
|
||||
SDF_API const SdfLayerTreeHandleVector & GetChildTrees() const;
|
||||
|
||||
private:
|
||||
SdfLayerTree( const SdfLayerHandle & layer,
|
||||
const SdfLayerTreeHandleVector & childTrees,
|
||||
const SdfLayerOffset & cumulativeOffset );
|
||||
|
||||
private:
|
||||
const SdfLayerHandle _layer;
|
||||
const SdfLayerOffset _offset;
|
||||
const SdfLayerTreeHandleVector _childTrees;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_LAYER_TREE_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_SDF_LAYER_UTILS_H
|
||||
#define PXR_USD_SDF_LAYER_UTILS_H
|
||||
|
||||
/// \file sdf/layerUtils.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/usd/sdf/layer.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
SDF_DECLARE_HANDLES(SdfLayer);
|
||||
|
||||
/// Returns the path to the asset specified by \p assetPath, using the
|
||||
/// \p anchor layer to anchor the path if it is relative. If the result of
|
||||
/// anchoring \p assetPath to \p anchor's path cannot be resolved and
|
||||
/// \p assetPath is a search path, \p assetPath will be returned. If
|
||||
/// \p assetPath is not relative, \p assetPath will be returned. Otherwise,
|
||||
/// the anchored path will be returned.
|
||||
///
|
||||
/// Note that if \p anchor is an anonymous layer, we will always return
|
||||
/// the untouched \p assetPath.
|
||||
SDF_API std::string
|
||||
SdfComputeAssetPathRelativeToLayer(
|
||||
const SdfLayerHandle& anchor,
|
||||
const std::string& assetPath);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_LAYER_UTILS_H
|
||||
@@ -0,0 +1,351 @@
|
||||
//
|
||||
// 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_SDF_LIST_EDITOR_H
|
||||
#define PXR_USD_SDF_LIST_EDITOR_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/usd/sdf/allowed.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/usd/sdf/listOp.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/usd/sdf/schema.h"
|
||||
#include "pxr/usd/sdf/spec.h"
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include <functional>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
SDF_DECLARE_HANDLES(SdfLayer);
|
||||
SDF_DECLARE_HANDLES(SdfSpec);
|
||||
|
||||
/// \class Sdf_ListEditor
|
||||
///
|
||||
/// Base class for list editor implementations in which list editing operations
|
||||
/// are stored in data field(s) associated with an owning spec.
|
||||
///
|
||||
template <class TypePolicy>
|
||||
class Sdf_ListEditor
|
||||
: public boost::noncopyable
|
||||
{
|
||||
private:
|
||||
typedef Sdf_ListEditor<TypePolicy> This;
|
||||
|
||||
public:
|
||||
typedef typename TypePolicy::value_type value_type;
|
||||
typedef std::vector<value_type> value_vector_type;
|
||||
|
||||
SdfLayerHandle GetLayer() const
|
||||
{
|
||||
return _owner ? _owner->GetLayer() : SdfLayerHandle();
|
||||
}
|
||||
|
||||
SdfPath GetPath() const
|
||||
{
|
||||
return _owner ? _owner->GetPath() : SdfPath();
|
||||
}
|
||||
|
||||
bool IsValid() const
|
||||
{
|
||||
return !IsExpired();
|
||||
}
|
||||
|
||||
bool IsExpired() const
|
||||
{
|
||||
return !_owner;
|
||||
}
|
||||
|
||||
bool HasKeys() const
|
||||
{
|
||||
if (IsExplicit()) {
|
||||
return true;
|
||||
}
|
||||
else if (IsOrderedOnly()) {
|
||||
return !_GetOperations(SdfListOpTypeOrdered).empty();
|
||||
}
|
||||
else {
|
||||
return (!_GetOperations(SdfListOpTypeAdded).empty() ||
|
||||
!_GetOperations(SdfListOpTypePrepended).empty() ||
|
||||
!_GetOperations(SdfListOpTypeAppended).empty() ||
|
||||
!_GetOperations(SdfListOpTypeDeleted).empty() ||
|
||||
!_GetOperations(SdfListOpTypeOrdered).empty());
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool IsExplicit() const = 0;
|
||||
virtual bool IsOrderedOnly() const = 0;
|
||||
|
||||
virtual SdfAllowed PermissionToEdit(SdfListOpType op) const
|
||||
{
|
||||
if (!_owner) {
|
||||
return SdfAllowed("List editor is expired");
|
||||
}
|
||||
|
||||
if (!_owner->PermissionToEdit()) {
|
||||
return SdfAllowed("Permission denied");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool CopyEdits(const Sdf_ListEditor& rhs) = 0;
|
||||
virtual bool ClearEdits() = 0;
|
||||
virtual bool ClearEditsAndMakeExplicit() = 0;
|
||||
|
||||
typedef std::function<
|
||||
boost::optional<value_type>(const value_type&)
|
||||
>
|
||||
ModifyCallback;
|
||||
|
||||
/// Modifies the operations stored in all operation lists.
|
||||
/// \p callback is called for every key. If the returned key is
|
||||
/// invalid then the key is removed, otherwise it's replaced with the
|
||||
/// returned key.
|
||||
virtual void ModifyItemEdits(const ModifyCallback& cb) = 0;
|
||||
|
||||
typedef std::function<
|
||||
boost::optional<value_type>(SdfListOpType, const value_type&)
|
||||
>
|
||||
ApplyCallback;
|
||||
|
||||
/// Apply the list operations represented by this interface to the given
|
||||
/// vector of values \p vec. If \p callback is valid then it's called
|
||||
/// for every key in the editor before applying it to \p vec. If the
|
||||
/// returned key is empty then the key will not be applied. Otherwise
|
||||
/// the returned key is applied, allowing callbacks to perform key
|
||||
/// translation. Note that this means list editors can't meaningfully
|
||||
/// hold the empty key.
|
||||
virtual void ApplyEditsToList(
|
||||
value_vector_type* vec,
|
||||
const ApplyCallback& cb = ApplyCallback()) = 0;
|
||||
|
||||
/// Returns the number of elements in the specified list of operations.
|
||||
size_t GetSize(SdfListOpType op) const
|
||||
{
|
||||
return _GetOperations(op).size();
|
||||
}
|
||||
|
||||
/// Returns the \p i'th value in the specified list of operations.
|
||||
value_type Get(SdfListOpType op, size_t i) const
|
||||
{
|
||||
return _GetOperations(op)[i];
|
||||
}
|
||||
|
||||
/// Returns the specified list of operations.
|
||||
value_vector_type GetVector(SdfListOpType op) const
|
||||
{
|
||||
return _GetOperations(op);
|
||||
}
|
||||
|
||||
/// Returns the number of occurrences of \p val in the specified list of
|
||||
/// operations.
|
||||
size_t Count(SdfListOpType op, const value_type& val) const
|
||||
{
|
||||
const value_vector_type& ops = _GetOperations(op);
|
||||
return std::count(ops.begin(), ops.end(), _typePolicy.Canonicalize(val));
|
||||
}
|
||||
|
||||
/// Returns the index of \p val in the specified list of operations, -1
|
||||
/// if \p val is not found.
|
||||
size_t Find(SdfListOpType op, const value_type& val) const
|
||||
{
|
||||
const value_vector_type& vec = _GetOperations(op);
|
||||
typename value_vector_type::const_iterator findIt =
|
||||
std::find(vec.begin(), vec.end(), _typePolicy.Canonicalize(val));
|
||||
if (findIt != vec.end()) {
|
||||
return std::distance(vec.begin(), findIt);
|
||||
}
|
||||
|
||||
return size_t(-1);
|
||||
}
|
||||
|
||||
/// Replaces the operations in the specified list of operations in range
|
||||
/// [index, index + n) with the given \p elems.
|
||||
virtual bool ReplaceEdits(
|
||||
SdfListOpType op, size_t index, size_t n,
|
||||
const value_vector_type& elems) = 0;
|
||||
|
||||
/// Applies a \p rhs opinions about a given operation list to this one.
|
||||
virtual void ApplyList(SdfListOpType op, const Sdf_ListEditor& rhs) = 0;
|
||||
|
||||
protected:
|
||||
Sdf_ListEditor()
|
||||
{
|
||||
}
|
||||
|
||||
Sdf_ListEditor(const SdfSpecHandle& owner, const TfToken& field,
|
||||
const TypePolicy& typePolicy)
|
||||
: _owner(owner),
|
||||
_field(field),
|
||||
_typePolicy(typePolicy)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~Sdf_ListEditor() = default;
|
||||
|
||||
const SdfSpecHandle& _GetOwner() const
|
||||
{
|
||||
return _owner;
|
||||
}
|
||||
|
||||
const TfToken& _GetField() const
|
||||
{
|
||||
return _field;
|
||||
}
|
||||
|
||||
const TypePolicy& _GetTypePolicy() const
|
||||
{
|
||||
return _typePolicy;
|
||||
}
|
||||
|
||||
virtual bool _ValidateEdit(SdfListOpType op,
|
||||
const value_vector_type& oldValues,
|
||||
const value_vector_type& newValues) const
|
||||
{
|
||||
// Disallow duplicate items from being stored in the new list
|
||||
// editor values. This is O(n^2), but we expect the number of elements
|
||||
// stored to be small enough that this won't matter.
|
||||
//
|
||||
// XXX:
|
||||
// We assume that duplicate data items are never allowed to be
|
||||
// authored. For full generality, this information ought to come from
|
||||
// the layer schema.
|
||||
|
||||
// We also assume that the `oldValues` are already valid and do not
|
||||
// contain duplicates. With this assumption, we can accelerate the
|
||||
// common case of appending new items at the end and skip over a common
|
||||
// prefix of oldValues and newValues. Then we can only check for dupes
|
||||
// in the tail of newValues.
|
||||
|
||||
typename value_vector_type::const_iterator
|
||||
oldValuesTail = oldValues.begin(),
|
||||
newValuesTail = newValues.begin();
|
||||
auto oldEnd = oldValues.end(), newEnd = newValues.end();
|
||||
while (oldValuesTail != oldEnd && newValuesTail != newEnd &&
|
||||
*oldValuesTail == *newValuesTail) {
|
||||
++oldValuesTail, ++newValuesTail;
|
||||
}
|
||||
|
||||
for (auto i = newValuesTail; i != newEnd; ++i) {
|
||||
// Have to check unmatched new items for dupes.
|
||||
for (auto j = newValues.begin(); j != i; ++j) {
|
||||
if (*i == *j) {
|
||||
TF_CODING_ERROR("Duplicate item '%s' not allowed for "
|
||||
"field '%s' on <%s>",
|
||||
TfStringify(*i).c_str(),
|
||||
_field.GetText(),
|
||||
this->GetPath().GetText());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure that all new values are valid for this field.
|
||||
const SdfSchema::FieldDefinition* fieldDef =
|
||||
_owner->GetSchema().GetFieldDefinition(_field);
|
||||
if (!fieldDef) {
|
||||
TF_CODING_ERROR("No field definition for field '%s'",
|
||||
_field.GetText());
|
||||
}
|
||||
else {
|
||||
for (auto i = newValuesTail; i != newEnd; ++i) {
|
||||
if (SdfAllowed isValid = fieldDef->IsValidListValue(*i)) { }
|
||||
else {
|
||||
TF_CODING_ERROR("%s", isValid.GetWhyNot().c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void _OnEdit(SdfListOpType op,
|
||||
const value_vector_type& oldValues,
|
||||
const value_vector_type& newValues) const
|
||||
{
|
||||
}
|
||||
|
||||
virtual const value_vector_type& _GetOperations(SdfListOpType op) const = 0;
|
||||
|
||||
private:
|
||||
SdfSpecHandle _owner;
|
||||
TfToken _field;
|
||||
TypePolicy _typePolicy;
|
||||
|
||||
};
|
||||
|
||||
template <class TypePolicy>
|
||||
std::ostream&
|
||||
operator<<(std::ostream& s, const Sdf_ListEditor<TypePolicy>& x)
|
||||
{
|
||||
struct Util {
|
||||
typedef typename Sdf_ListEditor<TypePolicy>::value_vector_type
|
||||
value_vector_type;
|
||||
|
||||
static void _Write(std::ostream& s, const value_vector_type& v)
|
||||
{
|
||||
s << '[';
|
||||
for (size_t i = 0, n = v.size(); i < n; ++i) {
|
||||
if (i != 0) {
|
||||
s << ", ";
|
||||
}
|
||||
s << v[i];
|
||||
}
|
||||
s << ']';
|
||||
}
|
||||
};
|
||||
|
||||
if (!x.IsValid()) {
|
||||
return s;
|
||||
}
|
||||
else if (x.IsExplicit()) {
|
||||
Util::_Write(s, x.GetVector(SdfListOpTypeExplicit));
|
||||
return s;
|
||||
}
|
||||
else {
|
||||
s << "{ ";
|
||||
if (!x.IsOrderedOnly()) {
|
||||
s << "'added': ";
|
||||
Util::_Write(s, x.GetVector(SdfListOpTypeAdded));
|
||||
s << "'prepended': ";
|
||||
Util::_Write(s, x.GetVector(SdfListOpTypePrepended));
|
||||
s << "'appended': ";
|
||||
Util::_Write(s, x.GetVector(SdfListOpTypeAppended));
|
||||
s << ", 'deleted': ";
|
||||
Util::_Write(s, x.GetVector(SdfListOpTypeDeleted));
|
||||
s << ", ";
|
||||
}
|
||||
s << "'ordered': ";
|
||||
Util::_Write(s, x.GetVector(SdfListOpTypeOrdered));
|
||||
return s << " }";
|
||||
}
|
||||
}
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_LIST_EDITOR_H
|
||||
@@ -0,0 +1,478 @@
|
||||
//
|
||||
// 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_SDF_LIST_EDITOR_PROXY_H
|
||||
#define PXR_USD_SDF_LIST_EDITOR_PROXY_H
|
||||
|
||||
/// \file sdf/listEditorProxy.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/listEditor.h"
|
||||
#include "pxr/usd/sdf/listProxy.h"
|
||||
#include "pxr/usd/sdf/changeBlock.h"
|
||||
|
||||
#include "pxr/base/vt/value.h" // for Vt_DefaultValueFactory
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <functional>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class SdfListEditorProxy
|
||||
///
|
||||
/// Represents a set of list editing operations.
|
||||
///
|
||||
/// An SdfListEditorProxy allows consumers to specify a transformation to be
|
||||
/// applied to a list via a set of list editing operations. Given a starting
|
||||
/// ordered list, it can either replace the result with another ordered list
|
||||
/// or apply a sequence of three operations: deleting keys, then adding keys
|
||||
/// to the end (if they aren't already in the starting list), then reordering
|
||||
/// keys.
|
||||
///
|
||||
/// The type policy defines the value type that a particular proxy can operate
|
||||
/// on.
|
||||
template <class _TypePolicy>
|
||||
class SdfListEditorProxy {
|
||||
public:
|
||||
typedef _TypePolicy TypePolicy;
|
||||
typedef SdfListEditorProxy<TypePolicy> This;
|
||||
typedef SdfListProxy<TypePolicy> ListProxy;
|
||||
typedef typename TypePolicy::value_type value_type;
|
||||
typedef std::vector<value_type> value_vector_type;
|
||||
|
||||
// ApplyEdits types.
|
||||
typedef std::function<boost::optional<value_type>
|
||||
(SdfListOpType, const value_type&)> ApplyCallback;
|
||||
|
||||
// ModifyEdits types.
|
||||
typedef std::function<boost::optional<value_type>
|
||||
(const value_type&)> ModifyCallback;
|
||||
|
||||
/// Creates a default proxy object. The object evaluates to \c false in a
|
||||
/// boolean context and all operations on this object have no effect.
|
||||
SdfListEditorProxy()
|
||||
{
|
||||
}
|
||||
|
||||
/// Creates a new proxy object backed by the supplied list editor.
|
||||
explicit SdfListEditorProxy(
|
||||
const boost::shared_ptr<Sdf_ListEditor<TypePolicy> >& listEditor)
|
||||
: _listEditor(listEditor)
|
||||
{
|
||||
}
|
||||
|
||||
/// Returns true if the list editor is expired.
|
||||
bool IsExpired() const
|
||||
{
|
||||
if (!_listEditor) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return _listEditor->IsExpired();
|
||||
}
|
||||
|
||||
/// Returns \c true if the editor has an explicit list, \c false if
|
||||
/// it has list operations.
|
||||
bool IsExplicit() const
|
||||
{
|
||||
return _Validate() ? _listEditor->IsExplicit() : true;
|
||||
}
|
||||
|
||||
/// Returns \c true if the editor is not explicit and allows ordering
|
||||
/// only.
|
||||
bool IsOrderedOnly() const
|
||||
{
|
||||
return _Validate() ? _listEditor->IsOrderedOnly() : false;
|
||||
}
|
||||
|
||||
/// Returns \c true if the editor has an explicit list (even if it's
|
||||
/// empty) or it has any added, prepended, appended, deleted,
|
||||
/// or ordered keys.
|
||||
bool HasKeys() const
|
||||
{
|
||||
return _Validate() ? _listEditor->HasKeys() : true;
|
||||
}
|
||||
|
||||
/// Apply the edits to \p vec.
|
||||
void ApplyEditsToList(value_vector_type* vec) const
|
||||
{
|
||||
if (_Validate()) {
|
||||
_listEditor->ApplyEditsToList(vec, ApplyCallback());
|
||||
}
|
||||
}
|
||||
|
||||
/// Apply the edits to \p vec. If \p callback is valid then it's called
|
||||
/// for every key in the editor before applying it to \p vec. If the
|
||||
/// returned key is invalid then the key will not be applied. Otherwise
|
||||
/// the returned key is applied, allowing callbacks to perform key
|
||||
/// translation.
|
||||
template <class CB>
|
||||
void ApplyEditsToList(value_vector_type* vec, CB callback) const
|
||||
{
|
||||
if (_Validate()) {
|
||||
_listEditor->ApplyEditsToList(vec, ApplyCallback(callback));
|
||||
}
|
||||
}
|
||||
|
||||
/// Copies the keys from \p other. This differs from assignment
|
||||
/// because assignment just makes two list editors refer to the
|
||||
/// same lists.
|
||||
///
|
||||
/// Not all list editors support changing their mode. If the mode
|
||||
/// can't be changed to the mode of \p other then this does nothing
|
||||
/// and returns \c false, otherwise it returns \c true.
|
||||
bool CopyItems(const This& other)
|
||||
{
|
||||
return _Validate() && other._Validate() ?
|
||||
_listEditor->CopyEdits(*other._listEditor) : false;
|
||||
}
|
||||
|
||||
/// Removes all keys and changes the editor to have list operations.
|
||||
///
|
||||
/// Not all list editors support changing their mode. If the mode
|
||||
/// can't be changed to the mode of \p other then this does nothing
|
||||
/// and returns \c false, otherwise it returns \c true.
|
||||
bool ClearEdits()
|
||||
{
|
||||
return _Validate() ? _listEditor->ClearEdits() : false;
|
||||
}
|
||||
|
||||
/// Removes all keys and changes the editor to be explicit.
|
||||
///
|
||||
/// Not all list editors support changing their mode. If the mode
|
||||
/// can't be changed to the mode of \p other then this does nothing
|
||||
/// and returns \c false, otherwise it returns \c true.
|
||||
bool ClearEditsAndMakeExplicit()
|
||||
{
|
||||
return _Validate() ? _listEditor->ClearEditsAndMakeExplicit() : false;
|
||||
}
|
||||
|
||||
/// \p callback is called for every key. If the returned key is
|
||||
/// invalid then the key is removed, otherwise it's replaced with the
|
||||
/// returned key.
|
||||
template <class CB>
|
||||
void ModifyItemEdits(CB callback)
|
||||
{
|
||||
if (_Validate()) {
|
||||
_listEditor->ModifyItemEdits(ModifyCallback(callback));
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if the given item is explicit, added, prepended, appended,
|
||||
/// deleted, or ordered by this editor. If \p onlyAddOrExplicit is
|
||||
/// \c true we only check the added or explicit items.
|
||||
bool ContainsItemEdit(const value_type& item,
|
||||
bool onlyAddOrExplicit = false) const
|
||||
{
|
||||
if (_Validate()) {
|
||||
size_t i;
|
||||
|
||||
i = GetExplicitItems().Find(item);
|
||||
if (i != size_t(-1)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
i = GetAddedItems().Find(item);
|
||||
if (i != size_t(-1)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
i = GetPrependedItems().Find(item);
|
||||
if (i != size_t(-1)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
i = GetAppendedItems().Find(item);
|
||||
if (i != size_t(-1)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!onlyAddOrExplicit) {
|
||||
i = GetDeletedItems().Find(item);
|
||||
if (i != size_t(-1)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
i = GetOrderedItems().Find(item);
|
||||
if (i != size_t(-1)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Remove all occurrences of the given item, regardless of whether
|
||||
/// the item is explicit, added, prepended, appended, deleted, or ordered.
|
||||
void RemoveItemEdits(const value_type& item)
|
||||
{
|
||||
if (_Validate()) {
|
||||
SdfChangeBlock block;
|
||||
|
||||
GetExplicitItems().Remove(item);
|
||||
GetAddedItems().Remove(item);
|
||||
GetPrependedItems().Remove(item);
|
||||
GetAppendedItems().Remove(item);
|
||||
GetDeletedItems().Remove(item);
|
||||
GetOrderedItems().Remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
/// Replace all occurrences of the given item, regardless of
|
||||
/// whether the item is explicit, added, prepended, appended,
|
||||
/// deleted or ordered.
|
||||
void ReplaceItemEdits(const value_type& oldItem, const value_type& newItem)
|
||||
{
|
||||
if (_Validate()) {
|
||||
SdfChangeBlock block;
|
||||
|
||||
GetExplicitItems().Replace(oldItem, newItem);
|
||||
GetAddedItems().Replace(oldItem, newItem);
|
||||
GetPrependedItems().Replace(oldItem, newItem);
|
||||
GetAppendedItems().Replace(oldItem, newItem);
|
||||
GetDeletedItems().Replace(oldItem, newItem);
|
||||
GetOrderedItems().Replace(oldItem, newItem);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the explicitly set items.
|
||||
ListProxy GetExplicitItems() const
|
||||
{
|
||||
return ListProxy(_listEditor, SdfListOpTypeExplicit);
|
||||
}
|
||||
|
||||
/// Returns the items added by this list editor
|
||||
ListProxy GetAddedItems() const
|
||||
{
|
||||
return ListProxy(_listEditor, SdfListOpTypeAdded);
|
||||
}
|
||||
|
||||
/// Returns the items prepended by this list editor
|
||||
ListProxy GetPrependedItems() const
|
||||
{
|
||||
return ListProxy(_listEditor, SdfListOpTypePrepended);
|
||||
}
|
||||
|
||||
/// Returns the items appended by this list editor
|
||||
ListProxy GetAppendedItems() const
|
||||
{
|
||||
return ListProxy(_listEditor, SdfListOpTypeAppended);
|
||||
}
|
||||
|
||||
/// Returns the items deleted by this list editor
|
||||
ListProxy GetDeletedItems() const
|
||||
{
|
||||
return ListProxy(_listEditor, SdfListOpTypeDeleted);
|
||||
}
|
||||
|
||||
/// Returns the items reordered by this list editor
|
||||
ListProxy GetOrderedItems() const
|
||||
{
|
||||
return ListProxy(_listEditor, SdfListOpTypeOrdered);
|
||||
}
|
||||
|
||||
/// Returns the added or explicitly set items.
|
||||
value_vector_type GetAddedOrExplicitItems() const
|
||||
{
|
||||
value_vector_type result;
|
||||
if (_Validate()) {
|
||||
_listEditor->ApplyEditsToList(&result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Add(const value_type& value)
|
||||
{
|
||||
if (_Validate()) {
|
||||
if (!_listEditor->IsOrderedOnly()) {
|
||||
if (_listEditor->IsExplicit()) {
|
||||
_AddOrReplace(SdfListOpTypeExplicit, value);
|
||||
}
|
||||
else {
|
||||
GetDeletedItems().Remove(value);
|
||||
_AddOrReplace(SdfListOpTypeAdded, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Prepend(const value_type& value)
|
||||
{
|
||||
if (_Validate()) {
|
||||
if (!_listEditor->IsOrderedOnly()) {
|
||||
if (_listEditor->IsExplicit()) {
|
||||
_Prepend(SdfListOpTypeExplicit, value);
|
||||
}
|
||||
else {
|
||||
GetDeletedItems().Remove(value);
|
||||
_Prepend(SdfListOpTypePrepended, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Append(const value_type& value)
|
||||
{
|
||||
if (_Validate()) {
|
||||
if (!_listEditor->IsOrderedOnly()) {
|
||||
if (_listEditor->IsExplicit()) {
|
||||
_Append(SdfListOpTypeExplicit, value);
|
||||
}
|
||||
else {
|
||||
GetDeletedItems().Remove(value);
|
||||
_Append(SdfListOpTypeAppended, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Remove(const value_type& value)
|
||||
{
|
||||
if (_Validate()) {
|
||||
if (_listEditor->IsExplicit()) {
|
||||
GetExplicitItems().Remove(value);
|
||||
}
|
||||
else if (!_listEditor->IsOrderedOnly()) {
|
||||
GetAddedItems().Remove(value);
|
||||
GetPrependedItems().Remove(value);
|
||||
GetAppendedItems().Remove(value);
|
||||
_AddIfMissing(SdfListOpTypeDeleted, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Erase(const value_type& value)
|
||||
{
|
||||
if (_Validate()) {
|
||||
if (!_listEditor->IsOrderedOnly()) {
|
||||
if (_listEditor->IsExplicit()) {
|
||||
GetExplicitItems().Remove(value);
|
||||
}
|
||||
else {
|
||||
GetAddedItems().Remove(value);
|
||||
GetPrependedItems().Remove(value);
|
||||
GetAppendedItems().Remove(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Explicit bool conversion operator. A ListEditorProxy object
|
||||
/// converts to \c true iff the list editor is valid, converts to \c false
|
||||
/// otherwise.
|
||||
explicit operator bool() const
|
||||
{
|
||||
return _listEditor && _listEditor->IsValid();
|
||||
}
|
||||
|
||||
private:
|
||||
bool _Validate()
|
||||
{
|
||||
if (!_listEditor) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsExpired()) {
|
||||
TF_CODING_ERROR("Accessing expired list editor");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _Validate() const
|
||||
{
|
||||
if (!_listEditor) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsExpired()) {
|
||||
TF_CODING_ERROR("Accessing expired list editor");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void _AddIfMissing(SdfListOpType op, const value_type& value)
|
||||
{
|
||||
ListProxy proxy(_listEditor, op);
|
||||
size_t index = proxy.Find(value);
|
||||
if (index == size_t(-1)) {
|
||||
proxy.push_back(value);
|
||||
}
|
||||
}
|
||||
|
||||
void _AddOrReplace(SdfListOpType op, const value_type& value)
|
||||
{
|
||||
ListProxy proxy(_listEditor, op);
|
||||
size_t index = proxy.Find(value);
|
||||
if (index == size_t(-1)) {
|
||||
proxy.push_back(value);
|
||||
}
|
||||
else if (value != static_cast<value_type>(proxy[index])) {
|
||||
proxy[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
void _Prepend(SdfListOpType op, const value_type& value)
|
||||
{
|
||||
ListProxy proxy(_listEditor, op);
|
||||
size_t index = proxy.Find(value);
|
||||
if (index != 0) {
|
||||
if (index != size_t(-1)) {
|
||||
proxy.Erase(index);
|
||||
}
|
||||
proxy.insert(proxy.begin(), value);
|
||||
}
|
||||
}
|
||||
|
||||
void _Append(SdfListOpType op, const value_type& value)
|
||||
{
|
||||
ListProxy proxy(_listEditor, op);
|
||||
size_t index = proxy.Find(value);
|
||||
if (proxy.empty() || (index != proxy.size()-1)) {
|
||||
if (index != size_t(-1)) {
|
||||
proxy.Erase(index);
|
||||
}
|
||||
proxy.push_back(value);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
boost::shared_ptr<Sdf_ListEditor<TypePolicy> > _listEditor;
|
||||
|
||||
friend class Sdf_ListEditorProxyAccess;
|
||||
template <class T> friend class SdfPyWrapListEditorProxy;
|
||||
};
|
||||
|
||||
// Cannot get from a VtValue except as the correct type.
|
||||
template <class TP>
|
||||
struct Vt_DefaultValueFactory<SdfListEditorProxy<TP> > {
|
||||
static Vt_DefaultValueHolder Invoke() = delete;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_LIST_EDITOR_PROXY_H
|
||||
@@ -0,0 +1,323 @@
|
||||
//
|
||||
// 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_SDF_LIST_OP_H
|
||||
#define PXR_USD_SDF_LIST_OP_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <boost/optional/optional_fwd.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <iosfwd>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \enum SdfListOpType
|
||||
///
|
||||
/// Enum for specifying one of the list editing operation types.
|
||||
///
|
||||
enum SdfListOpType {
|
||||
SdfListOpTypeExplicit,
|
||||
SdfListOpTypeAdded,
|
||||
SdfListOpTypeDeleted,
|
||||
SdfListOpTypeOrdered,
|
||||
SdfListOpTypePrepended,
|
||||
SdfListOpTypeAppended
|
||||
};
|
||||
|
||||
/// \struct Sdf_ListOpTraits
|
||||
///
|
||||
/// Trait classes for specializing behaviors of SdfListOp for a given item
|
||||
/// type.
|
||||
///
|
||||
template <class T>
|
||||
struct Sdf_ListOpTraits
|
||||
{
|
||||
typedef std::less<T> ItemComparator;
|
||||
};
|
||||
|
||||
/// \class SdfListOp
|
||||
///
|
||||
/// Value type representing a list-edit operation.
|
||||
///
|
||||
/// SdfListOp is a value type representing an operation that edits a list.
|
||||
/// It may add or remove items, reorder them, or replace the list entirely.
|
||||
///
|
||||
template <typename T>
|
||||
class SdfListOp {
|
||||
public:
|
||||
typedef T ItemType;
|
||||
typedef std::vector<ItemType> ItemVector;
|
||||
typedef ItemType value_type;
|
||||
typedef ItemVector value_vector_type;
|
||||
|
||||
/// Create a ListOp in explicit mode with the given \p explicitItems.
|
||||
SDF_API
|
||||
static SdfListOp CreateExplicit(
|
||||
const ItemVector& explicitItems = ItemVector());
|
||||
|
||||
/// Create a ListOp in non-explicit mode with the given
|
||||
/// \p prependedItems, \p appendedItems, and \p deletedItems
|
||||
SDF_API
|
||||
static SdfListOp Create(
|
||||
const ItemVector& prependedItems = ItemVector(),
|
||||
const ItemVector& appendedItems = ItemVector(),
|
||||
const ItemVector& deletedItems = ItemVector());
|
||||
|
||||
/// Create an empty ListOp in non-explicit mode.
|
||||
SDF_API SdfListOp();
|
||||
|
||||
SDF_API void Swap(SdfListOp<T>& rhs);
|
||||
|
||||
/// Returns \c true if the editor has an explicit list (even if it's
|
||||
/// empty) or it has any added, prepended, appended, deleted,
|
||||
/// or ordered keys.
|
||||
bool HasKeys() const
|
||||
{
|
||||
if (IsExplicit()) {
|
||||
return true;
|
||||
}
|
||||
if (_addedItems.size() != 0 ||
|
||||
_prependedItems.size() != 0 ||
|
||||
_appendedItems.size() != 0 ||
|
||||
_deletedItems.size() != 0) {
|
||||
return true;
|
||||
}
|
||||
return _orderedItems.size() != 0;
|
||||
}
|
||||
|
||||
/// Returns \c true if the given item is in any of the item lists.
|
||||
SDF_API bool HasItem(const T& item) const;
|
||||
|
||||
/// Returns \c true if the list is explicit.
|
||||
bool IsExplicit() const
|
||||
{
|
||||
return _isExplicit;
|
||||
}
|
||||
|
||||
/// Returns the explicit items.
|
||||
const ItemVector& GetExplicitItems() const
|
||||
{
|
||||
return _explicitItems;
|
||||
}
|
||||
|
||||
/// Returns the explicit items.
|
||||
const ItemVector& GetAddedItems() const
|
||||
{
|
||||
return _addedItems;
|
||||
}
|
||||
|
||||
/// Returns the explicit items.
|
||||
const ItemVector& GetPrependedItems() const
|
||||
{
|
||||
return _prependedItems;
|
||||
}
|
||||
|
||||
/// Returns the explicit items.
|
||||
const ItemVector& GetAppendedItems() const
|
||||
{
|
||||
return _appendedItems;
|
||||
}
|
||||
|
||||
/// Returns the deleted items.
|
||||
const ItemVector& GetDeletedItems() const
|
||||
{
|
||||
return _deletedItems;
|
||||
}
|
||||
|
||||
/// Returns the ordered items.
|
||||
const ItemVector& GetOrderedItems() const
|
||||
{
|
||||
return _orderedItems;
|
||||
}
|
||||
|
||||
/// Return the item vector identified by \p type.
|
||||
SDF_API const ItemVector& GetItems(SdfListOpType type) const;
|
||||
|
||||
SDF_API void SetExplicitItems(const ItemVector &items);
|
||||
SDF_API void SetAddedItems(const ItemVector &items);
|
||||
SDF_API void SetPrependedItems(const ItemVector &items);
|
||||
SDF_API void SetAppendedItems(const ItemVector &items);
|
||||
SDF_API void SetDeletedItems(const ItemVector &items);
|
||||
SDF_API void SetOrderedItems(const ItemVector &items);
|
||||
|
||||
/// Sets the item vector for the given operation \p type.
|
||||
SDF_API void SetItems(const ItemVector &items, SdfListOpType type);
|
||||
|
||||
/// Removes all items and changes the list to be non-explicit.
|
||||
SDF_API void Clear();
|
||||
|
||||
/// Removes all items and changes the list to be explicit.
|
||||
SDF_API void ClearAndMakeExplicit();
|
||||
|
||||
/// Callback type for ApplyOperations.
|
||||
typedef std::function<
|
||||
boost::optional<ItemType>(SdfListOpType, const ItemType&)
|
||||
> ApplyCallback;
|
||||
|
||||
/// Applies edit operations to the given ItemVector.
|
||||
/// If supplied, \p cb will be called on each item in the operation vectors
|
||||
/// before they are applied to \p vec. Consumers can use this to transform
|
||||
/// the items stored in the operation vectors to match what's stored in
|
||||
/// \p vec.
|
||||
SDF_API
|
||||
void ApplyOperations(ItemVector* vec,
|
||||
const ApplyCallback& cb = ApplyCallback()) const;
|
||||
|
||||
/// Applies edit operations to the given ListOp.
|
||||
///
|
||||
/// The result is a ListOp that, when applied to a list, has the same
|
||||
/// effect as applying \p inner and then \p this in sequence.
|
||||
///
|
||||
/// The result will be empty if the result is not well defined.
|
||||
/// The result is well-defined when \p inner and \p this do not
|
||||
/// use the 'ordered' or 'added' item lists. In other words, only
|
||||
/// the explicit, prepended, appended, and deleted portions of
|
||||
/// SdfListOp are closed under composition with ApplyOperations().
|
||||
SDF_API
|
||||
boost::optional<SdfListOp<T>>
|
||||
ApplyOperations(const SdfListOp<T> &inner) const;
|
||||
|
||||
/// Callback type for ModifyOperations.
|
||||
typedef std::function<
|
||||
boost::optional<ItemType>(const ItemType&)
|
||||
> ModifyCallback;
|
||||
|
||||
/// Modifies operations specified in this object.
|
||||
/// \p callback is called for every item in all operation vectors. If the
|
||||
/// returned key is empty then the key is removed, otherwise it's replaced
|
||||
/// with the returned key.
|
||||
///
|
||||
/// Returns true if a change was made, false otherwise.
|
||||
SDF_API bool ModifyOperations(const ModifyCallback& callback);
|
||||
|
||||
/// Replaces the items in the specified operation vector in the range
|
||||
/// (index, index + n] with the given \p newItems. If \p newItems is empty
|
||||
/// the items in the range will simply be removed.
|
||||
SDF_API
|
||||
bool ReplaceOperations(const SdfListOpType op, size_t index, size_t n,
|
||||
const ItemVector& newItems);
|
||||
|
||||
/// Composes a stronger SdfListOp's opinions for a given operation list
|
||||
/// over this one.
|
||||
SDF_API
|
||||
void ComposeOperations(const SdfListOp<T>& stronger, SdfListOpType op);
|
||||
|
||||
friend inline size_t hash_value(const SdfListOp &op) {
|
||||
size_t h = 0;
|
||||
boost::hash_combine(h, op._isExplicit);
|
||||
boost::hash_combine(h, op._explicitItems);
|
||||
boost::hash_combine(h, op._addedItems);
|
||||
boost::hash_combine(h, op._prependedItems);
|
||||
boost::hash_combine(h, op._appendedItems);
|
||||
boost::hash_combine(h, op._deletedItems);
|
||||
boost::hash_combine(h, op._orderedItems);
|
||||
return h;
|
||||
}
|
||||
|
||||
bool operator==(const SdfListOp<T> &rhs) const {
|
||||
return _isExplicit == rhs._isExplicit &&
|
||||
_explicitItems == rhs._explicitItems &&
|
||||
_addedItems == rhs._addedItems &&
|
||||
_prependedItems == rhs._prependedItems &&
|
||||
_appendedItems == rhs._appendedItems &&
|
||||
_deletedItems == rhs._deletedItems &&
|
||||
_orderedItems == rhs._orderedItems;
|
||||
};
|
||||
|
||||
bool operator!=(const SdfListOp<T> &rhs) const {
|
||||
return !(*this == rhs);
|
||||
};
|
||||
|
||||
private:
|
||||
void _SetExplicit(bool isExplicit);
|
||||
|
||||
typedef typename Sdf_ListOpTraits<T>::ItemComparator _ItemComparator;
|
||||
typedef std::list<ItemType> _ApplyList;
|
||||
typedef std::map<ItemType, typename _ApplyList::iterator, _ItemComparator>
|
||||
_ApplyMap;
|
||||
|
||||
void _AddKeys(SdfListOpType, const ApplyCallback& cb,
|
||||
_ApplyList* result, _ApplyMap* search) const;
|
||||
void _PrependKeys(SdfListOpType, const ApplyCallback& cb,
|
||||
_ApplyList* result, _ApplyMap* search) const;
|
||||
void _AppendKeys(SdfListOpType, const ApplyCallback& cb,
|
||||
_ApplyList* result, _ApplyMap* search) const;
|
||||
void _DeleteKeys(SdfListOpType, const ApplyCallback& cb,
|
||||
_ApplyList* result, _ApplyMap* search) const;
|
||||
void _ReorderKeys(SdfListOpType, const ApplyCallback& cb,
|
||||
_ApplyList* result, _ApplyMap* search) const;
|
||||
|
||||
private:
|
||||
bool _isExplicit;
|
||||
ItemVector _explicitItems;
|
||||
ItemVector _addedItems;
|
||||
ItemVector _prependedItems;
|
||||
ItemVector _appendedItems;
|
||||
ItemVector _deletedItems;
|
||||
ItemVector _orderedItems;
|
||||
};
|
||||
|
||||
// ADL swap.
|
||||
template <class T>
|
||||
void swap(SdfListOp<T> &x, SdfListOp<T> &y)
|
||||
{
|
||||
x.Swap(y);
|
||||
}
|
||||
|
||||
// Helper function for applying an ordering operation described by \p orderVector
|
||||
// to vector \p v.
|
||||
template <class ItemType>
|
||||
SDF_API
|
||||
void SdfApplyListOrdering(std::vector<ItemType>* v,
|
||||
const std::vector<ItemType>& order);
|
||||
|
||||
// Ostream output methods for list values (useful for debugging and required
|
||||
// for storing a list value in a VtValue).
|
||||
template <typename T>
|
||||
SDF_API
|
||||
std::ostream & operator<<( std::ostream &, const SdfListOp<T> & );
|
||||
|
||||
// Concrete, instantiated listop types.
|
||||
typedef class SdfListOp<int> SdfIntListOp;
|
||||
typedef class SdfListOp<unsigned int> SdfUIntListOp;
|
||||
typedef class SdfListOp<int64_t> SdfInt64ListOp;
|
||||
typedef class SdfListOp<uint64_t> SdfUInt64ListOp;
|
||||
typedef class SdfListOp<TfToken> SdfTokenListOp;
|
||||
typedef class SdfListOp<std::string> SdfStringListOp;
|
||||
typedef class SdfListOp<class SdfPath> SdfPathListOp;
|
||||
typedef class SdfListOp<class SdfReference> SdfReferenceListOp;
|
||||
typedef class SdfListOp<class SdfPayload> SdfPayloadListOp;
|
||||
typedef class SdfListOp<class SdfUnregisteredValue> SdfUnregisteredValueListOp;
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_LIST_OP_H
|
||||
@@ -0,0 +1,616 @@
|
||||
//
|
||||
// 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_SDF_LIST_PROXY_H
|
||||
#define PXR_USD_SDF_LIST_PROXY_H
|
||||
|
||||
/// \file sdf/listProxy.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/allowed.h"
|
||||
#include "pxr/usd/sdf/listEditor.h"
|
||||
#include "pxr/usd/sdf/listOp.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include "pxr/base/tf/diagnostic.h"
|
||||
#include "pxr/base/tf/errorMark.h"
|
||||
#include "pxr/base/tf/iterator.h"
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
#include <boost/iterator/reverse_iterator.hpp>
|
||||
#include <boost/operators.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/type_traits/is_base_of.hpp>
|
||||
#include <boost/type_traits/remove_cv.hpp>
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class SdfListProxy
|
||||
///
|
||||
/// Represents a single list of list editing operations.
|
||||
///
|
||||
/// An SdfListProxy represents a single list of list editing operations, making
|
||||
/// it look like an STL vector (modeling a random access container and back
|
||||
/// insertion sequence).
|
||||
///
|
||||
template <class _TypePolicy>
|
||||
class SdfListProxy :
|
||||
boost::totally_ordered<SdfListProxy<_TypePolicy>,
|
||||
std::vector<typename _TypePolicy::value_type> > {
|
||||
public:
|
||||
typedef _TypePolicy TypePolicy;
|
||||
typedef SdfListProxy<TypePolicy> This;
|
||||
typedef typename TypePolicy::value_type value_type;
|
||||
typedef std::vector<value_type> value_vector_type;
|
||||
|
||||
private:
|
||||
// Proxies an item in a list editor list.
|
||||
class _ItemProxy : boost::totally_ordered<_ItemProxy> {
|
||||
public:
|
||||
explicit _ItemProxy(This* owner, size_t index) :
|
||||
_owner(owner), _index(index)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
_ItemProxy& operator=(const _ItemProxy& x) {
|
||||
_owner->_Edit(_index, 1, value_vector_type(1, x));
|
||||
return *this;
|
||||
}
|
||||
|
||||
_ItemProxy& operator=(const value_type& x) {
|
||||
_owner->_Edit(_index, 1, value_vector_type(1, x));
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator value_type() const {
|
||||
return _owner->_Get(_index);
|
||||
}
|
||||
|
||||
bool operator==(const value_type& x) const {
|
||||
return _owner->_Get(_index) == x;
|
||||
}
|
||||
|
||||
bool operator<(const value_type& x) const {
|
||||
return _owner->_Get(_index) < x;
|
||||
}
|
||||
|
||||
private:
|
||||
This* _owner;
|
||||
size_t _index;
|
||||
};
|
||||
friend class _ItemProxy;
|
||||
|
||||
class _GetHelper {
|
||||
public:
|
||||
typedef _ItemProxy result_type;
|
||||
|
||||
result_type operator()(This* owner, size_t index) const {
|
||||
return _ItemProxy(owner, index);
|
||||
}
|
||||
};
|
||||
class _ConstGetHelper {
|
||||
public:
|
||||
typedef value_type result_type;
|
||||
|
||||
result_type operator()(const This* owner, size_t index) const {
|
||||
return owner->_Get(index);
|
||||
}
|
||||
};
|
||||
friend class _GetHelper;
|
||||
friend class _ConstGetHelper;
|
||||
|
||||
template <class Owner, class GetItem>
|
||||
class _Iterator :
|
||||
public boost::iterator_facade<
|
||||
_Iterator<Owner, GetItem>,
|
||||
typename boost::remove_cv<
|
||||
typename boost::remove_reference<
|
||||
typename GetItem::result_type
|
||||
>::type
|
||||
>::type,
|
||||
std::random_access_iterator_tag,
|
||||
typename GetItem::result_type> {
|
||||
public:
|
||||
typedef _Iterator<Owner, GetItem> This;
|
||||
typedef
|
||||
boost::iterator_facade<
|
||||
_Iterator<Owner, GetItem>,
|
||||
typename boost::remove_cv<
|
||||
typename boost::remove_reference<
|
||||
typename GetItem::result_type
|
||||
>::type
|
||||
>::type,
|
||||
std::random_access_iterator_tag,
|
||||
typename GetItem::result_type> Parent;
|
||||
typedef typename Parent::reference reference;
|
||||
typedef typename Parent::difference_type difference_type;
|
||||
|
||||
_Iterator() : _owner(NULL), _index(0)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
_Iterator(Owner owner, size_t index) : _owner(owner), _index(index)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
private:
|
||||
friend class boost::iterator_core_access;
|
||||
|
||||
reference dereference() const {
|
||||
return _getItem(_owner, _index);
|
||||
}
|
||||
|
||||
bool equal(const This& other) const {
|
||||
if (_owner != other._owner) {
|
||||
TF_CODING_ERROR("Comparing SdfListProxy iterators from "
|
||||
"different proxies!");
|
||||
return false;
|
||||
}
|
||||
return _index == other._index;
|
||||
}
|
||||
|
||||
void increment() {
|
||||
++_index;
|
||||
}
|
||||
|
||||
void decrement() {
|
||||
--_index;
|
||||
}
|
||||
|
||||
void advance(difference_type n) {
|
||||
_index += n;
|
||||
}
|
||||
|
||||
difference_type distance_to(const This& other) const {
|
||||
return other._index - _index;
|
||||
}
|
||||
|
||||
private:
|
||||
GetItem _getItem;
|
||||
Owner _owner;
|
||||
size_t _index;
|
||||
};
|
||||
|
||||
public:
|
||||
typedef _ItemProxy reference;
|
||||
typedef _Iterator<This*, _GetHelper> iterator;
|
||||
typedef _Iterator<const This*, _ConstGetHelper> const_iterator;
|
||||
typedef boost::reverse_iterator<iterator> reverse_iterator;
|
||||
typedef boost::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
|
||||
/// Creates a default list proxy object for list operation vector specified
|
||||
/// \p op. This object evaluates to false in a boolean context and all
|
||||
/// operations on this object have no effect.
|
||||
SdfListProxy(SdfListOpType op) :
|
||||
_op(op)
|
||||
{
|
||||
}
|
||||
|
||||
/// Create a new proxy wrapping the list operation vector specified by
|
||||
/// \p op in the underlying \p listEditor.
|
||||
SdfListProxy(const boost::shared_ptr<Sdf_ListEditor<TypePolicy> >& editor,
|
||||
SdfListOpType op) :
|
||||
_listEditor(editor),
|
||||
_op(op)
|
||||
{
|
||||
}
|
||||
|
||||
/// Return an iterator to the start of the sequence.
|
||||
iterator begin() {
|
||||
return iterator(_GetThis(), 0);
|
||||
}
|
||||
/// Return an iterator to the end of the sequence.
|
||||
iterator end() {
|
||||
return iterator(_GetThis(), _GetSize());
|
||||
}
|
||||
|
||||
/// Return a reverse iterator to the last item of the sequence.
|
||||
reverse_iterator rbegin() {
|
||||
return reverse_iterator(end());
|
||||
}
|
||||
/// Return a reverse iterator past the start item of the sequence.
|
||||
reverse_iterator rend() {
|
||||
return reverse_iterator(begin());
|
||||
}
|
||||
|
||||
/// Return a const iterator to the start of the sequence.
|
||||
const_iterator begin() const {
|
||||
return const_iterator(_GetThis(), 0);
|
||||
}
|
||||
/// Return a const iterator to the end of the sequence.
|
||||
const_iterator end() const {
|
||||
return const_iterator(_GetThis(), _GetSize());
|
||||
}
|
||||
|
||||
/// Return a const reverse iterator to the last item of the sequence.
|
||||
const_reverse_iterator rbegin() const {
|
||||
return const_reverse_iterator(end());
|
||||
}
|
||||
/// Return a const reverse iterator past the start item of the
|
||||
/// sequence.
|
||||
const_reverse_iterator rend() const {
|
||||
return const_reverse_iterator(begin());
|
||||
}
|
||||
|
||||
/// Return the size of the sequence.
|
||||
size_t size() const {
|
||||
return _Validate() ? _GetSize() : 0;
|
||||
}
|
||||
|
||||
/// Return true if size() == 0.
|
||||
bool empty() const {
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
/// Return a \p reference to the item at index \p n.
|
||||
reference operator[](size_t n) {
|
||||
return reference(_GetThis(), n);
|
||||
}
|
||||
|
||||
/// Return a copy of the item at index \p n.
|
||||
value_type operator[](size_t n) const {
|
||||
return _Get(n);
|
||||
}
|
||||
|
||||
/// Return a \p reference to the item at the front of the sequence.
|
||||
reference front() {
|
||||
return reference(_GetThis(), 0);
|
||||
}
|
||||
|
||||
/// Return a \p reference to the item at the back of the sequence.
|
||||
reference back() {
|
||||
return reference(_GetThis(), _GetSize() - 1);
|
||||
}
|
||||
|
||||
/// Return a copy of the item at the front of the sequence.
|
||||
value_type front() const {
|
||||
return _Get(0);
|
||||
}
|
||||
|
||||
/// Return a copy of the item at the back of the sequence.
|
||||
value_type back() const {
|
||||
return _Get(_GetSize() - 1);
|
||||
}
|
||||
|
||||
/// Append \p elem to this sequence.
|
||||
void push_back(const value_type& elem) {
|
||||
_Edit(_GetSize(), 0, value_vector_type(1, elem));
|
||||
}
|
||||
|
||||
/// Remove the last element from this sequence.
|
||||
void pop_back() {
|
||||
_Edit(_GetSize() - 1, 1, value_vector_type());
|
||||
}
|
||||
|
||||
/// Insert \p x into this sequence at position \p pos.
|
||||
iterator insert(iterator pos, const value_type& x) {
|
||||
_Edit(pos - iterator(this, 0), 0, value_vector_type(1, x));
|
||||
return pos;
|
||||
}
|
||||
|
||||
/// Insert copies of the elements in [\p f, \p l) into this sequence
|
||||
/// starting at position \p pos.
|
||||
template <class InputIterator>
|
||||
void insert(iterator pos, InputIterator f, InputIterator l) {
|
||||
_Edit(pos - iterator(this, 0), 0, value_vector_type(f, l));
|
||||
}
|
||||
|
||||
/// Erase the element at \p pos.
|
||||
void erase(iterator pos) {
|
||||
_Edit(pos - iterator(this, 0), 1, value_vector_type());
|
||||
}
|
||||
|
||||
/// Erase all the elements in the range [\p f, \p l).
|
||||
void erase(iterator f, iterator l) {
|
||||
_Edit(f - iterator(this, 0), l - f, value_vector_type());
|
||||
}
|
||||
|
||||
/// Clear the contents of the sequence.
|
||||
void clear() {
|
||||
_Edit(0, _GetSize(), value_vector_type());
|
||||
}
|
||||
|
||||
/// Resize the contents of the sequence.
|
||||
///
|
||||
/// Inserts or erases copies of \p t at the end
|
||||
/// such that the size becomes \p n.
|
||||
void resize(size_t n, const value_type& t = value_type()) {
|
||||
size_t s = _GetSize();
|
||||
if (n > s) {
|
||||
_Edit(s, 0, value_vector_type(n - s, t));
|
||||
}
|
||||
else if (n < s) {
|
||||
_Edit(n, s - n, value_vector_type());
|
||||
}
|
||||
}
|
||||
|
||||
/// Produce a copy of the contents of this sequence into a vector.
|
||||
operator value_vector_type() const {
|
||||
return _listEditor ? _listEditor->GetVector(_op) : value_vector_type();
|
||||
}
|
||||
|
||||
/// Replace all elements in this sequence with the elements in
|
||||
/// the \p other sequence.
|
||||
template <class T2>
|
||||
This& operator=(const SdfListProxy<T2>& other) {
|
||||
_Edit(0, _GetSize(), static_cast<value_vector_type>(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Replace all elements in this sequence with the given vector.
|
||||
This& operator=(const value_vector_type& other) {
|
||||
_Edit(0, _GetSize(), other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Replace all elements in this sequence with the given vector.
|
||||
template <class Y>
|
||||
This& operator=(const std::vector<Y>& v) {
|
||||
_Edit(0, _GetSize(), value_vector_type(v.begin(), v.end()));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Equality comparison.
|
||||
template <class T2>
|
||||
bool operator==(const SdfListProxy<T2>& y) const {
|
||||
return value_vector_type(*this) == value_vector_type(y);
|
||||
}
|
||||
|
||||
/// Inequality comparison.
|
||||
template <class T2>
|
||||
bool operator!=(const SdfListProxy<T2>& y) const {
|
||||
return !(*this == y);
|
||||
}
|
||||
|
||||
/// Less-than comparison.
|
||||
template <class T2>
|
||||
bool operator<(const SdfListProxy<T2>& y) const {
|
||||
return value_vector_type(*this) < value_vector_type(y);
|
||||
}
|
||||
|
||||
/// Less-than-or-equal comparison.
|
||||
template <class T2>
|
||||
bool operator<=(const SdfListProxy<T2>& y) const {
|
||||
return value_vector_type(*this) <= value_vector_type(y);
|
||||
}
|
||||
|
||||
/// Greater-than comparison.
|
||||
template <class T2>
|
||||
bool operator>(const SdfListProxy<T2>& y) const {
|
||||
return !(*this <= y);
|
||||
}
|
||||
|
||||
/// Greater-than-or-equal comparison.
|
||||
template <class T2>
|
||||
bool operator>=(const SdfListProxy<T2>& y) const {
|
||||
return !(*this < y);
|
||||
}
|
||||
|
||||
/// Equality comparison.
|
||||
bool operator==(const value_vector_type& y) const {
|
||||
return value_vector_type(*this) == y;
|
||||
}
|
||||
|
||||
/// Less-than comparison.
|
||||
bool operator<(const value_vector_type& y) const {
|
||||
return value_vector_type(*this) < y;
|
||||
}
|
||||
|
||||
/// Greater-than comparison.
|
||||
bool operator>(const value_vector_type& y) const {
|
||||
return value_vector_type(*this) > y;
|
||||
}
|
||||
|
||||
/// Explicit bool conversion operator. The list proxy object converts to
|
||||
/// \c true if the list editor is valid, \c false otherwise.
|
||||
explicit operator bool() const
|
||||
{
|
||||
return _listEditor && _listEditor->IsValid() && _IsRelevant();
|
||||
}
|
||||
|
||||
// Extensions
|
||||
|
||||
/// Returns the layer that this list editor belongs to.
|
||||
SdfLayerHandle GetLayer() const
|
||||
{
|
||||
return _listEditor ? _listEditor->GetLayer() : SdfLayerHandle();
|
||||
}
|
||||
|
||||
/// Returns the path to this list editor's value.
|
||||
SdfPath GetPath() const
|
||||
{
|
||||
return _listEditor ? _listEditor->GetPath() : SdfPath();
|
||||
}
|
||||
|
||||
/// Returns true if the list editor is expired.
|
||||
bool IsExpired() const
|
||||
{
|
||||
return _listEditor && _listEditor->IsExpired();
|
||||
}
|
||||
|
||||
size_t Count(const value_type& value) const
|
||||
{
|
||||
return (_Validate() ? _listEditor->Count(_op, value) : 0);
|
||||
}
|
||||
|
||||
size_t Find(const value_type& value) const
|
||||
{
|
||||
return (_Validate() ? _listEditor->Find(_op, value) : size_t(-1));
|
||||
}
|
||||
|
||||
void Insert(int index, const value_type& value)
|
||||
{
|
||||
if (index == -1) {
|
||||
index = static_cast<int>(_GetSize());
|
||||
}
|
||||
_Edit(index, 0, value_vector_type(1, value));
|
||||
}
|
||||
|
||||
void Remove(const value_type& value)
|
||||
{
|
||||
size_t index = Find(value);
|
||||
if (index != size_t(-1)) {
|
||||
Erase(index);
|
||||
}
|
||||
else {
|
||||
// Allow policy to raise an error even though we're not
|
||||
// doing anything.
|
||||
_Edit(_GetSize(), 0, value_vector_type());
|
||||
}
|
||||
}
|
||||
|
||||
void Replace(const value_type& oldValue, const value_type& newValue)
|
||||
{
|
||||
size_t index = Find(oldValue);
|
||||
if (index != size_t(-1)) {
|
||||
_Edit(index, 1, value_vector_type(1, newValue));
|
||||
}
|
||||
else {
|
||||
// Allow policy to raise an error even though we're not
|
||||
// doing anything.
|
||||
_Edit(_GetSize(), 0, value_vector_type());
|
||||
}
|
||||
}
|
||||
|
||||
void Erase(size_t index)
|
||||
{
|
||||
_Edit(index, 1, value_vector_type());
|
||||
}
|
||||
|
||||
/// Applies the edits in the given list to this one.
|
||||
void ApplyList(const SdfListProxy &list)
|
||||
{
|
||||
if (_Validate() && list._Validate()) {
|
||||
_listEditor->ApplyList(_op, *list._listEditor);
|
||||
}
|
||||
}
|
||||
|
||||
/// Apply the edits in this list to the given \p vec.
|
||||
void ApplyEditsToList(value_vector_type* vec)
|
||||
{
|
||||
if (_Validate()) {
|
||||
_listEditor->ApplyEditsToList(vec);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool _Validate()
|
||||
{
|
||||
if (!_listEditor) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsExpired()) {
|
||||
TF_CODING_ERROR("Accessing expired list editor");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _Validate() const
|
||||
{
|
||||
if (!_listEditor) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsExpired()) {
|
||||
TF_CODING_ERROR("Accessing expired list editor");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
This* _GetThis()
|
||||
{
|
||||
return _Validate() ? this : NULL;
|
||||
}
|
||||
|
||||
const This* _GetThis() const
|
||||
{
|
||||
return _Validate() ? this : NULL;
|
||||
}
|
||||
|
||||
bool _IsRelevant() const
|
||||
{
|
||||
if (_listEditor->IsExplicit()) {
|
||||
return _op == SdfListOpTypeExplicit;
|
||||
}
|
||||
else if (_listEditor->IsOrderedOnly()) {
|
||||
return _op == SdfListOpTypeOrdered;
|
||||
}
|
||||
else {
|
||||
return _op != SdfListOpTypeExplicit;
|
||||
}
|
||||
}
|
||||
|
||||
size_t _GetSize() const
|
||||
{
|
||||
return _listEditor ? _listEditor->GetSize(_op) : 0;
|
||||
}
|
||||
|
||||
value_type _Get(size_t n) const
|
||||
{
|
||||
return _Validate() ? _listEditor->Get(_op, n) : value_type();
|
||||
}
|
||||
|
||||
void _Edit(size_t index, size_t n, const value_vector_type& elems)
|
||||
{
|
||||
if (_Validate()) {
|
||||
// Allow policy to raise an error even if we're not
|
||||
// doing anything.
|
||||
if (n == 0 && elems.empty()) {
|
||||
SdfAllowed canEdit = _listEditor->PermissionToEdit(_op);
|
||||
if (!canEdit) {
|
||||
TF_CODING_ERROR("Editing list: %s",
|
||||
canEdit.GetWhyNot().c_str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
bool valid =
|
||||
_listEditor->ReplaceEdits(_op, index, n, elems);
|
||||
if (!valid) {
|
||||
TF_CODING_ERROR("Inserting invalid value into list editor");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
boost::shared_ptr<Sdf_ListEditor<TypePolicy> > _listEditor;
|
||||
SdfListOpType _op;
|
||||
|
||||
template <class> friend class SdfPyWrapListProxy;
|
||||
};
|
||||
|
||||
// Allow TfIteration over list proxies.
|
||||
template <typename T>
|
||||
struct Tf_ShouldIterateOverCopy<SdfListProxy<T> > : boost::true_type
|
||||
{
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_LIST_PROXY_H
|
||||
@@ -0,0 +1,930 @@
|
||||
//
|
||||
// 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_SDF_MAP_EDIT_PROXY_H
|
||||
#define PXR_USD_SDF_MAP_EDIT_PROXY_H
|
||||
|
||||
/// \file sdf/mapEditProxy.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/allowed.h"
|
||||
#include "pxr/usd/sdf/changeBlock.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/usd/sdf/mapEditor.h"
|
||||
#include "pxr/usd/sdf/spec.h"
|
||||
|
||||
#include "pxr/base/vt/value.h" // for Vt_DefaultValueFactory
|
||||
#include "pxr/base/tf/diagnostic.h"
|
||||
#include "pxr/base/tf/mallocTag.h"
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
#include <boost/iterator/reverse_iterator.hpp>
|
||||
#include <boost/operators.hpp>
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class TfToken;
|
||||
|
||||
SDF_DECLARE_HANDLES(SdfSpec);
|
||||
|
||||
/// \class SdfIdentityMapEditProxyValuePolicy
|
||||
///
|
||||
/// A value policy for \c SdfMapEditProxy that does nothing.
|
||||
///
|
||||
/// A \c SdfMapEditProxy value policy converts incoming keys and values
|
||||
/// into a canonical form used for storage. This is useful if you have
|
||||
/// a key where multiple values are equivalent for the purposes of the
|
||||
/// map but don't compare equal and you can store any one of the
|
||||
/// equivalent values. Note that the policy is only used on inputs to
|
||||
/// the map proxy; it's never used when returning keys or values from
|
||||
/// the proxy.
|
||||
///
|
||||
template <class T>
|
||||
class SdfIdentityMapEditProxyValuePolicy {
|
||||
public:
|
||||
typedef T Type;
|
||||
typedef typename Type::key_type key_type;
|
||||
typedef typename Type::mapped_type mapped_type;
|
||||
typedef typename Type::value_type value_type;
|
||||
|
||||
/// Canonicalize an entire \c Type object. \c Type must be convertible
|
||||
/// to the type of \p x. The return value must be convertible to a
|
||||
/// \c Type.
|
||||
static const Type& CanonicalizeType(const SdfSpecHandle&, const Type& x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
/// Canonicalize a key. \c key_type must be convertible to the type of
|
||||
/// \p x. The return value must be convertible to a \c key_type.
|
||||
static const key_type& CanonicalizeKey(const SdfSpecHandle&,
|
||||
const key_type& x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
/// Canonicalize a value. \c mapped_type must be convertible to the type
|
||||
/// of \p x. The return value must be convertible to a \c mapped_type.
|
||||
static const mapped_type& CanonicalizeValue(const SdfSpecHandle&,
|
||||
const mapped_type& x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
/// Canonicalize a key/value pair. \c value_type must be convertible
|
||||
/// to the type of \p x. The return value must be convertible to a
|
||||
/// \c value_type.
|
||||
static const value_type& CanonicalizePair(const SdfSpecHandle&,
|
||||
const value_type& x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
/// \class SdfMapEditProxy
|
||||
///
|
||||
/// A proxy for editing map-like values.
|
||||
///
|
||||
/// A \c SdfMapEditProxy provides an interface for editing fields
|
||||
/// containing map-like values. The proxy allows consumers to
|
||||
/// interact with these values like a typical std::map while
|
||||
/// taking into account additional editing and validation policies.
|
||||
///
|
||||
/// The \c _ValuePolicy is used to canonicalize keys and values before
|
||||
/// storage or comparison.
|
||||
///
|
||||
/// \sa SdfIdentityMapEditProxyValuePolicy
|
||||
///
|
||||
template <class T, class _ValuePolicy = SdfIdentityMapEditProxyValuePolicy<T> >
|
||||
class SdfMapEditProxy :
|
||||
boost::totally_ordered<SdfMapEditProxy<T, _ValuePolicy>, T> {
|
||||
public:
|
||||
typedef T Type;
|
||||
typedef _ValuePolicy ValuePolicy;
|
||||
typedef SdfMapEditProxy<Type, ValuePolicy> This;
|
||||
typedef typename Type::key_type key_type;
|
||||
typedef typename Type::mapped_type mapped_type;
|
||||
typedef typename Type::value_type value_type;
|
||||
|
||||
private:
|
||||
// Note: We're playing a dangerous game with copy-on-write and
|
||||
// iterators. Our iterators wrap iterators on the proxied
|
||||
// Type. When and if we copy-on-write then all of our
|
||||
// existing iterators use the old proxied object's iterators
|
||||
// and any new iterators will use the new proxied object's
|
||||
// iterators. Therefore old and new iterators are no longer
|
||||
// compatible and an old and new iterator that refer to the
|
||||
// same key will not compare equal.
|
||||
//
|
||||
// It turns out that this is okay because we don't promise
|
||||
// to keep iterators valid across an edit. However, we'd
|
||||
// like dereferencing an old iterator to either report an
|
||||
// error or yield the current state. We can do that by
|
||||
// storing the Type* in use when the iterator was created
|
||||
// and comparing it to the current Type*. If they're
|
||||
// different we need to report an error or use the key from
|
||||
// the old iterator and lookup that key in the new Type*.
|
||||
// We currently choose to return the current state.
|
||||
|
||||
typedef typename Type::iterator inner_iterator;
|
||||
typedef typename Type::const_iterator const_inner_iterator;
|
||||
|
||||
class _ValueProxy {
|
||||
public:
|
||||
_ValueProxy(This* owner, const Type* data, inner_iterator i) :
|
||||
_owner(owner), _data(data), _pos(i)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
template <class U>
|
||||
_ValueProxy& operator=(const U& other)
|
||||
{
|
||||
if (!_owner) {
|
||||
TF_CODING_ERROR("Assignment to invalid map proxy");
|
||||
} else {
|
||||
_owner->_Set(_data, _pos, other);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator mapped_type() const
|
||||
{
|
||||
return Get();
|
||||
}
|
||||
|
||||
// Required for _PairProxy::operator value_type().
|
||||
mapped_type Get() const
|
||||
{
|
||||
if (!_owner) {
|
||||
TF_CODING_ERROR("Read from invalid map proxy");
|
||||
return mapped_type();
|
||||
}
|
||||
return _owner->_Get(_data, _pos);
|
||||
}
|
||||
|
||||
private:
|
||||
This* _owner;
|
||||
const Type* _data;
|
||||
inner_iterator _pos;
|
||||
};
|
||||
|
||||
class _PairProxy {
|
||||
public:
|
||||
explicit _PairProxy(This* owner, const Type* data, inner_iterator i) :
|
||||
first(i->first), second(_ValueProxy(owner, data, i)) { }
|
||||
|
||||
const key_type first;
|
||||
_ValueProxy second;
|
||||
|
||||
operator value_type() const
|
||||
{
|
||||
// Note that we cannot simply use 'second' or we'll use the
|
||||
// mapped_type c'tor instead of the _ValueProxy implicit
|
||||
// conversion if one is available. If mapped_type is VtValue
|
||||
// then we'll type erase _ValueProxy instead of just getting
|
||||
// the VtValue out of the _ValueProxy.
|
||||
return value_type(first, second.Get());
|
||||
}
|
||||
};
|
||||
|
||||
class Traits {
|
||||
public:
|
||||
static _PairProxy Dereference(This* owner,
|
||||
const Type* data, inner_iterator i)
|
||||
{
|
||||
if (!owner) {
|
||||
TF_FATAL_ERROR("Dereferenced an invalid map proxy iterator");
|
||||
}
|
||||
return _PairProxy(owner, data, i);
|
||||
}
|
||||
|
||||
static const value_type& Dereference(const This* owner,
|
||||
const Type* data,
|
||||
const_inner_iterator i)
|
||||
{
|
||||
if (!owner) {
|
||||
TF_FATAL_ERROR("Dereferenced an invalid map proxy iterator");
|
||||
}
|
||||
return owner->_Get(data, i);
|
||||
}
|
||||
};
|
||||
|
||||
template <class Owner, class I, class R>
|
||||
class _Iterator :
|
||||
public boost::iterator_facade<_Iterator<Owner, I, R>, R,
|
||||
std::bidirectional_iterator_tag, R> {
|
||||
public:
|
||||
_Iterator() :
|
||||
_owner(NULL), _data(NULL) { }
|
||||
|
||||
_Iterator(Owner owner, const Type* data, I i) :
|
||||
_owner(owner), _data(data), _pos(i)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
template <class Owner2, class I2, class R2>
|
||||
_Iterator(const _Iterator<Owner2, I2, R2>& other) :
|
||||
_owner(other._owner), _data(other._data), _pos(other._pos)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
const I& base() const
|
||||
{
|
||||
return _pos;
|
||||
}
|
||||
|
||||
private:
|
||||
R dereference() const
|
||||
{
|
||||
return Traits::Dereference(_owner, _data, _pos);
|
||||
}
|
||||
|
||||
template <class Owner2, class I2, class R2>
|
||||
bool equal(const _Iterator<Owner2, I2, R2>& other) const
|
||||
{
|
||||
if (_owner == other._owner && _pos == other._pos) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
// All iterators at the end compare equal.
|
||||
return atEnd() && other.atEnd();
|
||||
}
|
||||
}
|
||||
|
||||
void increment() {
|
||||
++_pos;
|
||||
}
|
||||
|
||||
void decrement() {
|
||||
--_pos;
|
||||
}
|
||||
|
||||
bool atEnd() const {
|
||||
// We consider an iterator with no owner to be at the end.
|
||||
return !_owner || _pos == _owner->_ConstData()->end();
|
||||
}
|
||||
|
||||
private:
|
||||
Owner _owner;
|
||||
const Type* _data;
|
||||
I _pos;
|
||||
|
||||
friend class boost::iterator_core_access;
|
||||
template <class Owner2, class I2, class R2> friend class _Iterator;
|
||||
};
|
||||
|
||||
public:
|
||||
typedef _ValueProxy reference;
|
||||
typedef const value_type& const_reference;
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef _Iterator<This*, inner_iterator, _PairProxy> iterator;
|
||||
typedef _Iterator<const This*, const_inner_iterator,
|
||||
const value_type&> const_iterator;
|
||||
typedef boost::reverse_iterator<iterator> reverse_iterator;
|
||||
typedef boost::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
|
||||
explicit SdfMapEditProxy(const SdfSpecHandle& owner, const TfToken& field) :
|
||||
_editor(Sdf_CreateMapEditor<T>(owner, field))
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
SdfMapEditProxy()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
This& operator=(const This& other)
|
||||
{
|
||||
if (other._Validate()) {
|
||||
_Copy(*other._ConstData());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class U, class UVP>
|
||||
This& operator=(const SdfMapEditProxy<U, UVP>& other)
|
||||
{
|
||||
if (other._Validate()) {
|
||||
_Copy(Type(other._ConstData()->begin(), other._ConstData()->end()));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
This& operator=(const Type& data)
|
||||
{
|
||||
_Copy(data);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Returns a copy of the value.
|
||||
operator Type() const
|
||||
{
|
||||
return _Validate() ? *_ConstData() : Type();
|
||||
}
|
||||
|
||||
iterator begin()
|
||||
{
|
||||
return _Validate() ? iterator(this, _Data(), _Data()->begin()) :
|
||||
iterator();
|
||||
}
|
||||
iterator end()
|
||||
{
|
||||
return _Validate() ? iterator(this, _Data(), _Data()->end()) :
|
||||
iterator();
|
||||
}
|
||||
const_iterator begin() const
|
||||
{
|
||||
return _Validate() ?
|
||||
const_iterator(this, _ConstData(), _ConstData()->begin()) :
|
||||
const_iterator();
|
||||
}
|
||||
const_iterator end() const
|
||||
{
|
||||
return _Validate() ?
|
||||
const_iterator(this, _ConstData(), _ConstData()->end()) :
|
||||
const_iterator();
|
||||
}
|
||||
|
||||
reverse_iterator rbegin()
|
||||
{
|
||||
return reverse_iterator(end());
|
||||
}
|
||||
reverse_iterator rend()
|
||||
{
|
||||
return reverse_iterator(begin());
|
||||
}
|
||||
const_reverse_iterator rbegin() const
|
||||
{
|
||||
return const_reverse_iterator(end());
|
||||
}
|
||||
const_reverse_iterator rend() const
|
||||
{
|
||||
return const_reverse_iterator(begin());
|
||||
}
|
||||
|
||||
size_type size() const
|
||||
{
|
||||
return _Validate() ? _ConstData()->size() : 0;
|
||||
}
|
||||
|
||||
size_type max_size() const
|
||||
{
|
||||
return _Validate() ? _ConstData()->max_size() : 0;
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return _Validate() ? _ConstData()->empty() : true;
|
||||
}
|
||||
|
||||
std::pair<iterator, bool> insert(const value_type& value)
|
||||
{
|
||||
return _Insert(value);
|
||||
}
|
||||
|
||||
iterator insert(iterator pos, const value_type& value)
|
||||
{
|
||||
return _Insert(value).first;
|
||||
}
|
||||
|
||||
template <class InputIterator>
|
||||
void insert(InputIterator first, InputIterator last)
|
||||
{
|
||||
if (_Validate()) {
|
||||
SdfChangeBlock block;
|
||||
for (; first != last; ++first) {
|
||||
const value_type& v =
|
||||
ValuePolicy::CanonicalizePair(_Owner(), *first);
|
||||
|
||||
if (_ValidateInsert(v)) {
|
||||
_editor->Insert(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void erase(iterator pos)
|
||||
{
|
||||
if (_Validate() && _ValidateErase(pos->first)) {
|
||||
_Erase(pos->first);
|
||||
}
|
||||
}
|
||||
|
||||
size_type erase(const key_type& key)
|
||||
{
|
||||
if (_Validate()) {
|
||||
const key_type& k = ValuePolicy::CanonicalizeKey(_Owner(), key);
|
||||
if (_ValidateErase(k)) {
|
||||
return _editor->Erase(k) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void erase(iterator first, iterator last)
|
||||
{
|
||||
if (_Validate()) {
|
||||
SdfChangeBlock block;
|
||||
while (first != last) {
|
||||
const key_type& key = first->first;
|
||||
++first;
|
||||
if (_ValidateErase(key)) {
|
||||
_editor->Erase(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
_Copy(Type());
|
||||
}
|
||||
|
||||
iterator find(const key_type& key)
|
||||
{
|
||||
return
|
||||
_Validate() ?
|
||||
iterator(this, _Data(),
|
||||
_Data()->find(ValuePolicy::CanonicalizeKey(_Owner(), key))) :
|
||||
iterator();
|
||||
}
|
||||
|
||||
const_iterator find(const key_type& key) const
|
||||
{
|
||||
return
|
||||
_Validate() ?
|
||||
const_iterator(this, _ConstData(),
|
||||
_ConstData()->find(
|
||||
ValuePolicy::CanonicalizeKey(_Owner(), key))) :
|
||||
const_iterator();
|
||||
}
|
||||
|
||||
size_type count(const key_type& key) const
|
||||
{
|
||||
return
|
||||
_Validate() ?
|
||||
_ConstData()->count(
|
||||
ValuePolicy::CanonicalizeKey(_Owner(), key)) :
|
||||
0;
|
||||
}
|
||||
|
||||
iterator lower_bound(const key_type& key)
|
||||
{
|
||||
return
|
||||
_Validate() ?
|
||||
iterator(this, _Data(),
|
||||
_Data()->lower_bound(
|
||||
ValuePolicy::CanonicalizeKey(_Owner(), key))) :
|
||||
iterator();
|
||||
}
|
||||
|
||||
const_iterator lower_bound(const key_type& key) const
|
||||
{
|
||||
return
|
||||
_Validate() ?
|
||||
const_iterator(this, _ConstData(),
|
||||
_ConstData()->lower_bound(
|
||||
ValuePolicy::CanonicalizeKey(_Owner(), key))) :
|
||||
const_iterator();
|
||||
}
|
||||
|
||||
iterator upper_bound(const key_type& key)
|
||||
{
|
||||
return
|
||||
_Validate() ?
|
||||
iterator(this, _Data(),
|
||||
_Data()->upper_bound(
|
||||
ValuePolicy::CanonicalizeKey(_Owner(), key))) :
|
||||
iterator();
|
||||
}
|
||||
|
||||
const_iterator upper_bound(const key_type& key) const
|
||||
{
|
||||
return
|
||||
_Validate() ?
|
||||
const_iterator(this, _ConstData(),
|
||||
_ConstData()->upper_bound(
|
||||
ValuePolicy::CanonicalizeKey(_Owner(), key))) :
|
||||
const_iterator();
|
||||
}
|
||||
|
||||
std::pair<iterator, iterator> equal_range(const key_type& key)
|
||||
{
|
||||
if (_Validate()) {
|
||||
std::pair<inner_iterator, inner_iterator> result =
|
||||
_Data()->equal_range(
|
||||
ValuePolicy::CanonicalizeKey(_Owner(), key));
|
||||
return std::make_pair(iterator(this, _Data(), result.first),
|
||||
iterator(this, _Data(), result.second));
|
||||
}
|
||||
else {
|
||||
return std::make_pair(iterator(), iterator());
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<const_iterator,const_iterator>
|
||||
equal_range(const key_type& key) const
|
||||
{
|
||||
if (_Validate()) {
|
||||
std::pair<const_inner_iterator, const_inner_iterator> result =
|
||||
_ConstData()->equal_range(
|
||||
ValuePolicy::CanonicalizeKey(_Owner(), key));
|
||||
return std::make_pair(
|
||||
const_iterator(this, _ConstData(), result.first),
|
||||
const_iterator(this, _ConstData(), result.second));
|
||||
}
|
||||
else {
|
||||
return std::make_pair(const_iterator(), const_iterator());
|
||||
}
|
||||
}
|
||||
|
||||
reference operator[](const key_type& key)
|
||||
{
|
||||
auto iter = _Insert(value_type(key, mapped_type())).first;
|
||||
bool failed = iter == iterator();
|
||||
return reference(failed ? nullptr : this,
|
||||
failed ? nullptr : _Data(),
|
||||
iter.base());
|
||||
}
|
||||
|
||||
bool operator==(const Type& other) const
|
||||
{
|
||||
return _Validate() ? _CompareEqual(other) : false;
|
||||
}
|
||||
|
||||
bool operator<(const Type& other) const
|
||||
{
|
||||
return _Validate() ? _Compare(other) < 0 : false;
|
||||
}
|
||||
|
||||
bool operator>(const Type& other) const
|
||||
{
|
||||
return _Validate() ? _Compare(other) > 0 : false;
|
||||
}
|
||||
|
||||
template <class U, class UVP>
|
||||
bool operator==(const SdfMapEditProxy<U, UVP>& other) const
|
||||
{
|
||||
return _Validate() && other._Validate() ?
|
||||
_CompareEqual(*other._ConstData()) : false;
|
||||
}
|
||||
|
||||
template <class U, class UVP>
|
||||
bool operator!=(const SdfMapEditProxy<U, UVP>& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
template <class U, class UVP>
|
||||
bool operator<(const SdfMapEditProxy<U, UVP>& other) const
|
||||
{
|
||||
return _Validate() && other._Validate() ?
|
||||
_Compare(*other._ConstData()) < 0 : false;
|
||||
}
|
||||
|
||||
template <class U, class UVP>
|
||||
bool operator<=(const SdfMapEditProxy<U, UVP>& other) const
|
||||
{
|
||||
return _Validate() && other._Validate() ?
|
||||
_Compare(*other._ConstData()) <= 0 : false;
|
||||
}
|
||||
|
||||
template <class U, class UVP>
|
||||
bool operator>(const SdfMapEditProxy<U, UVP>& other) const
|
||||
{
|
||||
return !(*this <= other);
|
||||
}
|
||||
|
||||
template <class U, class UVP>
|
||||
bool operator>=(const SdfMapEditProxy<U, UVP>& other) const
|
||||
{
|
||||
return !(*this < other);
|
||||
}
|
||||
|
||||
/// Returns true if the value is expired. Note this a default-constructed
|
||||
/// MapEditProxy is considered to be invalid but *not* expired.
|
||||
bool IsExpired() const
|
||||
{
|
||||
return _editor && _editor->IsExpired();
|
||||
}
|
||||
|
||||
/// Explicit bool conversion operator. Returns \c true if the value is
|
||||
/// valid, \c false otherwise.
|
||||
explicit operator bool() const
|
||||
{
|
||||
return _ConstData() && !IsExpired();
|
||||
}
|
||||
|
||||
private:
|
||||
bool _Validate()
|
||||
{
|
||||
if (_ConstData() && !IsExpired()) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
TF_CODING_ERROR("Editing an invalid map proxy");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool _Validate() const
|
||||
{
|
||||
if (_ConstData() && !IsExpired()) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
TF_CODING_ERROR("Accessing an invalid map proxy");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Type* _Data()
|
||||
{
|
||||
return _editor ? _editor->GetData() : NULL;
|
||||
}
|
||||
|
||||
const Type* _ConstData() const
|
||||
{
|
||||
return _editor ? _editor->GetData() : NULL;
|
||||
}
|
||||
|
||||
SdfSpecHandle _Owner() const
|
||||
{
|
||||
return _editor ? _editor->GetOwner() : SdfSpecHandle();
|
||||
}
|
||||
|
||||
std::string _Location() const
|
||||
{
|
||||
return _editor ? _editor->GetLocation() : std::string();
|
||||
}
|
||||
|
||||
bool _CompareEqual(const Type& other) const
|
||||
{
|
||||
if (_ConstData()->size() < other.size()) {
|
||||
return false;
|
||||
}
|
||||
if (_ConstData()->size() > other.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Same size -- find the first mismatch.
|
||||
const Type& x = ValuePolicy::CanonicalizeType(_Owner(), other);
|
||||
std::pair<const_inner_iterator, const_inner_iterator> result =
|
||||
std::mismatch(_ConstData()->begin(), _ConstData()->end(),
|
||||
x.begin());
|
||||
return result.first == _ConstData()->end();
|
||||
}
|
||||
|
||||
int _Compare(const Type& other) const
|
||||
{
|
||||
if (_ConstData()->size() < other.size()) {
|
||||
return -1;
|
||||
}
|
||||
if (_ConstData()->size() > other.size()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Same size -- find the first mismatch.
|
||||
const Type& x = ValuePolicy::CanonicalizeType(_Owner(), other);
|
||||
std::pair<const_inner_iterator, const_inner_iterator> result =
|
||||
std::mismatch(_ConstData()->begin(), _ConstData()->end(),
|
||||
x.begin());
|
||||
if (*result.first < *result.second) {
|
||||
return -1;
|
||||
}
|
||||
else if (*result.first > *result.second) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
template <class D>
|
||||
bool _CompareEqual(const D& other) const
|
||||
{
|
||||
// This is expensive but yields reliable results.
|
||||
return _CompareEqual(Type(other.begin(), other.end()));
|
||||
}
|
||||
|
||||
template <class D>
|
||||
int _Compare(const D& other) const
|
||||
{
|
||||
// This is expensive but yields reliable ordering.
|
||||
return _Compare(Type(other.begin(), other.end()));
|
||||
}
|
||||
|
||||
mapped_type _Get(const Type* data, const inner_iterator& i)
|
||||
{
|
||||
if (_Validate()) {
|
||||
if (data == _ConstData()) {
|
||||
return i->second;
|
||||
}
|
||||
else {
|
||||
// Data has changed since we created the iterator.
|
||||
// Look up same key in new data.
|
||||
return _ConstData()->find(i->first)->second;
|
||||
}
|
||||
}
|
||||
return mapped_type();
|
||||
}
|
||||
|
||||
const value_type& _Get(const Type* data,
|
||||
const const_inner_iterator& i) const
|
||||
{
|
||||
// If data has changed since we created the iterator then look up
|
||||
// the same key in the new data.
|
||||
return (data == _ConstData()) ? *i : *_ConstData()->find(i->first);
|
||||
}
|
||||
|
||||
void _Copy(const Type& other)
|
||||
{
|
||||
if (_Validate()) {
|
||||
// Canonicalize the given map before copying it into ourselves.
|
||||
// If multiple keys in the given map would conflict with each
|
||||
// other in the canonicalized map, we consider this an error.
|
||||
// This is primarily to avoid confusing the consumer, who would
|
||||
// otherwise observe a key/value pair to be missing entirely.
|
||||
Type canonicalOther;
|
||||
TF_FOR_ALL(it, other) {
|
||||
const value_type canonicalValue =
|
||||
ValuePolicy::CanonicalizePair(_Owner(), *it);
|
||||
if (!canonicalOther.insert(canonicalValue).second) {
|
||||
TF_CODING_ERROR("Can't copy to %s: Duplicate key '%s' "
|
||||
"exists in map.",
|
||||
_Location().c_str(),
|
||||
TfStringify(canonicalValue.first).c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (_ValidateCopy(canonicalOther)) {
|
||||
_editor->Copy(canonicalOther);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool _ValidateCopy(const Type& other)
|
||||
{
|
||||
SdfSpecHandle owner = _Owner();
|
||||
if (owner && !owner->PermissionToEdit()) {
|
||||
TF_CODING_ERROR("Can't copy to %s: Permission denied.",
|
||||
_Location().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (other.empty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
TF_FOR_ALL(it, other) {
|
||||
if (!_ValidateInsert(*it)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class U>
|
||||
void _Set(const Type* data, const inner_iterator& i, const U& value)
|
||||
{
|
||||
if (_Validate()) {
|
||||
const mapped_type& x =
|
||||
ValuePolicy::CanonicalizeValue(_Owner(), value);
|
||||
if (_ValidateSet(i->first, x)) {
|
||||
_editor->Set(i->first, x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool _ValidateSet(const key_type& key, const mapped_type& value)
|
||||
{
|
||||
SdfSpecHandle owner = _Owner();
|
||||
if (owner && !owner->PermissionToEdit()) {
|
||||
TF_CODING_ERROR("Can't set value in %s: Permission denied.",
|
||||
_Location().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (SdfAllowed allowed = _editor->IsValidValue(value)) {
|
||||
// Do nothing
|
||||
}
|
||||
else {
|
||||
TF_CODING_ERROR("Can't set value in %s: %s",
|
||||
_Location().c_str(),
|
||||
allowed.GetWhyNot().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::pair<iterator, bool> _Insert(const value_type& value)
|
||||
{
|
||||
if (_Validate()) {
|
||||
const value_type& v = ValuePolicy::CanonicalizePair(_Owner(), value);
|
||||
if (_ValidateInsert(v)) {
|
||||
std::pair<inner_iterator, bool> status = _editor->Insert(v);
|
||||
return std::make_pair(iterator(this, _Data(), status.first),
|
||||
status.second);
|
||||
}
|
||||
else {
|
||||
return std::make_pair(iterator(), false);
|
||||
}
|
||||
}
|
||||
return std::make_pair(iterator(), false);
|
||||
}
|
||||
|
||||
bool _ValidateInsert(const value_type& value)
|
||||
{
|
||||
SdfSpecHandle owner = _Owner();
|
||||
if (owner && !owner->PermissionToEdit()) {
|
||||
TF_CODING_ERROR("Can't insert value in %s: Permission denied.",
|
||||
_Location().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (SdfAllowed allowed = _editor->IsValidKey(value.first)) {
|
||||
// Do nothing
|
||||
}
|
||||
else {
|
||||
TF_CODING_ERROR("Can't insert key in %s: %s",
|
||||
_Location().c_str(),
|
||||
allowed.GetWhyNot().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (SdfAllowed allowed = _editor->IsValidValue(value.second)) {
|
||||
// Do nothing
|
||||
}
|
||||
else {
|
||||
TF_CODING_ERROR("Can't insert value in %s: %s",
|
||||
_Location().c_str(),
|
||||
allowed.GetWhyNot().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void _Erase(const key_type& key)
|
||||
{
|
||||
if (_Validate() && _ValidateErase(key)) {
|
||||
_editor->Erase(key);
|
||||
}
|
||||
}
|
||||
|
||||
bool _ValidateErase(const key_type& key)
|
||||
{
|
||||
SdfSpecHandle owner = _Owner();
|
||||
if (owner && !owner->PermissionToEdit()) {
|
||||
TF_CODING_ERROR("Can't erase value from %s: Permission denied.",
|
||||
_Location().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
template <class ProxyT> friend class SdfPyWrapMapEditProxy;
|
||||
|
||||
boost::shared_ptr<Sdf_MapEditor<T> > _editor;
|
||||
};
|
||||
|
||||
// Cannot get from a VtValue except as the correct type.
|
||||
template <class T, class _ValuePolicy>
|
||||
struct Vt_DefaultValueFactory<SdfMapEditProxy<T, _ValuePolicy> > {
|
||||
static Vt_DefaultValueHolder Invoke() = delete;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_MAP_EDIT_PROXY_H
|
||||
@@ -0,0 +1,97 @@
|
||||
//
|
||||
// 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_SDF_MAP_EDITOR_H
|
||||
#define PXR_USD_SDF_MAP_EDITOR_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/allowed.h"
|
||||
#include "pxr/usd/sdf/spec.h"
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class TfToken;
|
||||
|
||||
/// \class Sdf_MapEditor
|
||||
///
|
||||
/// Interface for private implementations used by SdfMapEditProxy.
|
||||
///
|
||||
template <class MapType>
|
||||
class Sdf_MapEditor {
|
||||
public:
|
||||
typedef typename MapType::key_type key_type;
|
||||
typedef typename MapType::mapped_type mapped_type;
|
||||
typedef typename MapType::value_type value_type;
|
||||
typedef typename MapType::iterator iterator;
|
||||
|
||||
virtual ~Sdf_MapEditor();
|
||||
|
||||
/// Returns a string describing the location of the map being edited.
|
||||
/// This is used for debugging and error messages.
|
||||
virtual std::string GetLocation() const = 0;
|
||||
|
||||
/// Returns owner of the map being edited.
|
||||
virtual SdfSpecHandle GetOwner() const = 0;
|
||||
|
||||
/// Returns true if the map being edited is expired, false otherwise.
|
||||
virtual bool IsExpired() const = 0;
|
||||
|
||||
/// Returns const pointer to map being edited.
|
||||
virtual const MapType* GetData() const = 0;
|
||||
|
||||
/// Returns non-const pointer to map being edited.
|
||||
/// All edits to the map should be done using the editing functions below.
|
||||
/// This function is primarily here for convenience. Ideally, only the
|
||||
/// const version of this function would exist.
|
||||
virtual MapType* GetData() = 0;
|
||||
|
||||
/// \name Editing Operations
|
||||
/// @{
|
||||
|
||||
virtual void Copy(const MapType& other) = 0;
|
||||
virtual void Set(const key_type& key, const mapped_type& other) = 0;
|
||||
virtual std::pair<iterator, bool> Insert(const value_type& value) = 0;
|
||||
virtual bool Erase(const key_type& key) = 0;
|
||||
|
||||
virtual SdfAllowed IsValidKey(const key_type& key) const = 0;
|
||||
virtual SdfAllowed IsValidValue(const mapped_type& value) const = 0;
|
||||
|
||||
/// @}
|
||||
|
||||
protected:
|
||||
Sdf_MapEditor();
|
||||
|
||||
};
|
||||
|
||||
template <class T>
|
||||
boost::shared_ptr<Sdf_MapEditor<T> >
|
||||
Sdf_CreateMapEditor(const SdfSpecHandle& owner, const TfToken& field);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_MAP_EDITOR_H
|
||||
@@ -0,0 +1,301 @@
|
||||
//
|
||||
// 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_SDF_NAMESPACE_EDIT_H
|
||||
#define PXR_USD_SDF_NAMESPACE_EDIT_H
|
||||
|
||||
/// \file sdf/namespaceEdit.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include <boost/operators.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class SdfNamespaceEdit
|
||||
///
|
||||
/// A single namespace edit. It supports renaming, reparenting, reparenting
|
||||
/// with a rename, reordering, and removal.
|
||||
///
|
||||
struct SdfNamespaceEdit :
|
||||
boost::equality_comparable<SdfNamespaceEdit> {
|
||||
public:
|
||||
typedef SdfNamespaceEdit This;
|
||||
typedef SdfPath Path;
|
||||
typedef int Index;
|
||||
|
||||
/// Special index that means at the end.
|
||||
static const Index AtEnd = -1;
|
||||
|
||||
/// Special index that means don't move. It's only meaningful when
|
||||
/// renaming. In other cases implementations may assume \c AtEnd.
|
||||
static const Index Same = -2;
|
||||
|
||||
/// The default edit maps the empty path to the empty path.
|
||||
SdfNamespaceEdit() : index(AtEnd) { }
|
||||
|
||||
/// The fully general edit.
|
||||
SdfNamespaceEdit(const Path& currentPath_, const Path& newPath_,
|
||||
Index index_ = AtEnd) :
|
||||
currentPath(currentPath_), newPath(newPath_), index(index_) { }
|
||||
|
||||
/// Returns a namespace edit that removes the object at \p currentPath.
|
||||
static This Remove(const Path& currentPath)
|
||||
{
|
||||
return This(currentPath, Path::EmptyPath());
|
||||
}
|
||||
|
||||
/// Returns a namespace edit that renames the prim or property at
|
||||
/// \p currentPath to \p name
|
||||
static This Rename(const Path& currentPath, const TfToken& name)
|
||||
{
|
||||
return This(currentPath, currentPath.ReplaceName(name), Same);
|
||||
}
|
||||
|
||||
/// Returns a namespace edit to reorder the prim or property at
|
||||
/// \p currentPath to index \p index.
|
||||
static This Reorder(const Path& currentPath, Index index)
|
||||
{
|
||||
return This(currentPath, currentPath, index);
|
||||
}
|
||||
|
||||
/// Returns a namespace edit to reparent the prim or property at
|
||||
/// \p currentPath to be under \p newParentPath at index \p index.
|
||||
static This Reparent(const Path& currentPath,
|
||||
const Path& newParentPath,
|
||||
Index index)
|
||||
{
|
||||
return This(currentPath,
|
||||
currentPath.ReplacePrefix(currentPath.GetParentPath(),
|
||||
newParentPath),
|
||||
index);
|
||||
}
|
||||
|
||||
/// Returns a namespace edit to reparent the prim or property at
|
||||
/// \p currentPath to be under \p newParentPath at index \p index
|
||||
/// with the name \p name.
|
||||
static This ReparentAndRename(const Path& currentPath,
|
||||
const Path& newParentPath,
|
||||
const TfToken& name,
|
||||
Index index)
|
||||
{
|
||||
return This(currentPath,
|
||||
currentPath.ReplacePrefix(currentPath.GetParentPath(),
|
||||
newParentPath).
|
||||
ReplaceName(name),
|
||||
index);
|
||||
}
|
||||
|
||||
SDF_API bool operator==(const This& rhs) const;
|
||||
|
||||
public:
|
||||
Path currentPath; ///< Path of the object when this edit starts.
|
||||
Path newPath; ///< Path of the object when this edit ends.
|
||||
Index index; ///< Index for prim insertion.
|
||||
};
|
||||
|
||||
/// A sequence of \c SdfNamespaceEdit.
|
||||
typedef std::vector<SdfNamespaceEdit> SdfNamespaceEditVector;
|
||||
|
||||
SDF_API std::ostream& operator<<(std::ostream&, const SdfNamespaceEdit&);
|
||||
SDF_API std::ostream& operator<<(std::ostream&, const SdfNamespaceEditVector&);
|
||||
|
||||
/// \struct SdfNamespaceEditDetail
|
||||
///
|
||||
/// Detailed information about a namespace edit.
|
||||
///
|
||||
struct SdfNamespaceEditDetail :
|
||||
boost::equality_comparable<SdfNamespaceEditDetail> {
|
||||
public:
|
||||
/// Validity of an edit.
|
||||
enum Result {
|
||||
Error, ///< Edit will fail.
|
||||
Unbatched, ///< Edit will succeed but not batched.
|
||||
Okay, ///< Edit will succeed as a batch.
|
||||
};
|
||||
|
||||
SDF_API SdfNamespaceEditDetail();
|
||||
SDF_API SdfNamespaceEditDetail(Result, const SdfNamespaceEdit& edit,
|
||||
const std::string& reason);
|
||||
|
||||
SDF_API bool operator==(const SdfNamespaceEditDetail& rhs) const;
|
||||
|
||||
public:
|
||||
Result result; ///< Validity.
|
||||
SdfNamespaceEdit edit; ///< The edit.
|
||||
std::string reason; ///< The reason the edit will not succeed cleanly.
|
||||
};
|
||||
|
||||
/// A sequence of \c SdfNamespaceEditDetail.
|
||||
typedef std::vector<SdfNamespaceEditDetail> SdfNamespaceEditDetailVector;
|
||||
|
||||
SDF_API std::ostream& operator<<(std::ostream&, const SdfNamespaceEditDetail&);
|
||||
SDF_API std::ostream& operator<<(std::ostream&, const SdfNamespaceEditDetailVector&);
|
||||
|
||||
/// Combine two results, yielding Error over Unbatched over Okay.
|
||||
inline
|
||||
SdfNamespaceEditDetail::Result
|
||||
CombineResult(
|
||||
SdfNamespaceEditDetail::Result lhs,
|
||||
SdfNamespaceEditDetail::Result rhs)
|
||||
{
|
||||
return lhs < rhs ? lhs : rhs;
|
||||
}
|
||||
|
||||
/// Combine a result with Error, yielding Error over Unbatched over Okay.
|
||||
inline
|
||||
SdfNamespaceEditDetail::Result
|
||||
CombineError(SdfNamespaceEditDetail::Result)
|
||||
{
|
||||
return SdfNamespaceEditDetail::Error;
|
||||
}
|
||||
|
||||
/// Combine a result with Unbatched, yielding Error over Unbatched over Okay.
|
||||
inline
|
||||
SdfNamespaceEditDetail::Result
|
||||
CombineUnbatched(SdfNamespaceEditDetail::Result other)
|
||||
{
|
||||
return CombineResult(other, SdfNamespaceEditDetail::Unbatched);
|
||||
}
|
||||
|
||||
/// \class SdfBatchNamespaceEdit
|
||||
///
|
||||
/// A description of an arbitrarily complex namespace edit.
|
||||
///
|
||||
/// A \c SdfBatchNamespaceEdit object describes zero or more namespace edits.
|
||||
/// Various types providing a namespace will allow the edits to be applied
|
||||
/// in a single operation and also allow testing if this will work.
|
||||
///
|
||||
/// Clients are encouraged to group several edits into one object because
|
||||
/// that may allow more efficient processing of the edits. If, for example,
|
||||
/// you need to reparent several prims it may be faster to add all of the
|
||||
/// reparents to a single \c SdfBatchNamespaceEdit and apply them at once
|
||||
/// than to apply each separately.
|
||||
///
|
||||
/// Objects that allow applying edits are free to apply the edits in any way
|
||||
/// and any order they see fit but they should guarantee that the resulting
|
||||
/// namespace will be as if each edit was applied one at a time in the order
|
||||
/// they were added.
|
||||
///
|
||||
/// Note that the above rule permits skipping edits that have no effect or
|
||||
/// generate a non-final state. For example, if renaming A to B then to C
|
||||
/// we could just rename A to C. This means notices may be elided. However,
|
||||
/// implementations must not elide notices that contain information about any
|
||||
/// edit that clients must be able to know but otherwise cannot determine.
|
||||
///
|
||||
class SdfBatchNamespaceEdit {
|
||||
public:
|
||||
/// Create an empty sequence of edits.
|
||||
SDF_API SdfBatchNamespaceEdit();
|
||||
SDF_API SdfBatchNamespaceEdit(const SdfBatchNamespaceEdit&);
|
||||
SDF_API SdfBatchNamespaceEdit(const SdfNamespaceEditVector&);
|
||||
SDF_API ~SdfBatchNamespaceEdit();
|
||||
|
||||
SDF_API SdfBatchNamespaceEdit& operator=(const SdfBatchNamespaceEdit&);
|
||||
|
||||
/// Add a namespace edit.
|
||||
void Add(const SdfNamespaceEdit& edit)
|
||||
{
|
||||
_edits.push_back(edit);
|
||||
}
|
||||
|
||||
/// Add a namespace edit.
|
||||
void Add(const SdfNamespaceEdit::Path& currentPath,
|
||||
const SdfNamespaceEdit::Path& newPath,
|
||||
SdfNamespaceEdit::Index index = SdfNamespaceEdit::AtEnd)
|
||||
{
|
||||
Add(SdfNamespaceEdit(currentPath, newPath, index));
|
||||
}
|
||||
|
||||
/// Returns the edits.
|
||||
const SdfNamespaceEditVector& GetEdits() const
|
||||
{
|
||||
return _edits;
|
||||
}
|
||||
|
||||
/// Functor that returns \c true iff an object exists at the given path.
|
||||
typedef std::function<bool(const SdfPath&)> HasObjectAtPath;
|
||||
|
||||
/// Functor that returns \c true iff the namespace edit will succeed.
|
||||
/// If not it returns \c false and sets the string argument.
|
||||
typedef std::function<bool(const SdfNamespaceEdit&,std::string*)> CanEdit;
|
||||
|
||||
/// Validate the edits and generate a possibly more efficient edit
|
||||
/// sequence. Edits are treated as if they were performed one at time
|
||||
/// in sequence, therefore each edit occurs in the namespace resulting
|
||||
/// from all previous edits.
|
||||
///
|
||||
/// Editing the descendants of the object in each edit is implied. If
|
||||
/// an object is removed then the new path will be empty. If an object
|
||||
/// is removed after being otherwise edited, the other edits will be
|
||||
/// processed and included in \p processedEdits followed by the removal.
|
||||
/// This allows clients to fixup references to point to the object's
|
||||
/// final location prior to removal.
|
||||
///
|
||||
/// This function needs help to determine if edits are allowed. The
|
||||
/// callbacks provide that help. \p hasObjectAtPath returns \c true
|
||||
/// iff there's an object at the given path. This path will be in the
|
||||
/// original namespace not any intermediate or final namespace.
|
||||
/// \p canEdit returns \c true iff the object at the current path can
|
||||
/// be namespace edited to the new path, ignoring whether an object
|
||||
/// already exists at the new path. Both paths are in the original
|
||||
/// namespace. If it returns \c false it should set the string to the
|
||||
/// reason why the edit isn't allowed. It should not write either path
|
||||
/// to the string.
|
||||
///
|
||||
/// If \p hasObjectAtPath is invalid then this assumes objects exist
|
||||
/// where they should and don't exist where they shouldn't. Use this
|
||||
/// with care. If \p canEdit in invalid then it's assumed all edits
|
||||
/// are valid.
|
||||
///
|
||||
/// If \p fixBackpointers is \c true then target/connection paths are
|
||||
/// expected to be in the intermediate namespace resulting from all
|
||||
/// previous edits. If \c false and any current or new path contains a
|
||||
/// target or connection path that has been edited then this will
|
||||
/// generate an error.
|
||||
///
|
||||
/// This method returns \c true if the edits are allowed and sets
|
||||
/// \p processedEdits to a new edit sequence at least as efficient as
|
||||
/// the input sequence. If not allowed it returns \c false and appends
|
||||
/// reasons why not to \p details.
|
||||
SDF_API
|
||||
bool Process(SdfNamespaceEditVector* processedEdits,
|
||||
const HasObjectAtPath& hasObjectAtPath,
|
||||
const CanEdit& canEdit,
|
||||
SdfNamespaceEditDetailVector* details = NULL,
|
||||
bool fixBackpointers = true) const;
|
||||
|
||||
private:
|
||||
SdfNamespaceEditVector _edits;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_NAMESPACE_EDIT_H
|
||||
@@ -0,0 +1,237 @@
|
||||
//
|
||||
// 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_SDF_NOTICE_H
|
||||
#define PXR_USD_SDF_NOTICE_H
|
||||
|
||||
/// \file sdf/notice.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
#include "pxr/usd/sdf/changeList.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/tf/notice.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
SDF_DECLARE_HANDLES(SdfLayer);
|
||||
|
||||
/// \class SdfNotice
|
||||
///
|
||||
/// Wrapper class for Sdf notices.
|
||||
///
|
||||
class SdfNotice {
|
||||
public:
|
||||
/// \class Base
|
||||
///
|
||||
/// Base notification class for scene. Only useful for type hierarchy
|
||||
/// purposes.
|
||||
///
|
||||
class Base : public TfNotice {
|
||||
public:
|
||||
SDF_API ~Base();
|
||||
};
|
||||
|
||||
/// \class BaseLayersDidChange
|
||||
///
|
||||
/// Base class for LayersDidChange and LayersDidChangeSentPerLayer.
|
||||
///
|
||||
class BaseLayersDidChange {
|
||||
public:
|
||||
BaseLayersDidChange(const SdfLayerChangeListVec &changeVec,
|
||||
size_t serialNumber)
|
||||
: _vec(&changeVec)
|
||||
, _serialNumber(serialNumber)
|
||||
{}
|
||||
|
||||
using const_iterator = SdfLayerChangeListVec::const_iterator;
|
||||
using iterator = const_iterator;
|
||||
|
||||
/// A list of layers changed.
|
||||
SDF_API
|
||||
SdfLayerHandleVector GetLayers() const;
|
||||
|
||||
/// A list of layers and the changes that occurred to them.
|
||||
const SdfLayerChangeListVec &GetChangeListVec() const { return *_vec; }
|
||||
|
||||
const_iterator begin() const { return _vec->begin(); }
|
||||
const_iterator cbegin() const { return _vec->cbegin(); }
|
||||
const_iterator end() const { return _vec->end(); }
|
||||
const_iterator cend() const { return _vec->cend(); }
|
||||
|
||||
const_iterator find(SdfLayerHandle const &layer) const {
|
||||
return std::find_if(
|
||||
begin(), end(),
|
||||
[&layer](SdfLayerChangeListVec::value_type const &p) {
|
||||
return p.first == layer;
|
||||
});
|
||||
}
|
||||
|
||||
bool count(SdfLayerHandle const &layer) const {
|
||||
return find(layer) != end();
|
||||
}
|
||||
|
||||
/// The serial number for this round of change processing.
|
||||
size_t GetSerialNumber() const { return _serialNumber; }
|
||||
|
||||
private:
|
||||
const SdfLayerChangeListVec *_vec;
|
||||
const size_t _serialNumber;
|
||||
};
|
||||
|
||||
/// \class LayersDidChangeSentPerLayer
|
||||
///
|
||||
/// Notice sent per-layer indicating all layers whose contents have changed
|
||||
/// within a single round of change processing. If more than one layer
|
||||
/// changes in a single round of change processing, we send this notice once
|
||||
/// per layer with the same changeVec and serialNumber. This is so clients
|
||||
/// can listen to notices from only the set of layers they care about rather
|
||||
/// than listening to the global LayersDidChange notice.
|
||||
///
|
||||
class LayersDidChangeSentPerLayer
|
||||
: public Base, public BaseLayersDidChange {
|
||||
public:
|
||||
LayersDidChangeSentPerLayer(const SdfLayerChangeListVec &changeVec,
|
||||
size_t serialNumber)
|
||||
: BaseLayersDidChange(changeVec, serialNumber) {}
|
||||
SDF_API virtual ~LayersDidChangeSentPerLayer();
|
||||
};
|
||||
|
||||
/// \class LayersDidChange
|
||||
///
|
||||
/// Global notice sent to indicate that layer contents have changed.
|
||||
///
|
||||
class LayersDidChange
|
||||
: public Base, public BaseLayersDidChange {
|
||||
public:
|
||||
LayersDidChange(const SdfLayerChangeListVec &changeVec,
|
||||
size_t serialNumber)
|
||||
: BaseLayersDidChange(changeVec, serialNumber) {}
|
||||
SDF_API virtual ~LayersDidChange();
|
||||
};
|
||||
|
||||
/// \class LayerInfoDidChange
|
||||
///
|
||||
/// Sent when the (scene spec) info of a layer have changed.
|
||||
///
|
||||
class LayerInfoDidChange : public Base {
|
||||
public:
|
||||
LayerInfoDidChange( const TfToken &key ) :
|
||||
_key(key) {}
|
||||
SDF_API ~LayerInfoDidChange();
|
||||
|
||||
/// Return the key affected.
|
||||
const TfToken & key() const { return _key; }
|
||||
private:
|
||||
TfToken _key;
|
||||
};
|
||||
|
||||
/// \class LayerIdentifierDidChange
|
||||
///
|
||||
/// Sent when the identifier of a layer has changed.
|
||||
///
|
||||
class LayerIdentifierDidChange : public Base {
|
||||
public:
|
||||
SDF_API
|
||||
LayerIdentifierDidChange(const std::string& oldIdentifier,
|
||||
const std::string& newIdentifier);
|
||||
SDF_API
|
||||
~LayerIdentifierDidChange();
|
||||
|
||||
/// Returns the old identifier for the layer.
|
||||
const std::string& GetOldIdentifier() const { return _oldId; }
|
||||
|
||||
/// Returns the new identifier for the layer.
|
||||
const std::string& GetNewIdentifier() const { return _newId; }
|
||||
|
||||
private:
|
||||
std::string _oldId;
|
||||
std::string _newId;
|
||||
};
|
||||
|
||||
/// \class LayerDidReplaceContent
|
||||
///
|
||||
/// Sent after a menv layer has been loaded from a file.
|
||||
///
|
||||
class LayerDidReplaceContent : public Base {
|
||||
public:
|
||||
SDF_API ~LayerDidReplaceContent();
|
||||
};
|
||||
|
||||
/// \class LayerDidReloadContent
|
||||
/// Sent after a layer is reloaded.
|
||||
class LayerDidReloadContent : public LayerDidReplaceContent {
|
||||
public:
|
||||
SDF_API virtual ~LayerDidReloadContent();
|
||||
};
|
||||
|
||||
/// \class LayerDidSaveLayerToFile
|
||||
///
|
||||
/// Sent after a layer is saved to file.
|
||||
///
|
||||
class LayerDidSaveLayerToFile : public Base {
|
||||
public:
|
||||
SDF_API ~LayerDidSaveLayerToFile();
|
||||
};
|
||||
|
||||
/// \class LayerDirtinessChanged
|
||||
///
|
||||
/// Similar behavior to LayersDidChange, but only gets sent if a change
|
||||
/// in the dirty status of a layer occurs.
|
||||
///
|
||||
class LayerDirtinessChanged : public Base {
|
||||
public:
|
||||
SDF_API ~LayerDirtinessChanged();
|
||||
};
|
||||
|
||||
/// \class LayerMutenessChanged
|
||||
///
|
||||
/// Sent after a layer has been added or removed from the set of
|
||||
/// muted layers. Note this does not necessarily mean the specified
|
||||
/// layer is currently loaded.
|
||||
///
|
||||
class LayerMutenessChanged : public Base {
|
||||
public:
|
||||
LayerMutenessChanged(const std::string& layerPath, bool wasMuted)
|
||||
: _layerPath(layerPath)
|
||||
, _wasMuted(wasMuted)
|
||||
{ }
|
||||
|
||||
SDF_API ~LayerMutenessChanged();
|
||||
|
||||
/// Returns the path of the layer that was muted or unmuted.
|
||||
const std::string& GetLayerPath() const { return _layerPath; }
|
||||
|
||||
/// Returns true if the layer was muted, false if unmuted.
|
||||
bool WasMuted() const { return _wasMuted; }
|
||||
|
||||
private:
|
||||
std::string _layerPath;
|
||||
bool _wasMuted;
|
||||
};
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_NOTICE_H
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,87 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
/* A Bison parser, made by GNU Bison 2.4.1. */
|
||||
|
||||
/* Skeleton interface for Bison's Yacc-like parsers in C
|
||||
|
||||
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* As a special exception, you may create a larger work that contains
|
||||
part or all of the Bison parser skeleton and distribute that work
|
||||
under terms of your choice, so long as that work isn't itself a
|
||||
parser generator using the skeleton or a modified version thereof
|
||||
as a parser skeleton. Alternatively, if you modify or redistribute
|
||||
the parser skeleton itself, you may (at your option) remove this
|
||||
special exception, which will cause the skeleton and the resulting
|
||||
Bison output files to be licensed under the GNU General Public
|
||||
License without this special exception.
|
||||
|
||||
This special exception was added by the Free Software Foundation in
|
||||
version 2.2 of Bison. */
|
||||
|
||||
|
||||
/* Tokens. */
|
||||
#ifndef YYTOKENTYPE
|
||||
# define YYTOKENTYPE
|
||||
/* Put the tokens into the symbol table, so that GDB and other debuggers
|
||||
know about them. */
|
||||
enum yytokentype {
|
||||
TOK_MAPPER = 258,
|
||||
TOK_EXPRESSION = 259,
|
||||
TOK_IDENTIFIER = 260,
|
||||
TOK_NAMESPACED_IDENTIFIER = 261,
|
||||
TOK_PRIM_NAME = 262,
|
||||
TOK_VARIANT_NAME = 263,
|
||||
TOK_DOTDOT = 264,
|
||||
TOK_WHITESPACE = 265
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
typedef int YYSTYPE;
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,732 @@
|
||||
//
|
||||
// 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_SDF_PATH_NODE_H
|
||||
#define PXR_USD_SDF_PATH_NODE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/api.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/tf/mallocTag.h"
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/intrusive_ptr.hpp>
|
||||
|
||||
#include <tbb/atomic.h>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
// Sdf_PathNode
|
||||
//
|
||||
// This class is the root of the path node hierarchy. It used to use ordinary
|
||||
// C++ polymorphism, but it no longer does. This is primarily a space
|
||||
// optimization: the set of node types is fixed, we already have an enum 'type'
|
||||
// field, and we typically have lots (e.g. ~1e8) of these objects. Dropping the
|
||||
// C++ polymorphism saves us the vtable pointer, and we can pack the '_nodeType'
|
||||
// field in a much smaller space with other flags.
|
||||
//
|
||||
// We currently store PathNode objects in two prefix trees. The "prim like"
|
||||
// path nodes (the root nodes '/' and '.', prim path nodes, and prim variant
|
||||
// selection nodes are in one prefix tree, and the "property like" nodes are in
|
||||
// another prefix tree (prim property nodes, target nodes, expression nodes,
|
||||
// mapper arg nodes). We do this because there are far fewer unique property
|
||||
// nodes (generally) than there are prim nodes. We allocate these in Sdf_Pools,
|
||||
// so that the SdfPath class can store a handle to an element in each tree in 64
|
||||
// bits total. (Sdf_Pool is designed so that we can refer to objects in memory
|
||||
// using 32-bit indexes instead of 64-bit pointers). An SdfPath joins together
|
||||
// these two elements to form a whole path. For example, the path
|
||||
// '/Foo/Bar.attr' would store a prim-part handle to the '/Foo/Bar' node, and a
|
||||
// property-part handle to 'attr'.
|
||||
//
|
||||
class Sdf_PathNode {
|
||||
Sdf_PathNode(Sdf_PathNode const &) = delete;
|
||||
Sdf_PathNode &operator=(Sdf_PathNode const &) = delete;
|
||||
public:
|
||||
// Node types identify what kind of path node a given instance is.
|
||||
// There are restrictions on what type of children each node type
|
||||
// can have,
|
||||
enum NodeType {
|
||||
|
||||
/********************************************************/
|
||||
/******************************* Prim portion nodes *****/
|
||||
|
||||
RootNode,
|
||||
// Allowable child node types:
|
||||
// PrimNode
|
||||
// PrimPropertyNode (only for relative root)
|
||||
// PrimVariantSelectionNode (only for relative root)
|
||||
|
||||
PrimNode,
|
||||
// Allowable child node types:
|
||||
// PrimNode
|
||||
// PrimPropertyNode
|
||||
// PrimVariantSelectionNode
|
||||
|
||||
PrimVariantSelectionNode,
|
||||
// Allowable child node types:
|
||||
// PrimNode
|
||||
// PrimPropertyNode
|
||||
// PrimVariantSelectionNode
|
||||
// (for variants that contain variant sets)
|
||||
|
||||
/********************************************************/
|
||||
/******************************* Property portion nodes */
|
||||
|
||||
PrimPropertyNode,
|
||||
// Allowable child node types:
|
||||
// TargetNode
|
||||
// MapperNode
|
||||
// ExpressionNode
|
||||
|
||||
TargetNode,
|
||||
// Allowable child node types:
|
||||
// RelationalAttributeNode (only if parent is PrimPropertyNode)
|
||||
|
||||
MapperNode,
|
||||
// Allowable child node types:
|
||||
// MapperArgNode
|
||||
|
||||
RelationalAttributeNode,
|
||||
// Allowable child node types:
|
||||
// TargetNode
|
||||
// MapperNode
|
||||
// ExpressionNode
|
||||
|
||||
MapperArgNode,
|
||||
// Allowable child node types:
|
||||
// <none>
|
||||
|
||||
ExpressionNode,
|
||||
// Allowable child node types:
|
||||
// <none>
|
||||
|
||||
NumNodeTypes ///< Internal sentinel value
|
||||
};
|
||||
|
||||
static Sdf_PathPrimNodeHandle
|
||||
FindOrCreatePrim(Sdf_PathNode const *parent, const TfToken &name);
|
||||
|
||||
static Sdf_PathPropNodeHandle
|
||||
FindOrCreatePrimProperty(Sdf_PathNode const *parent, const TfToken &name);
|
||||
|
||||
static Sdf_PathPrimNodeHandle
|
||||
FindOrCreatePrimVariantSelection(Sdf_PathNode const *parent,
|
||||
const TfToken &variantSet,
|
||||
const TfToken &variant);
|
||||
|
||||
static Sdf_PathPropNodeHandle
|
||||
FindOrCreateTarget(Sdf_PathNode const *parent,
|
||||
SdfPath const &targetPath);
|
||||
|
||||
static Sdf_PathPropNodeHandle
|
||||
FindOrCreateRelationalAttribute(Sdf_PathNode const *parent,
|
||||
const TfToken &name);
|
||||
|
||||
static Sdf_PathPropNodeHandle
|
||||
FindOrCreateMapper(Sdf_PathNode const *parent, SdfPath const &targetPath);
|
||||
|
||||
static Sdf_PathPropNodeHandle
|
||||
FindOrCreateMapperArg(Sdf_PathNode const *parent, const TfToken &name);
|
||||
|
||||
static Sdf_PathPropNodeHandle
|
||||
FindOrCreateExpression(Sdf_PathNode const *parent);
|
||||
|
||||
static Sdf_PathNode const *GetAbsoluteRootNode();
|
||||
static Sdf_PathNode const *GetRelativeRootNode();
|
||||
|
||||
NodeType GetNodeType() const { return NodeType(_nodeType); }
|
||||
|
||||
static std::pair<Sdf_PathNode const *, Sdf_PathNode const *>
|
||||
RemoveCommonSuffix(Sdf_PathNode const *a,
|
||||
Sdf_PathNode const *b,
|
||||
bool stopAtRootPrim);
|
||||
|
||||
// This method returns a node pointer
|
||||
Sdf_PathNode const *GetParentNode() const { return _parent.get(); }
|
||||
|
||||
size_t GetElementCount() const { return size_t(_elementCount); }
|
||||
bool IsAbsolutePath() const { return _isAbsolute; }
|
||||
bool IsAbsoluteRoot() const { return (_isAbsolute) & (!_elementCount); }
|
||||
bool ContainsTargetPath() const { return _containsTargetPath; }
|
||||
bool IsNamespaced() const {
|
||||
return (_nodeType == PrimPropertyNode ||
|
||||
_nodeType == RelationalAttributeNode) && _IsNamespacedImpl();
|
||||
}
|
||||
|
||||
bool ContainsPrimVariantSelection() const {
|
||||
return _containsPrimVariantSelection;
|
||||
}
|
||||
|
||||
// For PrimNode, PrimPropertyNode, RelationalAttributeNode, and
|
||||
// MapperArgNode this is the name (with no "dot" for
|
||||
// properties/relational attributes/mapper args). For others, it
|
||||
// is EmptyToken.
|
||||
inline const TfToken &GetName() const;
|
||||
|
||||
// For TargetNode and MapperNode this is the target path.
|
||||
// For others, it is InvalidPath.
|
||||
inline const SdfPath &GetTargetPath() const;
|
||||
|
||||
typedef std::pair<TfToken, TfToken> VariantSelectionType;
|
||||
inline const VariantSelectionType& GetVariantSelection() const;
|
||||
|
||||
// Returns the path element string (".name" for properties, "[path]" for
|
||||
// targets, etc...)
|
||||
inline TfToken GetElement() const;
|
||||
|
||||
// Append this element's text (same as GetElement()) to \p str.
|
||||
void AppendText(std::string *str) const;
|
||||
|
||||
// Return the stringified path to this node as a TfToken lvalue.
|
||||
SDF_API static const TfToken &
|
||||
GetPathToken(Sdf_PathNode const *primPart, Sdf_PathNode const *propPart);
|
||||
|
||||
// Return the stringified path to this node as a TfToken rvalue.
|
||||
SDF_API static TfToken
|
||||
GetPathAsToken(Sdf_PathNode const *primPart, Sdf_PathNode const *propPart);
|
||||
|
||||
// Lexicographic ordering for Compare().
|
||||
struct LessThan {
|
||||
template <class T>
|
||||
inline bool operator()(T const &a, T const &b) const {
|
||||
return a < b;
|
||||
}
|
||||
};
|
||||
|
||||
// This operator only works properly when the rhs has the same parent
|
||||
// as this node.
|
||||
template <class Less>
|
||||
inline bool Compare(const Sdf_PathNode &rhs) const;
|
||||
|
||||
// Return the current ref-count.
|
||||
// Meant for diagnostic use.
|
||||
unsigned int GetCurrentRefCount() const { return _refCount; }
|
||||
|
||||
protected:
|
||||
Sdf_PathNode(Sdf_PathNode const *parent, NodeType nodeType)
|
||||
: _parent(parent)
|
||||
, _refCount(1)
|
||||
, _elementCount(parent ? parent->_elementCount + 1 : 1)
|
||||
, _nodeType(nodeType)
|
||||
, _isAbsolute(parent && parent->IsAbsolutePath())
|
||||
, _containsPrimVariantSelection(
|
||||
nodeType == PrimVariantSelectionNode ||
|
||||
(parent && parent->_containsPrimVariantSelection))
|
||||
, _containsTargetPath(nodeType == TargetNode ||
|
||||
nodeType == MapperNode ||
|
||||
(parent && parent->_containsTargetPath))
|
||||
, _hasToken(false)
|
||||
{}
|
||||
|
||||
// This constructor is used only to create the two special root nodes.
|
||||
explicit Sdf_PathNode(bool isAbsolute);
|
||||
|
||||
~Sdf_PathNode() {
|
||||
if (_hasToken)
|
||||
_RemovePathTokenFromTable();
|
||||
}
|
||||
|
||||
// Helper to downcast and destroy the dynamic type of this object -- this is
|
||||
// required since this class hierarchy doesn't use normal C++ polymorphism
|
||||
// for space reasons.
|
||||
inline void _Destroy() const;
|
||||
|
||||
// // Helper function for GetPathToken, which lazily creates its token
|
||||
static TfToken _CreatePathToken(Sdf_PathNode const *primPart,
|
||||
Sdf_PathNode const *propPart);
|
||||
|
||||
// Helper for dtor, removes this path node's token from the token table.
|
||||
SDF_API void _RemovePathTokenFromTable() const;
|
||||
|
||||
struct _EqualElement {
|
||||
template <class T>
|
||||
inline bool operator()(T const &a, T const &b) const {
|
||||
return a == b;
|
||||
}
|
||||
};
|
||||
|
||||
friend struct Sdf_PathNodePrivateAccess;
|
||||
|
||||
// Ref-counting ops manage _refCount.
|
||||
friend void intrusive_ptr_add_ref(const Sdf_PathNode*);
|
||||
friend void intrusive_ptr_release(const Sdf_PathNode*);
|
||||
|
||||
private:
|
||||
// Downcast helper, just sugar to static_cast this to Derived const *.
|
||||
template <class Derived>
|
||||
Derived const *_Downcast() const {
|
||||
return static_cast<Derived const *>(this);
|
||||
}
|
||||
|
||||
// Helper to scan this node's name for the property namespace delimiter.
|
||||
bool _IsNamespacedImpl() const;
|
||||
|
||||
// Helper to return a const lvalue variant selection.
|
||||
VariantSelectionType const &_GetEmptyVariantSelection() const;
|
||||
|
||||
// Instance variables. PathNode's size is important to keep small. Please
|
||||
// be mindful of that when making any changes here.
|
||||
const Sdf_PathNodeConstRefPtr _parent;
|
||||
mutable tbb::atomic<unsigned int> _refCount;
|
||||
|
||||
const short _elementCount;
|
||||
const unsigned char _nodeType;
|
||||
const bool _isAbsolute:1;
|
||||
const bool _containsPrimVariantSelection:1;
|
||||
const bool _containsTargetPath:1;
|
||||
|
||||
// This is racy -- we ensure that the token creation code carefully
|
||||
// synchronizes so that if we read 'true' from this flag, it guarantees that
|
||||
// there's a token for this path node in the token table. If we read
|
||||
// 'false' it means there may or may not be, unless we're in the destructor,
|
||||
// which must run exclusively, then reading 'false' guarantees there is no
|
||||
// token in the table. We use this flag to do that optimization in the
|
||||
// destructor so we can avoid looking in the table in the case where we
|
||||
// haven't created a token.
|
||||
mutable bool _hasToken:1;
|
||||
};
|
||||
|
||||
class Sdf_PrimPartPathNode : public Sdf_PathNode {
|
||||
public:
|
||||
using Sdf_PathNode::Sdf_PathNode;
|
||||
SDF_API void operator delete (void *p);
|
||||
};
|
||||
|
||||
class Sdf_PropPartPathNode : public Sdf_PathNode {
|
||||
public:
|
||||
using Sdf_PathNode::Sdf_PathNode;
|
||||
SDF_API void operator delete (void *p);
|
||||
};
|
||||
|
||||
class Sdf_RootPathNode : public Sdf_PrimPartPathNode {
|
||||
public:
|
||||
typedef bool ComparisonType;
|
||||
static const NodeType nodeType = Sdf_PathNode::RootNode;
|
||||
|
||||
static SDF_API Sdf_PathNode const *New(bool isAbsolute);
|
||||
|
||||
private:
|
||||
// This constructor is used only to create the two special root nodes.
|
||||
Sdf_RootPathNode(bool isAbsolute) : Sdf_PrimPartPathNode(isAbsolute) {}
|
||||
|
||||
ComparisonType _GetComparisonValue() const {
|
||||
// Root nodes, there are only two, one absolute and one relative.
|
||||
// (absolute < relative...)
|
||||
return !IsAbsolutePath();
|
||||
}
|
||||
|
||||
friend class Sdf_PathNode;
|
||||
template <int nodeType, class Comp> friend struct Sdf_PathNodeCompare;
|
||||
};
|
||||
|
||||
class Sdf_PrimPathNode : public Sdf_PrimPartPathNode {
|
||||
public:
|
||||
typedef TfToken ComparisonType;
|
||||
static const NodeType nodeType = Sdf_PathNode::PrimNode;
|
||||
|
||||
private:
|
||||
Sdf_PrimPathNode(Sdf_PathNode const *parent,
|
||||
const TfToken &name)
|
||||
: Sdf_PrimPartPathNode(parent, nodeType)
|
||||
, _name(name) {}
|
||||
|
||||
SDF_API ~Sdf_PrimPathNode();
|
||||
|
||||
const ComparisonType &_GetComparisonValue() const { return _name; }
|
||||
|
||||
friend class Sdf_PathNode;
|
||||
friend struct Sdf_PathNodePrivateAccess;
|
||||
template <int nodeType, class Comp> friend struct Sdf_PathNodeCompare;
|
||||
|
||||
// Instance variables
|
||||
TfToken _name;
|
||||
};
|
||||
|
||||
class Sdf_PrimPropertyPathNode : public Sdf_PropPartPathNode {
|
||||
public:
|
||||
typedef TfToken ComparisonType;
|
||||
static const NodeType nodeType = Sdf_PathNode::PrimPropertyNode;
|
||||
|
||||
private:
|
||||
Sdf_PrimPropertyPathNode(Sdf_PathNode const *parent,
|
||||
const TfToken &name)
|
||||
: Sdf_PropPartPathNode(parent, nodeType)
|
||||
, _name(name) {}
|
||||
|
||||
SDF_API ~Sdf_PrimPropertyPathNode();
|
||||
|
||||
friend class Sdf_PathNode;
|
||||
friend struct Sdf_PathNodePrivateAccess;
|
||||
template <int nodeType, class Comp> friend struct Sdf_PathNodeCompare;
|
||||
|
||||
const ComparisonType &_GetComparisonValue() const { return _name; }
|
||||
|
||||
// Instance variables
|
||||
TfToken _name;
|
||||
};
|
||||
|
||||
class Sdf_PrimVariantSelectionNode : public Sdf_PrimPartPathNode {
|
||||
public:
|
||||
typedef VariantSelectionType ComparisonType;
|
||||
static const NodeType nodeType = Sdf_PathNode::PrimVariantSelectionNode;
|
||||
|
||||
const TfToken &_GetNameImpl() const;
|
||||
void _AppendText(std::string *str) const;
|
||||
|
||||
private:
|
||||
Sdf_PrimVariantSelectionNode(Sdf_PathNode const *parent,
|
||||
const VariantSelectionType &variantSelection)
|
||||
: Sdf_PrimPartPathNode(parent, nodeType)
|
||||
, _variantSelection(new VariantSelectionType(variantSelection)) {}
|
||||
|
||||
SDF_API ~Sdf_PrimVariantSelectionNode();
|
||||
|
||||
const ComparisonType &_GetComparisonValue() const {
|
||||
return *_variantSelection;
|
||||
}
|
||||
|
||||
friend class Sdf_PathNode;
|
||||
friend struct Sdf_PathNodePrivateAccess;
|
||||
template <int nodeType, class Comp> friend struct Sdf_PathNodeCompare;
|
||||
|
||||
// Instance variables
|
||||
std::unique_ptr<VariantSelectionType> _variantSelection;
|
||||
};
|
||||
|
||||
class Sdf_TargetPathNode : public Sdf_PropPartPathNode {
|
||||
public:
|
||||
typedef SdfPath ComparisonType;
|
||||
static const NodeType nodeType = Sdf_PathNode::TargetNode;
|
||||
|
||||
void _AppendText(std::string *str) const;
|
||||
|
||||
private:
|
||||
Sdf_TargetPathNode(Sdf_PathNode const *parent,
|
||||
const SdfPath &targetPath)
|
||||
: Sdf_PropPartPathNode(parent, nodeType)
|
||||
, _targetPath(targetPath) {}
|
||||
|
||||
SDF_API ~Sdf_TargetPathNode();
|
||||
|
||||
const ComparisonType& _GetComparisonValue() const { return _targetPath; }
|
||||
|
||||
friend class Sdf_PathNode;
|
||||
friend struct Sdf_PathNodePrivateAccess;
|
||||
template <int nodeType, class Comp> friend struct Sdf_PathNodeCompare;
|
||||
|
||||
// Instance variables
|
||||
SdfPath _targetPath;
|
||||
};
|
||||
|
||||
class Sdf_RelationalAttributePathNode : public Sdf_PropPartPathNode {
|
||||
public:
|
||||
typedef TfToken ComparisonType;
|
||||
static const NodeType nodeType = Sdf_PathNode::RelationalAttributeNode;
|
||||
|
||||
private:
|
||||
Sdf_RelationalAttributePathNode(Sdf_PathNode const *parent,
|
||||
const TfToken &name)
|
||||
: Sdf_PropPartPathNode(parent, nodeType)
|
||||
, _name(name) {}
|
||||
|
||||
SDF_API ~Sdf_RelationalAttributePathNode();
|
||||
|
||||
const ComparisonType& _GetComparisonValue() const { return _name; }
|
||||
|
||||
friend class Sdf_PathNode;
|
||||
friend struct Sdf_PathNodePrivateAccess;
|
||||
template <int nodeType, class Comp> friend struct Sdf_PathNodeCompare;
|
||||
|
||||
// Instance variables
|
||||
TfToken _name;
|
||||
};
|
||||
|
||||
class Sdf_MapperPathNode : public Sdf_PropPartPathNode {
|
||||
public:
|
||||
typedef SdfPath ComparisonType;
|
||||
static const NodeType nodeType = Sdf_PathNode::MapperNode;
|
||||
|
||||
void _AppendText(std::string *str) const;
|
||||
|
||||
private:
|
||||
Sdf_MapperPathNode(Sdf_PathNode const *parent,
|
||||
const SdfPath &targetPath)
|
||||
: Sdf_PropPartPathNode(parent, nodeType)
|
||||
, _targetPath(targetPath) {}
|
||||
|
||||
SDF_API ~Sdf_MapperPathNode();
|
||||
|
||||
const ComparisonType& _GetComparisonValue() const { return _targetPath; }
|
||||
|
||||
friend class Sdf_PathNode;
|
||||
friend struct Sdf_PathNodePrivateAccess;
|
||||
template <int nodeType, class Comp> friend struct Sdf_PathNodeCompare;
|
||||
|
||||
// Instance variables
|
||||
SdfPath _targetPath;
|
||||
};
|
||||
|
||||
class Sdf_MapperArgPathNode : public Sdf_PropPartPathNode {
|
||||
public:
|
||||
typedef TfToken ComparisonType;
|
||||
static const NodeType nodeType = Sdf_PathNode::MapperArgNode;
|
||||
|
||||
void _AppendText(std::string *str) const;
|
||||
|
||||
private:
|
||||
Sdf_MapperArgPathNode(Sdf_PathNode const *parent,
|
||||
const TfToken &name)
|
||||
: Sdf_PropPartPathNode(parent, nodeType)
|
||||
, _name(name) {}
|
||||
|
||||
SDF_API ~Sdf_MapperArgPathNode();
|
||||
|
||||
const ComparisonType& _GetComparisonValue() const { return _name; }
|
||||
|
||||
friend class Sdf_PathNode;
|
||||
friend struct Sdf_PathNodePrivateAccess;
|
||||
template <int nodeType, class Comp> friend struct Sdf_PathNodeCompare;
|
||||
|
||||
// Instance variables
|
||||
TfToken _name;
|
||||
};
|
||||
|
||||
class Sdf_ExpressionPathNode : public Sdf_PropPartPathNode {
|
||||
public:
|
||||
typedef void *ComparisonType;
|
||||
static const NodeType nodeType = Sdf_PathNode::ExpressionNode;
|
||||
|
||||
void _AppendText(std::string *str) const;
|
||||
|
||||
private:
|
||||
Sdf_ExpressionPathNode(Sdf_PathNode const *parent)
|
||||
: Sdf_PropPartPathNode(parent, nodeType) {}
|
||||
|
||||
SDF_API ~Sdf_ExpressionPathNode();
|
||||
|
||||
ComparisonType _GetComparisonValue() const { return nullptr; }
|
||||
|
||||
friend class Sdf_PathNode;
|
||||
friend struct Sdf_PathNodePrivateAccess;
|
||||
template <int nodeType, class Comp> friend struct Sdf_PathNodeCompare;
|
||||
|
||||
// Instance variables
|
||||
// <none>
|
||||
};
|
||||
|
||||
template <int nodeType>
|
||||
struct Sdf_PathNodeTypeToType {
|
||||
};
|
||||
template <> struct Sdf_PathNodeTypeToType<Sdf_PathNode::PrimNode> {
|
||||
typedef Sdf_PrimPathNode Type;
|
||||
};
|
||||
template <> struct Sdf_PathNodeTypeToType<Sdf_PathNode::PrimPropertyNode> {
|
||||
typedef Sdf_PrimPropertyPathNode Type;
|
||||
};
|
||||
template <> struct Sdf_PathNodeTypeToType<Sdf_PathNode::RelationalAttributeNode> {
|
||||
typedef Sdf_RelationalAttributePathNode Type;
|
||||
};
|
||||
template <> struct Sdf_PathNodeTypeToType<Sdf_PathNode::MapperArgNode> {
|
||||
typedef Sdf_MapperArgPathNode Type;
|
||||
};
|
||||
template <> struct Sdf_PathNodeTypeToType<Sdf_PathNode::TargetNode> {
|
||||
typedef Sdf_TargetPathNode Type;
|
||||
};
|
||||
template <> struct Sdf_PathNodeTypeToType<Sdf_PathNode::MapperNode> {
|
||||
typedef Sdf_MapperPathNode Type;
|
||||
};
|
||||
template <> struct Sdf_PathNodeTypeToType<Sdf_PathNode::PrimVariantSelectionNode> {
|
||||
typedef Sdf_PrimVariantSelectionNode Type;
|
||||
};
|
||||
template <> struct Sdf_PathNodeTypeToType<Sdf_PathNode::ExpressionNode> {
|
||||
typedef Sdf_ExpressionPathNode Type;
|
||||
};
|
||||
template <> struct Sdf_PathNodeTypeToType<Sdf_PathNode::RootNode> {
|
||||
typedef Sdf_RootPathNode Type;
|
||||
};
|
||||
|
||||
template <int nodeType, class Comp>
|
||||
struct Sdf_PathNodeCompare {
|
||||
inline bool operator()(const Sdf_PathNode &lhs,
|
||||
const Sdf_PathNode &rhs) const {
|
||||
typedef typename Sdf_PathNodeTypeToType<nodeType>::Type Type;
|
||||
return Comp()(static_cast<const Type&>(lhs)._GetComparisonValue(),
|
||||
static_cast<const Type&>(rhs)._GetComparisonValue());
|
||||
}
|
||||
};
|
||||
|
||||
template <class Comp>
|
||||
inline bool
|
||||
Sdf_PathNode::Compare(const Sdf_PathNode &rhs) const
|
||||
{
|
||||
// Compare two nodes.
|
||||
// We first compare types, then, if types match, we compare
|
||||
// based on the type-specific content.
|
||||
// Names are compared lexicographically.
|
||||
|
||||
// Compare types. If node types are different use Comp() on them, otherwise
|
||||
// continue to node-specific comparisons.
|
||||
|
||||
NodeType nodeType = GetNodeType(), rhsNodeType = rhs.GetNodeType();
|
||||
if (nodeType != rhsNodeType) {
|
||||
return Comp()(nodeType, rhsNodeType);
|
||||
}
|
||||
|
||||
// Types are the same. Avoid virtual function calls for performance.
|
||||
switch (nodeType) {
|
||||
case Sdf_PathNode::PrimNode:
|
||||
return Sdf_PathNodeCompare<Sdf_PathNode::PrimNode,
|
||||
Comp>()(*this, rhs);
|
||||
case Sdf_PathNode::PrimPropertyNode:
|
||||
return Sdf_PathNodeCompare<Sdf_PathNode::PrimPropertyNode,
|
||||
Comp>()(*this, rhs);
|
||||
case Sdf_PathNode::RelationalAttributeNode:
|
||||
return Sdf_PathNodeCompare<Sdf_PathNode::RelationalAttributeNode,
|
||||
Comp>()(*this, rhs);
|
||||
case Sdf_PathNode::MapperArgNode:
|
||||
return Sdf_PathNodeCompare<Sdf_PathNode::MapperArgNode,
|
||||
Comp>()(*this, rhs);
|
||||
case Sdf_PathNode::TargetNode:
|
||||
return Sdf_PathNodeCompare<Sdf_PathNode::TargetNode,
|
||||
Comp>()(*this, rhs);
|
||||
case Sdf_PathNode::MapperNode:
|
||||
return Sdf_PathNodeCompare<Sdf_PathNode::MapperNode,
|
||||
Comp>()(*this, rhs);
|
||||
case Sdf_PathNode::PrimVariantSelectionNode:
|
||||
return Sdf_PathNodeCompare<Sdf_PathNode::PrimVariantSelectionNode,
|
||||
Comp>()(*this, rhs);
|
||||
case Sdf_PathNode::ExpressionNode:
|
||||
return Sdf_PathNodeCompare<Sdf_PathNode::ExpressionNode,
|
||||
Comp>()(*this, rhs);
|
||||
case Sdf_PathNode::RootNode:
|
||||
return Sdf_PathNodeCompare<Sdf_PathNode::RootNode,
|
||||
Comp>()(*this, rhs);
|
||||
default:
|
||||
TF_CODING_ERROR("Unhandled Sdf_PathNode::NodeType enumerant");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline void
|
||||
Sdf_PathNode::_Destroy() const
|
||||
{
|
||||
// Note: This function deletes this object!
|
||||
switch (_nodeType) {
|
||||
case RootNode:
|
||||
return delete _Downcast<Sdf_RootPathNode>();
|
||||
case PrimNode:
|
||||
return delete _Downcast<Sdf_PrimPathNode>();
|
||||
case PrimPropertyNode:
|
||||
return delete _Downcast<Sdf_PrimPropertyPathNode>();
|
||||
case PrimVariantSelectionNode:
|
||||
return delete _Downcast<Sdf_PrimVariantSelectionNode>();
|
||||
case TargetNode:
|
||||
return delete _Downcast<Sdf_TargetPathNode>();
|
||||
case RelationalAttributeNode:
|
||||
return delete _Downcast<Sdf_RelationalAttributePathNode>();
|
||||
case MapperNode:
|
||||
return delete _Downcast<Sdf_MapperPathNode>();
|
||||
case MapperArgNode:
|
||||
return delete _Downcast<Sdf_MapperArgPathNode>();
|
||||
case ExpressionNode:
|
||||
return delete _Downcast<Sdf_ExpressionPathNode>();
|
||||
default:
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
inline const TfToken &
|
||||
Sdf_PathNode::GetName() const
|
||||
{
|
||||
switch (_nodeType) {
|
||||
default:
|
||||
return SdfPathTokens->empty;
|
||||
case RootNode:
|
||||
return IsAbsolutePath() ?
|
||||
SdfPathTokens->absoluteIndicator : SdfPathTokens->relativeRoot;
|
||||
case PrimNode:
|
||||
return _Downcast<Sdf_PrimPathNode>()->_name;
|
||||
case PrimPropertyNode:
|
||||
return _Downcast<Sdf_PrimPropertyPathNode>()->_name;
|
||||
case PrimVariantSelectionNode:
|
||||
return _Downcast<Sdf_PrimVariantSelectionNode>()->_GetNameImpl();
|
||||
case RelationalAttributeNode:
|
||||
return _Downcast<Sdf_RelationalAttributePathNode>()->_name;
|
||||
case MapperArgNode:
|
||||
return _Downcast<Sdf_MapperArgPathNode>()->_name;
|
||||
case ExpressionNode:
|
||||
return SdfPathTokens->expressionIndicator;
|
||||
}
|
||||
}
|
||||
|
||||
inline const SdfPath &
|
||||
Sdf_PathNode::GetTargetPath() const
|
||||
{
|
||||
switch (_nodeType) {
|
||||
default:
|
||||
return SdfPath::EmptyPath();
|
||||
case TargetNode:
|
||||
return _Downcast<Sdf_TargetPathNode>()->_targetPath;
|
||||
case MapperNode:
|
||||
return _Downcast<Sdf_MapperPathNode>()->_targetPath;
|
||||
};
|
||||
}
|
||||
|
||||
inline const Sdf_PathNode::VariantSelectionType &
|
||||
Sdf_PathNode::GetVariantSelection() const
|
||||
{
|
||||
if (ARCH_LIKELY(_nodeType == PrimVariantSelectionNode)) {
|
||||
return *_Downcast<Sdf_PrimVariantSelectionNode>()->_variantSelection;
|
||||
}
|
||||
return _GetEmptyVariantSelection();
|
||||
}
|
||||
|
||||
inline TfToken
|
||||
Sdf_PathNode::GetElement() const
|
||||
{
|
||||
switch (_nodeType) {
|
||||
case RootNode:
|
||||
return TfToken();
|
||||
case PrimNode:
|
||||
return _Downcast<Sdf_PrimPathNode>()->_name;
|
||||
default:
|
||||
std::string str;
|
||||
AppendText(&str);
|
||||
return TfToken(str);
|
||||
};
|
||||
}
|
||||
|
||||
/// Diagnostic output.
|
||||
SDF_API void Sdf_DumpPathStats();
|
||||
|
||||
inline void intrusive_ptr_add_ref(const PXR_NS::Sdf_PathNode* p) {
|
||||
++p->_refCount;
|
||||
}
|
||||
inline void intrusive_ptr_release(const PXR_NS::Sdf_PathNode* p) {
|
||||
if (p->_refCount.fetch_and_decrement() == 1)
|
||||
p->_Destroy();
|
||||
}
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_SDF_PATH_NODE_H
|
||||
Loaded 100 of 15675 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user