2008-12-20 10:02:00 +00:00
|
|
|
/*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-12-20 10:02:00 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
|
* All rights reserved.
|
2011-10-23 17:52:20 +00:00
|
|
|
*/
|
2008-12-20 10:02:00 +00:00
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#pragma once
|
2008-12-20 10:02:00 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bli
|
2011-02-18 13:58:08 +00:00
|
|
|
*/
|
|
|
|
|
|
2014-02-13 13:19:56 +11:00
|
|
|
#include "BLI_compiler_attrs.h"
|
2013-02-22 14:12:55 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2010-03-31 12:35:05 +00:00
|
|
|
#include "DNA_listBase.h"
|
2019-05-01 11:09:22 +10:00
|
|
|
// struct ListBase;
|
|
|
|
|
// struct LinkData;
|
2008-12-20 10:02:00 +00:00
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Returns the position of \a vlink within \a listbase, numbering from 0, or -1 if not found.
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT
|
|
|
|
|
ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Returns the 0-based index of the first element of listbase which contains the specified
|
|
|
|
|
* null-terminated string at the specified offset, or -1 if not found.
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
int BLI_findstringindex(const struct ListBase *listbase,
|
|
|
|
|
const char *id,
|
2022-01-07 11:38:08 +11:00
|
|
|
int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
2011-05-02 13:35:04 +00:00
|
|
|
|
2021-12-17 17:31:15 +01:00
|
|
|
/**
|
|
|
|
|
* Return a ListBase representing the entire list the given Link is in.
|
|
|
|
|
*/
|
|
|
|
|
ListBase BLI_listbase_from_link(struct Link *some_link);
|
|
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/* Find forwards. */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the nth element of \a listbase, numbering from 0.
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
void *BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT
|
|
|
|
|
ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Finds the first element of \a listbase which contains the null-terminated
|
|
|
|
|
* string \a id at the specified offset, returning NULL if not found.
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
void *BLI_findstring(const struct ListBase *listbase,
|
|
|
|
|
const char *id,
|
2022-01-07 11:38:08 +11:00
|
|
|
int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Finds the first element of \a listbase which contains a pointer to the
|
|
|
|
|
* null-terminated string \a id at the specified offset, returning NULL if not found.
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
void *BLI_findstring_ptr(const struct ListBase *listbase,
|
|
|
|
|
const char *id,
|
2022-01-07 11:38:08 +11:00
|
|
|
int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Finds the first element of listbase which contains the specified pointer value
|
|
|
|
|
* at the specified offset, returning NULL if not found.
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
void *BLI_findptr(const struct ListBase *listbase,
|
|
|
|
|
const void *ptr,
|
2022-01-07 11:38:08 +11:00
|
|
|
int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Finds the first element of listbase which contains the specified bytes
|
|
|
|
|
* at the specified offset, returning NULL if not found.
|
|
|
|
|
*/
|
2017-11-16 12:49:31 +01:00
|
|
|
void *BLI_listbase_bytes_find(const ListBase *listbase,
|
|
|
|
|
const void *bytes,
|
BLI: Refactor vector types & functions to use templates
This patch implements the vector types (i.e:`float2`) by making heavy
usage of templating. All vector functions are now outside of the vector
classes (inside the `blender::math` namespace) and are not vector size
dependent for the most part.
In the ongoing effort to make shaders less GL centric, we are aiming
to share more code between GLSL and C++ to avoid code duplication.
####Motivations:
- We are aiming to share UBO and SSBO structures between GLSL and C++.
This means we will use many of the existing vector types and others
we currently don't have (uintX, intX). All these variations were
asking for many more code duplication.
- Deduplicate existing code which is duplicated for each vector size.
- We also want to share small functions. Which means that vector
functions should be static and not in the class namespace.
- Reduce friction to use these types in new projects due to their
incompleteness.
- The current state of the `BLI_(float|double|mpq)(2|3|4).hh` is a
bit of a let down. Most clases are incomplete, out of sync with each
others with different codestyles, and some functions that should be
static are not (i.e: `float3::reflect()`).
####Upsides:
- Still support `.x, .y, .z, .w` for readability.
- Compact, readable and easilly extendable.
- All of the vector functions are available for all the vectors types
and can be restricted to certain types. Also template specialization
let us define exception for special class (like mpq).
- With optimization ON, the compiler unroll the loops and performance
is the same.
####Downsides:
- Might impact debugability. Though I would arge that the bugs are
rarelly caused by the vector class itself (since the operations are
quite trivial) but by the type conversions.
- Might impact compile time. I did not saw a significant impact since
the usage is not really widespread.
- Functions needs to be rewritten to support arbitrary vector length.
For instance, one can't call `len_squared_v3v3` in
`math::length_squared()` and call it a day.
- Type cast does not work with the template version of the `math::`
vector functions. Meaning you need to manually cast `float *` and
`(float *)[3]` to `float3` for the function calls.
i.e: `math::distance_squared(float3(nearest.co), positions[i]);`
- Some parts might loose in readability:
`float3::dot(v1.normalized(), v2.normalized())`
becoming
`math::dot(math::normalize(v1), math::normalize(v2))`
But I propose, when appropriate, to use
`using namespace blender::math;` on function local or file scope to
increase readability.
`dot(normalize(v1), normalize(v2))`
####Consideration:
- Include back `.length()` method. It is quite handy and is more C++
oriented.
- I considered the GLM library as a candidate for replacement. It felt
like too much for what we need and would be difficult to extend / modify
to our needs.
- I used Macros to reduce code in operators declaration and potential
copy paste bugs. This could reduce debugability and could be reverted.
- This touches `delaunay_2d.cc` and the intersection code. I would like
to know @howardt opinion on the matter.
- The `noexcept` on the copy constructor of `mpq(2|3)` is being removed.
But according to @JacquesLucke it is not a real problem for now.
I would like to give a huge thanks to @JacquesLucke who helped during this
and pushed me to reduce the duplication further.
Reviewed By: brecht, sergey, JacquesLucke
Differential Revision: https://developer.blender.org/D13791
2022-01-12 12:46:52 +01:00
|
|
|
const size_t bytes_size,
|
2022-01-07 11:38:08 +11:00
|
|
|
int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Find the first item in the list that matches the given string, or the given index as fallback.
|
|
|
|
|
*
|
|
|
|
|
* \note The string is only used is non-NULL and non-empty.
|
|
|
|
|
*
|
|
|
|
|
* \return The found item, or NULL.
|
|
|
|
|
*/
|
2021-11-19 14:39:40 +01:00
|
|
|
void *BLI_listbase_string_or_index_find(const struct ListBase *listbase,
|
|
|
|
|
const char *string,
|
BLI: Refactor vector types & functions to use templates
This patch implements the vector types (i.e:`float2`) by making heavy
usage of templating. All vector functions are now outside of the vector
classes (inside the `blender::math` namespace) and are not vector size
dependent for the most part.
In the ongoing effort to make shaders less GL centric, we are aiming
to share more code between GLSL and C++ to avoid code duplication.
####Motivations:
- We are aiming to share UBO and SSBO structures between GLSL and C++.
This means we will use many of the existing vector types and others
we currently don't have (uintX, intX). All these variations were
asking for many more code duplication.
- Deduplicate existing code which is duplicated for each vector size.
- We also want to share small functions. Which means that vector
functions should be static and not in the class namespace.
- Reduce friction to use these types in new projects due to their
incompleteness.
- The current state of the `BLI_(float|double|mpq)(2|3|4).hh` is a
bit of a let down. Most clases are incomplete, out of sync with each
others with different codestyles, and some functions that should be
static are not (i.e: `float3::reflect()`).
####Upsides:
- Still support `.x, .y, .z, .w` for readability.
- Compact, readable and easilly extendable.
- All of the vector functions are available for all the vectors types
and can be restricted to certain types. Also template specialization
let us define exception for special class (like mpq).
- With optimization ON, the compiler unroll the loops and performance
is the same.
####Downsides:
- Might impact debugability. Though I would arge that the bugs are
rarelly caused by the vector class itself (since the operations are
quite trivial) but by the type conversions.
- Might impact compile time. I did not saw a significant impact since
the usage is not really widespread.
- Functions needs to be rewritten to support arbitrary vector length.
For instance, one can't call `len_squared_v3v3` in
`math::length_squared()` and call it a day.
- Type cast does not work with the template version of the `math::`
vector functions. Meaning you need to manually cast `float *` and
`(float *)[3]` to `float3` for the function calls.
i.e: `math::distance_squared(float3(nearest.co), positions[i]);`
- Some parts might loose in readability:
`float3::dot(v1.normalized(), v2.normalized())`
becoming
`math::dot(math::normalize(v1), math::normalize(v2))`
But I propose, when appropriate, to use
`using namespace blender::math;` on function local or file scope to
increase readability.
`dot(normalize(v1), normalize(v2))`
####Consideration:
- Include back `.length()` method. It is quite handy and is more C++
oriented.
- I considered the GLM library as a candidate for replacement. It felt
like too much for what we need and would be difficult to extend / modify
to our needs.
- I used Macros to reduce code in operators declaration and potential
copy paste bugs. This could reduce debugability and could be reverted.
- This touches `delaunay_2d.cc` and the intersection code. I would like
to know @howardt opinion on the matter.
- The `noexcept` on the copy constructor of `mpq(2|3)` is being removed.
But according to @JacquesLucke it is not a real problem for now.
I would like to give a huge thanks to @JacquesLucke who helped during this
and pushed me to reduce the duplication further.
Reviewed By: brecht, sergey, JacquesLucke
Differential Revision: https://developer.blender.org/D13791
2022-01-12 12:46:52 +01:00
|
|
|
const size_t string_offset,
|
2022-01-07 11:38:08 +11:00
|
|
|
int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
2011-05-02 13:35:04 +00:00
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/* Find backwards. */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the nth-last element of \a listbase, numbering from 0.
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
void *BLI_rfindlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT
|
|
|
|
|
ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Finds the last element of \a listbase which contains the
|
|
|
|
|
* null-terminated string \a id at the specified offset, returning NULL if not found.
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
void *BLI_rfindstring(const struct ListBase *listbase,
|
|
|
|
|
const char *id,
|
2022-01-07 11:38:08 +11:00
|
|
|
int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Finds the last element of \a listbase which contains a pointer to the
|
|
|
|
|
* null-terminated string \a id at the specified offset, returning NULL if not found.
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
void *BLI_rfindstring_ptr(const struct ListBase *listbase,
|
|
|
|
|
const char *id,
|
2022-01-07 11:38:08 +11:00
|
|
|
int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Finds the last element of listbase which contains the specified pointer value
|
|
|
|
|
* at the specified offset, returning NULL if not found.
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
void *BLI_rfindptr(const struct ListBase *listbase,
|
|
|
|
|
const void *ptr,
|
2022-01-07 11:38:08 +11:00
|
|
|
int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Finds the last element of listbase which contains the specified bytes
|
|
|
|
|
* at the specified offset, returning NULL if not found.
|
|
|
|
|
*/
|
2017-11-16 12:49:31 +01:00
|
|
|
void *BLI_listbase_bytes_rfind(const ListBase *listbase,
|
|
|
|
|
const void *bytes,
|
BLI: Refactor vector types & functions to use templates
This patch implements the vector types (i.e:`float2`) by making heavy
usage of templating. All vector functions are now outside of the vector
classes (inside the `blender::math` namespace) and are not vector size
dependent for the most part.
In the ongoing effort to make shaders less GL centric, we are aiming
to share more code between GLSL and C++ to avoid code duplication.
####Motivations:
- We are aiming to share UBO and SSBO structures between GLSL and C++.
This means we will use many of the existing vector types and others
we currently don't have (uintX, intX). All these variations were
asking for many more code duplication.
- Deduplicate existing code which is duplicated for each vector size.
- We also want to share small functions. Which means that vector
functions should be static and not in the class namespace.
- Reduce friction to use these types in new projects due to their
incompleteness.
- The current state of the `BLI_(float|double|mpq)(2|3|4).hh` is a
bit of a let down. Most clases are incomplete, out of sync with each
others with different codestyles, and some functions that should be
static are not (i.e: `float3::reflect()`).
####Upsides:
- Still support `.x, .y, .z, .w` for readability.
- Compact, readable and easilly extendable.
- All of the vector functions are available for all the vectors types
and can be restricted to certain types. Also template specialization
let us define exception for special class (like mpq).
- With optimization ON, the compiler unroll the loops and performance
is the same.
####Downsides:
- Might impact debugability. Though I would arge that the bugs are
rarelly caused by the vector class itself (since the operations are
quite trivial) but by the type conversions.
- Might impact compile time. I did not saw a significant impact since
the usage is not really widespread.
- Functions needs to be rewritten to support arbitrary vector length.
For instance, one can't call `len_squared_v3v3` in
`math::length_squared()` and call it a day.
- Type cast does not work with the template version of the `math::`
vector functions. Meaning you need to manually cast `float *` and
`(float *)[3]` to `float3` for the function calls.
i.e: `math::distance_squared(float3(nearest.co), positions[i]);`
- Some parts might loose in readability:
`float3::dot(v1.normalized(), v2.normalized())`
becoming
`math::dot(math::normalize(v1), math::normalize(v2))`
But I propose, when appropriate, to use
`using namespace blender::math;` on function local or file scope to
increase readability.
`dot(normalize(v1), normalize(v2))`
####Consideration:
- Include back `.length()` method. It is quite handy and is more C++
oriented.
- I considered the GLM library as a candidate for replacement. It felt
like too much for what we need and would be difficult to extend / modify
to our needs.
- I used Macros to reduce code in operators declaration and potential
copy paste bugs. This could reduce debugability and could be reverted.
- This touches `delaunay_2d.cc` and the intersection code. I would like
to know @howardt opinion on the matter.
- The `noexcept` on the copy constructor of `mpq(2|3)` is being removed.
But according to @JacquesLucke it is not a real problem for now.
I would like to give a huge thanks to @JacquesLucke who helped during this
and pushed me to reduce the duplication further.
Reviewed By: brecht, sergey, JacquesLucke
Differential Revision: https://developer.blender.org/D13791
2022-01-12 12:46:52 +01:00
|
|
|
const size_t bytes_size,
|
2022-01-07 11:38:08 +11:00
|
|
|
int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2);
|
2011-05-02 13:35:04 +00:00
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Removes and disposes of the entire contents of \a listbase using guardedalloc.
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Appends \a vlink (assumed to begin with a Link) onto listbase.
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Removes \a vlink from \a listbase. Assumes it is linked into there!
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Checks that \a vlink is linked into listbase, removing it from there if so.
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
bool BLI_remlink_safe(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Removes the head from \a listbase and returns it.
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
void *BLI_pophead(ListBase *listbase) ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Removes the tail from \a listbase and returns it.
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
void *BLI_poptail(ListBase *listbase) ATTR_NONNULL(1);
|
2008-12-20 10:02:00 +00:00
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Prepends \a vlink (assumed to begin with a Link) onto listbase.
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
void BLI_addhead(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Inserts \a vnewlink immediately preceding \a vnextlink in listbase.
|
|
|
|
|
* Or, if \a vnextlink is NULL, puts \a vnewlink at the end of the list.
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
void BLI_insertlinkbefore(struct ListBase *listbase, void *vnextlink, void *vnewlink)
|
|
|
|
|
ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Inserts \a vnewlink immediately following \a vprevlink in \a listbase.
|
|
|
|
|
* Or, if \a vprevlink is NULL, puts \a vnewlink at the front of the list.
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
void BLI_insertlinkafter(struct ListBase *listbase, void *vprevlink, void *vnewlink)
|
|
|
|
|
ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Insert a link in place of another, without changing its position in the list.
|
|
|
|
|
*
|
|
|
|
|
* Puts `vnewlink` in the position of `vreplacelink`, removing `vreplacelink`.
|
|
|
|
|
* - `vreplacelink` *must* be in the list.
|
|
|
|
|
* - `vnewlink` *must not* be in the list.
|
|
|
|
|
*/
|
2020-09-04 20:59:13 +02:00
|
|
|
void BLI_insertlinkreplace(ListBase *listbase, void *vreplacelink, void *vnewlink)
|
|
|
|
|
ATTR_NONNULL(1, 2, 3);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Sorts the elements of listbase into the order defined by cmp
|
|
|
|
|
* (which should return 1 if its first arg should come after its second arg).
|
|
|
|
|
* This uses insertion sort, so NOT ok for large list.
|
|
|
|
|
*/
|
2014-11-16 13:57:58 +01:00
|
|
|
void BLI_listbase_sort(struct ListBase *listbase, int (*cmp)(const void *, const void *))
|
|
|
|
|
ATTR_NONNULL(1, 2);
|
2015-06-11 15:07:14 +10:00
|
|
|
void BLI_listbase_sort_r(ListBase *listbase,
|
|
|
|
|
int (*cmp)(void *, const void *, const void *),
|
|
|
|
|
void *thunk) ATTR_NONNULL(1, 2);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Reinsert \a vlink relative to its current position but offset by \a step. Doesn't move
|
|
|
|
|
* item if new position would exceed list (could optionally move to head/tail).
|
|
|
|
|
*
|
|
|
|
|
* \param step: Absolute value defines step size, sign defines direction. E.g pass -1
|
|
|
|
|
* to move \a vlink before previous, or 1 to move behind next.
|
|
|
|
|
* \return If position of \a vlink has changed.
|
|
|
|
|
*/
|
2016-09-18 21:36:34 +02:00
|
|
|
bool BLI_listbase_link_move(ListBase *listbase, void *vlink, int step) ATTR_NONNULL();
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Move the link at the index \a from to the position at index \a to.
|
|
|
|
|
*
|
|
|
|
|
* \return If the move was successful.
|
|
|
|
|
*/
|
2019-09-04 22:09:57 +03:00
|
|
|
bool BLI_listbase_move_index(ListBase *listbase, int from, int to) ATTR_NONNULL();
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Removes and disposes of the entire contents of listbase using direct free(3).
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
void BLI_freelist(struct ListBase *listbase) ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Returns the number of elements in \a listbase, up until (and including count_max)
|
|
|
|
|
*
|
|
|
|
|
* \note Use to avoid redundant looping.
|
|
|
|
|
*/
|
2018-04-03 17:05:21 +02:00
|
|
|
int BLI_listbase_count_at_most(const struct ListBase *listbase,
|
2022-01-07 11:38:08 +11:00
|
|
|
int count_max) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Returns the number of elements in \a listbase.
|
|
|
|
|
*/
|
2014-11-16 13:57:58 +01:00
|
|
|
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Removes \a vlink from listbase and disposes of it. Assumes it is linked into there!
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
void BLI_freelinkN(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1);
|
2010-12-21 14:49:34 +00:00
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Swaps \a vlinka and \a vlinkb in the list. Assumes they are both already in the list!
|
|
|
|
|
*/
|
2014-10-21 14:06:16 +02:00
|
|
|
void BLI_listbase_swaplinks(struct ListBase *listbase, void *vlinka, void *vlinkb)
|
|
|
|
|
ATTR_NONNULL(1, 2);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Swaps \a vlinka and \a vlinkb from their respective lists.
|
|
|
|
|
* Assumes they are both already in their \a listbasea!
|
|
|
|
|
*/
|
2017-11-14 16:10:48 +11:00
|
|
|
void BLI_listbases_swaplinks(struct ListBase *listbasea,
|
|
|
|
|
struct ListBase *listbaseb,
|
|
|
|
|
void *vlinka,
|
|
|
|
|
void *vlinkb) ATTR_NONNULL(2, 3);
|
2014-10-21 11:56:46 +02:00
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Moves the entire contents of \a src onto the end of \a dst.
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
void BLI_movelisttolist(struct ListBase *dst, struct ListBase *src) ATTR_NONNULL(1, 2);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Moves the entire contents of \a src at the beginning of \a dst.
|
|
|
|
|
*/
|
2018-09-29 16:39:45 +02:00
|
|
|
void BLI_movelisttolist_reverse(struct ListBase *dst, struct ListBase *src) ATTR_NONNULL(1, 2);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Sets dst to a duplicate of the entire contents of src. dst may be the same as src.
|
|
|
|
|
*/
|
2014-02-13 13:19:56 +11:00
|
|
|
void BLI_duplicatelist(struct ListBase *dst, const struct ListBase *src) ATTR_NONNULL(1, 2);
|
2014-06-25 19:33:35 +10:00
|
|
|
void BLI_listbase_reverse(struct ListBase *lb) ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* \param vlink: Link to make first.
|
|
|
|
|
*/
|
2014-07-30 15:01:16 +10:00
|
|
|
void BLI_listbase_rotate_first(struct ListBase *lb, void *vlink) ATTR_NONNULL(1, 2);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* \param vlink: Link to make last.
|
|
|
|
|
*/
|
2014-07-30 15:01:16 +10:00
|
|
|
void BLI_listbase_rotate_last(struct ListBase *lb, void *vlink) ATTR_NONNULL(1, 2);
|
2008-12-20 10:02:00 +00:00
|
|
|
|
2014-02-08 06:07:10 +11:00
|
|
|
/**
|
|
|
|
|
* Utility functions to avoid first/last references inline all over.
|
|
|
|
|
*/
|
|
|
|
|
BLI_INLINE bool BLI_listbase_is_single(const struct ListBase *lb)
|
|
|
|
|
{
|
|
|
|
|
return (lb->first && lb->first == lb->last);
|
|
|
|
|
}
|
2014-02-08 08:09:49 +11:00
|
|
|
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
|
|
|
|
|
{
|
|
|
|
|
return (lb->first == (void *)0);
|
|
|
|
|
}
|
|
|
|
|
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
|
|
|
|
|
{
|
|
|
|
|
lb->first = lb->last = (void *)0;
|
|
|
|
|
}
|
2014-02-08 06:07:10 +11:00
|
|
|
|
2021-12-17 17:31:15 +01:00
|
|
|
/**
|
|
|
|
|
* Equality check for ListBase.
|
|
|
|
|
*
|
|
|
|
|
* This only shallowly compares the ListBase itself (so the first/last
|
|
|
|
|
* pointers), and does not do any equality checks on the list items.
|
|
|
|
|
*/
|
|
|
|
|
BLI_INLINE bool BLI_listbase_equal(const struct ListBase *a, const struct ListBase *b)
|
|
|
|
|
{
|
|
|
|
|
if (a == NULL) {
|
|
|
|
|
return b == NULL;
|
|
|
|
|
}
|
|
|
|
|
if (b == NULL) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return a->first == b->first && a->last == b->last;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* Create a generic list node containing link to provided data.
|
|
|
|
|
*/
|
2009-09-17 10:14:56 +00:00
|
|
|
struct LinkData *BLI_genericNodeN(void *data);
|
|
|
|
|
|
2013-03-28 20:58:14 +00:00
|
|
|
/**
|
|
|
|
|
* Does a full loop on the list, with any value acting as first
|
|
|
|
|
* (handy for cycling items)
|
|
|
|
|
*
|
|
|
|
|
* \code{.c}
|
|
|
|
|
*
|
2018-02-15 12:41:35 +01:00
|
|
|
* LISTBASE_CIRCULAR_FORWARD_BEGIN(listbase, item, item_init)
|
|
|
|
|
* {
|
2013-03-28 20:58:14 +00:00
|
|
|
* ...operate on marker...
|
|
|
|
|
* }
|
2018-02-15 12:38:21 +01:00
|
|
|
* LISTBASE_CIRCULAR_FORWARD_END (listbase, item, item_init);
|
2013-03-28 20:58:14 +00:00
|
|
|
*
|
|
|
|
|
* \endcode
|
|
|
|
|
*/
|
2018-02-15 12:38:21 +01:00
|
|
|
#define LISTBASE_CIRCULAR_FORWARD_BEGIN(lb, lb_iter, lb_init) \
|
2013-03-28 20:58:14 +00:00
|
|
|
if ((lb)->first && (lb_init || (lb_init = (lb)->first))) { \
|
|
|
|
|
lb_iter = lb_init; \
|
|
|
|
|
do {
|
2018-02-15 12:38:21 +01:00
|
|
|
#define LISTBASE_CIRCULAR_FORWARD_END(lb, lb_iter, lb_init) \
|
2013-03-28 20:58:14 +00:00
|
|
|
} \
|
|
|
|
|
while ((lb_iter = (lb_iter)->next ? (lb_iter)->next : (lb)->first), (lb_iter != lb_init)) \
|
|
|
|
|
; \
|
2019-04-02 17:54:04 +11:00
|
|
|
} \
|
|
|
|
|
((void)0)
|
2013-03-28 20:58:14 +00:00
|
|
|
|
2018-02-15 12:38:21 +01:00
|
|
|
#define LISTBASE_CIRCULAR_BACKWARD_BEGIN(lb, lb_iter, lb_init) \
|
2013-03-28 20:58:14 +00:00
|
|
|
if ((lb)->last && (lb_init || (lb_init = (lb)->last))) { \
|
|
|
|
|
lb_iter = lb_init; \
|
|
|
|
|
do {
|
2018-02-15 12:38:21 +01:00
|
|
|
#define LISTBASE_CIRCULAR_BACKWARD_END(lb, lb_iter, lb_init) \
|
2013-03-28 20:58:14 +00:00
|
|
|
} \
|
|
|
|
|
while ((lb_iter = (lb_iter)->prev ? (lb_iter)->prev : (lb)->last), (lb_iter != lb_init)) \
|
|
|
|
|
; \
|
2019-04-02 17:54:04 +11:00
|
|
|
} \
|
|
|
|
|
((void)0)
|
2013-03-28 20:58:14 +00:00
|
|
|
|
2018-02-15 12:38:21 +01:00
|
|
|
#define LISTBASE_FOREACH(type, var, list) \
|
2018-01-19 21:39:18 +11:00
|
|
|
for (type var = (type)((list)->first); var != NULL; var = (type)(((Link *)(var))->next))
|
2019-02-20 09:15:43 +11:00
|
|
|
|
2020-08-18 21:38:18 -04:00
|
|
|
/**
|
|
|
|
|
* A version of #LISTBASE_FOREACH that supports incrementing an index variable at every step.
|
|
|
|
|
* Including this in the macro helps prevent mistakes where "continue" mistakenly skips the
|
|
|
|
|
* incrementation.
|
|
|
|
|
*/
|
|
|
|
|
#define LISTBASE_FOREACH_INDEX(type, var, list, index_var) \
|
|
|
|
|
for (type var = (((void)(index_var = 0)), (type)((list)->first)); var != NULL; \
|
|
|
|
|
var = (type)(((Link *)(var))->next), index_var++)
|
|
|
|
|
|
Shading: Add more operators to Vector Math node.
Add Multiply, Divide, Project, Reflect, Distance, Length, Scale, Snap,
Floor, Ceil, Modulo, Fraction, Absolute, Minimum, and Maximum operators
to the Vector Math node. The Value output has been removed from operators
whose output is a vector, and the other way around. All of those removals
has been handled properly in versioning code.
The patch doesn't include tests for the new operators. Tests will be added
in a later patch.
Reviewers: brecht, JacquesLucke
Differential Revision: https://developer.blender.org/D5523
2019-08-21 19:36:33 +02:00
|
|
|
#define LISTBASE_FOREACH_BACKWARD(type, var, list) \
|
|
|
|
|
for (type var = (type)((list)->last); var != NULL; var = (type)(((Link *)(var))->prev))
|
|
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* A version of #LISTBASE_FOREACH that supports removing the item we're looping over.
|
|
|
|
|
*/
|
2019-02-20 09:15:43 +11:00
|
|
|
#define LISTBASE_FOREACH_MUTABLE(type, var, list) \
|
|
|
|
|
for (type var = (type)((list)->first), *var##_iter_next; \
|
|
|
|
|
((var != NULL) ? ((void)(var##_iter_next = (type)(((Link *)(var))->next)), 1) : 0); \
|
|
|
|
|
var = var##_iter_next)
|
2017-05-30 12:21:19 +02:00
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
|
* A version of #LISTBASE_FOREACH_BACKWARD that supports removing the item we're looping over.
|
|
|
|
|
*/
|
Shading: Add more operators to Vector Math node.
Add Multiply, Divide, Project, Reflect, Distance, Length, Scale, Snap,
Floor, Ceil, Modulo, Fraction, Absolute, Minimum, and Maximum operators
to the Vector Math node. The Value output has been removed from operators
whose output is a vector, and the other way around. All of those removals
has been handled properly in versioning code.
The patch doesn't include tests for the new operators. Tests will be added
in a later patch.
Reviewers: brecht, JacquesLucke
Differential Revision: https://developer.blender.org/D5523
2019-08-21 19:36:33 +02:00
|
|
|
#define LISTBASE_FOREACH_BACKWARD_MUTABLE(type, var, list) \
|
|
|
|
|
for (type var = (type)((list)->last), *var##_iter_prev; \
|
|
|
|
|
((var != NULL) ? ((void)(var##_iter_prev = (type)(((Link *)(var))->prev)), 1) : 0); \
|
|
|
|
|
var = var##_iter_prev)
|
|
|
|
|
|
2008-12-20 10:02:00 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2021-12-17 17:31:15 +01:00
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
BLI_INLINE bool operator==(const ListBase &a, const ListBase &b)
|
|
|
|
|
{
|
|
|
|
|
return BLI_listbase_equal(&a, &b);
|
|
|
|
|
}
|
|
|
|
|
#endif
|