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
68 rhs._data.
Get()->NewEmpty(0, &_data);
69 rhs._data.
Get()->Clone(&_data);
80 rhs._data.
Get()->NewEmpty(0, &_data);
85 rhs._data.
Get()->Clone(&_data);
87 rhs._data.
Get()->CloneSubset(mask, &_data);
104 "size mismatch: rhs.GetSize() (%zu) != mask.GetSize() (%zu)",
110 rhs._data.
Get()->NewEmpty(0, &_data);
124 rhs._data.
Get()->NewEmpty(0, &_data);
125 }
else if (size == 1){
126 rhs._data.
Get()->NewSingle(&_data);
128 rhs._data.
Get()->NewDense(size, &_data);
136 rhs._data.
Get()->NewEmpty(0, &_data);
137 rhs._data.
Get()->MoveInto(&_data);
159 return _data.
Get()->GetNumStoredElements();
164 template<
typename TYPE>
170 using T =
typename std::decay<TYPE>::type;
179 template <
typename TYPE>
191 template <
typename TYPE>
197 template <
typename TYPE>
206 template <
typename TYPE>
220 template<
typename TYPE>
246 template<
typename TYPE>
258 const size_t size = bits.
GetSize();
289 if (ARCH_UNLIKELY(_data.
Get()->GetInfo().ownership ==
290 Vdf_VectorData::Info::Ownership::Shared)) {
291 Vdf_VectorImplShared::Detach(&_data);
297 rhs._data.
Get()->Clone(&_data);
301 rhs._data.
Get()->CloneSubset(mask, &_data);
311 rhs._data.
Get()->NewEmpty(mask.
GetSize(), &_data);
340 if (!_data.
Get()->IsSharable()) {
350 tmp.
Get()->MoveInto(&_data);
362 return _data.
Get()->GetInfo().ownership ==
363 Vdf_VectorData::Info::Ownership::Shared;
370 return _data.
Get()->IsSharable();
378 template <
typename T>
383 const Vdf_VectorData::Info& info = data->GetInfo();
385 if (ARCH_UNLIKELY(info.compressedIndexMapping)) {
386 return _DecompressAsVtArray(
387 reinterpret_cast<T *
>(info.data),
388 *info.compressedIndexMapping, size, offset);
395 if (info.layout == Vdf_VectorData::Info::Layout::Boxed) {
397 access =
reinterpret_cast<BoxedVectorType *
>(info.data)->data();
399 access =
reinterpret_cast<T *
>(info.data) - info.first;
404 return info.ownership == Vdf_VectorData::Info::Ownership::Shared
405 ?
VtArray<T>(data->GetSharedSource(), access, size)
412 template <
typename TYPE >
445 const Vdf_VectorData::Info &info) :
446 _accessor(data, info)
458 template<
typename TYPE>
461 Vdf_VectorData::Info info = _data.
Get()->GetInfo();
463 if (ARCH_UNLIKELY(info.ownership ==
464 Vdf_VectorData::Info::Ownership::Shared)) {
466 Vdf_VectorImplShared::Detach(&_data);
469 info = _data.
Get()->GetInfo();
478 template <
typename TYPE>
501 const TYPE&
operator[](
size_t i)
const {
return _accessor[i]; }
511 const Vdf_VectorData::Info& info):
512 _accessor(data, info)
523 template <
typename TYPE>
534 template <
typename TYPE>
538 _data.
Get(), _data.
Get()->GetInfo());
542 template <
typename TYPE>
547 template<
typename TYPE>
551 !Vdf_IsBoxedContainer<TYPE>,
552 "VdfVector::Holds cannot check for boxed-ness");
570 rhs._data.
Get()->Clone(&_data);
587 rhs._data.
Get()->MoveInto(&_data);
601 return _data.
Get()->EstimateElementMemory();
627 _data(data), _mask(mask)
666 template <
typename T>
668 const T*
const access,
678 if (
size_t dataIdx; _ComputeCompressedExtractionIndex(
679 indexMapping, size, offset, &dataIdx)) {
680 const T*
const src = access + dataIdx;
681 array.assign(src, src+size);
692 static bool _ComputeCompressedExtractionIndex(
700 static void _PostTypeError(
701 const std::type_info &thisTypeInfo,
702 const std::type_info &otherTypeInfo);
705 const std::type_info &otherTypeInfo)
const
707 const std::type_info &thisTypeInfo = _GetTypeInfo();
709 _PostTypeError(thisTypeInfo, otherTypeInfo);
713 void _CheckType(
const VdfVector &rhs)
const
715 _CheckType(rhs._GetTypeInfo());
718 template <
typename TYPE>
719 void _CheckType()
const
721 _CheckType(
typeid(TYPE));
724 const std::type_info &_GetTypeInfo()
const
726 return _data.
Get()->GetTypeInfo();
737template <
typename TYPE>
741 const std::type_info &haveType = _GetTypeInfo();
743 "Invalid type. Vector is holding %s, tried to use as %s",
752PXR_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...
VdfVectorIterator< TYPE > GetIterator() const
Returns a read-only iterator over values held by this vector.
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.
A read-only iterator over values held by a VdfVector.
Represents an arbitrary dimensional rectangular container class.
std::string ArchGetDemangled()
Return demangled RTTI generated-type name.
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
Safely compare C++ RTTI type structures.
bool TfSafeTypeCompare(const std::type_info &t1, const std::type_info &t2)
Safely compare std::type_info structures.