Loading...
Searching...
No Matches
vectorDataTyped.h
1//
2// Copyright 2025 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_EXEC_VDF_VECTOR_DATA_TYPED_H
8#define PXR_EXEC_VDF_VECTOR_DATA_TYPED_H
9
10#include "pxr/pxr.h"
11
12#include "pxr/exec/vdf/api.h"
13#include "pxr/exec/vdf/forEachCommonType.h"
14#include "pxr/exec/vdf/vectorData.h"
15
16PXR_NAMESPACE_OPEN_SCOPE
17
18template<typename TYPE> class Vdf_VectorImplEmpty;
19template<typename TYPE> class Vdf_VectorImplSingle;
20template<typename TYPE> class Vdf_VectorImplContiguous;
21template<typename TYPE> class Vdf_VectorImplBoxed;
22
23// Vdf_VectorDataTypedBase is used as templated base class for
24// Vdf_VectorDataTyped implementing methods that are the same for
25// all types.
26//
27template<typename TYPE>
28class VDF_API_TYPE Vdf_VectorDataTyped : public Vdf_VectorData
29{
30public:
31 const std::type_info &GetTypeInfo() const override final
32 {
33 return typeid(TYPE);
34 }
35
36 void NewEmpty(size_t size, DataHolder *destData) const override final
37 {
38 destData->New< Vdf_VectorImplEmpty<TYPE> >(size);
39 }
40
41 void NewSingle(DataHolder *destData) const override final
42 {
43 destData->New< Vdf_VectorImplSingle<TYPE> >();
44 }
45
46 void NewSparse(
47 size_t size, size_t first, size_t last,
48 DataHolder *destData) const override final
49 {
50 destData->New< Vdf_VectorImplContiguous<TYPE> >(size, first, last);
51 }
52
53 void NewDense(size_t size, DataHolder *destData) const override final
54 {
55 destData->New< Vdf_VectorImplContiguous<TYPE> >(size);
56 }
57
58 size_t EstimateElementMemory() const override
59 {
60 // We estimate the size of the element based on the type only. Note
61 // that this is an approximation, as individual instances of TYPE may
62 // heap allocate memory.
63 return sizeof(TYPE);
64 }
65};
66
67#if !defined(ARCH_OS_WINDOWS)
68#define VDF_DECLARE_EXTERN_VECTOR_DATA_TYPED(type) \
69 extern template class VDF_API_TYPE Vdf_VectorDataTyped<type>;
70VDF_FOR_EACH_COMMON_TYPE(VDF_DECLARE_EXTERN_VECTOR_DATA_TYPED)
71#undef VDF_DECLARE_EXTERN_VECTOR_DATA_TYPED
72#endif // !defined(ARCH_OS_WINDOWS)
73
74PXR_NAMESPACE_CLOSE_SCOPE
75
76#endif
Abstract base class for storing data in a VdfVector.
Definition: vectorData.h:27
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 that is holds a single element.