forked from bartvdbraak/blender
reverse string lookup listbase function BLI_findstring counterparts, added BLI_rfindstring, BLI_rfindstring_ptr, these search from the end of the listbase (like pythons rfind).
This commit is contained in:
parent
6baa456dfd
commit
08d8914b3d
@ -619,24 +619,14 @@ void BKE_reset_undo(void)
|
||||
/* based on index nr it does a restore */
|
||||
void BKE_undo_number(bContext *C, int nr)
|
||||
{
|
||||
UndoElem *uel;
|
||||
int a=1;
|
||||
|
||||
for(uel= undobase.first; uel; uel= uel->next, a++) {
|
||||
if(a==nr) break;
|
||||
}
|
||||
curundo= uel;
|
||||
curundo= BLI_findlink(&undobase, nr - 1);
|
||||
BKE_undo_step(C, 0);
|
||||
}
|
||||
|
||||
/* go back to the last occurance of name in stack */
|
||||
void BKE_undo_name(bContext *C, const char *name)
|
||||
{
|
||||
UndoElem *uel;
|
||||
|
||||
for(uel= undobase.last; uel; uel= uel->prev)
|
||||
if(strcmp(name, uel->name)==0)
|
||||
break;
|
||||
UndoElem *uel= BLI_rfindstring(&undobase, name, offsetof(UndoElem, name));
|
||||
|
||||
if(uel && uel->prev) {
|
||||
curundo= uel->prev;
|
||||
@ -648,12 +638,7 @@ void BKE_undo_name(bContext *C, const char *name)
|
||||
int BKE_undo_valid(const char *name)
|
||||
{
|
||||
if(name) {
|
||||
UndoElem *uel;
|
||||
|
||||
for(uel= undobase.last; uel; uel= uel->prev)
|
||||
if(strcmp(name, uel->name)==0)
|
||||
break;
|
||||
|
||||
UndoElem *uel= BLI_rfindstring(&undobase, name, offsetof(UndoElem, name));
|
||||
return uel && uel->prev;
|
||||
}
|
||||
|
||||
|
@ -451,12 +451,10 @@ static int ctx_data_get(bContext *C, const char *member, bContextDataResult *res
|
||||
|
||||
C->data.recursion= 1;
|
||||
|
||||
for(entry=C->wm.store->entries.last; entry; entry=entry->prev) {
|
||||
if(strcmp(entry->name, member) == 0) {
|
||||
entry= BLI_rfindstring(&C->wm.store->entries, member, offsetof(bContextStoreEntry, name));
|
||||
if(entry) {
|
||||
result->ptr= entry->ptr;
|
||||
done= 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(done!=1 && recursion < 2 && C->wm.region) {
|
||||
|
@ -45,9 +45,16 @@ extern "C" {
|
||||
void BLI_insertlink(struct ListBase *listbase, void *vprevlink, void *vnewlink);
|
||||
void *BLI_findlink(const struct ListBase *listbase, int number);
|
||||
int BLI_findindex(const struct ListBase *listbase, void *vlink);
|
||||
int BLI_findstringindex(const struct ListBase *listbase, const char *id, const int offset);
|
||||
|
||||
/* find forwards */
|
||||
void *BLI_findstring(const struct ListBase *listbase, const char *id, const int offset);
|
||||
void *BLI_findstring_ptr(const struct ListBase *listbase, const char *id, const int offset);
|
||||
int BLI_findstringindex(const struct ListBase *listbase, const char *id, const int offset);
|
||||
|
||||
/* find backwards */
|
||||
void *BLI_rfindstring(const struct ListBase *listbase, const char *id, const int offset);
|
||||
void *BLI_rfindstring_ptr(const struct ListBase *listbase, const char *id, const int offset);
|
||||
|
||||
void BLI_freelistN(struct ListBase *listbase);
|
||||
void BLI_addtail(struct ListBase *listbase, void *vlink);
|
||||
void BLI_remlink(struct ListBase *listbase, void *vlink);
|
||||
|
@ -366,14 +366,30 @@ void *BLI_findstring(const ListBase *listbase, const char *id, const int offset)
|
||||
|
||||
if (listbase == NULL) return NULL;
|
||||
|
||||
link= listbase->first;
|
||||
while (link) {
|
||||
for (link= listbase->first; link; link= link->next) {
|
||||
id_iter= ((const char *)link) + offset;
|
||||
|
||||
if(id[0] == id_iter[0] && strcmp(id, id_iter)==0)
|
||||
if (id[0] == id_iter[0] && strcmp(id, id_iter)==0) {
|
||||
return link;
|
||||
}
|
||||
}
|
||||
|
||||
link= link->next;
|
||||
return NULL;
|
||||
}
|
||||
/* same as above but find reverse */
|
||||
void *BLI_rfindstring(const ListBase *listbase, const char *id, const int offset)
|
||||
{
|
||||
Link *link= NULL;
|
||||
const char *id_iter;
|
||||
|
||||
if (listbase == NULL) return NULL;
|
||||
|
||||
for (link= listbase->last; link; link= link->prev) {
|
||||
id_iter= ((const char *)link) + offset;
|
||||
|
||||
if (id[0] == id_iter[0] && strcmp(id, id_iter)==0) {
|
||||
return link;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -386,15 +402,32 @@ void *BLI_findstring_ptr(const ListBase *listbase, const char *id, const int off
|
||||
|
||||
if (listbase == NULL) return NULL;
|
||||
|
||||
link= listbase->first;
|
||||
while (link) {
|
||||
for (link= listbase->first; link; link= link->next) {
|
||||
/* exact copy of BLI_findstring(), except for this line */
|
||||
id_iter= *((const char **)(((const char *)link) + offset));
|
||||
|
||||
if(id[0] == id_iter[0] && strcmp(id, id_iter)==0)
|
||||
if (id[0] == id_iter[0] && strcmp(id, id_iter)==0) {
|
||||
return link;
|
||||
}
|
||||
}
|
||||
|
||||
link= link->next;
|
||||
return NULL;
|
||||
}
|
||||
/* same as above but find reverse */
|
||||
void *BLI_rfindstring_ptr(const ListBase *listbase, const char *id, const int offset)
|
||||
{
|
||||
Link *link= NULL;
|
||||
const char *id_iter;
|
||||
|
||||
if (listbase == NULL) return NULL;
|
||||
|
||||
for (link= listbase->last; link; link= link->prev) {
|
||||
/* exact copy of BLI_rfindstring(), except for this line */
|
||||
id_iter= *((const char **)(((const char *)link) + offset));
|
||||
|
||||
if (id[0] == id_iter[0] && strcmp(id, id_iter)==0) {
|
||||
return link;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -1919,14 +1919,7 @@ uiBlock *uiBeginBlock(const bContext *C, ARegion *region, const char *name, shor
|
||||
|
||||
uiBlock *uiGetBlock(const char *name, ARegion *ar)
|
||||
{
|
||||
uiBlock *block= ar->uiblocks.first;
|
||||
|
||||
while(block) {
|
||||
if( strcmp(name, block->name)==0 ) return block;
|
||||
block= block->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return BLI_findstring(&ar->uiblocks, name, offsetof(uiBlock, name));
|
||||
}
|
||||
|
||||
void uiBlockSetEmboss(uiBlock *block, char dt)
|
||||
|
Loading…
Reference in New Issue
Block a user