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
|
|
|
|
|
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);
|
|
|
|
int BLI_findstringindex(const struct ListBase *listbase,
|
|
|
|
const char *id,
|
|
|
|
const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
2011-05-02 13:35:04 +00:00
|
|
|
|
|
|
|
/* find forwards */
|
2014-02-13 13:19:56 +11:00
|
|
|
void *BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT
|
|
|
|
ATTR_NONNULL(1);
|
|
|
|
void *BLI_findstring(const struct ListBase *listbase,
|
|
|
|
const char *id,
|
|
|
|
const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
|
|
|
void *BLI_findstring_ptr(const struct ListBase *listbase,
|
|
|
|
const char *id,
|
|
|
|
const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
|
|
|
void *BLI_findptr(const struct ListBase *listbase,
|
|
|
|
const void *ptr,
|
|
|
|
const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
2017-11-16 12:49:31 +01:00
|
|
|
void *BLI_listbase_bytes_find(const ListBase *listbase,
|
|
|
|
const void *bytes,
|
|
|
|
const size_t bytes_size,
|
|
|
|
const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2);
|
2011-05-02 13:35:04 +00:00
|
|
|
|
|
|
|
/* find backwards */
|
2014-02-13 13:19:56 +11:00
|
|
|
void *BLI_rfindlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT
|
|
|
|
ATTR_NONNULL(1);
|
|
|
|
void *BLI_rfindstring(const struct ListBase *listbase,
|
|
|
|
const char *id,
|
|
|
|
const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
|
|
|
void *BLI_rfindstring_ptr(const struct ListBase *listbase,
|
|
|
|
const char *id,
|
|
|
|
const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
|
|
|
void *BLI_rfindptr(const struct ListBase *listbase,
|
|
|
|
const void *ptr,
|
|
|
|
const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
2017-11-16 12:49:31 +01:00
|
|
|
void *BLI_listbase_bytes_rfind(const ListBase *listbase,
|
|
|
|
const void *bytes,
|
|
|
|
const size_t bytes_size,
|
|
|
|
const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2);
|
2011-05-02 13:35:04 +00:00
|
|
|
|
2014-02-13 13:19:56 +11:00
|
|
|
void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1);
|
|
|
|
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1);
|
|
|
|
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1);
|
|
|
|
bool BLI_remlink_safe(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1);
|
|
|
|
void *BLI_pophead(ListBase *listbase) ATTR_NONNULL(1);
|
|
|
|
void *BLI_poptail(ListBase *listbase) ATTR_NONNULL(1);
|
2008-12-20 10:02:00 +00:00
|
|
|
|
2014-02-13 13:19:56 +11:00
|
|
|
void BLI_addhead(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1);
|
|
|
|
void BLI_insertlinkbefore(struct ListBase *listbase, void *vnextlink, void *vnewlink)
|
|
|
|
ATTR_NONNULL(1);
|
|
|
|
void BLI_insertlinkafter(struct ListBase *listbase, void *vprevlink, void *vnewlink)
|
|
|
|
ATTR_NONNULL(1);
|
2020-09-04 20:59:13 +02:00
|
|
|
void BLI_insertlinkreplace(ListBase *listbase, void *vreplacelink, void *vnewlink)
|
|
|
|
ATTR_NONNULL(1, 2, 3);
|
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);
|
2016-09-18 21:36:34 +02:00
|
|
|
bool BLI_listbase_link_move(ListBase *listbase, void *vlink, int step) ATTR_NONNULL();
|
2019-09-04 22:09:57 +03:00
|
|
|
bool BLI_listbase_move_index(ListBase *listbase, int from, int to) ATTR_NONNULL();
|
2014-02-13 13:19:56 +11:00
|
|
|
void BLI_freelist(struct ListBase *listbase) ATTR_NONNULL(1);
|
2018-04-03 17:05:21 +02:00
|
|
|
int BLI_listbase_count_at_most(const struct ListBase *listbase,
|
|
|
|
const int count_max) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
2014-11-16 13:57:58 +01:00
|
|
|
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
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
|
|
|
|
2014-10-21 14:06:16 +02:00
|
|
|
void BLI_listbase_swaplinks(struct ListBase *listbase, void *vlinka, void *vlinkb)
|
|
|
|
ATTR_NONNULL(1, 2);
|
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
|
|
|
|
2014-02-13 13:19:56 +11:00
|
|
|
void BLI_movelisttolist(struct ListBase *dst, struct ListBase *src) ATTR_NONNULL(1, 2);
|
2018-09-29 16:39:45 +02:00
|
|
|
void BLI_movelisttolist_reverse(struct ListBase *dst, struct ListBase *src) ATTR_NONNULL(1, 2);
|
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);
|
2014-07-30 15:01:16 +10:00
|
|
|
void BLI_listbase_rotate_first(struct ListBase *lb, void *vlink) ATTR_NONNULL(1, 2);
|
|
|
|
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
|
|
|
|
2009-09-17 10:14:56 +00:00
|
|
|
/* create a generic list node containing link to provided data */
|
|
|
|
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))
|
|
|
|
|
2019-08-01 13:53:25 +10: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
|
|
|
|
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
|
|
|
/** A version of #LISTBASE_FOREACH_BACKWARD that supports removing the item we're looping over. */
|
|
|
|
#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
|