X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=src%2Fstorage%2Findividual.c;h=f5a94df17e4b04895362c5662eb11a74b6e6da8c;hb=d82f06ff5e5b5cef51709d4618779772931e5e90;hp=33a0a08c9f5e809b583e28092db013ed349ef0b5;hpb=961bbb87dca7f5406440d32c06dfc7552044e08a;p=familia.git diff --git a/src/storage/individual.c b/src/storage/individual.c index 33a0a08..f5a94df 100644 --- a/src/storage/individual.c +++ b/src/storage/individual.c @@ -21,6 +21,7 @@ struct familia_individual * familia_individual_new() individual->families = NULL; individual->families_no = 0; individual->parents = NULL; + individual->birth = NULL; return individual; } @@ -53,6 +54,11 @@ void familia_individual_free(struct familia_individual * individual) individual->parents = NULL; } + if (individual->birth) { + free(individual->birth); + individual->birth = NULL; + } + free(individual); } @@ -190,3 +196,33 @@ void familia_individual_remove_parents(struct familia_individual * individual) { individual->parents = NULL; } + +int familia_individual_nth_child_of_family(struct familia_individual * individual, struct familia_family * family) +{ + unsigned int i; + unsigned int children_no = family->children_no; + + for (i = 0; i < children_no; i++) { + if (family->children[i]->id == individual->id) { + return i; + } + } + + return -1; +} + +void familia_individual_set_birth_date(struct familia_individual * individual, struct date_value dv) +{ + /* TODO: Add multiple birth dates (in case there are many different sources) */ + if (!individual->birth) { + struct date_value * date = NULL; + date = gedcom_new_date_value(NULL); + + /* Just copy parsed date_value to newly allocated variable... */ + memcpy(date, &dv, sizeof(struct date_value)); + individual->birth = date; + } + else { + fprintf(stderr, "> Date has been already set, ignoring new one: %s\n", gedcom_date_to_string(&dv)); + } +} \ No newline at end of file