Automatically set parent family in individual, when adding child to the family.
[familia.git] / src / storage / family.h
1 /****************************************************************************
2  *  Familia Lignum - Genealogical program                                   *
3  *  Copyright (C) 2011-2012 Rafał Długołęcki <rafal@dlugolecki.net.pl>      *
4  *                                                                          *
5  *  This program is free software; you can redistribute it and/or modify    *
6  *  it under the terms of the GNU General Public License as published by    *
7  *  the Free Software Foundation; version 2 of the License.                 *
8  *                                                                          *
9  *  This program is distributed in the hope that it will be useful,         *
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
12  *  GNU General Public License for more details.                            *
13  *                                                                          *
14  *  You should have received a copy of the GNU General Public License along *
15  *  with this program; if not, write to the Free Software Foundation, Inc., *
16  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.             *
17  *                                                                          *
18  ****************************************************************************/
19
20 #ifndef _FAMILIA_FAMILY_H
21 #define _FAMILIA_FAMILY_H
22
23 #include "individual.h"
24
25 enum FFamilyIndividualIndex {
26         Individual1,
27         Individual2
28 };
29
30 /**
31  * Structure holding family data.
32  */
33 struct familia_family {
34         /** Marriage identifier */
35         unsigned int id;
36
37         /** First individual of family */
38         struct familia_individual * individual1;
39
40         /** Second individual of family */
41         struct familia_individual * individual2;
42
43         /** Children of this family */
44         struct familia_individual ** children;
45
46         /** Number of children of this family */
47         unsigned short children_no;
48 };
49
50 /**
51  * Creates new family structure
52  * @return Newly allocated individual.If allocation failed, returns NULL, like
53  *         malloc.
54  */
55 struct familia_family * familia_family_new();
56
57 /**
58  * Frees allocated memory of the given family
59  * DISCLAIMER! This function does not free memory of linked individuals. You have to
60  * remove them manually from storage.
61  * @parameter individual free
62  */
63 void familia_family_free(struct familia_family * family);
64
65 /**
66  * Sets individual1 in the given family
67  * @parameter family to set the individual
68  * @parameter individual which will be set
69  */
70 void familia_family_set_individual(struct familia_family * family, struct familia_individual * individual, enum FFamilyIndividualIndex index);
71
72 /**
73  * Gets individual from the given family
74  * @parameter family to get the individual
75  * @parameter individual index of which individual get
76  */
77 struct familia_individual * familia_family_get_individual(struct familia_family * family, enum FFamilyIndividualIndex index);
78
79 /**
80  * Removes individual from the given family
81  * DISCLAIMER! This function does not free memory of linked individuals. You have to
82  * remove them manually from storage.
83  * @parameter family to remove the individual
84  * @parameter individual index of which individual to remove
85  * @return returns removed individual, NULL if such does not exist.
86  */
87 struct familia_individual * familia_family_remove_individual(struct familia_family * family, enum FFamilyIndividualIndex index);
88
89 /**
90  * Adds new child in the given family
91  * Automatically sets family as parents in individual variable.
92  *
93  * @parameter family to set the individual
94  * @parameter individual which will be added
95  */
96 void familia_family_add_child(struct familia_family * family, struct familia_individual * individual);
97
98 /**
99  * Gets the nth child from the given family
100  * Child with index = 0 is the oldest. Bigger the index, the child is younger
101  * @parameter family to get the child
102  * @parameter individual index of which individual get
103  * @return selected child. If index is bigger than child_no of the family
104  *         returns NULL.
105  */
106 struct familia_individual * familia_family_get_child_by_id(struct familia_family * family, unsigned short index);
107
108 /**
109  * Removes child from the given family
110  * DISCLAIMER! This function does not free memory of linked children. You have to
111  * remove them manually from storage.
112  * @parameter family to remove the child
113  * @parameter index of which child should be removed
114  * @return removed child. If such does not exist or index is bigger than child_no
115  *         of the family, returns NULL.
116  */
117 struct familia_individual * familia_family_remove_child_by_id(struct familia_family * family, unsigned short index);
118
119 #endif /*_FAMILIA_FAMILY_H */