1 /***************************************************************************/
5 /* Generic list support for FreeType (body). */
7 /* Copyright 1996-2000 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */
16 /***************************************************************************/
18 /*************************************************************************/
20 /* This file implements functions relative to list processing. Its */
21 /* data structures are defined in `freetype/internal/ftlist.h'. */
23 /*************************************************************************/
26 #include <freetype/internal/ftlist.h>
27 #include <freetype/internal/ftdebug.h>
28 #include <freetype/internal/ftobjs.h>
31 /*************************************************************************/
33 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
34 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
35 /* messages during execution. */
38 #define FT_COMPONENT trace_list
41 /*************************************************************************/
47 /* Finds the list node for a given listed object. */
50 /* list :: A pointer to the parent list. */
51 /* data :: The address of the listed object. */
54 /* List node. NULL if it wasn't found. */
56 BASE_FUNC( FT_ListNode
) FT_List_Find( FT_List list
,
65 if ( cur
->data
== data
)
71 return (FT_ListNode
)0;
75 /*************************************************************************/
81 /* Appends an element to the end of a list. */
84 /* list :: A pointer to the parent list. */
85 /* node :: The node to append. */
87 BASE_FUNC( void ) FT_List_Add( FT_List list
,
90 FT_ListNode before
= list
->tail
;
105 /*************************************************************************/
111 /* Inserts an element at the head of a list. */
114 /* list :: A pointer to parent list. */
115 /* node :: The node to insert. */
117 BASE_FUNC( void ) FT_List_Insert( FT_List list
,
120 FT_ListNode after
= list
->head
;
135 /*************************************************************************/
141 /* Removes a node from a list. This function doesn't check whether */
142 /* the node is in the list! */
145 /* node :: The node to remove. */
148 /* list :: A pointer to the parent list. */
150 BASE_FUNC( void ) FT_List_Remove( FT_List list
,
153 FT_ListNode before
, after
;
160 before
->next
= after
;
165 after
->prev
= before
;
171 /*************************************************************************/
177 /* Moves a node to the head/top of a list. Used to maintain LRU */
181 /* list :: A pointer to the parent list. */
182 /* node :: The node to move. */
184 BASE_FUNC( void ) FT_List_Up( FT_List list
,
187 FT_ListNode before
, after
;
193 /* check whether we are already on top of the list */
197 before
->next
= after
;
200 after
->prev
= before
;
205 node
->next
= list
->head
;
206 list
->head
->prev
= node
;
211 /*************************************************************************/
214 /* FT_List_Iterate */
217 /* Parses a list and calls a given iterator function on each element. */
218 /* Note that parsing is stopped as soon as one of the iterator calls */
219 /* returns a non-zero value. */
222 /* list :: A handle to the list. */
223 /* iterator :: An interator function, called on each node of the */
225 /* user :: A user-supplied field which is passed as the second */
226 /* argument to the iterator. */
229 /* The result (a FreeType error code) of the last iterator call. */
231 BASE_FUNC( FT_Error
) FT_List_Iterate( FT_List list
,
232 FT_List_Iterator iterator
,
235 FT_ListNode cur
= list
->head
;
236 FT_Error error
= FT_Err_Ok
;
241 FT_ListNode next
= cur
->next
;
244 error
= iterator( cur
, user
);
255 /*************************************************************************/
258 /* FT_List_Finalize */
261 /* Destroys all elements in the list as well as the list itself. */
264 /* list :: A handle to the list. */
266 /* destroy :: A list destructor that will be applied to each element */
269 /* memory :: The current memory object which handles deallocation. */
271 /* user :: A user-supplied field which is passed as the last */
272 /* argument to the destructor. */
274 BASE_FUNC( void ) FT_List_Finalize( FT_List list
,
275 FT_List_Destructor destroy
,
285 FT_ListNode next
= cur
->next
;
286 void* data
= cur
->data
;
290 destroy( memory
, data
, user
);