diff --git a/Building/Building.c b/Building/Building.c index c7b0b9b..d57756e 100644 --- a/Building/Building.c +++ b/Building/Building.c @@ -2,3 +2,35 @@ // Created by Antoine Bartuccio on 05/06/2018. // #include "Building.h" + +GETTER(Building, Elevator **, elevators) + +void _free__Building(THIS(Building)){ + int i = 0; + DELETE(this->residents); + DELETE(this->box); + for (i=0; ielevators[i]); + free(this->elevators); + + free(this); +} + +Building *_init_Building(){ + Building * new_building = malloc_or_die(sizeof(Building)); + int i; + + new_building->floors = FLOORS; + new_building->elevators = malloc_or_die(sizeof(Elevator*) * ELEVATOR_NB); + new_building->residents = NEW(List); + new_building->box = NEW(CommunicationBox); + for (i=0; ielevators[i] = NEW(Elevator); + + + LINK_ALL(Building, new_building, + get_elevators + ) + + return new_building; +} \ No newline at end of file diff --git a/Building/Building.h b/Building/Building.h index f0af2a6..6f34488 100644 --- a/Building/Building.h +++ b/Building/Building.h @@ -6,6 +6,7 @@ #define LO41_BUILDING_H #define ELEVATOR_NB 3 +#define FLOORS 10 #include "../Objects.h" #include "../List/List.h" @@ -16,8 +17,13 @@ typedef struct o_Building { int floors; List * residents; CommunicationBox * box; - Elevator elevators[ELEVATOR_NB]; + Elevator ** elevators; + + SYNCHRONIZE Elevator ** (*get_elevators)(_THIS(Building)); + + DESTRUCTOR(Building); } Building; +Building *_init_Building(); #endif //LO41_BUILDING_H diff --git a/CommunicationBox/CommunicationBox.c b/CommunicationBox/CommunicationBox.c index 1fc7b63..e712b2f 100644 --- a/CommunicationBox/CommunicationBox.c +++ b/CommunicationBox/CommunicationBox.c @@ -3,3 +3,15 @@ // #include "CommunicationBox.h" + +void _free__CommunicationBox(THIS(CommunicationBox)){ + free(this); +} + +CommunicationBox *_init_CommunicationBox(){ + CommunicationBox * new_box = malloc_or_die(sizeof(CommunicationBox)); + + LINK(CommunicationBox, new_box, _free_); + + return new_box; +} \ No newline at end of file diff --git a/CommunicationBox/CommunicationBox.h b/CommunicationBox/CommunicationBox.h index ed572b9..dbc378b 100644 --- a/CommunicationBox/CommunicationBox.h +++ b/CommunicationBox/CommunicationBox.h @@ -9,6 +9,9 @@ typedef struct o_CommunicationBox { + DESTRUCTOR(CommunicationBox); } CommunicationBox; +CommunicationBox *_init_CommunicationBox(); + #endif //LO41_COMMUNICATIONBOX_H diff --git a/Elevator/Elevator.c b/Elevator/Elevator.c index c7d1ce5..50ab7d5 100644 --- a/Elevator/Elevator.c +++ b/Elevator/Elevator.c @@ -3,3 +3,15 @@ // #include "Elevator.h" + +void _free__Elevator(THIS(Elevator)){ + free(this); +} + +Elevator *_init_Elevator(){ + Elevator * new_elevator = malloc_or_die(sizeof(Elevator)); + + LINK(Elevator, new_elevator, _free_); + + return new_elevator; +} \ No newline at end of file diff --git a/Elevator/Elevator.h b/Elevator/Elevator.h index 84f11d4..c7b51f8 100644 --- a/Elevator/Elevator.h +++ b/Elevator/Elevator.h @@ -9,6 +9,9 @@ typedef struct o_Elevator { + DESTRUCTOR(Elevator); } Elevator; +Elevator *_init_Elevator(); + #endif //LO41_ELEVATOR_H diff --git a/main.c b/main.c index 861e44b..5d322aa 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,7 @@ #include #include "Objects.h" #include "List/List.h" +#include "Building/Building.h" int main() { List *l = NEW(List); @@ -22,6 +23,10 @@ int main() { printf("La taille est de %d\n", l->get_size(l)); DELETE(l); + Building *main_building = NEW(Building); + printf("Il y a %d étages dans l'immeuble\n", main_building->floors); + DELETE(main_building); + printf("Hello, World!\n"); return 0; } \ No newline at end of file