Basic Installation
==================
- Briefly, the shell commands `./configure; make; make install' should
-configure, build, and install this package. The following
+ Briefly, the shell command `./configure && make && make install'
+should configure, build, and install this package. The following
more-detailed instructions are generic; see the `README' file for
instructions specific to this package. Some packages provide this
`INSTALL' file but do not implement all of the features documented
family->individual1 = NULL;
family->individual2 = NULL;
+ family->children = NULL;
+ family->children_no = 0;
+
return family;
}
family->individual1 = NULL;
family->individual2 = NULL;
+ if (family->children) {
+ int i = 0;
+ /* Remove all children links. */
+ for (; i < family->children_no; i++) {
+ family->children[i] = NULL;
+ }
+ free(family->children);
+ family->children = NULL;
+ family->children_no = 0;
+ }
+
free(family);
}
struct familia_individual * familia_family_get_individual(struct familia_family * family, enum FFamilyIndividualIndex index)
{
+ struct familia_individual * individual = NULL;
+
switch (index) {
case Individual1:
- return family->individual1;
+ individual = family->individual1;
case Individual2:
- return family->individual2;
+ individual = family->individual2;
}
- return NULL;
+
+ return individual;
}
struct familia_individual * familia_family_remove_individual(struct familia_family * family, enum FFamilyIndividualIndex index)
{
+ struct familia_individual * individual = NULL;
+
switch (index) {
case Individual1:
+ individual = family->individual1;
family->individual1 = NULL;
case Individual2:
+ individual = family->individual2;
family->individual2 = NULL;
}
+
+ return individual;
+}
+
+void familia_family_add_child(struct familia_family * family, struct familia_individual * individual)
+{
+ struct familia_individual ** tmp = NULL;
+ int size = (family->children_no + 1);
+
+ tmp = realloc(family->children, size * sizeof(struct familia_individual *));
+
+ if (tmp) {
+ family->children = tmp;
+ family->children[family->children_no] = individual;
+ family->children_no++;
+ }
+ else {
+ debug("There were problems with allocating memory for family children.\n");
+ }
+}
+
+struct familia_individual * familia_family_get_child_by_id(struct familia_family * family, unsigned short index)
+{
+ struct familia_individual * child = NULL;
+
+ if (index < family->children_no) {
+ child = family->children[index];
+ }
+
+ return child;
+}
+
+struct familia_individual * familia_family_remove_child_by_id(struct familia_family * family, unsigned short index)
+{
+ struct familia_individual * child = NULL;
+
+ child = familia_family_get_child_by_id(family, index);
+
+ if (child) {
+ int i = index;
+ family->children[index] = NULL;
+
+ for (; i < family->children_no - 1; i++) {
+ family->children[i] = family->children[i + 1];
+ }
+
+ family->children[--(family->children_no)] = NULL;
+ }
+
+ return child;
}
* *
****************************************************************************/
-#ifndef _FAMILIA_MARRIAGE_H
-#define _FAMILIA_MARRIAGE_H
+#ifndef _FAMILIA_FAMILY_H
+#define _FAMILIA_FAMILY_H
#include "individual.h"
/** Second individual of family */
struct familia_individual * individual2;
+
+ /** Children of this family */
+ struct familia_individual ** children;
+
+ /** Number of children of this family */
+ unsigned short children_no;
};
/**
/**
* Frees allocated memory of the given family
- * DISCLAIMER! This function does not remove linked individuals. You have to
+ * DISCLAIMER! This function does not free memory of linked individuals. You have to
* remove them manually from storage.
* @parameter individual free
*/
/**
* Removes individual from the given family
- * DISCLAIMER! This function does not remove linked individuals. You have to
+ * DISCLAIMER! This function does not free memory of linked individuals. You have to
* remove them manually from storage.
* @parameter family to remove the individual
* @parameter individual index of which individual to remove
+ * @return returns removed individual, NULL if such does not exist.
*/
struct familia_individual * familia_family_remove_individual(struct familia_family * family, enum FFamilyIndividualIndex index);
-#endif /*_FAMILIA_MARRIAGE_H */
+/**
+ * Adds new child in the given family
+ * @parameter family to set the individual
+ * @parameter individual which will be added
+ */
+void familia_family_add_child(struct familia_family * family, struct familia_individual * individual);
+
+/**
+ * Gets the nth child from the given family
+ * Child with index = 0 is the oldest. Bigger the index, the child is younger
+ * @parameter family to get the child
+ * @parameter individual index of which individual get
+ * @return selected child. If index is bigger than child_no of the family
+ * returns NULL.
+ */
+struct familia_individual * familia_family_get_child_by_id(struct familia_family * family, unsigned short index);
+
+/**
+ * Removes child from the given family
+ * DISCLAIMER! This function does not free memory of linked children. You have to
+ * remove them manually from storage.
+ * @parameter family to remove the child
+ * @parameter index of which child should be removed
+ * @return removed child. If such does not exist or index is bigger than child_no
+ * of the family, returns NULL.
+ */
+struct familia_individual * familia_family_remove_child_by_id(struct familia_family * family, unsigned short index);
+
+#endif /*_FAMILIA_FAMILY_H */
individual->families_no--;
}
}
+
+void familia_individual_set_parents(struct familia_individual * individual, struct familia_family * family)
+{
+ individual->parents = family;
+}
+
+struct familia_family * familia_individual_get_parents(struct familia_individual * individual)
+{
+ return individual->parents;
+}
+
+void familia_individual_remove_parents(struct familia_individual * individual)
+{
+ individual->parents = NULL;
+}
/** Number of families */
unsigned int families_no;
+
+ /** Parent family. Family this individual comes from. */
+ struct familia_family * parents;
};
/**
/**
* Frees allocated memory of the given individual
- * DISCLAIMER! This function does not remove linked families. You have to
+ * DISCLAIMER! This function does not free memory of linked families. You have to
* remove them manually from storage.
* @parameter individual to free
*/
* Gets family with the given id of the given individual
* @parameter individual from whom get the family
* @parameter family id of the individual
- * @return individuals last name
+ * @return selected family or NULL if such does not exists or index is out of
+ * array bounds
*/
struct familia_family * familia_individual_get_family_by_id(struct familia_individual * individual, unsigned int id);
/**
* Removes family with the given id from the given individual
- * DISCLAIMER! This function does not remove linked families. You have to
+ * DISCLAIMER! This function does not free memory of linked families. You have to
* remove them manually from storage.
* @parameter individual from whom family will be removed
* @parameter family id of the individual
*/
void familia_individual_remove_family_by_id(struct familia_individual * individual, unsigned int id);
+/**
+ * Sets parents family of the given individual
+ * @parameter individual to set parents
+ * @parameter parents to set
+ */
+void familia_individual_set_parents(struct familia_individual * individual, struct familia_family * family);
+
+/**
+ * Gets family with the given id of the given individual
+ * @parameter individual from whom get the family
+ * @parameter family id of the individual
+ * @return individuals last name
+ */
+struct familia_family * familia_individual_get_parents(struct familia_individual * individual);
+
+/**
+ * Removes parents from the given individual
+ * DISCLAIMER! This function does not free memory of linked family. You have to
+ * remove them manually from storage.
+ * @parameter individual from whom parents will be removed
+ */
+void familia_individual_remove_parents(struct familia_individual * individual);
+
#endif /*_FAMILIA_INDIVIDUAL_H */