More generic use of event.
[familia.git] / src / storage / individual.c
index 33a0a08c9f5e809b583e28092db013ed349ef0b5..f5a94df17e4b04895362c5662eb11a74b6e6da8c 100644 (file)
@@ -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