All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
vectorSchema.h
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
13#include "pxr/imaging/hd/dataSource.h"
14
15PXR_NAMESPACE_OPEN_SCOPE
16
17// ----------------------------------------------------------------------------
18
22{
23public:
24 HdVectorSchema(HdVectorDataSourceHandle const &vector)
25 : _vector(vector) {}
26
27 HD_API
28 static HdVectorDataSourceHandle
29 BuildRetained(
30 size_t count,
31 const HdDataSourceBaseHandle *values);
32
34 HD_API
35 HdVectorDataSourceHandle GetVector();
36 HD_API
37 bool IsDefined() const;
38
41 explicit operator bool() const { return IsDefined(); }
42
44 HD_API
45 size_t GetNumElements() const;
46
48
49protected:
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
64template<typename T>
66{
67public:
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
79template<typename Schema>
81{
82public:
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
92PXR_NAMESPACE_CLOSE_SCOPE
93
94#endif
Template class wrapping a vector data source whose children are container data source conforming to a...
Definition: vectorSchema.h:81
Template class wrapping a vector data source whose children are data source of an expected type.
Definition: vectorSchema.h:66
A datasource representing indexed data.
Definition: dataSource.h:131
Base class wrapping a vector data source.
Definition: vectorSchema.h:22
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.