7#ifndef PXR_EXEC_VDF_VECTOR_H
8#define PXR_EXEC_VDF_VECTOR_H
14#include "pxr/exec/vdf/api.h"
15#include "pxr/exec/vdf/boxedContainerTraits.h"
17#include "pxr/exec/vdf/vectorAccessor.h"
18#include "pxr/exec/vdf/vectorImpl_Boxed.h"
19#include "pxr/exec/vdf/vectorImpl_Compressed.h"
20#include "pxr/exec/vdf/vectorImpl_Contiguous.h"
21#include "pxr/exec/vdf/vectorImpl_Empty.h"
22#include "pxr/exec/vdf/vectorImpl_Shared.h"
23#include "pxr/exec/vdf/vectorImpl_Single.h"
28#include "pxr/base/vt/value.h"
36PXR_NAMESPACE_OPEN_SCOPE
65 rhs._data.
Get()->NewEmpty(0, &_data);
66 rhs._data.
Get()->Clone(&_data);
77 rhs._data.
Get()->NewEmpty(0, &_data);
82 rhs._data.
Get()->Clone(&_data);
84 rhs._data.
Get()->CloneSubset(mask, &_data);
101 "size mismatch: rhs.GetSize() (%zu) != mask.GetSize() (%zu)",
107 rhs._data.
Get()->NewEmpty(0, &_data);
121 rhs._data.
Get()->NewEmpty(0, &_data);
122 }
else if (size == 1){
123 rhs._data.
Get()->NewSingle(&_data);
125 rhs._data.
Get()->NewDense(size, &_data);
133 rhs._data.
Get()->NewEmpty(0, &_data);
134 rhs._data.
Get()->MoveInto(&_data);
156 return _data.
Get()->GetNumStoredElements();
161 template<
typename TYPE>
167 using T =
typename std::decay<TYPE>::type;
176 template <
typename TYPE>
188 template <
typename TYPE>
194 template <
typename TYPE>
203 template <
typename TYPE>
217 template<
typename TYPE>
243 template<
typename TYPE>
255 const size_t size = bits.
GetSize();
279 if (ARCH_UNLIKELY(_data.
Get()->GetInfo().ownership ==
280 Vdf_VectorData::Info::Ownership::Shared)) {
281 Vdf_VectorImplShared::Detach(&_data);
287 rhs._data.
Get()->Clone(&_data);
291 rhs._data.
Get()->CloneSubset(mask, &_data);
301 rhs._data.
Get()->NewEmpty(mask.
GetSize(), &_data);
330 if (!_data.
Get()->IsSharable()) {
340 tmp.
Get()->MoveInto(&_data);
352 return _data.
Get()->GetInfo().ownership ==
353 Vdf_VectorData::Info::Ownership::Shared;
360 return _data.
Get()->IsSharable();
368 template <
typename T>
373 const Vdf_VectorData::Info& info = data->GetInfo();
375 if (ARCH_UNLIKELY(info.compressedIndexMapping)) {
376 return _DecompressAsVtArray(
377 reinterpret_cast<T *
>(info.data),
378 *info.compressedIndexMapping, size, offset);
385 if (info.layout == Vdf_VectorData::Info::Layout::Boxed) {
387 access =
reinterpret_cast<BoxedVectorType *
>(info.data)->data();
389 access =
reinterpret_cast<T *
>(info.data) - info.first;
394 return info.ownership == Vdf_VectorData::Info::Ownership::Shared
395 ?
VtArray<T>(data->GetSharedSource(), access, size)
402 template <
typename TYPE >
435 const Vdf_VectorData::Info &info) :
436 _accessor(data, info)
448 template<
typename TYPE>
451 Vdf_VectorData::Info info = _data.
Get()->GetInfo();
453 if (ARCH_UNLIKELY(info.ownership ==
454 Vdf_VectorData::Info::Ownership::Shared)) {
456 Vdf_VectorImplShared::Detach(&_data);
459 info = _data.
Get()->GetInfo();
468 template <
typename TYPE>
491 const TYPE&
operator[](
size_t i)
const {
return _accessor[i]; }
501 const Vdf_VectorData::Info& info):
502 _accessor(data, info)
513 template <
typename TYPE>
524 template <
typename TYPE>
528 _data.
Get(), _data.
Get()->GetInfo());
533 template<
typename TYPE>
537 !Vdf_IsBoxedContainer<TYPE>,
538 "VdfVector::Holds cannot check for boxed-ness");
556 rhs._data.
Get()->Clone(&_data);
573 rhs._data.
Get()->MoveInto(&_data);
587 return _data.
Get()->EstimateElementMemory();
613 _data(data), _mask(mask)
652 template <
typename T>
654 const T*
const access,
664 if (
size_t dataIdx; _ComputeCompressedExtractionIndex(
665 indexMapping, size, offset, &dataIdx)) {
666 const T*
const src = access + dataIdx;
667 array.
assign(src, src+size);
678 static bool _ComputeCompressedExtractionIndex(
686 static void _PostTypeError(
687 const std::type_info &thisTypeInfo,
688 const std::type_info &otherTypeInfo);
691 const std::type_info &otherTypeInfo)
const
693 const std::type_info &thisTypeInfo = _GetTypeInfo();
695 _PostTypeError(thisTypeInfo, otherTypeInfo);
699 void _CheckType(
const VdfVector &rhs)
const
701 _CheckType(rhs._GetTypeInfo());
704 template <
typename TYPE>
705 void _CheckType()
const
707 _CheckType(
typeid(TYPE));
710 const std::type_info &_GetTypeInfo()
const
712 return _data.
Get()->GetTypeInfo();
723PXR_NAMESPACE_CLOSE_SCOPE
Low-level utilities for informing users of various internal and external diagnostic conditions.
Fast, compressed bit array which is capable of performing logical operations without first decompress...
size_t GetSize() const
Returns the size of the bit array, ie.
bool AreAllUnset() const
Returns true, if all the bits in this bit array are unset.
This simple container stores multiple values that flow through the network as a single data flow elem...
This collection of IndexBlockMappings is all the info required to take a logical index into a compres...
void New(Args &&... args)
Creates an instance.
void Destroy()
Destroys a held instance.
Base const * Get() const
Returns a Base pointer to the held instance.
bool IsBoxed() const
Returns true if this accessor is providing element-wise access into a boxed container.
bool IsEmpty() const
Returns true if vector is empty.
size_t GetNumValues() const
Returns size of the vector, ie.
Abstract base class for storing data in a VdfVector.
Implements a Vdf_VectorData storage that holds a boxed element.
Implements Vdf_VectorData storage that holds a contiguous range of elements, which may be a subrange ...
Implements a Vdf_VectorData storage that is always empty.
Implements a Vdf_VectorData storage the supports reference counted sharing of other vector implementa...
Implements a Vdf_VectorData storage that is holds a single element.
Specialized vector accessor for read access to boxed containers.
A VdfMask is placed on connections to specify the data flowing through them.
size_t GetSize() const
Returns the size of the mask.
bool IsAnySet() const
Returns true, if there is at least a single set entry.
bool IsAllOnes() const
Returns true if this mask has all entries set.
VdfMask::Bits const & GetBits() const
Get this mask's content as CtCompressedfBits.
An ostream-able object wrapping a VdfVector instance, as well as a mask indicating which elements in ...
VDF_API friend std::ostream & operator<<(std::ostream &, const DebugPrintable &)
Ostream operator.
A read-only accessor for low-level acces to the contents of the VdfVector.
bool IsBoxed() const
Returns true if this accessor is providing element-wise access into a boxed container.
bool IsEmpty() const
Returns true if the vector is empty.
const TYPE & operator[](size_t i) const
Returns a const reference to an element.
size_t GetNumValues() const
Returns the size of the vector, i.e.
ReadAccessor()=default
Default constructor.
A read/write accessor for low-level access to the contents of the VdfVector.
bool IsBoxed() const
Returns true if this accessor is providing element-wise access into a boxed container.
TYPE & operator[](size_t i) const
Returns a mutable reference to an element.
bool IsEmpty() const
Returns true of the vector is empty.
ReadWriteAccessor()=default
Default constructor.
size_t GetNumValues() const
Returns the size of the vector, i.e.
This class is used to abstract away knowledge of the cache data used for each node.
void Set(TYPE &&data)
Forwards data into the vector.
size_t GetSize() const
Returns the number of elements held in this vector.
void Set(Vdf_BoxedContainer< TYPE > &&data)
Move boxed values into the vector.
size_t EstimateElementMemory() const
Returns the number of bytes necessary to store a single element of this VdfVector.
VdfVector(const VdfVector &rhs)
Copy constructor.
bool IsShared() const
Returns true if the vector has been shared.
VdfVector(VdfVector &&rhs)
Move constructor.
void Set(const Vdf_BoxedContainer< TYPE > &data)
Copy boxed values into the vector.
bool IsSharable() const
Returns true if the vector can be shared.
VdfVector & operator=(const VdfVector &rhs)
Copies the content of rhs into this vector.
void Resize(const VdfMask::Bits &bits)
Allocates space for the elements denoted by bits.
size_t GetNumStoredElements() const
Returns the number of elements for which this vector has storage.
VtArray< T > ExtractAsVtArray(const size_t size, const int offset) const
Extracts this vector's values into a VtArray<T>.
VdfVector(const VdfVector &rhs, size_t size)
Construct a vector with the same element type as rhs and of size size.
bool Share() const
Embeds the current vector's existing implementaion into a reference counted implementaion so that the...
bool IsEmpty() const
Returns whether or not this vector is empty.
DebugPrintable GetDebugPrintable(const VdfMask &mask) const
Returns an ostream-able object, which can be used to debug print the contents of this VdfVector,...
VdfVector(const VdfVector &rhs, const VdfMask &mask)
Copy constructor with subset copying.
VdfVector & operator=(VdfVector &&rhs)
Moves the content of rhs into this vector.
ReadAccessor< TYPE > GetReadAccessor() const
GetReadAccessor() allows low level read-only access to the content of of the VdfVector via the Vdf_Ve...
void Resize(size_t size)
Allocates space for size number of elements.
void Copy(const VdfVector &rhs, const VdfMask &mask)
Copies the contents of rhs into this vector.
Vdf_VectorSubrangeAccessor< TYPE > GetSubrangeAccessor() const
Provide read-only access to the boxed subranges held by this vector.
bool Holds() const
Checks if a vector holds a specific type.
ConstructBoxedCopyTag
Copy constructor with boxing.
ReadWriteAccessor< TYPE > GetReadWriteAccessor() const
GetReadWriteAccessor() allows low level access to the content of the VdfVector via the Vdf_VectorData...
VDF_API void Merge(const VdfVector &rhs, const VdfMask::Bits &bits)
Merges the contents of rhs into this vector.
void Merge(const VdfVector &rhs, const VdfMask &mask)
Same as Merge(), but takes a VdfMask instead of a bitset.
Represents an arbitrary dimensional rectangular container class.
std::enable_if<!std::is_integral< ForwardIter >::value >::type assign(ForwardIter first, ForwardIter last)
Assign array contents.
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
Safely compare C++ RTTI type structures.
bool TfSafeTypeCompare(const std::type_info &t1, const std::type_info &t2)
Safely compare std::type_info structures.