2018-06-20 16:19:49 +00:00
|
|
|
//
|
|
|
|
// Created by Antoine Bartuccio on 20/06/2018.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Passenger.h"
|
|
|
|
|
2018-06-20 17:36:00 +00:00
|
|
|
int compare_Passenger(void * passenger1, void * passenger2){
|
|
|
|
return (strcmp(((Passenger*) passenger1)->get_name((Passenger*) passenger1),
|
|
|
|
((Passenger*) passenger2)->get_name((Passenger*) passenger2)) == 0);
|
|
|
|
}
|
|
|
|
|
2018-06-20 20:06:45 +00:00
|
|
|
int get_destination_Passenger(THIS(Passenger)){
|
|
|
|
if (this->type == RESIDENT)
|
|
|
|
return this->resident->get_destination(this->resident);
|
|
|
|
if (this->type == VISITOR)
|
|
|
|
return this->visitor->get_destination(this->visitor);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-06-20 16:19:49 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-06-20 17:36:00 +00:00
|
|
|
Passenger *_init_Passenger(void* passenger_data, PASSENGER_TYPE type){
|
2018-06-20 16:19:49 +00:00
|
|
|
Passenger * new_passenger = malloc_or_die(sizeof(Passenger));
|
|
|
|
|
|
|
|
new_passenger->resident = NULL;
|
|
|
|
new_passenger->visitor = NULL;
|
|
|
|
new_passenger->type = type;
|
|
|
|
if (type == RESIDENT)
|
2018-06-20 17:36:00 +00:00
|
|
|
new_passenger->resident = (Resident*) passenger_data;
|
2018-06-20 16:19:49 +00:00
|
|
|
|
|
|
|
if (type == VISITOR)
|
2018-06-20 17:36:00 +00:00
|
|
|
new_passenger->visitor = (Visitor*) passenger_data;
|
2018-06-20 16:19:49 +00:00
|
|
|
|
2018-06-20 17:36:00 +00:00
|
|
|
//new_passenger->compare = compare_Passenger;
|
2018-06-20 16:19:49 +00:00
|
|
|
LINK_ALL(Passenger, new_passenger,
|
2018-06-20 20:06:45 +00:00
|
|
|
get_id,
|
|
|
|
get_name,
|
|
|
|
get_destination,
|
|
|
|
compare,
|
|
|
|
runnable
|
2018-06-20 16:19:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
return new_passenger;
|
2018-06-20 17:36:00 +00:00
|
|
|
}
|