1 /***************************************************************************/
5 /* FreeType MRU support (body). */
7 /* Copyright 2003, 2004, 2006, 2009 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 /***************************************************************************/
22 #include FT_INTERNAL_OBJECTS_H
23 #include FT_INTERNAL_DEBUG_H
29 FTC_MruNode_Prepend( FTC_MruNode
*plist
,
32 FTC_MruNode first
= *plist
;
37 FTC_MruNode last
= first
->prev
;
42 FTC_MruNode cnode
= first
;
49 fprintf( stderr
, "FTC_MruNode_Prepend: invalid action\n" );
54 } while ( cnode
!= first
);
73 FTC_MruNode_Up( FTC_MruNode
*plist
,
76 FTC_MruNode first
= *plist
;
79 FT_ASSERT( first
!= NULL
);
83 FTC_MruNode prev
, next
, last
;
88 FTC_MruNode cnode
= first
;
95 } while ( cnode
!= first
);
97 fprintf( stderr
, "FTC_MruNode_Up: invalid action\n" );
122 FTC_MruNode_Remove( FTC_MruNode
*plist
,
125 FTC_MruNode first
= *plist
;
126 FTC_MruNode prev
, next
;
129 FT_ASSERT( first
!= NULL
);
131 #ifdef FT_DEBUG_ERROR
133 FTC_MruNode cnode
= first
;
142 } while ( cnode
!= first
);
144 fprintf( stderr
, "FTC_MruNode_Remove: invalid action\n" );
158 FT_ASSERT( first
== node
);
159 FT_ASSERT( prev
== node
);
163 else if ( node
== first
)
169 FTC_MruList_Init( FTC_MruList list
,
170 FTC_MruListClass clazz
,
176 list
->max_nodes
= max_nodes
;
178 list
->clazz
= *clazz
;
180 list
->memory
= memory
;
185 FTC_MruList_Reset( FTC_MruList list
)
187 while ( list
->nodes
)
188 FTC_MruList_Remove( list
, list
->nodes
);
190 FT_ASSERT( list
->num_nodes
== 0 );
195 FTC_MruList_Done( FTC_MruList list
)
197 FTC_MruList_Reset( list
);
202 FT_LOCAL_DEF( FTC_MruNode
)
203 FTC_MruList_Find( FTC_MruList list
,
206 FTC_MruNode_CompareFunc compare
= list
->clazz
.node_compare
;
207 FTC_MruNode first
, node
;
218 if ( compare( node
, key
) )
221 FTC_MruNode_Up( &list
->nodes
, node
);
228 } while ( node
!= first
);
235 FT_LOCAL_DEF( FT_Error
)
236 FTC_MruList_New( FTC_MruList list
,
242 FT_Memory memory
= list
->memory
;
245 if ( list
->num_nodes
>= list
->max_nodes
&& list
->max_nodes
> 0 )
247 node
= list
->nodes
->prev
;
251 if ( list
->clazz
.node_reset
)
253 FTC_MruNode_Up( &list
->nodes
, node
);
255 error
= list
->clazz
.node_reset( node
, key
, list
->data
);
260 FTC_MruNode_Remove( &list
->nodes
, node
);
263 if ( list
->clazz
.node_done
)
264 list
->clazz
.node_done( node
, list
->data
);
266 else if ( FT_ALLOC( node
, list
->clazz
.node_size
) )
269 error
= list
->clazz
.node_init( node
, key
, list
->data
);
273 FTC_MruNode_Prepend( &list
->nodes
, node
);
281 if ( list
->clazz
.node_done
)
282 list
->clazz
.node_done( node
, list
->data
);
290 FT_LOCAL_DEF( FT_Error
)
291 FTC_MruList_Lookup( FTC_MruList list
,
298 node
= FTC_MruList_Find( list
, key
);
300 return FTC_MruList_New( list
, key
, anode
);
305 #endif /* FTC_INLINE */
308 FTC_MruList_Remove( FTC_MruList list
,
311 FTC_MruNode_Remove( &list
->nodes
, node
);
315 FT_Memory memory
= list
->memory
;
318 if ( list
->clazz
.node_done
)
319 list
->clazz
.node_done( node
, list
->data
);
327 FTC_MruList_RemoveSelection( FTC_MruList list
,
328 FTC_MruNode_CompareFunc selection
,
331 FTC_MruNode first
, node
, next
;
335 while ( first
&& ( selection
== NULL
|| selection( first
, key
) ) )
337 FTC_MruList_Remove( list
, first
);
344 while ( node
!= first
)
348 if ( selection( node
, key
) )
349 FTC_MruList_Remove( list
, node
);