/src/freetype/src/cache/ftcmru.h

https://bitbucket.org/cabalistic/ogredeps/ · C++ Header · 246 lines · 149 code · 57 blank · 40 comment · 9 complexity · de359ab58a415fa87a5baeef94ae367a MD5 · raw file

  1. /***************************************************************************/
  2. /* */
  3. /* ftcmru.h */
  4. /* */
  5. /* Simple MRU list-cache (specification). */
  6. /* */
  7. /* Copyright 2000-2001, 2003, 2004, 2005, 2006, 2010 by */
  8. /* David Turner, Robert Wilhelm, and Werner Lemberg. */
  9. /* */
  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. */
  15. /* */
  16. /***************************************************************************/
  17. /*************************************************************************/
  18. /* */
  19. /* An MRU is a list that cannot hold more than a certain number of */
  20. /* elements (`max_elements'). All elements in the list are sorted in */
  21. /* least-recently-used order, i.e., the `oldest' element is at the tail */
  22. /* of the list. */
  23. /* */
  24. /* When doing a lookup (either through `Lookup()' or `Lookup_Node()'), */
  25. /* the list is searched for an element with the corresponding key. If */
  26. /* it is found, the element is moved to the head of the list and is */
  27. /* returned. */
  28. /* */
  29. /* If no corresponding element is found, the lookup routine will try to */
  30. /* obtain a new element with the relevant key. If the list is already */
  31. /* full, the oldest element from the list is discarded and replaced by a */
  32. /* new one; a new element is added to the list otherwise. */
  33. /* */
  34. /* Note that it is possible to pre-allocate the element list nodes. */
  35. /* This is handy if `max_elements' is sufficiently small, as it saves */
  36. /* allocations/releases during the lookup process. */
  37. /* */
  38. /*************************************************************************/
  39. #ifndef __FTCMRU_H__
  40. #define __FTCMRU_H__
  41. #include <ft2build.h>
  42. #include FT_FREETYPE_H
  43. #ifdef FREETYPE_H
  44. #error "freetype.h of FreeType 1 has been loaded!"
  45. #error "Please fix the directory search order for header files"
  46. #error "so that freetype.h of FreeType 2 is found first."
  47. #endif
  48. #define xxFT_DEBUG_ERROR
  49. #define FTC_INLINE
  50. FT_BEGIN_HEADER
  51. typedef struct FTC_MruNodeRec_* FTC_MruNode;
  52. typedef struct FTC_MruNodeRec_
  53. {
  54. FTC_MruNode next;
  55. FTC_MruNode prev;
  56. } FTC_MruNodeRec;
  57. FT_LOCAL( void )
  58. FTC_MruNode_Prepend( FTC_MruNode *plist,
  59. FTC_MruNode node );
  60. FT_LOCAL( void )
  61. FTC_MruNode_Up( FTC_MruNode *plist,
  62. FTC_MruNode node );
  63. FT_LOCAL( void )
  64. FTC_MruNode_Remove( FTC_MruNode *plist,
  65. FTC_MruNode node );
  66. typedef struct FTC_MruListRec_* FTC_MruList;
  67. typedef struct FTC_MruListClassRec_ const * FTC_MruListClass;
  68. typedef FT_Bool
  69. (*FTC_MruNode_CompareFunc)( FTC_MruNode node,
  70. FT_Pointer key );
  71. typedef FT_Error
  72. (*FTC_MruNode_InitFunc)( FTC_MruNode node,
  73. FT_Pointer key,
  74. FT_Pointer data );
  75. typedef FT_Error
  76. (*FTC_MruNode_ResetFunc)( FTC_MruNode node,
  77. FT_Pointer key,
  78. FT_Pointer data );
  79. typedef void
  80. (*FTC_MruNode_DoneFunc)( FTC_MruNode node,
  81. FT_Pointer data );
  82. typedef struct FTC_MruListClassRec_
  83. {
  84. FT_Offset node_size;
  85. FTC_MruNode_CompareFunc node_compare;
  86. FTC_MruNode_InitFunc node_init;
  87. FTC_MruNode_ResetFunc node_reset;
  88. FTC_MruNode_DoneFunc node_done;
  89. } FTC_MruListClassRec;
  90. typedef struct FTC_MruListRec_
  91. {
  92. FT_UInt num_nodes;
  93. FT_UInt max_nodes;
  94. FTC_MruNode nodes;
  95. FT_Pointer data;
  96. FTC_MruListClassRec clazz;
  97. FT_Memory memory;
  98. } FTC_MruListRec;
  99. FT_LOCAL( void )
  100. FTC_MruList_Init( FTC_MruList list,
  101. FTC_MruListClass clazz,
  102. FT_UInt max_nodes,
  103. FT_Pointer data,
  104. FT_Memory memory );
  105. FT_LOCAL( void )
  106. FTC_MruList_Reset( FTC_MruList list );
  107. FT_LOCAL( void )
  108. FTC_MruList_Done( FTC_MruList list );
  109. FT_LOCAL( FT_Error )
  110. FTC_MruList_New( FTC_MruList list,
  111. FT_Pointer key,
  112. FTC_MruNode *anode );
  113. FT_LOCAL( void )
  114. FTC_MruList_Remove( FTC_MruList list,
  115. FTC_MruNode node );
  116. FT_LOCAL( void )
  117. FTC_MruList_RemoveSelection( FTC_MruList list,
  118. FTC_MruNode_CompareFunc selection,
  119. FT_Pointer key );
  120. #ifdef FTC_INLINE
  121. #define FTC_MRULIST_LOOKUP_CMP( list, key, compare, node, error ) \
  122. FT_BEGIN_STMNT \
  123. FTC_MruNode* _pfirst = &(list)->nodes; \
  124. FTC_MruNode_CompareFunc _compare = (FTC_MruNode_CompareFunc)(compare); \
  125. FTC_MruNode _first, _node; \
  126. \
  127. \
  128. error = FTC_Err_Ok; \
  129. _first = *(_pfirst); \
  130. _node = NULL; \
  131. \
  132. if ( _first ) \
  133. { \
  134. _node = _first; \
  135. do \
  136. { \
  137. if ( _compare( _node, (key) ) ) \
  138. { \
  139. if ( _node != _first ) \
  140. FTC_MruNode_Up( _pfirst, _node ); \
  141. \
  142. node = _node; \
  143. goto _MruOk; \
  144. } \
  145. _node = _node->next; \
  146. \
  147. } while ( _node != _first) ; \
  148. } \
  149. \
  150. error = FTC_MruList_New( (list), (key), (FTC_MruNode*)(void*)&(node) ); \
  151. _MruOk: \
  152. ; \
  153. FT_END_STMNT
  154. #define FTC_MRULIST_LOOKUP( list, key, node, error ) \
  155. FTC_MRULIST_LOOKUP_CMP( list, key, (list)->clazz.node_compare, node, error )
  156. #else /* !FTC_INLINE */
  157. FT_LOCAL( FTC_MruNode )
  158. FTC_MruList_Find( FTC_MruList list,
  159. FT_Pointer key );
  160. FT_LOCAL( FT_Error )
  161. FTC_MruList_Lookup( FTC_MruList list,
  162. FT_Pointer key,
  163. FTC_MruNode *pnode );
  164. #define FTC_MRULIST_LOOKUP( list, key, node, error ) \
  165. error = FTC_MruList_Lookup( (list), (key), (FTC_MruNode*)&(node) )
  166. #endif /* !FTC_INLINE */
  167. #define FTC_MRULIST_LOOP( list, node ) \
  168. FT_BEGIN_STMNT \
  169. FTC_MruNode _first = (list)->nodes; \
  170. \
  171. \
  172. if ( _first ) \
  173. { \
  174. FTC_MruNode _node = _first; \
  175. \
  176. \
  177. do \
  178. { \
  179. *(FTC_MruNode*)&(node) = _node;
  180. #define FTC_MRULIST_LOOP_END() \
  181. _node = _node->next; \
  182. \
  183. } while ( _node != _first ); \
  184. } \
  185. FT_END_STMNT
  186. /* */
  187. FT_END_HEADER
  188. #endif /* __FTCMRU_H__ */
  189. /* END */