mirror of
https://gitlab.com/klmp200/LO41.git
synced 2025-07-11 04:09:24 +00:00
On test les objets, attention, les listes ne sont pas fonctionelles
This commit is contained in:
37
List/Element.c
Normal file
37
List/Element.c
Normal file
@ -0,0 +1,37 @@
|
||||
//
|
||||
// Created by Antoine Bartuccio on 22/05/2018.
|
||||
//
|
||||
|
||||
#include <string.h>
|
||||
#include "List.h"
|
||||
|
||||
GETTER(Element, Element*, next)
|
||||
GETTER(Element, Element*, previous)
|
||||
GETTER(Element, void*, data)
|
||||
|
||||
void set_previous_Element(THIS(Element), Element *previous){
|
||||
this->previous = previous;
|
||||
}
|
||||
|
||||
void set_next_Element(THIS(Element), Element *next){
|
||||
this->next = next;
|
||||
}
|
||||
|
||||
void $_free__Element(THIS(Element)){
|
||||
free(this);
|
||||
}
|
||||
|
||||
Element *_init_element(void *data, size_t size, List *list){
|
||||
Element *el = (Element*) malloc_or_die(sizeof(Element));
|
||||
void *newData = malloc_or_die(sizeof(size));
|
||||
|
||||
memcpy(newData, data, size);
|
||||
el->list = list;
|
||||
el->data = newData;
|
||||
el->previous = NULL;
|
||||
el->next = NULL;
|
||||
|
||||
LINK_ALL(Element, el, get_next, get_previous, get_data, set_next, set_previous)
|
||||
|
||||
return el;
|
||||
}
|
30
List/Element.h
Normal file
30
List/Element.h
Normal file
@ -0,0 +1,30 @@
|
||||
//
|
||||
// Created by Antoine Bartuccio on 22/05/2018.
|
||||
//
|
||||
|
||||
#ifndef LO41_ELEMENT_H
|
||||
#define LO41_ELEMENT_H
|
||||
|
||||
typedef struct o_List List;
|
||||
|
||||
#include "List.h"
|
||||
|
||||
struct o_Element {
|
||||
List *list;
|
||||
void *data;
|
||||
struct o_Element *next;
|
||||
struct o_Element *previous;
|
||||
|
||||
struct o_Element *(*get_next)(O_THIS(Element));
|
||||
struct o_Element *(*get_previous)(O_THIS(Element));
|
||||
void *(*get_data)(O_THIS(Element));
|
||||
|
||||
void (*set_previous)(O_THIS(Element), struct o_Element *previous);
|
||||
void (*set_next)(O_THIS(Element), struct o_Element *next);
|
||||
|
||||
void (*$_free_)(O_THIS(Element));
|
||||
};
|
||||
|
||||
Element *$_init_Element(void *data, size_t size, List *list);
|
||||
|
||||
#endif //LO41_ELEMENT_H
|
23
List/List.c
Normal file
23
List/List.c
Normal file
@ -0,0 +1,23 @@
|
||||
//
|
||||
// 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)){
|
||||
free(this);
|
||||
}
|
||||
|
||||
List *$_init_List(){
|
||||
List *l = (List*) malloc_or_die(sizeof(List));
|
||||
l->size = 0;
|
||||
l->head = NULL;
|
||||
l->tail = NULL;
|
||||
|
||||
LINK_ALL(List, l, get_head, get_tail, get_size)
|
||||
return l;
|
||||
}
|
||||
|
29
List/List.h
Normal file
29
List/List.h
Normal file
@ -0,0 +1,29 @@
|
||||
//
|
||||
// Created by Antoine Bartuccio on 22/05/2018.
|
||||
//
|
||||
|
||||
#ifndef LO41_LIST_H
|
||||
#define LO41_LIST_H
|
||||
|
||||
#include "../Objects.h"
|
||||
|
||||
typedef struct o_Element Element;
|
||||
|
||||
#include "Element.h"
|
||||
|
||||
#define WRONG_ELEMENT CRASH("This element is not within the list\n")
|
||||
|
||||
struct o_List {
|
||||
Element *head;
|
||||
Element *tail;
|
||||
int size;
|
||||
|
||||
Element *(*get_head)(O_THIS(List));
|
||||
Element *(*get_tail)(O_THIS(List));
|
||||
int (*get_size)(O_THIS(List));
|
||||
void (*$_free_)(O_THIS(List));
|
||||
};
|
||||
|
||||
List *$_init_List();
|
||||
|
||||
#endif //LO41_LIST_H
|
Reference in New Issue
Block a user