Base du bâtiment

This commit is contained in:
Antoine Bartuccio 2018-06-06 03:00:35 +02:00
parent 0fd63b47dd
commit 00eebf97f2
Signed by: klmp200
GPG Key ID: E7245548C53F904B
7 changed files with 74 additions and 1 deletions

View File

@ -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; i<ELEVATOR_NB; i++)
DELETE(this->elevators[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; i<ELEVATOR_NB; i++)
new_building->elevators[i] = NEW(Elevator);
LINK_ALL(Building, new_building,
get_elevators
)
return new_building;
}

View File

@ -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

View File

@ -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;
}

View File

@ -9,6 +9,9 @@
typedef struct o_CommunicationBox {
DESTRUCTOR(CommunicationBox);
} CommunicationBox;
CommunicationBox *_init_CommunicationBox();
#endif //LO41_COMMUNICATIONBOX_H

View File

@ -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;
}

View File

@ -9,6 +9,9 @@
typedef struct o_Elevator {
DESTRUCTOR(Elevator);
} Elevator;
Elevator *_init_Elevator();
#endif //LO41_ELEVATOR_H

5
main.c
View File

@ -1,6 +1,7 @@
#include <stdio.h>
#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;
}