1 /****************************************************************************
2 * Familia Lignum - Genealogical program *
3 * Copyright (C) 2011-2012 Rafał Długołęcki <rafal@dlugolecki.net.pl> *
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. *
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. *
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. *
18 ****************************************************************************/
20 #ifndef _FAMILIA_FAMILY_H
21 #define _FAMILIA_FAMILY_H
23 #include "individual.h"
26 * @file storage/family.h
27 * @brief Code for managing families.
31 enum FFamilyIndividualIndex {
37 * Structure holding family data.
39 struct familia_family {
40 /** Marriage identifier */
43 /** First individual of family */
44 struct familia_individual * individual1;
46 /** Second individual of family */
47 struct familia_individual * individual2;
49 /** Children of this family */
50 struct familia_individual ** children;
52 /** Number of children of this family */
53 unsigned short children_no;
57 * Creates new family structure.
58 * @return Newly allocated @ref familia_family. If allocation failed, returns NULL, like
61 struct familia_family * familia_family_new();
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
69 void familia_family_free(struct familia_family * family);
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
77 void familia_family_set_parent(struct familia_family * family, struct familia_individual * individual, enum FFamilyIndividualIndex index);
80 * Gets parent from the given family.
81 * @param family family to get the individual
82 * @param index individual index of which individual get
84 struct familia_individual * familia_family_get_parent(struct familia_family * family, enum FFamilyIndividualIndex index);
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.
94 struct familia_individual * familia_family_remove_parent(struct familia_family * family, enum FFamilyIndividualIndex index);
97 * Adds new child in the given family
98 * Automatically sets family as parents in individual variable.
100 * @param family family to set the individual
101 * @param individual individual which will be added
103 void familia_family_add_child(struct familia_family * family, struct familia_individual * individual);
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
113 struct familia_individual * familia_family_get_child_by_id(struct familia_family * family, unsigned short index);
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.
124 struct familia_individual * familia_family_remove_child_by_id(struct familia_family * family, unsigned short index);
126 #endif /*_FAMILIA_FAMILY_H */