4 #include "individual.h"
8 struct familia_family * familia_family_new()
10 struct familia_family * family = NULL;
11 family = malloc(sizeof(struct familia_family));
14 debug("["__FILE__ "] There was a problem with allocating memory for family.\n");
19 family->individual1 = NULL;
20 family->individual2 = NULL;
22 family->children = NULL;
23 family->children_no = 0;
28 void familia_family_free(struct familia_family * family)
30 family->individual1 = NULL;
31 family->individual2 = NULL;
33 if (family->children) {
35 /* Remove all children links. */
36 for (; i < family->children_no; i++) {
37 family->children[i] = NULL;
39 free(family->children);
40 family->children = NULL;
41 family->children_no = 0;
47 void familia_family_set_individual(struct familia_family * family, struct familia_individual * individual, enum FFamilyIndividualIndex index)
51 family->individual1 = individual;
54 family->individual2 = individual;
59 struct familia_individual * familia_family_get_individual(struct familia_family * family, enum FFamilyIndividualIndex index)
61 struct familia_individual * individual = NULL;
65 individual = family->individual1;
67 individual = family->individual2;
73 struct familia_individual * familia_family_remove_individual(struct familia_family * family, enum FFamilyIndividualIndex index)
75 struct familia_individual * individual = NULL;
79 individual = family->individual1;
80 family->individual1 = NULL;
82 individual = family->individual2;
83 family->individual2 = NULL;
89 void familia_family_add_child(struct familia_family * family, struct familia_individual * individual)
91 struct familia_individual ** tmp = NULL;
92 int size = (family->children_no + 1);
94 tmp = realloc(family->children, size * sizeof(struct familia_individual *));
97 /* TODO: Add children by their age */
98 family->children = tmp;
99 family->children[family->children_no] = individual;
100 family->children_no++;
101 familia_individual_set_parents(individual, family);
104 debug("There were problems with allocating memory for family children.\n");
108 struct familia_individual * familia_family_get_child_by_id(struct familia_family * family, unsigned short index)
110 struct familia_individual * child = NULL;
112 if (index < family->children_no) {
113 child = family->children[index];
119 struct familia_individual * familia_family_remove_child_by_id(struct familia_family * family, unsigned short index)
121 struct familia_individual * child = NULL;
123 child = familia_family_get_child_by_id(family, index);
127 family->children[index] = NULL;
129 for (; i < family->children_no - 1; i++) {
130 family->children[i] = family->children[i + 1];
133 family->children[--(family->children_no)] = NULL;