From 338b1e4b2fd96379fa007962949fa99a7e070cd6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Sun, 12 Jan 2014 01:32:35 +0100 Subject: [PATCH] Added parents to the individual structure and children to family structure. --- INSTALL | 4 +- doc/model.dia | Bin 2701 -> 2729 bytes src/storage/family.c | 77 +++++++++++++++++++++++++++++++++++++-- src/storage/family.h | 45 ++++++++++++++++++++--- src/storage/individual.c | 15 ++++++++ src/storage/individual.h | 33 +++++++++++++++-- 6 files changed, 161 insertions(+), 13 deletions(-) diff --git a/INSTALL b/INSTALL index 007e939..2099840 100644 --- 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 diff --git a/doc/model.dia b/doc/model.dia index 2e8dd4bf96e5844884c5eef5370b4fc89e3305bd..5490dcd0428e17321f3afea9b88f09f31ec504f1 100644 GIT binary patch literal 2729 zcmV;a3Rd+WiwFP!000021MOYgZsRx-eebUj+;5G9(bba1lOD|Wps@|i?kq4f&ju~g zHn(NbOVLUEG7tN2`(H~+@Ai!OHJlz}+0L$S!BiY(SSMg92G%Pi8K2u~=BAA1JU zdm4!Y7Sed~*!%O3ulHW>r_UdL3@QFW{!BQYY4VCVQJ)@rQz7O*JUl!r_1_e7D-!oF!Bi5zBe0NJTyB zeXC4fDv^ca$>)zh+aI$gD`u zqupM~n&k9XQqr8Q?<5E5&YfW(!`bb6dE%&&FdFR&;IjQVoY?4NY03oO3N=I3%Gq zrt+2ySS(}(N#mB_k-SzK@orNNEz4)AbTOZEk|e|RKa$QxG3j(;A?KLRM6K4h6FXIO z%jyWaT$l1&v#Sn0b38w_Hw~rWu{7slFvX>rc0JG9dcFE{B@Ly!O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KQEKA37sez>1J4CKd*6?GRvXEw4Y>^wxg4|#Z8Uxy`G2MtN`hsfLj)cuHZkQlTr|fB1TYXoZ zf|X^5`{4K13UH=S+ukfcTf~CSX(*?W9;IyNs;ZEUg{&4`ET>oX-d6`_y)e2+FN`kH z3!^@JVboVI94A<*Gb~I+a&r1SHpA3W;N4irQ2eHQ%R;`QS{V*%2u;k0z{fJ_5tVCj zGnKfQ4l^5_ZMi+ge540b`I8GukcUxdCSsIHSNB1>nl1Xd7OL16Wk11sA@o}&(XG}P&j zL65))7)qwMwicvK(Rej&;5oO?Gwj;%i1$TnJ?JbV0Msa+^} z5-VD6kDU_0-y=iX?w%0+CC8*U_pr;q$nyn=(P|>>n-&ekXCOWU@fnEEKzs(`GZ3GF z_zc8nAU*@}8HmrPaL2yB09Erk31Ywkdta=}uP?y51kVA_0sdr%{K=omoFoxR!sS*D z+9-0+Uh5omC+N&cIcOc38DwN2UFD!19|c)XT1tM?2wSZQ_Y}2}X*$kXMHLX~9V9)i zQ|!A%0b#pZgzchyp5quod&&^U1>c~fZf*oY)}x5W5lHv)=Q8j>YEEtXC4Uln?s};<=4_^kDbaGJ0lWn862MCUF9Ey+@DjjF051W& z1n?5TO8_rVfnc6F84tgaB|Ji{i|0G7k88?zX3=J+CPNZ)$F@Cf!P~%$wrvd9XrxI`y=aYjrBI1dVq{ww^ zIEl15XA_QRTDB%6((@q$4jJ$l$bh$y11WGwfkO%$Qs9sRhZH!Zz##<=DexCdffr<< z^ra4d-p5?hK7E246(Cvn_H*DX=Ncvq9uERu1S#+9J}%wR;aE>N))S8PgkwG5^0A(q z+c9)x>b>4}a%&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; } diff --git a/src/storage/family.h b/src/storage/family.h index d369167..a8dc2fd 100644 --- a/src/storage/family.h +++ b/src/storage/family.h @@ -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 */ diff --git a/src/storage/individual.c b/src/storage/individual.c index 6293ce8..5e55bb6 100644 --- a/src/storage/individual.c +++ b/src/storage/individual.c @@ -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; +} diff --git a/src/storage/individual.h b/src/storage/individual.h index cd4d448..87045c1 100644 --- a/src/storage/individual.h +++ b/src/storage/individual.h @@ -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 */ -- 2.30.2