Lagrange
IndexedAttribute.h
1/*
2 * Copyright 2020 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/common.h>
15#include <lagrange/experimental/Attribute.h>
16#include <lagrange/utils/warning.h>
17
18namespace lagrange {
19namespace experimental {
20
22{
23public:
24 IndexedAttribute() = default;
25
26 template <typename ValueArrayDerived, typename IndexArrayDerived>
27 IndexedAttribute(ValueArrayDerived&& values, IndexArrayDerived&& indices)
28 : m_values(std::forward<ValueArrayDerived>(values))
29 , m_indices(std::forward<IndexArrayDerived>(indices))
30 {}
31
32public:
33 std::shared_ptr<const ArrayBase> get_values() const { return m_values.get(); }
34 std::shared_ptr<ArrayBase> get_values() { return m_values.get(); }
35
36 template <typename Derived>
37 decltype(auto) get_values() const
38 {
39 return m_values.template get<Derived>();
40 }
41
42 template <typename Derived>
43 decltype(auto) get_values()
44 {
45 return m_values.template get<Derived>();
46 }
47
48 template <typename Derived>
49 decltype(auto) view_values() const
50 {
51 return m_values.template view<Derived>();
52 }
53
54 template <typename Derived>
55 decltype(auto) view_values()
56 {
57 return m_values.template view<Derived>();
58 }
59
60 template <typename Derived>
61 void set_values(Derived&& values)
62 {
63 m_values.set(std::forward<Derived>(values));
64 }
65
66 std::shared_ptr<const ArrayBase> get_indices() const { return m_indices.get(); }
67
68 std::shared_ptr<ArrayBase> get_indices() { return m_indices.get(); }
69
70 template <typename Derived>
71 decltype(auto) get_indices() const
72 {
73 return m_indices.template get<Derived>();
74 }
75
76 template <typename Derived>
77 decltype(auto) get_indices()
78 {
79 return m_indices.template get<Derived>();
80 }
81
82 template <typename Derived>
83 decltype(auto) view_indices() const
84 {
85 return m_indices.template view<Derived>();
86 }
87
88 template <typename Derived>
89 decltype(auto) view_indices()
90 {
91 return m_indices.template view<Derived>();
92 }
93
94 template <typename Derived>
95 void set_indices(Derived&& indices)
96 {
97 m_indices.set(std::forward<Derived>(indices));
98 }
99
100 template <typename Archive>
101 void serialize_impl(Archive& ar)
102 {
104 enum { VALUES = 0, INDICES = 1 };
105 ar.object([&](auto& ar) {
106 ar("values", VALUES) & m_values;
107 ar("indices", INDICES) & m_indices;
108 });
109 LA_IGNORE_SHADOW_WARNING_END
110 }
111
112private:
113 Attribute m_values;
114 Attribute m_indices;
115};
116
117template <typename Archive>
118void serialize(::lagrange::experimental::IndexedAttribute& attribute, Archive& ar)
119{
120 attribute.serialize_impl(ar);
121}
122
123} // namespace experimental
124} // namespace lagrange
Definition: Attribute.h:23
Definition: IndexedAttribute.h:22
#define LA_IGNORE_SHADOW_WARNING_BEGIN
Ignore shadow warnings.
Definition: warning.h:68
Main namespace for Lagrange.
Definition: AABBIGL.h:30