|
|
|
|
@@ -22,56 +22,56 @@
|
|
|
|
|
|
|
|
|
|
void BLI_movelisttolist(ListBase *dst, ListBase *src)
|
|
|
|
|
{
|
|
|
|
|
if (src->first == NULL) {
|
|
|
|
|
if (src->first == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dst->first == NULL) {
|
|
|
|
|
if (dst->first == nullptr) {
|
|
|
|
|
dst->first = src->first;
|
|
|
|
|
dst->last = src->last;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
((Link *)dst->last)->next = src->first;
|
|
|
|
|
((Link *)src->first)->prev = dst->last;
|
|
|
|
|
((Link *)dst->last)->next = static_cast<Link *>(src->first);
|
|
|
|
|
((Link *)src->first)->prev = static_cast<Link *>(dst->last);
|
|
|
|
|
dst->last = src->last;
|
|
|
|
|
}
|
|
|
|
|
src->first = src->last = NULL;
|
|
|
|
|
src->first = src->last = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BLI_movelisttolist_reverse(ListBase *dst, ListBase *src)
|
|
|
|
|
{
|
|
|
|
|
if (src->first == NULL) {
|
|
|
|
|
if (src->first == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dst->first == NULL) {
|
|
|
|
|
if (dst->first == nullptr) {
|
|
|
|
|
dst->first = src->first;
|
|
|
|
|
dst->last = src->last;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
((Link *)src->last)->next = dst->first;
|
|
|
|
|
((Link *)dst->first)->prev = src->last;
|
|
|
|
|
((Link *)src->last)->next = static_cast<Link *>(dst->first);
|
|
|
|
|
((Link *)dst->first)->prev = static_cast<Link *>(src->last);
|
|
|
|
|
dst->first = src->first;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
src->first = src->last = NULL;
|
|
|
|
|
src->first = src->last = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BLI_addhead(ListBase *listbase, void *vlink)
|
|
|
|
|
{
|
|
|
|
|
Link *link = vlink;
|
|
|
|
|
Link *link = static_cast<Link *>(vlink);
|
|
|
|
|
|
|
|
|
|
if (link == NULL) {
|
|
|
|
|
if (link == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
link->next = listbase->first;
|
|
|
|
|
link->prev = NULL;
|
|
|
|
|
link->next = static_cast<Link *>(listbase->first);
|
|
|
|
|
link->prev = nullptr;
|
|
|
|
|
|
|
|
|
|
if (listbase->first) {
|
|
|
|
|
((Link *)listbase->first)->prev = link;
|
|
|
|
|
}
|
|
|
|
|
if (listbase->last == NULL) {
|
|
|
|
|
if (listbase->last == nullptr) {
|
|
|
|
|
listbase->last = link;
|
|
|
|
|
}
|
|
|
|
|
listbase->first = link;
|
|
|
|
|
@@ -79,19 +79,19 @@ void BLI_addhead(ListBase *listbase, void *vlink)
|
|
|
|
|
|
|
|
|
|
void BLI_addtail(ListBase *listbase, void *vlink)
|
|
|
|
|
{
|
|
|
|
|
Link *link = vlink;
|
|
|
|
|
Link *link = static_cast<Link *>(vlink);
|
|
|
|
|
|
|
|
|
|
if (link == NULL) {
|
|
|
|
|
if (link == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
link->next = NULL;
|
|
|
|
|
link->prev = listbase->last;
|
|
|
|
|
link->next = nullptr;
|
|
|
|
|
link->prev = static_cast<Link *>(listbase->last);
|
|
|
|
|
|
|
|
|
|
if (listbase->last) {
|
|
|
|
|
((Link *)listbase->last)->next = link;
|
|
|
|
|
}
|
|
|
|
|
if (listbase->first == NULL) {
|
|
|
|
|
if (listbase->first == nullptr) {
|
|
|
|
|
listbase->first = link;
|
|
|
|
|
}
|
|
|
|
|
listbase->last = link;
|
|
|
|
|
@@ -99,9 +99,9 @@ void BLI_addtail(ListBase *listbase, void *vlink)
|
|
|
|
|
|
|
|
|
|
void BLI_remlink(ListBase *listbase, void *vlink)
|
|
|
|
|
{
|
|
|
|
|
Link *link = vlink;
|
|
|
|
|
Link *link = static_cast<Link *>(vlink);
|
|
|
|
|
|
|
|
|
|
if (link == NULL) {
|
|
|
|
|
if (link == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -132,8 +132,8 @@ bool BLI_remlink_safe(ListBase *listbase, void *vlink)
|
|
|
|
|
|
|
|
|
|
void BLI_listbase_swaplinks(ListBase *listbase, void *vlinka, void *vlinkb)
|
|
|
|
|
{
|
|
|
|
|
Link *linka = vlinka;
|
|
|
|
|
Link *linkb = vlinkb;
|
|
|
|
|
Link *linka = static_cast<Link *>(vlinka);
|
|
|
|
|
Link *linkb = static_cast<Link *>(vlinkb);
|
|
|
|
|
|
|
|
|
|
if (!linka || !linkb) {
|
|
|
|
|
return;
|
|
|
|
|
@@ -185,15 +185,15 @@ void BLI_listbase_swaplinks(ListBase *listbase, void *vlinka, void *vlinkb)
|
|
|
|
|
|
|
|
|
|
void BLI_listbases_swaplinks(ListBase *listbasea, ListBase *listbaseb, void *vlinka, void *vlinkb)
|
|
|
|
|
{
|
|
|
|
|
Link *linka = vlinka;
|
|
|
|
|
Link *linkb = vlinkb;
|
|
|
|
|
Link linkc = {NULL};
|
|
|
|
|
Link *linka = static_cast<Link *>(vlinka);
|
|
|
|
|
Link *linkb = static_cast<Link *>(vlinkb);
|
|
|
|
|
Link linkc = {nullptr};
|
|
|
|
|
|
|
|
|
|
if (!linka || !linkb) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The reference to `linkc` assigns NULL, not a dangling pointer so it can be ignored. */
|
|
|
|
|
/* The reference to `linkc` assigns nullptr, not a dangling pointer so it can be ignored. */
|
|
|
|
|
#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 1201 /* gcc12.1+ only */
|
|
|
|
|
# pragma GCC diagnostic push
|
|
|
|
|
# pragma GCC diagnostic ignored "-Wdangling-pointer"
|
|
|
|
|
@@ -221,7 +221,7 @@ void BLI_listbases_swaplinks(ListBase *listbasea, ListBase *listbaseb, void *vli
|
|
|
|
|
void *BLI_pophead(ListBase *listbase)
|
|
|
|
|
{
|
|
|
|
|
Link *link;
|
|
|
|
|
if ((link = listbase->first)) {
|
|
|
|
|
if ((link = static_cast<Link *>(listbase->first))) {
|
|
|
|
|
BLI_remlink(listbase, link);
|
|
|
|
|
}
|
|
|
|
|
return link;
|
|
|
|
|
@@ -230,7 +230,7 @@ void *BLI_pophead(ListBase *listbase)
|
|
|
|
|
void *BLI_poptail(ListBase *listbase)
|
|
|
|
|
{
|
|
|
|
|
Link *link;
|
|
|
|
|
if ((link = listbase->last)) {
|
|
|
|
|
if ((link = static_cast<Link *>(listbase->last))) {
|
|
|
|
|
BLI_remlink(listbase, link);
|
|
|
|
|
}
|
|
|
|
|
return link;
|
|
|
|
|
@@ -238,9 +238,9 @@ void *BLI_poptail(ListBase *listbase)
|
|
|
|
|
|
|
|
|
|
void BLI_freelinkN(ListBase *listbase, void *vlink)
|
|
|
|
|
{
|
|
|
|
|
Link *link = vlink;
|
|
|
|
|
Link *link = static_cast<Link *>(vlink);
|
|
|
|
|
|
|
|
|
|
if (link == NULL) {
|
|
|
|
|
if (link == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -253,7 +253,7 @@ void BLI_freelinkN(ListBase *listbase, void *vlink)
|
|
|
|
|
*/
|
|
|
|
|
static void listbase_double_from_single(Link *iter, ListBase *listbase)
|
|
|
|
|
{
|
|
|
|
|
Link *prev = NULL;
|
|
|
|
|
Link *prev = nullptr;
|
|
|
|
|
listbase->first = iter;
|
|
|
|
|
do {
|
|
|
|
|
iter->prev = prev;
|
|
|
|
|
@@ -281,7 +281,7 @@ static void listbase_double_from_single(Link *iter, ListBase *listbase)
|
|
|
|
|
void BLI_listbase_sort(ListBase *listbase, int (*cmp)(const void *, const void *))
|
|
|
|
|
{
|
|
|
|
|
if (listbase->first != listbase->last) {
|
|
|
|
|
Link *head = listbase->first;
|
|
|
|
|
Link *head = static_cast<Link *>(listbase->first);
|
|
|
|
|
head = listbase_sort_fn(head, cmp);
|
|
|
|
|
listbase_double_from_single(head, listbase);
|
|
|
|
|
}
|
|
|
|
|
@@ -292,7 +292,7 @@ void BLI_listbase_sort_r(ListBase *listbase,
|
|
|
|
|
void *thunk)
|
|
|
|
|
{
|
|
|
|
|
if (listbase->first != listbase->last) {
|
|
|
|
|
Link *head = listbase->first;
|
|
|
|
|
Link *head = static_cast<Link *>(listbase->first);
|
|
|
|
|
head = listbase_sort_fn_r(head, cmp, thunk);
|
|
|
|
|
listbase_double_from_single(head, listbase);
|
|
|
|
|
}
|
|
|
|
|
@@ -300,25 +300,25 @@ void BLI_listbase_sort_r(ListBase *listbase,
|
|
|
|
|
|
|
|
|
|
void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink)
|
|
|
|
|
{
|
|
|
|
|
Link *prevlink = vprevlink;
|
|
|
|
|
Link *newlink = vnewlink;
|
|
|
|
|
Link *prevlink = static_cast<Link *>(vprevlink);
|
|
|
|
|
Link *newlink = static_cast<Link *>(vnewlink);
|
|
|
|
|
|
|
|
|
|
/* newlink before nextlink */
|
|
|
|
|
if (newlink == NULL) {
|
|
|
|
|
if (newlink == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* empty list */
|
|
|
|
|
if (listbase->first == NULL) {
|
|
|
|
|
if (listbase->first == nullptr) {
|
|
|
|
|
listbase->first = newlink;
|
|
|
|
|
listbase->last = newlink;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* insert at head of list */
|
|
|
|
|
if (prevlink == NULL) {
|
|
|
|
|
newlink->prev = NULL;
|
|
|
|
|
newlink->next = listbase->first;
|
|
|
|
|
if (prevlink == nullptr) {
|
|
|
|
|
newlink->prev = nullptr;
|
|
|
|
|
newlink->next = static_cast<Link *>(listbase->first);
|
|
|
|
|
newlink->next->prev = newlink;
|
|
|
|
|
listbase->first = newlink;
|
|
|
|
|
return;
|
|
|
|
|
@@ -339,25 +339,25 @@ void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink)
|
|
|
|
|
|
|
|
|
|
void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink)
|
|
|
|
|
{
|
|
|
|
|
Link *nextlink = vnextlink;
|
|
|
|
|
Link *newlink = vnewlink;
|
|
|
|
|
Link *nextlink = static_cast<Link *>(vnextlink);
|
|
|
|
|
Link *newlink = static_cast<Link *>(vnewlink);
|
|
|
|
|
|
|
|
|
|
/* newlink before nextlink */
|
|
|
|
|
if (newlink == NULL) {
|
|
|
|
|
if (newlink == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* empty list */
|
|
|
|
|
if (listbase->first == NULL) {
|
|
|
|
|
if (listbase->first == nullptr) {
|
|
|
|
|
listbase->first = newlink;
|
|
|
|
|
listbase->last = newlink;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* insert at end of list */
|
|
|
|
|
if (nextlink == NULL) {
|
|
|
|
|
newlink->prev = listbase->last;
|
|
|
|
|
newlink->next = NULL;
|
|
|
|
|
if (nextlink == nullptr) {
|
|
|
|
|
newlink->prev = static_cast<Link *>(listbase->last);
|
|
|
|
|
newlink->next = nullptr;
|
|
|
|
|
((Link *)listbase->last)->next = newlink;
|
|
|
|
|
listbase->last = newlink;
|
|
|
|
|
return;
|
|
|
|
|
@@ -378,14 +378,14 @@ void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink)
|
|
|
|
|
|
|
|
|
|
void BLI_insertlinkreplace(ListBase *listbase, void *vreplacelink, void *vnewlink)
|
|
|
|
|
{
|
|
|
|
|
Link *l_old = vreplacelink;
|
|
|
|
|
Link *l_new = vnewlink;
|
|
|
|
|
Link *l_old = static_cast<Link *>(vreplacelink);
|
|
|
|
|
Link *l_new = static_cast<Link *>(vnewlink);
|
|
|
|
|
|
|
|
|
|
/* update adjacent links */
|
|
|
|
|
if (l_old->next != NULL) {
|
|
|
|
|
if (l_old->next != nullptr) {
|
|
|
|
|
l_old->next->prev = l_new;
|
|
|
|
|
}
|
|
|
|
|
if (l_old->prev != NULL) {
|
|
|
|
|
if (l_old->prev != nullptr) {
|
|
|
|
|
l_old->prev->next = l_new;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -404,7 +404,7 @@ void BLI_insertlinkreplace(ListBase *listbase, void *vreplacelink, void *vnewlin
|
|
|
|
|
|
|
|
|
|
bool BLI_listbase_link_move(ListBase *listbase, void *vlink, int step)
|
|
|
|
|
{
|
|
|
|
|
Link *link = vlink;
|
|
|
|
|
Link *link = static_cast<Link *>(vlink);
|
|
|
|
|
Link *hook = link;
|
|
|
|
|
const bool is_up = step < 0;
|
|
|
|
|
|
|
|
|
|
@@ -453,7 +453,7 @@ void BLI_freelist(ListBase *listbase)
|
|
|
|
|
{
|
|
|
|
|
Link *link, *next;
|
|
|
|
|
|
|
|
|
|
link = listbase->first;
|
|
|
|
|
link = static_cast<Link *>(listbase->first);
|
|
|
|
|
while (link) {
|
|
|
|
|
next = link->next;
|
|
|
|
|
free(link);
|
|
|
|
|
@@ -467,7 +467,7 @@ void BLI_freelistN(ListBase *listbase)
|
|
|
|
|
{
|
|
|
|
|
Link *link, *next;
|
|
|
|
|
|
|
|
|
|
link = listbase->first;
|
|
|
|
|
link = static_cast<Link *>(listbase->first);
|
|
|
|
|
while (link) {
|
|
|
|
|
next = link->next;
|
|
|
|
|
MEM_freeN(link);
|
|
|
|
|
@@ -482,7 +482,8 @@ int BLI_listbase_count_at_most(const ListBase *listbase, const int count_max)
|
|
|
|
|
Link *link;
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
|
|
for (link = listbase->first; link && count != count_max; link = link->next) {
|
|
|
|
|
for (link = static_cast<Link *>(listbase->first); link && count != count_max;
|
|
|
|
|
link = link->next) {
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -494,7 +495,7 @@ int BLI_listbase_count(const ListBase *listbase)
|
|
|
|
|
Link *link;
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
|
|
for (link = listbase->first; link; link = link->next) {
|
|
|
|
|
for (link = static_cast<Link *>(listbase->first); link; link = link->next) {
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -503,11 +504,11 @@ int BLI_listbase_count(const ListBase *listbase)
|
|
|
|
|
|
|
|
|
|
void *BLI_findlink(const ListBase *listbase, int number)
|
|
|
|
|
{
|
|
|
|
|
Link *link = NULL;
|
|
|
|
|
Link *link = nullptr;
|
|
|
|
|
|
|
|
|
|
if (number >= 0) {
|
|
|
|
|
link = listbase->first;
|
|
|
|
|
while (link != NULL && number != 0) {
|
|
|
|
|
link = static_cast<Link *>(listbase->first);
|
|
|
|
|
while (link != nullptr && number != 0) {
|
|
|
|
|
number--;
|
|
|
|
|
link = link->next;
|
|
|
|
|
}
|
|
|
|
|
@@ -518,11 +519,11 @@ void *BLI_findlink(const ListBase *listbase, int number)
|
|
|
|
|
|
|
|
|
|
void *BLI_rfindlink(const ListBase *listbase, int number)
|
|
|
|
|
{
|
|
|
|
|
Link *link = NULL;
|
|
|
|
|
Link *link = nullptr;
|
|
|
|
|
|
|
|
|
|
if (number >= 0) {
|
|
|
|
|
link = listbase->last;
|
|
|
|
|
while (link != NULL && number != 0) {
|
|
|
|
|
link = static_cast<Link *>(listbase->last);
|
|
|
|
|
while (link != nullptr && number != 0) {
|
|
|
|
|
number--;
|
|
|
|
|
link = link->prev;
|
|
|
|
|
}
|
|
|
|
|
@@ -533,11 +534,11 @@ void *BLI_rfindlink(const ListBase *listbase, int number)
|
|
|
|
|
|
|
|
|
|
void *BLI_findlinkfrom(Link *start, int number)
|
|
|
|
|
{
|
|
|
|
|
Link *link = NULL;
|
|
|
|
|
Link *link = nullptr;
|
|
|
|
|
|
|
|
|
|
if (number >= 0) {
|
|
|
|
|
link = start;
|
|
|
|
|
while (link != NULL && number != 0) {
|
|
|
|
|
while (link != nullptr && number != 0) {
|
|
|
|
|
number--;
|
|
|
|
|
link = link->next;
|
|
|
|
|
}
|
|
|
|
|
@@ -548,14 +549,14 @@ void *BLI_findlinkfrom(Link *start, int number)
|
|
|
|
|
|
|
|
|
|
int BLI_findindex(const ListBase *listbase, const void *vlink)
|
|
|
|
|
{
|
|
|
|
|
Link *link = NULL;
|
|
|
|
|
Link *link = nullptr;
|
|
|
|
|
int number = 0;
|
|
|
|
|
|
|
|
|
|
if (vlink == NULL) {
|
|
|
|
|
if (vlink == nullptr) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
link = listbase->first;
|
|
|
|
|
link = static_cast<Link *>(listbase->first);
|
|
|
|
|
while (link) {
|
|
|
|
|
if (link == vlink) {
|
|
|
|
|
return number;
|
|
|
|
|
@@ -570,14 +571,14 @@ int BLI_findindex(const ListBase *listbase, const void *vlink)
|
|
|
|
|
|
|
|
|
|
void *BLI_findstring(const ListBase *listbase, const char *id, const int offset)
|
|
|
|
|
{
|
|
|
|
|
Link *link = NULL;
|
|
|
|
|
Link *link = nullptr;
|
|
|
|
|
const char *id_iter;
|
|
|
|
|
|
|
|
|
|
if (id == NULL) {
|
|
|
|
|
return NULL;
|
|
|
|
|
if (id == nullptr) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (link = listbase->first; link; link = link->next) {
|
|
|
|
|
for (link = static_cast<Link *>(listbase->first); link; link = link->next) {
|
|
|
|
|
id_iter = ((const char *)link) + offset;
|
|
|
|
|
|
|
|
|
|
if (id[0] == id_iter[0] && STREQ(id, id_iter)) {
|
|
|
|
|
@@ -585,16 +586,16 @@ void *BLI_findstring(const ListBase *listbase, const char *id, const int offset)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
void *BLI_rfindstring(const ListBase *listbase, const char *id, const int offset)
|
|
|
|
|
{
|
|
|
|
|
/* Same as #BLI_findstring but find reverse. */
|
|
|
|
|
|
|
|
|
|
Link *link = NULL;
|
|
|
|
|
Link *link = nullptr;
|
|
|
|
|
const char *id_iter;
|
|
|
|
|
|
|
|
|
|
for (link = listbase->last; link; link = link->prev) {
|
|
|
|
|
for (link = static_cast<Link *>(listbase->last); link; link = link->prev) {
|
|
|
|
|
id_iter = ((const char *)link) + offset;
|
|
|
|
|
|
|
|
|
|
if (id[0] == id_iter[0] && STREQ(id, id_iter)) {
|
|
|
|
|
@@ -602,15 +603,15 @@ void *BLI_rfindstring(const ListBase *listbase, const char *id, const int offset
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *BLI_findstring_ptr(const ListBase *listbase, const char *id, const int offset)
|
|
|
|
|
{
|
|
|
|
|
Link *link = NULL;
|
|
|
|
|
Link *link = nullptr;
|
|
|
|
|
const char *id_iter;
|
|
|
|
|
|
|
|
|
|
for (link = listbase->first; link; link = link->next) {
|
|
|
|
|
for (link = static_cast<Link *>(listbase->first); link; link = link->next) {
|
|
|
|
|
/* exact copy of BLI_findstring(), except for this line */
|
|
|
|
|
id_iter = *((const char **)(((const char *)link) + offset));
|
|
|
|
|
|
|
|
|
|
@@ -619,16 +620,16 @@ void *BLI_findstring_ptr(const ListBase *listbase, const char *id, const int off
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
void *BLI_rfindstring_ptr(const ListBase *listbase, const char *id, const int offset)
|
|
|
|
|
{
|
|
|
|
|
/* Same as #BLI_findstring_ptr but find reverse. */
|
|
|
|
|
|
|
|
|
|
Link *link = NULL;
|
|
|
|
|
Link *link = nullptr;
|
|
|
|
|
const char *id_iter;
|
|
|
|
|
|
|
|
|
|
for (link = listbase->last; link; link = link->prev) {
|
|
|
|
|
for (link = static_cast<Link *>(listbase->last); link; link = link->prev) {
|
|
|
|
|
/* exact copy of BLI_rfindstring(), except for this line */
|
|
|
|
|
id_iter = *((const char **)(((const char *)link) + offset));
|
|
|
|
|
|
|
|
|
|
@@ -637,15 +638,15 @@ void *BLI_rfindstring_ptr(const ListBase *listbase, const char *id, const int of
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *BLI_findptr(const ListBase *listbase, const void *ptr, const int offset)
|
|
|
|
|
{
|
|
|
|
|
Link *link = NULL;
|
|
|
|
|
Link *link = nullptr;
|
|
|
|
|
const void *ptr_iter;
|
|
|
|
|
|
|
|
|
|
for (link = listbase->first; link; link = link->next) {
|
|
|
|
|
for (link = static_cast<Link *>(listbase->first); link; link = link->next) {
|
|
|
|
|
/* exact copy of BLI_findstring(), except for this line */
|
|
|
|
|
ptr_iter = *((const void **)(((const char *)link) + offset));
|
|
|
|
|
|
|
|
|
|
@@ -654,16 +655,16 @@ void *BLI_findptr(const ListBase *listbase, const void *ptr, const int offset)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
void *BLI_rfindptr(const ListBase *listbase, const void *ptr, const int offset)
|
|
|
|
|
{
|
|
|
|
|
/* Same as #BLI_findptr but find reverse. */
|
|
|
|
|
|
|
|
|
|
Link *link = NULL;
|
|
|
|
|
Link *link = nullptr;
|
|
|
|
|
const void *ptr_iter;
|
|
|
|
|
|
|
|
|
|
for (link = listbase->last; link; link = link->prev) {
|
|
|
|
|
for (link = static_cast<Link *>(listbase->last); link; link = link->prev) {
|
|
|
|
|
/* exact copy of BLI_rfindstring(), except for this line */
|
|
|
|
|
ptr_iter = *((const void **)(((const char *)link) + offset));
|
|
|
|
|
|
|
|
|
|
@@ -672,7 +673,7 @@ void *BLI_rfindptr(const ListBase *listbase, const void *ptr, const int offset)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *BLI_listbase_bytes_find(const ListBase *listbase,
|
|
|
|
|
@@ -680,10 +681,10 @@ void *BLI_listbase_bytes_find(const ListBase *listbase,
|
|
|
|
|
const size_t bytes_size,
|
|
|
|
|
const int offset)
|
|
|
|
|
{
|
|
|
|
|
Link *link = NULL;
|
|
|
|
|
Link *link = nullptr;
|
|
|
|
|
const void *ptr_iter;
|
|
|
|
|
|
|
|
|
|
for (link = listbase->first; link; link = link->next) {
|
|
|
|
|
for (link = static_cast<Link *>(listbase->first); link; link = link->next) {
|
|
|
|
|
ptr_iter = (const void *)(((const char *)link) + offset);
|
|
|
|
|
|
|
|
|
|
if (memcmp(bytes, ptr_iter, bytes_size) == 0) {
|
|
|
|
|
@@ -691,7 +692,7 @@ void *BLI_listbase_bytes_find(const ListBase *listbase,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
void *BLI_listbase_bytes_rfind(const ListBase *listbase,
|
|
|
|
|
const void *bytes,
|
|
|
|
|
@@ -700,10 +701,10 @@ void *BLI_listbase_bytes_rfind(const ListBase *listbase,
|
|
|
|
|
{
|
|
|
|
|
/* Same as #BLI_listbase_bytes_find but find reverse. */
|
|
|
|
|
|
|
|
|
|
Link *link = NULL;
|
|
|
|
|
Link *link = nullptr;
|
|
|
|
|
const void *ptr_iter;
|
|
|
|
|
|
|
|
|
|
for (link = listbase->last; link; link = link->prev) {
|
|
|
|
|
for (link = static_cast<Link *>(listbase->last); link; link = link->prev) {
|
|
|
|
|
ptr_iter = (const void *)(((const char *)link) + offset);
|
|
|
|
|
|
|
|
|
|
if (memcmp(bytes, ptr_iter, bytes_size) == 0) {
|
|
|
|
|
@@ -711,7 +712,7 @@ void *BLI_listbase_bytes_rfind(const ListBase *listbase,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *BLI_listbase_string_or_index_find(const ListBase *listbase,
|
|
|
|
|
@@ -719,12 +720,13 @@ void *BLI_listbase_string_or_index_find(const ListBase *listbase,
|
|
|
|
|
const size_t string_offset,
|
|
|
|
|
const int index)
|
|
|
|
|
{
|
|
|
|
|
Link *link = NULL;
|
|
|
|
|
Link *link_at_index = NULL;
|
|
|
|
|
Link *link = nullptr;
|
|
|
|
|
Link *link_at_index = nullptr;
|
|
|
|
|
|
|
|
|
|
int index_iter;
|
|
|
|
|
for (link = listbase->first, index_iter = 0; link; link = link->next, index_iter++) {
|
|
|
|
|
if (string != NULL && string[0] != '\0') {
|
|
|
|
|
for (link = static_cast<Link *>(listbase->first), index_iter = 0; link;
|
|
|
|
|
link = link->next, index_iter++) {
|
|
|
|
|
if (string != nullptr && string[0] != '\0') {
|
|
|
|
|
const char *string_iter = ((const char *)link) + string_offset;
|
|
|
|
|
|
|
|
|
|
if (string[0] == string_iter[0] && STREQ(string, string_iter)) {
|
|
|
|
|
@@ -740,11 +742,11 @@ void *BLI_listbase_string_or_index_find(const ListBase *listbase,
|
|
|
|
|
|
|
|
|
|
int BLI_findstringindex(const ListBase *listbase, const char *id, const int offset)
|
|
|
|
|
{
|
|
|
|
|
Link *link = NULL;
|
|
|
|
|
Link *link = nullptr;
|
|
|
|
|
const char *id_iter;
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
link = listbase->first;
|
|
|
|
|
link = static_cast<Link *>(listbase->first);
|
|
|
|
|
while (link) {
|
|
|
|
|
id_iter = ((const char *)link) + offset;
|
|
|
|
|
|
|
|
|
|
@@ -761,17 +763,17 @@ int BLI_findstringindex(const ListBase *listbase, const char *id, const int offs
|
|
|
|
|
ListBase BLI_listbase_from_link(Link *some_link)
|
|
|
|
|
{
|
|
|
|
|
ListBase list = {some_link, some_link};
|
|
|
|
|
if (some_link == NULL) {
|
|
|
|
|
if (some_link == nullptr) {
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Find the first element. */
|
|
|
|
|
while (((Link *)list.first)->prev != NULL) {
|
|
|
|
|
while (((Link *)list.first)->prev != nullptr) {
|
|
|
|
|
list.first = ((Link *)list.first)->prev;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Find the last element. */
|
|
|
|
|
while (((Link *)list.last)->next != NULL) {
|
|
|
|
|
while (((Link *)list.last)->next != nullptr) {
|
|
|
|
|
list.last = ((Link *)list.last)->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -783,11 +785,11 @@ void BLI_duplicatelist(ListBase *dst, const ListBase *src)
|
|
|
|
|
struct Link *dst_link, *src_link;
|
|
|
|
|
|
|
|
|
|
/* in this order, to ensure it works if dst == src */
|
|
|
|
|
src_link = src->first;
|
|
|
|
|
dst->first = dst->last = NULL;
|
|
|
|
|
src_link = static_cast<Link *>(src->first);
|
|
|
|
|
dst->first = dst->last = nullptr;
|
|
|
|
|
|
|
|
|
|
while (src_link) {
|
|
|
|
|
dst_link = MEM_dupallocN(src_link);
|
|
|
|
|
dst_link = static_cast<Link *>(MEM_dupallocN(src_link));
|
|
|
|
|
BLI_addtail(dst, dst_link);
|
|
|
|
|
|
|
|
|
|
src_link = src_link->next;
|
|
|
|
|
@@ -796,9 +798,9 @@ void BLI_duplicatelist(ListBase *dst, const ListBase *src)
|
|
|
|
|
|
|
|
|
|
void BLI_listbase_reverse(ListBase *lb)
|
|
|
|
|
{
|
|
|
|
|
struct Link *curr = lb->first;
|
|
|
|
|
struct Link *prev = NULL;
|
|
|
|
|
struct Link *next = NULL;
|
|
|
|
|
struct Link *curr = static_cast<Link *>(lb->first);
|
|
|
|
|
struct Link *prev = nullptr;
|
|
|
|
|
struct Link *next = nullptr;
|
|
|
|
|
while (curr) {
|
|
|
|
|
next = curr->next;
|
|
|
|
|
curr->next = prev;
|
|
|
|
|
@@ -808,7 +810,7 @@ void BLI_listbase_reverse(ListBase *lb)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* swap first/last */
|
|
|
|
|
curr = lb->first;
|
|
|
|
|
curr = static_cast<Link *>(lb->first);
|
|
|
|
|
lb->first = lb->last;
|
|
|
|
|
lb->last = curr;
|
|
|
|
|
}
|
|
|
|
|
@@ -816,39 +818,39 @@ void BLI_listbase_reverse(ListBase *lb)
|
|
|
|
|
void BLI_listbase_rotate_first(ListBase *lb, void *vlink)
|
|
|
|
|
{
|
|
|
|
|
/* make circular */
|
|
|
|
|
((Link *)lb->first)->prev = lb->last;
|
|
|
|
|
((Link *)lb->last)->next = lb->first;
|
|
|
|
|
((Link *)lb->first)->prev = static_cast<Link *>(lb->last);
|
|
|
|
|
((Link *)lb->last)->next = static_cast<Link *>(lb->first);
|
|
|
|
|
|
|
|
|
|
lb->first = vlink;
|
|
|
|
|
lb->last = ((Link *)vlink)->prev;
|
|
|
|
|
|
|
|
|
|
((Link *)lb->first)->prev = NULL;
|
|
|
|
|
((Link *)lb->last)->next = NULL;
|
|
|
|
|
((Link *)lb->first)->prev = nullptr;
|
|
|
|
|
((Link *)lb->last)->next = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BLI_listbase_rotate_last(ListBase *lb, void *vlink)
|
|
|
|
|
{
|
|
|
|
|
/* make circular */
|
|
|
|
|
((Link *)lb->first)->prev = lb->last;
|
|
|
|
|
((Link *)lb->last)->next = lb->first;
|
|
|
|
|
((Link *)lb->first)->prev = static_cast<Link *>(lb->last);
|
|
|
|
|
((Link *)lb->last)->next = static_cast<Link *>(lb->first);
|
|
|
|
|
|
|
|
|
|
lb->first = ((Link *)vlink)->next;
|
|
|
|
|
lb->last = vlink;
|
|
|
|
|
|
|
|
|
|
((Link *)lb->first)->prev = NULL;
|
|
|
|
|
((Link *)lb->last)->next = NULL;
|
|
|
|
|
((Link *)lb->first)->prev = nullptr;
|
|
|
|
|
((Link *)lb->last)->next = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LinkData *BLI_genericNodeN(void *data)
|
|
|
|
|
{
|
|
|
|
|
LinkData *ld;
|
|
|
|
|
|
|
|
|
|
if (data == NULL) {
|
|
|
|
|
return NULL;
|
|
|
|
|
if (data == nullptr) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* create new link, and make it hold the given data */
|
|
|
|
|
ld = MEM_callocN(sizeof(LinkData), __func__);
|
|
|
|
|
ld = MEM_cnew<LinkData>(__func__);
|
|
|
|
|
ld->data = data;
|
|
|
|
|
|
|
|
|
|
return ld;
|