ReactOS  0.4.14-dev-384-g5b37caa
ftcmru.h
Go to the documentation of this file.
1 /***************************************************************************/
2 /* */
3 /* ftcmru.h */
4 /* */
5 /* Simple MRU list-cache (specification). */
6 /* */
7 /* Copyright 2000-2018 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  /*************************************************************************/
20  /* */
21  /* An MRU is a list that cannot hold more than a certain number of */
22  /* elements (`max_elements'). All elements in the list are sorted in */
23  /* least-recently-used order, i.e., the `oldest' element is at the tail */
24  /* of the list. */
25  /* */
26  /* When doing a lookup (either through `Lookup()' or `Lookup_Node()'), */
27  /* the list is searched for an element with the corresponding key. If */
28  /* it is found, the element is moved to the head of the list and is */
29  /* returned. */
30  /* */
31  /* If no corresponding element is found, the lookup routine will try to */
32  /* obtain a new element with the relevant key. If the list is already */
33  /* full, the oldest element from the list is discarded and replaced by a */
34  /* new one; a new element is added to the list otherwise. */
35  /* */
36  /* Note that it is possible to pre-allocate the element list nodes. */
37  /* This is handy if `max_elements' is sufficiently small, as it saves */
38  /* allocations/releases during the lookup process. */
39  /* */
40  /*************************************************************************/
41 
42 
43 #ifndef FTCMRU_H_
44 #define FTCMRU_H_
45 
46 
47 #include <ft2build.h>
48 #include FT_FREETYPE_H
49 
50 #ifdef FREETYPE_H
51 #error "freetype.h of FreeType 1 has been loaded!"
52 #error "Please fix the directory search order for header files"
53 #error "so that freetype.h of FreeType 2 is found first."
54 #endif
55 
56 #define xxFT_DEBUG_ERROR
57 #define FTC_INLINE
58 
60 
61  typedef struct FTC_MruNodeRec_* FTC_MruNode;
62 
63  typedef struct FTC_MruNodeRec_
64  {
67 
69 
70 
71  FT_LOCAL( void )
73  FTC_MruNode node );
74 
75  FT_LOCAL( void )
77  FTC_MruNode node );
78 
79  FT_LOCAL( void )
81  FTC_MruNode node );
82 
83 
84  typedef struct FTC_MruListRec_* FTC_MruList;
85 
87 
88 
89  typedef FT_Bool
91  FT_Pointer key );
92 
93  typedef FT_Error
96  FT_Pointer data );
97 
98  typedef FT_Error
100  FT_Pointer key,
101  FT_Pointer data );
102 
103  typedef void
105  FT_Pointer data );
106 
107 
108  typedef struct FTC_MruListClassRec_
109  {
111 
116 
118 
119 
120  typedef struct FTC_MruListRec_
121  {
128 
129  } FTC_MruListRec;
130 
131 
132  FT_LOCAL( void )
134  FTC_MruListClass clazz,
135  FT_UInt max_nodes,
137  FT_Memory memory );
138 
139  FT_LOCAL( void )
141 
142 
143  FT_LOCAL( void )
145 
146 
147  FT_LOCAL( FT_Error )
149  FT_Pointer key,
150  FTC_MruNode *anode );
151 
152  FT_LOCAL( void )
154  FTC_MruNode node );
155 
156  FT_LOCAL( void )
159  FT_Pointer key );
160 
161 
162 #ifdef FTC_INLINE
163 
164 #define FTC_MRULIST_LOOKUP_CMP( list, key, compare, node, error ) \
165  FT_BEGIN_STMNT \
166  FTC_MruNode* _pfirst = &(list)->nodes; \
167  FTC_MruNode_CompareFunc _compare = (FTC_MruNode_CompareFunc)(compare); \
168  FTC_MruNode _first, _node; \
169  \
170  \
171  error = FT_Err_Ok; \
172  _first = *(_pfirst); \
173  _node = NULL; \
174  \
175  if ( _first ) \
176  { \
177  _node = _first; \
178  do \
179  { \
180  if ( _compare( _node, (key) ) ) \
181  { \
182  if ( _node != _first ) \
183  FTC_MruNode_Up( _pfirst, _node ); \
184  \
185  node = _node; \
186  goto MruOk_; \
187  } \
188  _node = _node->next; \
189  \
190  } while ( _node != _first); \
191  } \
192  \
193  error = FTC_MruList_New( (list), (key), (FTC_MruNode*)(void*)&(node) ); \
194  MruOk_: \
195  ; \
196  FT_END_STMNT
197 
198 #define FTC_MRULIST_LOOKUP( list, key, node, error ) \
199  FTC_MRULIST_LOOKUP_CMP( list, key, (list)->clazz.node_compare, node, error )
200 
201 #else /* !FTC_INLINE */
202 
204  FTC_MruList_Find( FTC_MruList list,
205  FT_Pointer key );
206 
207  FT_LOCAL( FT_Error )
208  FTC_MruList_Lookup( FTC_MruList list,
209  FT_Pointer key,
210  FTC_MruNode *pnode );
211 
212 #define FTC_MRULIST_LOOKUP( list, key, node, error ) \
213  error = FTC_MruList_Lookup( (list), (key), (FTC_MruNode*)&(node) )
214 
215 #endif /* !FTC_INLINE */
216 
217 
218 #define FTC_MRULIST_LOOP( list, node ) \
219  FT_BEGIN_STMNT \
220  FTC_MruNode _first = (list)->nodes; \
221  \
222  \
223  if ( _first ) \
224  { \
225  FTC_MruNode _node = _first; \
226  \
227  \
228  do \
229  { \
230  *(FTC_MruNode*)&(node) = _node;
231 
232 
233 #define FTC_MRULIST_LOOP_END() \
234  _node = _node->next; \
235  \
236  } while ( _node != _first ); \
237  } \
238  FT_END_STMNT
239 
240  /* */
241 
243 
244 
245 #endif /* FTCMRU_H_ */
246 
247 
248 /* END */
int FT_Error
Definition: fttypes.h:300
FTC_MruNode_Prepend(FTC_MruNode *plist, FTC_MruNode node)
Definition: ftcmru.c:29
FT_Error(* FTC_MruNode_ResetFunc)(FTC_MruNode node, FT_Pointer key, FT_Pointer data)
Definition: ftcmru.h:99
FTC_MruList_Done(FTC_MruList list)
Definition: ftcmru.c:195
FTC_MruListClassRec clazz
Definition: ftcmru.h:126
struct FTC_MruListRec_ FTC_MruListRec
FTC_MruNode next
Definition: ftcmru.h:65
FT_Bool(* FTC_MruNode_CompareFunc)(FTC_MruNode node, FT_Pointer key)
Definition: ftcmru.h:90
static Parse plist[]
Definition: dwarfinfo.c:340
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define FT_END_HEADER
Definition: ftheader.h:54
FTC_MruNode prev
Definition: ftcmru.h:66
FTC_MruList_Remove(FTC_MruList list, FTC_MruNode node)
Definition: ftcmru.c:308
FT_Pointer data
Definition: ftcmru.h:125
FT_Memory memory
Definition: ftcmru.h:127
typedefFT_BEGIN_HEADER struct FTC_MruNodeRec_ * FTC_MruNode
Definition: ftcmru.h:61
static char memory[1024 *256]
Definition: process.c:116
int selection
Definition: ctm.c:92
FT_BEGIN_HEADER typedef unsigned char FT_Bool
Definition: fttypes.h:108
struct node node
#define FT_BEGIN_HEADER
Definition: ftheader.h:36
#define FT_LOCAL(x)
Definition: ftconfig.h:387
FTC_MruList_New(FTC_MruList list, FT_Pointer key, FTC_MruNode *anode)
Definition: ftcmru.c:236
FTC_MruNode_Up(FTC_MruNode *plist, FTC_MruNode node)
Definition: ftcmru.c:73
FTC_MruNode_DoneFunc node_done
Definition: ftcmru.h:115
FTC_MruNode_CompareFunc node_compare
Definition: ftcmru.h:112
struct FTC_MruListClassRec_ FTC_MruListClassRec
FTC_MruNode nodes
Definition: ftcmru.h:124
FTC_MruNode_InitFunc node_init
Definition: ftcmru.h:113
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
FTC_MruList_Init(FTC_MruList list, FTC_MruListClass clazz, FT_UInt max_nodes, FT_Pointer data, FT_Memory memory)
Definition: ftcmru.c:169
HKEY key
Definition: reg.c:42
FT_Offset node_size
Definition: ftcmru.h:110
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:66
Definition: _list.h:228
FT_UInt max_nodes
Definition: ftcmru.h:123
FT_UInt num_nodes
Definition: ftcmru.h:122
FT_Error(* FTC_MruNode_InitFunc)(FTC_MruNode node, FT_Pointer key, FT_Pointer data)
Definition: ftcmru.h:94
void(* FTC_MruNode_DoneFunc)(FTC_MruNode node, FT_Pointer data)
Definition: ftcmru.h:104
unsigned int FT_UInt
Definition: fttypes.h:231
FTC_MruNode_Remove(FTC_MruNode *plist, FTC_MruNode node)
Definition: ftcmru.c:122
struct FTC_MruNodeRec_ FTC_MruNodeRec
FTC_MruList_RemoveSelection(FTC_MruList list, FTC_MruNode_CompareFunc selection, FT_Pointer key)
Definition: ftcmru.c:327
#define const
Definition: zconf.h:230
struct FTC_MruListRec_ * FTC_MruList
Definition: ftcmru.h:84
struct FTC_MruListClassRec_ const * FTC_MruListClass
Definition: ftcmru.h:86
size_t FT_Offset
Definition: fttypes.h:324
FTC_MruNode_ResetFunc node_reset
Definition: ftcmru.h:114
Definition: path.c:42
Definition: dlist.c:348
FTC_MruList_Reset(FTC_MruList list)
Definition: ftcmru.c:185