Blender V4.3
BLI_listbase_wrapper.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
16#include "BLI_listbase.h"
17#include "BLI_vector.hh"
18
19#include "DNA_listBase.h"
20
21namespace blender {
22
23template<typename LB, typename T> class ListBaseWrapperTemplate {
24 private:
25 LB *listbase_;
26
27 public:
28 ListBaseWrapperTemplate(LB *listbase) : listbase_(listbase)
29 {
30 BLI_assert(listbase);
31 }
32
34
35 class Iterator {
36 private:
37 LB *listbase_;
38 T *current_;
39
40 public:
41 Iterator(LB *listbase, T *current) : listbase_(listbase), current_(current) {}
42
44 {
45 /* Some types store `next/prev` using `void *`, so cast is necessary. */
46 current_ = static_cast<T *>(current_->next);
47 return *this;
48 }
49
51 {
52 Iterator iterator = *this;
53 ++(*this);
54 return iterator;
55 }
56
57 bool operator!=(const Iterator &iterator) const
58 {
59 return current_ != iterator.current_;
60 }
61
62 T *operator*() const
63 {
64 return current_;
65 }
66 };
67
69 {
70 return Iterator(listbase_, static_cast<T *>(listbase_->first));
71 }
72
73 Iterator end() const
74 {
75 return Iterator(listbase_, nullptr);
76 }
77
78 T *get(uint index) const
79 {
80 void *ptr = BLI_findlink(listbase_, index);
82 return static_cast<T *>(ptr);
83 }
84
85 int64_t index_of(const T *value) const
86 {
87 int64_t index = 0;
88 for (T *ptr : *this) {
89 if (ptr == value) {
90 return index;
91 }
92 index++;
93 }
94 BLI_assert(false);
95 return -1;
96 }
97};
98
101
105template<typename T> Vector<T *> listbase_to_vector(ListBase &list)
106{
108
109 for (T *item : ListBaseWrapper<T>(list)) {
110 vector.append(item);
111 }
112 return vector;
113}
114
118template<typename T> Vector<T *> listbase_to_vector(const ListBase &list)
119{
121
122 for (T *item : ConstListBaseWrapper<T>(list)) {
123 vector.append(item);
124 }
125 return vector;
126}
127
128} /* namespace blender */
#define BLI_assert(a)
Definition BLI_assert.h:50
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
unsigned int uint
These structs are the foundation for all linked lists in the library system.
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a vector
bool operator!=(const Iterator &iterator) const
int64_t index_of(const T *value) const
#define LB
ListBaseWrapperTemplate< const ListBase, const T > ConstListBaseWrapper
Vector< T * > listbase_to_vector(ListBase &list)
ListBaseWrapperTemplate< ListBase, T > ListBaseWrapper
__int64 int64_t
Definition stdint.h:89
PointerRNA * ptr
Definition wm_files.cc:4126