OSDN Git Service

# fix typo
[ccunit/ccunit.git] / src / ccunit / CCUnitList.h
1 /* -*- mode: C; -*- */
2 /* Copyright (C) 2003 TSUTSUMI Kikuo.
3    This file is part of the CCUnit Library.
4
5    The CCUnit Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public License
7    as published by the Free Software Foundation; either version 2.1 of
8    the License, or (at your option) any later version.
9
10    The CCUnit Library is distributed in the hope that it will be
11    useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12    of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the CCUnit Library; see the file COPYING.LESSER.
17    If not, write to the Free Software Foundation, Inc., 59 Temple
18    Place - Suite 330, Boston, MA 02111-1307, USA.  
19 */
20
21 /*
22  * $Id$
23  */
24
25 /**
26  * @file
27  * Linked list module.
28  */
29 #ifndef CCUNITLIST_H
30 #define CCUNITLIST_H
31
32 #include <ccunit/CCUnitConfig.h>
33
34 /**
35  * @ingroup ModuleHierarchy
36  * @defgroup CCUnitList List
37  * Linked list container.
38  * @{
39  */
40
41 /**
42  * list container.
43  */
44 typedef struct CCUnitList
45 {
46   struct CCUnitListCell* head;          /**< first cell of a linked list */
47   struct CCUnitListCell** tailp;        /**< address of pointer to last cell*/
48   size_t length;                        /**< size of linked list */
49   bool isAllocated;                     /**< flag of allocated object */
50 } CCUnitList;
51
52 /**
53  * Create new list object.
54  * @return new list object.
55  */
56 extern inline CCUnitList* ccunit_newList ();
57
58 /**
59  * Add element to list object.
60  * @param list List object.
61  * @param contents A pointer to an object to register in the list.
62  */
63 extern void ccunit_addList (CCUnitList* list, void* contents);
64
65 /**
66  * Initialize list object.
67  * @param list initializing list.
68  * @return initialized list.
69  */
70 extern CCUnitList* ccunit_initList (CCUnitList* list);
71
72 /**
73  * Delete list object.
74  *
75  * @param list Deleting list.
76  * @param deleteContents A pointer to the function which the object
77  * registered in the list is deleted from.
78  */
79 extern void ccunit_deleteList (CCUnitList* list, void (*deleteContents)(void*));
80
81 /**
82  * @defgroup CCUnitListIterator ListIterator
83  * List iterator
84  * @{
85  */
86
87 /**
88  * list iterator.
89  */
90 typedef struct CCUnitListIterator
91 {
92   struct CCUnitListCell* current;               /**< current list cell  */
93   bool isAllocated;                             /**< flag of allocated object */
94 } CCUnitListIterator;
95
96 /**
97  * create new list iterator.
98  *
99  * @param list An owner list of iterator.
100  * @return New iterator.
101  */
102 extern CCUnitListIterator* ccunit_newListIterator (const struct CCUnitList* list);
103
104 /**
105  * initialize list iterator.
106  * @param list An owner list of iterator.
107  * @param it Iterator to initialize.
108  * @return Initialized iterator.
109  */
110 extern inline
111 CCUnitListIterator* ccunit_initListIterator (const struct CCUnitList* list,
112                                              struct CCUnitListIterator* it);
113
114 /**
115  * delete list iterator.
116  *
117  * @param it iterator to delete.
118  */
119 extern inline void ccunit_deleteListIterator (struct CCUnitListIterator* it);
120
121 /**
122  * Get next element.
123  * @param it An Iterator.
124  * @return pointer to next element object.
125  */
126 extern void* ccunit_nextListIterator (struct CCUnitListIterator* it);
127
128 /**
129  * Check is there next element of iterator.
130  * @param it An iterator.
131  * @return true if there is next element, or false.
132  */
133 extern bool ccunit_hasNextListIterator (struct CCUnitListIterator* it);
134
135 /** @}
136  * end group CCUnitListIterator
137  */
138
139 /** @}
140  * end group CCUnitList
141  */
142
143 #endif
144