24 #ifndef PXR_USD_PCP_MAP_FUNCTION_H
25 #define PXR_USD_PCP_MAP_FUNCTION_H
28 #include "pxr/usd/pcp/api.h"
29 #include "pxr/usd/sdf/path.h"
35 PXR_NAMESPACE_OPEN_SCOPE
84 typedef std::map<SdfPath, SdfPath, SdfPath::FastLessThan>
PathMap;
85 typedef std::pair<SdfPath, SdfPath> PathPair;
86 typedef std::vector<PathPair> PathPairVector;
185 PathPair
const *sourceToTargetEnd,
187 bool hasRootIdentity);
192 static const int _MaxLocalPairs = 2;
196 _Data(PathPair
const *begin, PathPair
const *end,
bool hasRootIdentity)
197 : numPairs(end-begin)
198 , hasRootIdentity(hasRootIdentity) {
201 if (numPairs <= _MaxLocalPairs) {
202 std::uninitialized_copy(begin, end, localPairs);
205 new (&remotePairs) std::shared_ptr<PathPair>(
206 new PathPair[numPairs], std::default_delete<PathPair[]>());
207 std::copy(begin, end, remotePairs.get());
211 _Data(_Data
const &other)
212 : numPairs(other.numPairs)
213 , hasRootIdentity(other.hasRootIdentity) {
214 if (numPairs <= _MaxLocalPairs) {
215 std::uninitialized_copy(
217 other.localPairs + other.numPairs, localPairs);
220 new (&remotePairs) std::shared_ptr<PathPair>(other.remotePairs);
224 : numPairs(other.numPairs)
225 , hasRootIdentity(other.hasRootIdentity) {
226 if (numPairs <= _MaxLocalPairs) {
227 PathPair *dst = localPairs;
228 PathPair *src = other.localPairs;
229 PathPair *srcEnd = other.localPairs + other.numPairs;
230 for (; src != srcEnd; ++src, ++dst) {
231 ::new (static_cast<void*>(std::addressof(*dst)))
232 PathPair(std::move(*src));
237 std::shared_ptr<PathPair>(std::move(other.remotePairs));
240 _Data &operator=(_Data
const &other) {
241 if (
this != &other) {
243 new (
this) _Data(other);
247 _Data &operator=(_Data &&other) {
248 if (
this != &other) {
250 new (
this) _Data(std::move(other));
255 if (numPairs <= _MaxLocalPairs) {
256 for (PathPair *p = localPairs; numPairs--; ++p) {
261 remotePairs.~shared_ptr<PathPair>();
266 return numPairs == 0 && !hasRootIdentity;
269 PathPair
const *begin()
const {
270 return numPairs <= _MaxLocalPairs ? localPairs : remotePairs.get();
273 PathPair
const *end()
const {
274 return begin() + numPairs;
278 return numPairs == other.numPairs &&
279 hasRootIdentity == other.hasRootIdentity &&
280 std::equal(begin(), end(), other.begin());
284 return !(*
this == other);
288 PathPair localPairs[_MaxLocalPairs > 0 ? _MaxLocalPairs : 1];
289 std::shared_ptr<PathPair> remotePairs;
291 typedef int PairCount;
292 PairCount numPairs = 0;
293 bool hasRootIdentity =
false;
307 PXR_NAMESPACE_CLOSE_SCOPE
309 #endif // PXR_USD_PCP_MAP_FUNCTION_H
const SdfLayerOffset & GetTimeOffset() const
The time offset of the mapping.
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...
PcpMapFunction()=default
Construct a null function.
PCP_API PathMap GetSourceToTargetMap() const
The set of path mappings, from source to target.
PCP_API bool operator==(const PcpMapFunction &map) const
Equality.
PCP_API SdfPath MapTargetToSource(const SdfPath &path) const
Map a path in the target namespace to the source.
static PCP_API const PathMap & IdentityPathMap()
Returns an identity path mapping.
PCP_API bool operator!=(const PcpMapFunction &map) const
Inequality.
A function that maps values from one namespace (and time domain) to another.
bool HasRootIdentity() const
Return true if the map function maps the absolute root path to the absolute root path, false otherwise.
A path value used to locate objects in layers or scenegraphs.
std::map< SdfPath, SdfPath, SdfPath::FastLessThan > PathMap
A mapping from path to path.
PCP_API size_t Hash() const
Return a size_t hash for this map function.
PCP_API PcpMapFunction Compose(const PcpMapFunction &f) const
Compose this map over the given map function.
PCP_API void Swap(PcpMapFunction &map)
Swap the contents of this map function with map.
PCP_API PcpMapFunction GetInverse() const
Return the inverse of this map function.
PCP_API SdfPath MapSourceToTarget(const SdfPath &path) const
Map a path in the source namespace to the target.
PCP_API bool IsIdentity() const
Return true if the map function is the identity function.
static PCP_API const PcpMapFunction & Identity()
Construct an identity map function.
PCP_API bool IsNull() const
Return true if this map function is the null function.
Represents a time offset and scale between layers.
PCP_API std::string GetString() const
Returns a string representation of this mapping for debugging purposes.
static PCP_API PcpMapFunction Create(const PathMap &sourceToTargetMap, const SdfLayerOffset &offset)
Constructs a map function with the given arguments.