mirror of
https://gitlab.com/klmp200/LO41.git
synced 2024-11-22 08:43:22 +00:00
Merge branch 'master' of gitlab.com:klmp200/LO41
This commit is contained in:
commit
0d7ebda7e0
@ -8,4 +8,4 @@ if(CMAKE_COMPILER_IS_GNUCC)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
|
||||
endif()
|
||||
|
||||
add_executable(LO41 main.c List/List.h List/List.c Objects.h List/Element.c List/Element.h Objects.c Building/Building.c Building/Building.h Elevator/Elevator.c Elevator/Elevator.h SharedData/SharedData.c SharedData/SharedData.h Visitor/Visitor.c Visitor/Visitor.h Resident/Resident.c Resident/Resident.h Passenger/Passenger.h)
|
||||
add_executable(LO41 main.c List/List.h List/List.c Objects.h List/Element.c List/Element.h Objects.c Building/Building.c Building/Building.h Elevator/Elevator.c Elevator/Elevator.h SharedData/SharedData.c SharedData/SharedData.h Visitor/Visitor.c Visitor/Visitor.h Resident/Resident.c Resident/Resident.h Passenger/Passenger.h Passenger/Passenger.c)
|
55
Passenger/Passenger.c
Normal file
55
Passenger/Passenger.c
Normal file
@ -0,0 +1,55 @@
|
||||
//
|
||||
// Created by Antoine Bartuccio on 20/06/2018.
|
||||
//
|
||||
|
||||
#include "Passenger.h"
|
||||
|
||||
int get_id_Passenger(THIS(Passenger)){
|
||||
if (this->type == RESIDENT)
|
||||
return this->resident->get_id(this->resident);
|
||||
if (this->type == VISITOR)
|
||||
return this->visitor->get_id(this->visitor);
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *get_name_Passenger(THIS(Passenger)){
|
||||
if (this->type == RESIDENT)
|
||||
return this->resident->get_name(this->resident);
|
||||
if (this->type == VISITOR)
|
||||
return this->visitor->get_name(this->visitor);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *runnable_Passenger(void * void_this){
|
||||
Passenger *this = (Passenger*) void_this;
|
||||
if (this->type == RESIDENT)
|
||||
this->resident->runnable((void*)this->resident);
|
||||
if (this->type == VISITOR)
|
||||
this->visitor->runnable((void*)this->visitor);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void _free__Passenger(THIS(Passenger)){
|
||||
free(this);
|
||||
}
|
||||
|
||||
Passenger *_init_Passenger(void *passenger, PASSENGER_TYPE type){
|
||||
Passenger * new_passenger = malloc_or_die(sizeof(Passenger));
|
||||
|
||||
new_passenger->resident = NULL;
|
||||
new_passenger->visitor = NULL;
|
||||
new_passenger->type = type;
|
||||
if (type == RESIDENT)
|
||||
new_passenger->resident = (Resident*) passenger;
|
||||
|
||||
if (type == VISITOR)
|
||||
new_passenger->visitor = (Visitor*) passenger;
|
||||
|
||||
LINK_ALL(Passenger, new_passenger,
|
||||
get_id,
|
||||
get_name,
|
||||
runnable
|
||||
)
|
||||
|
||||
return new_passenger;
|
||||
}
|
@ -10,12 +10,20 @@
|
||||
|
||||
typedef enum {RESIDENT, VISITOR} PASSENGER_TYPE;
|
||||
|
||||
typedef struct s_Passenger {
|
||||
typedef struct o_Passenger {
|
||||
PASSENGER_TYPE type;
|
||||
union {
|
||||
Resident * resident;
|
||||
Visitor * visitor;
|
||||
};
|
||||
|
||||
PUBLIC char * (*get_name)(_THIS(Passenger));
|
||||
PUBLIC int (*get_id)(_THIS(Passenger));
|
||||
PUBLIC void * (*runnable)(void* void_this);
|
||||
|
||||
DESTRUCTOR(Passenger);
|
||||
} Passenger;
|
||||
|
||||
Passenger *_init_Passenger(void *passenger, PASSENGER_TYPE type);
|
||||
|
||||
#endif //LO41_PASSENGER_H
|
||||
|
Loading…
Reference in New Issue
Block a user