HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vectorSubrangeAccessor.h
Go to the documentation of this file.
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_SUBRANGE_ACCESSOR_H
8 #define PXR_EXEC_VDF_VECTOR_SUBRANGE_ACCESSOR_H
9 
10 #include "pxr/pxr.h"
11 
12 #include "pxr/exec/vdf/api.h"
15 
17 
19 
20 template <typename T> class VdfIteratorRange;
21 template <typename T> class VdfReadIterator;
22 template <typename T> class VdfSubrangeView;
23 
24 // Post a TF_FATAL_ERROR on behalf of Vdf_VectorSubrangeAccessor when a
25 // type-mismatch is detected.
26 [[noreturn]]
27 VDF_API
28 void
30  const std::type_info &haveType,
31  const std::type_info &wantType);
32 
33 /// Specialized vector accessor for read access to boxed containers.
34 ///
35 /// Subrange accessors may be freely constructed for both boxed and non-boxed
36 /// vectors but clients must only call GetBoxedRanges() if the vector contains
37 /// boxed values.
38 ///
39 /// Only VdfSubrangeView has access to the methods of this type.
40 ///
41 template <typename T>
43 {
44 public:
45  /// Constructor.
46  ///
49  const Vdf_VectorData::Info &info)
50  : _boxedRanges(nullptr)
51  {
52  const std::type_info &haveType = data->GetTypeInfo();
53  const std::type_info &wantType = typeid(T);
54  if (ARCH_UNLIKELY(!TfSafeTypeCompare(haveType, wantType))) {
55  Vdf_VectorSubrangeAccessorPostFatalError(haveType, wantType);
56  }
57 
59  const Vdf_BoxedContainer<T> *boxedContainer =
60  static_cast<const Vdf_BoxedContainer<T>*>(info.data);
61  _boxedRanges = &boxedContainer->GetRanges();
62  }
63  }
64 
65 private:
67 
68  /// Returns true if the vector is holding boxed values.
69  ///
70  bool IsBoxed() const {
71  return _boxedRanges;
72  }
73 
74  /// Returns a reference to the boxed container ranges.
75  ///
76  /// Clients must ensure that IsBoxed() returns true before calling this
77  /// method.
78  ///
79  const Vdf_BoxedRanges &GetBoxedRanges() const {
80  return *_boxedRanges;
81  }
82 
83 private:
84  const Vdf_BoxedRanges *_boxedRanges;
85 };
86 
88 
89 #endif
const Vdf_BoxedRanges & GetRanges() const
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
#define VDF_API
Definition: api.h:25
Abstract base class for storing data in a VdfVector.
Definition: vectorData.h:26
#define ARCH_UNLIKELY(x)
Definition: hints.h:30
virtual const std::type_info & GetTypeInfo() const =0
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Vdf_VectorSubrangeAccessor(Vdf_VectorData *data, const Vdf_VectorData::Info &info)
PXR_NAMESPACE_OPEN_SCOPE bool TfSafeTypeCompare(const std::type_info &t1, const std::type_info &t2)
VDF_API void Vdf_VectorSubrangeAccessorPostFatalError(const std::type_info &haveType, const std::type_info &wantType)
Definition: format.h:1821