gwenhywfar  5.11.1beta
tree2.h
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Thu Jul 04 2019
3  copyright : (C) 2019 by Martin Preuss
4  email : martin@libchipcard.de
5 
6  ***************************************************************************
7  * *
8  * This library is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU Lesser General Public *
10  * License as published by the Free Software Foundation; either *
11  * version 2.1 of the License, or (at your option) any later version. *
12  * *
13  * This library is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16  * Lesser General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU Lesser General Public *
19  * License along with this library; if not, write to the Free Software *
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21  * MA 02111-1307 USA *
22  * *
23  ***************************************************************************/
24 
25 #ifndef GWEN_TREE2_H
26 #define GWEN_TREE2_H
27 
28 
30 #include <gwenhywfar/types.h>
31 #include <assert.h>
32 
33 
34 #ifndef GWEN_DUMMY_EMPTY_ARG
37 # define GWEN_DUMMY_EMPTY_ARG
38 #endif
39 
40 
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 
146 
147 
156 
157 
164 
165 
171 void GWEN_Tree2_Replace(GWEN_TREE2_ELEMENT *elToReplace, GWEN_TREE2_ELEMENT *elReplacement);
172 
176 
180 
181 
185 
189 
190 
191 
195 
199 
205 
211 
222 
226 
230 
233 
237 
246 
251 #define GWEN_TREE2_ELEMENT(t) \
252 GWEN_TREE2_ELEMENT *_tree2_element;
253 
260 #define GWEN_TREE2_FUNCTION_LIB_DEFS_CONST(t, pr, decl) \
261  decl t* pr##_Tree2_GetNext(const t *element); \
262  decl t* pr##_Tree2_GetPrevious(const t *element); \
263  decl t* pr##_Tree2_GetBelow(const t *element); \
264  decl t* pr##_Tree2_GetFirstChild(const t *element); \
265  decl t* pr##_Tree2_GetLastChild(const t *element); \
266  decl t* pr##_Tree2_GetParent(const t *element);
267 
268 
269 #define GWEN_TREE2_FUNCTION_LIB_DEFS_NOCONST(t, pr, decl) \
270  typedef GWEN_TREE2_ELEMENT t##_TREE2_ELEMENT; \
271  \
272  decl void pr##_Tree2_Unlink(t *element); \
273  decl void pr##_Tree2_Replace(t *elToReplace, t *elReplacement); \
274  \
275  decl void pr##_Tree2_AddChild(t *where, t *element); \
276  decl void pr##_Tree2_InsertChild(t *where, t *element); \
277  \
278  decl void pr##_Tree2_ClearChildren(t *element); \
279  decl void pr##_Tree2_free(t *element);
280 
281 
282 #define GWEN_TREE2_FUNCTION_DEFS_CONST(t, pr) \
283  GWEN_TREE2_FUNCTION_LIB_DEFS_CONST(t, pr, GWEN_DUMMY_EMPTY_ARG)
284 
285 #define GWEN_TREE2_FUNCTION_DEFS_NOCONST(t, pr) \
286  GWEN_TREE2_FUNCTION_LIB_DEFS_NOCONST(t, pr, GWEN_DUMMY_EMPTY_ARG)
287 
288 
336 #define GWEN_TREE2_FUNCTION_LIB_DEFS(t, pr, decl) \
337  GWEN_TREE2_FUNCTION_LIB_DEFS_CONST(t, pr, decl) \
338  GWEN_TREE2_FUNCTION_LIB_DEFS_NOCONST(t, pr, decl)
339 
340 
345 #define GWEN_TREE2_FUNCTION_DEFS(t, pr) \
346  GWEN_TREE2_FUNCTION_LIB_DEFS(t, pr, GWEN_DUMMY_EMPTY_ARG)
347 
348 
354 #define GWEN_TREE2_FUNCTIONS(t, pr) \
355  \
356  void pr##_Tree2_Unlink(t *element){ \
357  assert(element); \
358  assert(element->_tree2_element);\
359  GWEN_Tree2_Unlink(element->_tree2_element); \
360  }\
361  \
362  void pr##_Tree2_Replace(t *elToReplace, t *elReplacement) { \
363  assert(elToReplace); \
364  assert(elToReplace->_tree2_element);\
365  assert(elReplacement); \
366  assert(elReplacement->_tree2_element);\
367  GWEN_Tree2_Replace(elToReplace->_tree2_element, elReplacement->_tree2_element); \
368  } \
369  \
370  \
371  t* pr##_Tree2_GetNext(const t *element) { \
372  assert(element); \
373  assert(element->_tree2_element);\
374  return (t*)GWEN_Tree2Element_GetNext(element->_tree2_element);\
375  } \
376  \
377  t* pr##_Tree2_GetPrevious(const t *element) { \
378  assert(element); \
379  assert(element->_tree2_element);\
380  return (t*)GWEN_Tree2Element_GetPrevious(element->_tree2_element);\
381  } \
382  \
383  t* pr##_Tree2_GetBelow(const t *element) { \
384  assert(element); \
385  assert(element->_tree2_element);\
386  return (t*)GWEN_Tree2Element_GetBelow(element->_tree2_element);\
387  } \
388  \
389  void pr##_Tree2_AddChild(t *where, t *element) { \
390  assert(where); \
391  assert(where->_tree2_element);\
392  assert(element); \
393  assert(element->_tree2_element);\
394  GWEN_Tree2_AddChild(where->_tree2_element, element->_tree2_element); \
395  } \
396  \
397  void pr##_Tree2_InsertChild(t *where, t *element) { \
398  assert(where); \
399  assert(where->_tree2_element);\
400  assert(element); \
401  assert(element->_tree2_element);\
402  GWEN_Tree2_InsertChild(where->_tree2_element, element->_tree2_element); \
403  } \
404  \
405  void pr##_Tree2_ClearChildren(t *element) { \
406  t* c; \
407  while( (c=GWEN_Tree2Element_GetFirstChild(element->_tree2_element)) ) {\
408  pr##_Tree2_ClearChildren(c);\
409  pr##_Tree2_Unlink(c);\
410  pr##_free(c);\
411  } /* while */ \
412  } \
413  \
414  void pr##_Tree2_free(t *element) { \
415  pr##_Tree2_ClearChildren(element);\
416  pr##_Tree2_Unlink(element);\
417  pr##_free(element);\
418  } \
419  \
420  t* pr##_Tree2_GetFirstChild(const t *element) { \
421  assert(element); \
422  assert(element->_tree2_element);\
423  return (t*)GWEN_Tree2Element_GetFirstChild(element->_tree2_element);\
424  } \
425  \
426  t* pr##_Tree2_GetLastChild(const t *element) { \
427  assert(element); \
428  assert(element->_tree2_element);\
429  return (t*)GWEN_Tree2Element_GetLastChild(element->_tree2_element);\
430  } \
431  \
432  t* pr##_Tree2_GetParent(const t *element) { \
433  assert(element); \
434  assert(element->_tree2_element);\
435  return (t*)GWEN_Tree2Element_GetParent(element->_tree2_element);\
436  } \
437  \
438 
439 
445 #define GWEN_TREE2_INIT(t, element, pr) \
446  element->_tree2_element=GWEN_Tree2Element_new(element);
447 
448 
457 #define GWEN_TREE2_FINI(t, element, pr) \
458  if (element && element->_tree2_element) { \
459  pr##_Tree2_ClearChildren(element);\
460  pr##_Tree2_Unlink(element);\
461  GWEN_Tree2Element_free(element->_tree2_element); \
462  element->_tree2_element=0; \
463  }
464  /* defgroup */
469 
470 
471 #ifdef __cplusplus
472 }
473 #endif
474 
475 
476 #endif
477 
478 
#define GWENHYWFAR_API
Definition: gwenhywfarapi.h:67
GWENHYWFAR_API void * GWEN_Tree2Element_GetNext(const GWEN_TREE2_ELEMENT *el)
GWENHYWFAR_API uint32_t GWEN_Tree2Element_GetChildrenCount(const GWEN_TREE2_ELEMENT *el)
GWENHYWFAR_API void * GWEN_Tree2Element_GetLastChild(const GWEN_TREE2_ELEMENT *el)
GWENHYWFAR_API void * GWEN_Tree2Element_GetPrevious(const GWEN_TREE2_ELEMENT *el)
GWENHYWFAR_API void GWEN_Tree2_Replace(GWEN_TREE2_ELEMENT *elToReplace, GWEN_TREE2_ELEMENT *elReplacement)
GWENHYWFAR_API void * GWEN_Tree2_GetLastChild(const GWEN_TREE2_ELEMENT *el)
GWENHYWFAR_API void * GWEN_Tree2_GetFirstChild(const GWEN_TREE2_ELEMENT *el)
GWENHYWFAR_API void * GWEN_Tree2Element_GetParent(const GWEN_TREE2_ELEMENT *el)
GWENHYWFAR_API void GWEN_Tree2_AddChild(GWEN_TREE2_ELEMENT *where, GWEN_TREE2_ELEMENT *el)
GWENHYWFAR_API void GWEN_Tree2_Unlink(GWEN_TREE2_ELEMENT *el)
GWENHYWFAR_API void GWEN_Tree2_InsertChild(GWEN_TREE2_ELEMENT *where, GWEN_TREE2_ELEMENT *el)
struct GWEN_TREE2_ELEMENT GWEN_TREE2_ELEMENT
Definition: tree2.h:155
GWENHYWFAR_API void * GWEN_Tree2Element_GetFirstChild(const GWEN_TREE2_ELEMENT *el)
GWENHYWFAR_API void GWEN_Tree2Element_free(GWEN_TREE2_ELEMENT *el)
GWENHYWFAR_API GWEN_TREE2_ELEMENT * GWEN_Tree2Element_new(void *d)
GWENHYWFAR_API void * GWEN_Tree2Element_GetBelow(const GWEN_TREE2_ELEMENT *el)