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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 
25 #ifndef PXR_IMAGING_HD_VECTOR_SCHEMA_H
26 #define PXR_IMAGING_HD_VECTOR_SCHEMA_H
27 
28 #include "pxr/imaging/hd/api.h"
29 
31 
33 
34 // ----------------------------------------------------------------------------
35 
36 /// Base class wrapping a vector data source.
37 ///
39 {
40 public:
41  HdVectorSchema(HdVectorDataSourceHandle const &vector)
42  : _vector(vector) {}
43 
44  HD_API
45  static HdVectorDataSourceHandle
47  size_t count,
48  const HdDataSourceBaseHandle *values);
49 
50  /// Returns the vector data source that this schema is interpreting.
51  HD_API
52  HdVectorDataSourceHandle GetVector();
53  HD_API
54  bool IsDefined() const;
55 
56  /// Returns \c true if this schema is applied on top of a non-null
57  /// vector.
58  explicit operator bool() const { return IsDefined(); }
59 
60  /// Number of elements in the vector.
61  HD_API
62  size_t GetNumElements() const;
63 
65 
66 protected:
67  template<typename T>
68  typename T::Handle _GetTyped(const size_t element) const {
69  return
70  _vector
71  ? T::Cast(_vector->GetElement(element))
72  : nullptr;
73  }
74 
75  HdVectorDataSourceHandle _vector;
76 };
77 
78 /// Template class wrapping a vector data source whose children are
79 /// data source of an expected type.
80 ///
81 template<typename T>
83 {
84 public:
85  HdTypedVectorSchema(HdVectorDataSourceHandle const &vector)
86  : HdVectorSchema(vector) {}
87 
88  typename T::Handle GetElement(const size_t element) const {
89  return _GetTyped<T>(element);
90  }
91 };
92 
93 /// Template class wrapping a vector data source whose children are
94 /// container data source conforming to an expected schema.
95 ///
96 template<typename Schema>
98 {
99 public:
100  HdSchemaBasedVectorSchema(HdVectorDataSourceHandle const &vector)
101  : HdVectorSchema(vector) {}
102 
103  Schema GetElement(const size_t element) const {
104  using DataSource = typename Schema::UnderlyingDataSource;
105  return Schema(_GetTyped<DataSource>(element));
106  }
107 };
108 
110 
111 #endif
HD_API size_t GetNumElements() const
Number of elements in the vector.
Schema GetElement(const size_t element) const
Definition: vectorSchema.h:103
HdVectorSchema(HdVectorDataSourceHandle const &vector)
Definition: vectorSchema.h:41
#define HD_API
Definition: api.h:40
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:88
T::Handle _GetTyped(const size_t element) const
Definition: vectorSchema.h:68
HdVectorDataSourceHandle _vector
Definition: vectorSchema.h:75
HdSchemaBasedVectorSchema(HdVectorDataSourceHandle const &vector)
Definition: vectorSchema.h:100
static HD_API HdVectorDataSourceHandle BuildRetained(size_t count, const HdDataSourceBaseHandle *values)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
HdTypedVectorSchema(HdVectorDataSourceHandle const &vector)
Definition: vectorSchema.h:85
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
GLint GLsizei count
Definition: glcorearb.h:405
void * Handle
Definition: plugin.h:27