Blender V5.0
NOD_geometry_nodes_list.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include <variant>
8
11
13
14namespace blender::nodes {
15
16class List : public ImplicitSharingMixin {
17 public:
18 class ArrayData {
19 public:
20 void *data;
22 static ArrayData ForValue(const GPointer &value, int64_t size);
23 static ArrayData ForDefaultValue(const CPPType &type, int64_t size);
24 static ArrayData ForConstructed(const CPPType &type, int64_t size);
25 static ArrayData ForUninitialized(const CPPType &type, int64_t size);
26 };
27
28 class SingleData {
29 public:
30 void *value;
32 static SingleData ForValue(const GPointer &value);
33 static SingleData ForDefaultValue(const CPPType &type);
34 };
35
36 using DataVariant = std::variant<ArrayData, SingleData>;
37
38 private:
39 const CPPType &cpp_type_;
40 DataVariant data_;
41 int64_t size_ = 0;
42
43 public:
44 explicit List(const CPPType &type, DataVariant data, const int64_t size)
45 : cpp_type_(type), data_(std::move(data)), size_(size)
46 {
47 }
48
49 static ListPtr create(const CPPType &type, DataVariant data, const int64_t size)
50 {
51 return ListPtr(MEM_new<List>(__func__, type, std::move(data), size));
52 }
53
54 const DataVariant &data() const;
55 const CPPType &cpp_type() const;
56 int64_t size() const;
57
58 void delete_self() override;
59
61 GVArray varray() const;
62 template<typename T> VArray<T> varray() const;
63};
64
65inline const List::DataVariant &List::data() const
66{
67 return data_;
68}
69
70inline const CPPType &List::cpp_type() const
71{
72 return cpp_type_;
73}
74
75inline int64_t List::size() const
76{
77 return size_;
78}
79
80template<typename T> inline VArray<T> List::varray() const
81{
82 return this->varray().typed<T>();
83}
84
85} // namespace blender::nodes
long long int int64_t
static ArrayData ForDefaultValue(const CPPType &type, int64_t size)
static ArrayData ForConstructed(const CPPType &type, int64_t size)
static ArrayData ForUninitialized(const CPPType &type, int64_t size)
static ArrayData ForValue(const GPointer &value, int64_t size)
static SingleData ForValue(const GPointer &value)
static SingleData ForDefaultValue(const CPPType &type)
const DataVariant & data() const
std::variant< ArrayData, SingleData > DataVariant
List(const CPPType &type, DataVariant data, const int64_t size)
static ListPtr create(const CPPType &type, DataVariant data, const int64_t size)
const CPPType & cpp_type() const
#define T
ImplicitSharingPtr< List > ListPtr