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;
191 PathPair
const *sourceToTargetEnd,
193 bool hasRootIdentity);
198 static const int _MaxLocalPairs = 2;
202 _Data(PathPair
const *begin, PathPair
const *end,
bool hasRootIdentity)
203 : numPairs(end-begin)
204 , hasRootIdentity(hasRootIdentity) {
207 if (numPairs <= _MaxLocalPairs) {
208 std::uninitialized_copy(begin, end, localPairs);
211 new (&remotePairs) std::shared_ptr<PathPair>(
212 new PathPair[numPairs], std::default_delete<PathPair[]>());
213 std::copy(begin, end, remotePairs.get());
217 _Data(_Data
const &other)
218 : numPairs(other.numPairs)
219 , hasRootIdentity(other.hasRootIdentity) {
220 if (numPairs <= _MaxLocalPairs) {
221 std::uninitialized_copy(
223 other.localPairs + other.numPairs, localPairs);
226 new (&remotePairs) std::shared_ptr<PathPair>(other.remotePairs);
230 : numPairs(other.numPairs)
231 , hasRootIdentity(other.hasRootIdentity) {
232 if (numPairs <= _MaxLocalPairs) {
233 PathPair *dst = localPairs;
234 PathPair *src = other.localPairs;
235 PathPair *srcEnd = other.localPairs + other.numPairs;
236 for (; src != srcEnd; ++src, ++dst) {
237 ::new (static_cast<void*>(std::addressof(*dst)))
238 PathPair(std::move(*src));
243 std::shared_ptr<PathPair>(std::move(other.remotePairs));
246 _Data &operator=(_Data
const &other) {
247 if (
this != &other) {
249 new (
this) _Data(other);
253 _Data &operator=(_Data &&other) {
254 if (
this != &other) {
256 new (
this) _Data(std::move(other));
261 if (numPairs <= _MaxLocalPairs) {
262 for (PathPair *p = localPairs; numPairs--; ++p) {
267 remotePairs.~shared_ptr<PathPair>();
272 return numPairs == 0 && !hasRootIdentity;
275 PathPair
const *begin()
const {
276 return numPairs <= _MaxLocalPairs ? localPairs : remotePairs.get();
279 PathPair
const *end()
const {
280 return begin() + numPairs;
284 return numPairs == other.numPairs &&
285 hasRootIdentity == other.hasRootIdentity &&
286 std::equal(begin(), end(), other.begin());
290 return !(*
this == other);
294 PathPair localPairs[_MaxLocalPairs > 0 ? _MaxLocalPairs : 1];
295 std::shared_ptr<PathPair> remotePairs;
297 typedef int PairCount;
298 PairCount numPairs = 0;
299 bool hasRootIdentity =
false;
313 PXR_NAMESPACE_CLOSE_SCOPE
315 #endif // PXR_USD_PCP_MAP_FUNCTION_H PCP_API bool operator!=(const PcpMapFunction &map) const
Inequality.
const SdfLayerOffset & GetTimeOffset() const
The time offset of the mapping.
PCP_API PathMap GetSourceToTargetMap() const
The set of path mappings, from source to target.
PCP_API bool IsIdentityPathMapping() const
Return true if the map function uses the identity path mapping.
PCP_API bool IsNull() const
Return true if this map function is the null function.
PcpMapFunction()=default
Construct a null function.
PCP_API bool IsIdentity() const
Return true if the map function is the identity function.
bool HasRootIdentity() const
Return true if the map function maps the absolute root path to the absolute root path,...
PCP_API PcpMapFunction Compose(const PcpMapFunction &f) const
Compose this map over the given map function.
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.
A function that maps values from one namespace (and time domain) to another.
A path value used to locate objects in layers or scenegraphs.
PCP_API PcpMapFunction GetInverse() const
Return the inverse of this map function.
std::map< SdfPath, SdfPath, SdfPath::FastLessThan > PathMap
A mapping from path to path.
PCP_API void Swap(PcpMapFunction &map)
Swap the contents of this map function with map.
PCP_API SdfPath MapTargetToSource(const SdfPath &path) const
Map a path in the target namespace to the source.
std::enable_if< std::is_same< Half, half >::value, size_t >::type hash_value(const Half &h)
Overload hash_value for half.
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 bool operator==(const PcpMapFunction &map) const
Equality.
static PCP_API const PcpMapFunction & Identity()
Construct an identity map function.
PCP_API SdfPath MapSourceToTarget(const SdfPath &path) const
Map a path in the source namespace to the target.
Represents a time offset and scale between layers.
PCP_API size_t Hash() const
Return a size_t hash for this map function.
static PCP_API PcpMapFunction Create(const PathMap &sourceToTargetMap, const SdfLayerOffset &offset)
Constructs a map function with the given arguments.