More generic use of event.
[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 /**
26  * @file storage/family.h
27  * @brief Code for managing families.
28  *
29  */
30
31 enum FFamilyIndividualIndex {
32         Individual1,
33         Individual2
34 };
35
36 /**
37  * Structure holding family data.
38  */
39 struct familia_family {
40         /** Marriage identifier */
41         unsigned int id;
42
43         /** First individual of family */
44         struct familia_individual * individual1;
45
46         /** Second individual of family */
47         struct familia_individual * individual2;
48
49         /** Children of this family */
50         struct familia_individual ** children;
51
52         /** Number of children of this family */
53         unsigned short children_no;
54 };
55
56 /**
57  * Creates new family structure.
58  * @return Newly allocated @ref familia_family. If allocation failed, returns NULL, like
59  *         malloc.
60  */
61 struct familia_family * familia_family_new();
62
63 /**
64  * Frees allocated memory of the given family.
65  * @attention This function does not free memory of linked individuals. You have to
66  * remove them manually from @ref familia_storage, by using @ref familia_storage_free.
67  * @param family family to free
68  */
69 void familia_family_free(struct familia_family * family);
70
71 /**
72  * Sets parent in the given family.
73  * @param family family to set the parent
74  * @param individual individual which will be a parent in family
75  * @param index individual type which will be set
76  */
77 void familia_family_set_parent(struct familia_family * family, struct familia_individual * individual, enum FFamilyIndividualIndex index);
78
79 /**
80  * Gets parent from the given family.
81  * @param family family to get the individual
82  * @param index individual index of which individual get
83  */
84 struct familia_individual * familia_family_get_parent(struct familia_family * family, enum FFamilyIndividualIndex index);
85
86 /**
87  * Removes parent from the given family
88  * @attention This function does not free memory of linked individuals. You have to
89  * remove them manually from @ref familia_storage, by using @ref familia_storage_free.
90  * @param family family to remove the individual
91  * @param index individual index of which individual to remove
92  * @return returns removed individual, NULL if such does not exist.
93  */
94 struct familia_individual * familia_family_remove_parent(struct familia_family * family, enum FFamilyIndividualIndex index);
95
96 /**
97  * Adds new child in the given family
98  * Automatically sets family as parents in individual variable.
99  *
100  * @param family family to set the individual
101  * @param individual individual which will be added
102  */
103 void familia_family_add_child(struct familia_family * family, struct familia_individual * individual);
104
105 /**
106  * Gets the nth child from the given family
107  * Child with index = 0 is the oldest. Bigger the index, the child is younger
108  * @param family family to get the child
109  * @param index individual index of which individual get
110  * @return selected child. If index is bigger than child_no of the family
111  *         returns NULL.
112  */
113 struct familia_individual * familia_family_get_child_by_id(struct familia_family * family, unsigned short index);
114
115 /**
116  * Removes child from the given family
117  * @attention This function does not free memory of linked children. You have to
118  * remove them manually from @ref familia_storage, by using @ref familia_storage_free.
119  * @param family family to remove the child
120  * @param index index of which child should be removed
121  * @return removed child. If such does not exist or index is bigger than child_no
122  *         of the family, returns NULL.
123  */
124 struct familia_individual * familia_family_remove_child_by_id(struct familia_family * family, unsigned short index);
125
126 #endif /*_FAMILIA_FAMILY_H */