Loading...
Searching...
No Matches
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
32PXR_NAMESPACE_OPEN_SCOPE
33
34// ----------------------------------------------------------------------------
35
39{
40public:
41 HdVectorSchema(HdVectorDataSourceHandle const &vector)
42 : _vector(vector) {}
43
44 HD_API
45 static HdVectorDataSourceHandle
46 BuildRetained(
47 size_t count,
48 const HdDataSourceBaseHandle *values);
49
51 HD_API
52 HdVectorDataSourceHandle GetVector();
53 HD_API
54 bool IsDefined() const;
55
58 explicit operator bool() const { return IsDefined(); }
59
61 HD_API
62 size_t GetNumElements() const;
63
65
66protected:
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
81template<typename T>
83{
84public:
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
96template<typename Schema>
98{
99public:
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
109PXR_NAMESPACE_CLOSE_SCOPE
110
111#endif
Template class wrapping a vector data source whose children are container data source conforming to a...
Definition: vectorSchema.h:98
Template class wrapping a vector data source whose children are data source of an expected type.
Definition: vectorSchema.h:83
A datasource representing indexed data.
Definition: dataSource.h:148
Base class wrapping a vector data source.
Definition: vectorSchema.h:39
HD_API size_t GetNumElements() const
Number of elements in the vector.
HD_API HdVectorDataSourceHandle GetVector()
Returns the vector data source that this schema is interpreting.