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();
286 if (ARCH_UNLIKELY(_data.
Get()->GetInfo().ownership ==
287 Vdf_VectorData::Info::Ownership::Shared)) {
288 Vdf_VectorImplShared::Detach(&_data);
294 rhs._data.
Get()->Clone(&_data);
298 rhs._data.
Get()->CloneSubset(mask, &_data);
308 rhs._data.
Get()->NewEmpty(mask.
GetSize(), &_data);
337 if (!_data.
Get()->IsSharable()) {
347 tmp.
Get()->MoveInto(&_data);
359 return _data.
Get()->GetInfo().ownership ==
360 Vdf_VectorData::Info::Ownership::Shared;
367 return _data.
Get()->IsSharable();
375 template <
typename T>
380 const Vdf_VectorData::Info& info = data->GetInfo();
382 if (ARCH_UNLIKELY(info.compressedIndexMapping)) {
383 return _DecompressAsVtArray(
384 reinterpret_cast<T *
>(info.data),
385 *info.compressedIndexMapping, size, offset);
392 if (info.layout == Vdf_VectorData::Info::Layout::Boxed) {
394 access =
reinterpret_cast<BoxedVectorType *
>(info.data)->data();
396 access =
reinterpret_cast<T *
>(info.data) - info.first;
401 return info.ownership == Vdf_VectorData::Info::Ownership::Shared
402 ?
VtArray<T>(data->GetSharedSource(), access, size)
409 template <
typename TYPE >
442 const Vdf_VectorData::Info &info) :
443 _accessor(data, info)
455 template<
typename TYPE>
458 Vdf_VectorData::Info info = _data.
Get()->GetInfo();
460 if (ARCH_UNLIKELY(info.ownership ==
461 Vdf_VectorData::Info::Ownership::Shared)) {
463 Vdf_VectorImplShared::Detach(&_data);
466 info = _data.
Get()->GetInfo();
475 template <
typename TYPE>
498 const TYPE&
operator[](
size_t i)
const {
return _accessor[i]; }
508 const Vdf_VectorData::Info& info):
509 _accessor(data, info)
520 template <
typename TYPE>
531 template <
typename TYPE>
535 _data.
Get(), _data.
Get()->GetInfo());
540 template<
typename TYPE>
544 !Vdf_IsBoxedContainer<TYPE>,
545 "VdfVector::Holds cannot check for boxed-ness");
563 rhs._data.
Get()->Clone(&_data);
580 rhs._data.
Get()->MoveInto(&_data);
594 return _data.
Get()->EstimateElementMemory();
620 _data(data), _mask(mask)
659 template <
typename T>
661 const T*
const access,
671 if (
size_t dataIdx; _ComputeCompressedExtractionIndex(
672 indexMapping, size, offset, &dataIdx)) {
673 const T*
const src = access + dataIdx;
674 array.
assign(src, src+size);
685 static bool _ComputeCompressedExtractionIndex(
693 static void _PostTypeError(
694 const std::type_info &thisTypeInfo,
695 const std::type_info &otherTypeInfo);
698 const std::type_info &otherTypeInfo)
const
700 const std::type_info &thisTypeInfo = _GetTypeInfo();
702 _PostTypeError(thisTypeInfo, otherTypeInfo);
706 void _CheckType(
const VdfVector &rhs)
const
708 _CheckType(rhs._GetTypeInfo());
711 template <
typename TYPE>
712 void _CheckType()
const
714 _CheckType(
typeid(TYPE));
717 const std::type_info &_GetTypeInfo()
const
719 return _data.
Get()->GetTypeInfo();
730PXR_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.
VDF_API void Clear()
Destroys contents of this vector.
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.