7#ifndef PXR_USD_PCP_MAP_FUNCTION_H
8#define PXR_USD_PCP_MAP_FUNCTION_H
11#include "pxr/usd/pcp/api.h"
12#include "pxr/usd/sdf/path.h"
14#include "pxr/usd/sdf/pathExpression.h"
19PXR_NAMESPACE_OPEN_SCOPE
68 typedef std::map<SdfPath, SdfPath, SdfPath::FastLessThan>
PathMap;
69 typedef std::pair<SdfPath, SdfPath> PathPair;
70 typedef std::vector<PathPair> PathPairVector;
164 std::vector<SdfPathExpression::PathPattern>
165 *unmappedPatterns =
nullptr,
166 std::vector<SdfPathExpression::ExpressionReference>
167 *unmappedRefs =
nullptr
187 std::vector<SdfPathExpression::PathPattern>
188 *unmappedPatterns =
nullptr,
189 std::vector<SdfPathExpression::ExpressionReference>
190 *unmappedRefs =
nullptr
231 PathPair
const *sourceToTargetEnd,
233 bool hasRootIdentity);
237 _MapPathExpressionImpl(
240 std::vector<SdfPathExpression::PathPattern> *unmappedPatterns,
241 std::vector<SdfPathExpression::ExpressionReference> *unmappedRefs
247 static const int _MaxLocalPairs = 2;
251 _Data(PathPair
const *begin, PathPair
const *end,
bool hasRootIdentity)
252 : numPairs(end-begin)
253 , hasRootIdentity(hasRootIdentity) {
256 if (numPairs <= _MaxLocalPairs) {
257 std::uninitialized_copy(begin, end, localPairs);
260 new (&remotePairs) std::shared_ptr<PathPair>(
261 new PathPair[numPairs], std::default_delete<PathPair[]>());
262 std::copy(begin, end, remotePairs.get());
266 _Data(_Data
const &other)
267 : numPairs(other.numPairs)
268 , hasRootIdentity(other.hasRootIdentity) {
269 if (numPairs <= _MaxLocalPairs) {
270 std::uninitialized_copy(
272 other.localPairs + other.numPairs, localPairs);
275 new (&remotePairs) std::shared_ptr<PathPair>(other.remotePairs);
279 : numPairs(other.numPairs)
280 , hasRootIdentity(other.hasRootIdentity) {
281 if (numPairs <= _MaxLocalPairs) {
282 PathPair *dst = localPairs;
283 PathPair *src = other.localPairs;
284 PathPair *srcEnd = other.localPairs + other.numPairs;
285 for (; src != srcEnd; ++src, ++dst) {
286 ::new (
static_cast<void*
>(std::addressof(*dst)))
287 PathPair(std::move(*src));
292 std::shared_ptr<PathPair>(std::move(other.remotePairs));
295 _Data &operator=(_Data
const &other) {
296 if (
this != &other) {
298 new (
this) _Data(other);
302 _Data &operator=(_Data &&other) {
303 if (
this != &other) {
305 new (
this) _Data(std::move(other));
310 if (numPairs <= _MaxLocalPairs) {
311 for (PathPair *p = localPairs; numPairs--; ++p) {
316 remotePairs.~shared_ptr<PathPair>();
320 bool IsNull()
const {
321 return numPairs == 0 && !hasRootIdentity;
324 PathPair
const *begin()
const {
325 return numPairs <= _MaxLocalPairs ? localPairs : remotePairs.get();
328 PathPair
const *end()
const {
329 return begin() + numPairs;
332 bool operator==(_Data
const &other)
const {
333 return numPairs == other.numPairs &&
334 hasRootIdentity == other.hasRootIdentity &&
335 std::equal(begin(), end(), other.begin());
338 bool operator!=(_Data
const &other)
const {
339 return !(*
this == other);
342 template <
class HashState>
343 friend void TfHashAppend(HashState &h, _Data
const &data){
344 h.Append(data.hasRootIdentity);
345 h.Append(data.numPairs);
346 h.AppendRange(std::begin(data), std::end(data));
350 PathPair localPairs[_MaxLocalPairs > 0 ? _MaxLocalPairs : 1];
351 std::shared_ptr<PathPair> remotePairs;
353 typedef int PairCount;
354 PairCount numPairs = 0;
355 bool hasRootIdentity =
false;
359 template <
typename HashState>
377PXR_NAMESPACE_CLOSE_SCOPE
A function that maps values from one namespace (and time domain) to another.
static PCP_API PcpMapFunction Create(const PathMap &sourceToTargetMap, const SdfLayerOffset &offset)
Constructs a map function with the given arguments.
PCP_API void Swap(PcpMapFunction &map)
Swap the contents of this map function with map.
PCP_API SdfPathExpression MapTargetToSource(const SdfPathExpression &pathExpr, std::vector< SdfPathExpression::PathPattern > *unmappedPatterns=nullptr, std::vector< SdfPathExpression::ExpressionReference > *unmappedRefs=nullptr) const
Map all path pattern prefix paths and expression reference paths in the target namespace to the sourc...
PCP_API SdfPath MapSourceToTarget(const SdfPath &path) const
Map a path in the source namespace to the target.
bool HasRootIdentity() const
Return true if the map function maps the absolute root path to the absolute root path,...
static PCP_API PcpMapFunction ImpliedClass(const PcpMapFunction &transferFunc, const PcpMapFunction &classArc)
Constructs a map function that is equivalent to.
PCP_API bool IsIdentity() const
Return true if the map function is the identity function.
PCP_API size_t Hash() const
Return a size_t hash for this map function.
PCP_API SdfPathExpression MapSourceToTarget(const SdfPathExpression &pathExpr, std::vector< SdfPathExpression::PathPattern > *unmappedPatterns=nullptr, std::vector< SdfPathExpression::ExpressionReference > *unmappedRefs=nullptr) const
Map all path pattern prefix paths and expression reference paths in the source namespace to the targe...
PCP_API std::string GetString() const
Returns a string representation of this mapping for debugging purposes.
static PCP_API const PathMap & IdentityPathMap()
Returns an identity path mapping.
PcpMapFunction()=default
Construct a null function.
PCP_API SdfPath MapTargetToSource(const SdfPath &path) const
Map a path in the target namespace to the source.
PCP_API bool operator!=(const PcpMapFunction &map) const
Inequality.
const SdfLayerOffset & GetTimeOffset() const
The time offset of the mapping.
std::map< SdfPath, SdfPath, SdfPath::FastLessThan > PathMap
A mapping from path to path.
static PCP_API const PcpMapFunction & Identity()
Construct an identity map function.
PCP_API PcpMapFunction ComposeOffset(const SdfLayerOffset &newOffset) const
Compose this map function over a hypothetical map function that has an identity path mapping and offs...
PCP_API PcpMapFunction GetInverse() const
Return the inverse of this map function.
PCP_API PcpMapFunction Compose(const PcpMapFunction &f) const
Compose this map over the given map function.
PCP_API bool IsIdentityPathMapping() const
Return true if the map function uses the identity path mapping.
PCP_API bool operator==(const PcpMapFunction &map) const
Equality.
PCP_API bool IsNull() const
Return true if this map function is the null function.
PCP_API PathMap GetSourceToTargetMap() const
The set of path mappings, from source to target.
Represents a time offset and scale between layers.
Objects of this class represent a logical expression syntax tree consisting of SdfPathPattern s,...
A path value used to locate objects in layers or scenegraphs.
A user-extensible hashing mechanism for use with runtime hash tables.
std::size_t hash_value(const half h)
Overload hash_value for half.