vectorSchema.h
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 
30 #include "pxr/imaging/hd/dataSource.h"
31 
32 PXR_NAMESPACE_OPEN_SCOPE
33 
34 // ----------------------------------------------------------------------------
35 
40 {
41 public:
42  HdVectorSchema(HdVectorDataSourceHandle const &vector)
43  : _vector(vector) {}
44 
45  HD_API
46  static HdVectorDataSourceHandle
47  BuildRetained(
48  size_t count,
49  HdDataSourceBaseHandle *values);
50 
52  HD_API
53  HdVectorDataSourceHandle GetVector();
54  HD_API
55  bool IsDefined() const;
56 
59  explicit operator bool() const { return IsDefined(); }
60 
62  HD_API
63  size_t GetNumElements() const;
64 
65 protected:
66  HdVectorDataSourceHandle _vector;
67 };
68 
72 template<typename T>
74 {
75 public:
77  using DataSourceHandle = typename DataSource::Handle;
78 
79  HdTypedVectorSchema(HdVectorDataSourceHandle const &vector)
80  : HdVectorSchema(vector) {}
81 
82  DataSourceHandle GetElement(const size_t element) const {
83  return
84  _vector
85  ? DataSource::Cast(_vector->GetElement(element))
86  : nullptr;
87  }
88 };
89 
94 template<typename Schema>
96 {
97 public:
98  HdSchemaBasedVectorSchema(HdVectorDataSourceHandle const &vector)
99  : HdVectorSchema(vector) {}
100 
101  Schema GetElement(const size_t element) const {
102  return Schema(
103  _vector
104  ? HdContainerDataSource::Cast(_vector->GetElement(element))
105  : nullptr);
106  }
107 };
108 
109 PXR_NAMESPACE_CLOSE_SCOPE
110 
111 #endif
HD_API HdVectorDataSourceHandle GetVector()
Returns the vector data source that this schema is interpreting.
A datasource representing a concretely-typed sampled value.
Definition: dataSource.h:204
Vector schema classes represent a view of a vector data source which is returning untyped data source...
Definition: vectorSchema.h:39
HD_API size_t GetNumElements() const
Number of elements in the vector.
Base class for vector schema classes that represent a view of a vector data source containing data so...
Definition: vectorSchema.h:73
Base class for vector schema classes that represent a view of a vector data source containing contain...
Definition: vectorSchema.h:95