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_parent(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_parent(struct familia_family * family, enum FFamilyIndividualIndex index)
61 struct familia_individual * individual = NULL;
65 individual = family->individual1;
68 individual = family->individual2;
75 struct familia_individual * familia_family_remove_parent(struct familia_family * family, enum FFamilyIndividualIndex index)
77 struct familia_individual * individual = NULL;
81 individual = family->individual1;
82 family->individual1 = NULL;
84 individual = family->individual2;
85 family->individual2 = NULL;
91 void familia_family_add_child(struct familia_family * family, struct familia_individual * individual)
93 struct familia_individual ** tmp = NULL;
94 int size = (family->children_no + 1);
96 tmp = realloc(family->children, size * sizeof(struct familia_individual *));
99 /* TODO: Add children by their age */
100 family->children = tmp;
101 family->children[family->children_no] = individual;
102 family->children_no++;
103 /* familia_individual_set_parents(individual, family);*/
106 debug("There were problems with allocating memory for family children.\n");
110 struct familia_individual * familia_family_get_child_by_id(struct familia_family * family, unsigned short index)
112 struct familia_individual * child = NULL;
114 if (index < family->children_no) {
115 child = family->children[index];
121 struct familia_individual * familia_family_remove_child_by_id(struct familia_family * family, unsigned short index)
123 struct familia_individual * child = NULL;
125 child = familia_family_get_child_by_id(family, index);
129 family->children[index] = NULL;
131 for (; i < family->children_no - 1; i++) {
132 family->children[i] = family->children[i + 1];
135 family->children[--(family->children_no)] = NULL;