ui/common/types.c

branch
newapi
changeset 395
b8277deb75b8
parent 380
aad99285865c
equal deleted inserted replaced
394:bedd499b640d 395:b8277deb75b8
542 for (int i = 0; i < list.nfiles; i++) { 542 for (int i = 0; i < list.nfiles; i++) {
543 free(list.files[i]); 543 free(list.files[i]);
544 } 544 }
545 free(list.files); 545 free(list.files);
546 } 546 }
547
548
549 typedef struct UiObserverDestructor {
550 UiList *list;
551 UiObserver *observer;
552 } UiObserverDestructor;
553
554 static void observer_destructor(UiObserverDestructor *destr) {
555 UiObserver *remove_obs = destr->observer;
556 UiObserver *obs = destr->list->observers;
557 UiObserver *prev = NULL;
558 while(obs) {
559 if(obs == remove_obs) {
560 if(prev) {
561 prev->next = obs->next;
562 } else {
563 destr->list->observers = obs->next;
564 }
565 break;
566 }
567 prev = obs;
568 obs = obs->next;
569 }
570 free(remove_obs);
571 }
572
573 void uic_list_register_observer_destructor(UiContext *ctx, UiList *list, UiObserver *observer) {
574 CxMempool *mp = ctx->mp;
575 UiObserverDestructor *destr = cxMalloc(mp->allocator, sizeof(UiObserverDestructor));
576 destr->list = list;
577 destr->observer = observer;
578 cxMempoolSetDestructor(destr, (cx_destructor_func)observer_destructor);
579 }

mercurial