Added parents to the individual structure and children to family structure.
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Sun, 12 Jan 2014 00:32:35 +0000 (01:32 +0100)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Sun, 12 Jan 2014 00:32:35 +0000 (01:32 +0100)
INSTALL
doc/model.dia
src/storage/family.c
src/storage/family.h
src/storage/individual.c
src/storage/individual.h

diff --git a/INSTALL b/INSTALL
index 007e9396d0a2492cd2d6e17d42f359655dfe0b5e..2099840756e6302d837dcd51b5dcd6262f7adb16 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -12,8 +12,8 @@ without warranty of any kind.
 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
index 2e8dd4bf96e5844884c5eef5370b4fc89e3305bd..5490dcd0428e17321f3afea9b88f09f31ec504f1 100644 (file)
Binary files a/doc/model.dia and b/doc/model.dia differ
index e08223cd2a15eebb684c1b340aa2f0549d9c2d21..f3806096d1f4923623e3e92ce1f2fc62927f7667 100644 (file)
@@ -18,6 +18,9 @@ struct familia_family * familia_family_new()
        family->individual1 = NULL;
        family->individual2 = NULL;
 
+       family->children = NULL;
+       family->children_no = 0;
+
        return family;
 }
 
@@ -26,6 +29,17 @@ void familia_family_free(struct familia_family * 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);
 }
 
@@ -43,21 +57,78 @@ void familia_family_set_individual(struct familia_family * family, struct famili
 
 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;
 }
index d3691673a6b17cfd98a02df4f0d923487c60d885..a8dc2fd95b4079443c75aa2ee255e9b3a37042d2 100644 (file)
@@ -17,8 +17,8 @@
  *                                                                          *
  ****************************************************************************/
 
-#ifndef _FAMILIA_MARRIAGE_H
-#define _FAMILIA_MARRIAGE_H
+#ifndef _FAMILIA_FAMILY_H
+#define _FAMILIA_FAMILY_H
 
 #include "individual.h"
 
@@ -39,6 +39,12 @@ struct familia_family {
 
        /** 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;
 };
 
 /**
@@ -50,7 +56,7 @@ struct familia_family * familia_family_new();
 
 /**
  * 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
  */
@@ -72,11 +78,40 @@ struct familia_individual * familia_family_get_individual(struct familia_family
 
 /**
  * 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 */
index 6293ce8cbbedf486754f217e2f1d995b1ec00229..5e55bb61a42889fabbd7a64e6f95e30cbb0592e3 100644 (file)
@@ -170,3 +170,18 @@ void familia_individual_remove_family_by_id(struct familia_individual * individu
                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;
+}
index cd4d448e675c7e914bb27c80a5e5456ef85c94af..87045c179bdefa3c9d28dfec75a1c46e5dcd099a 100644 (file)
@@ -40,6 +40,9 @@ struct familia_individual {
 
        /** Number of families */
        unsigned int families_no;
+
+       /** Parent family. Family this individual comes from. */
+       struct familia_family * parents;
 };
 
 /**
@@ -51,7 +54,7 @@ struct familia_individual * familia_individual_new();
 
 /**
  * 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
  */
@@ -96,17 +99,41 @@ void familia_individual_add_family(struct familia_individual * individual, struc
  * 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 */