HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vectorSchema.h
Go to the documentation of this file.
1 //
2 // Copyright 2022 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 
8 #ifndef PXR_IMAGING_HD_VECTOR_SCHEMA_H
9 #define PXR_IMAGING_HD_VECTOR_SCHEMA_H
10 
11 #include "pxr/imaging/hd/api.h"
12 
14 
16 
17 // ----------------------------------------------------------------------------
18 
19 /// Base class wrapping a vector data source.
20 ///
22 {
23 public:
24  HdVectorSchema(HdVectorDataSourceHandle const &vector)
25  : _vector(vector) {}
26 
27  HD_API
28  static HdVectorDataSourceHandle
30  size_t count,
31  const HdDataSourceBaseHandle *values);
32 
33  /// Returns the vector data source that this schema is interpreting.
34  HD_API
35  HdVectorDataSourceHandle GetVector();
36  HD_API
37  bool IsDefined() const;
38 
39  /// Returns \c true if this schema is applied on top of a non-null
40  /// vector.
41  explicit operator bool() const { return IsDefined(); }
42 
43  /// Number of elements in the vector.
44  HD_API
45  size_t GetNumElements() const;
46 
48 
49 protected:
50  template<typename T>
51  typename T::Handle _GetTyped(const size_t element) const {
52  return
53  _vector
54  ? T::Cast(_vector->GetElement(element))
55  : nullptr;
56  }
57 
58  HdVectorDataSourceHandle _vector;
59 };
60 
61 /// Template class wrapping a vector data source whose children are
62 /// data source of an expected type.
63 ///
64 template<typename T>
66 {
67 public:
68  HdTypedVectorSchema(HdVectorDataSourceHandle const &vector)
69  : HdVectorSchema(vector) {}
70 
71  typename T::Handle GetElement(const size_t element) const {
72  return _GetTyped<T>(element);
73  }
74 };
75 
76 /// Template class wrapping a vector data source whose children are
77 /// container data source conforming to an expected schema.
78 ///
79 template<typename Schema>
81 {
82 public:
83  HdSchemaBasedVectorSchema(HdVectorDataSourceHandle const &vector)
84  : HdVectorSchema(vector) {}
85 
86  Schema GetElement(const size_t element) const {
87  using DataSource = typename Schema::UnderlyingDataSource;
88  return Schema(_GetTyped<DataSource>(element));
89  }
90 };
91 
93 
94 #endif
HD_API size_t GetNumElements() const
Number of elements in the vector.
Schema GetElement(const size_t element) const
Definition: vectorSchema.h:86
HdVectorSchema(HdVectorDataSourceHandle const &vector)
Definition: vectorSchema.h:24
#define HD_API
Definition: api.h:23
OutGridT const XformOp bool bool
HD_API bool IsDefined() const
HD_API HdVectorDataSourceHandle GetVector()
Returns the vector data source that this schema is interpreting.
T::Handle GetElement(const size_t element) const
Definition: vectorSchema.h:71
T::Handle _GetTyped(const size_t element) const
Definition: vectorSchema.h:51
HdVectorDataSourceHandle _vector
Definition: vectorSchema.h:58
HdSchemaBasedVectorSchema(HdVectorDataSourceHandle const &vector)
Definition: vectorSchema.h:83
static HD_API HdVectorDataSourceHandle BuildRetained(size_t count, const HdDataSourceBaseHandle *values)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
HdTypedVectorSchema(HdVectorDataSourceHandle const &vector)
Definition: vectorSchema.h:68
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
GLint GLsizei count
Definition: glcorearb.h:405
void * Handle
Definition: plugin.h:27