2018-06-04 22:26:48 +00:00
|
|
|
//
|
|
|
|
// Created by Antoine Bartuccio on 22/05/2018.
|
|
|
|
//
|
|
|
|
#include "List.h"
|
|
|
|
|
|
|
|
GETTER(List, Element*, head)
|
|
|
|
GETTER(List, Element*, tail)
|
|
|
|
GETTER(List, int, size)
|
|
|
|
|
|
|
|
void $_free__List(THIS(List)){
|
2018-06-05 11:43:45 +00:00
|
|
|
this->clear(this);
|
2018-06-04 22:26:48 +00:00
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
|
2018-06-05 11:43:45 +00:00
|
|
|
void clear_List(THIS(List)){
|
|
|
|
Element * el = this->head;
|
|
|
|
Element * el_tmp;
|
|
|
|
while (el != NULL){
|
|
|
|
el->list = NULL;
|
|
|
|
el_tmp = el;
|
|
|
|
el = el_tmp->next;
|
|
|
|
DELETE(el_tmp);
|
|
|
|
}
|
|
|
|
this->size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void remove_head_List(THIS(List)){
|
|
|
|
DELETE(this->head);
|
|
|
|
}
|
|
|
|
|
|
|
|
void remove_tail_List(THIS(List)){
|
|
|
|
DELETE(this->tail);
|
|
|
|
}
|
|
|
|
|
2018-06-04 22:26:48 +00:00
|
|
|
List *$_init_List(){
|
|
|
|
List *l = (List*) malloc_or_die(sizeof(List));
|
|
|
|
l->size = 0;
|
|
|
|
l->head = NULL;
|
|
|
|
l->tail = NULL;
|
|
|
|
|
2018-06-05 11:43:45 +00:00
|
|
|
LINK_ALL(List, l,
|
|
|
|
get_head,
|
|
|
|
get_tail,
|
|
|
|
get_size,
|
|
|
|
clear,
|
|
|
|
remove_head,
|
|
|
|
remove_tail
|
|
|
|
)
|
2018-06-04 22:26:48 +00:00
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|