tree2.h
Go to the documentation of this file.
/***************************************************************************
begin : Thu Jul 04 2019
copyright : (C) 2019 by Martin Preuss
email : martin@libchipcard.de
***************************************************************************
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
* MA 02111-1307 USA *
* *
***************************************************************************/
#ifndef GWEN_TREE2_H
#define GWEN_TREE2_H
#include <gwenhywfar/gwenhywfarapi.h>
#include <gwenhywfar/types.h>
#include <assert.h>
#ifndef GWEN_DUMMY_EMPTY_ARG
# define GWEN_DUMMY_EMPTY_ARG
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef struct GWEN_TREE2_ELEMENT GWEN_TREE2_ELEMENT;
GWENHYWFAR_API
void GWEN_Tree2_Unlink(GWEN_TREE2_ELEMENT *el);
GWENHYWFAR_API
void GWEN_Tree2_Replace(GWEN_TREE2_ELEMENT *elToReplace, GWEN_TREE2_ELEMENT *elReplacement);
GWENHYWFAR_API
void GWEN_Tree2_AddChild(GWEN_TREE2_ELEMENT *where, GWEN_TREE2_ELEMENT *el);
GWENHYWFAR_API
void GWEN_Tree2_InsertChild(GWEN_TREE2_ELEMENT *where, GWEN_TREE2_ELEMENT *el);
GWENHYWFAR_API
void *GWEN_Tree2_GetFirstChild(const GWEN_TREE2_ELEMENT *el);
GWENHYWFAR_API
void *GWEN_Tree2_GetLastChild(const GWEN_TREE2_ELEMENT *el);
GWENHYWFAR_API
GWEN_TREE2_ELEMENT *GWEN_Tree2Element_new(void *d);
GWENHYWFAR_API
void GWEN_Tree2Element_free(GWEN_TREE2_ELEMENT *el);
GWENHYWFAR_API
void *GWEN_Tree2Element_GetPrevious(const GWEN_TREE2_ELEMENT *el);
GWENHYWFAR_API
void *GWEN_Tree2Element_GetNext(const GWEN_TREE2_ELEMENT *el);
GWENHYWFAR_API
void *GWEN_Tree2Element_GetBelow(const GWEN_TREE2_ELEMENT *el);
GWENHYWFAR_API
void *GWEN_Tree2Element_GetFirstChild(const GWEN_TREE2_ELEMENT *el);
GWENHYWFAR_API
void *GWEN_Tree2Element_GetLastChild(const GWEN_TREE2_ELEMENT *el);
GWENHYWFAR_API
void *GWEN_Tree2Element_GetParent(const GWEN_TREE2_ELEMENT *el);
GWENHYWFAR_API
uint32_t GWEN_Tree2Element_GetChildrenCount(const GWEN_TREE2_ELEMENT *el);
#define GWEN_TREE2_ELEMENT(t) \
GWEN_TREE2_ELEMENT *_tree2_element;
#define GWEN_TREE2_FUNCTION_LIB_DEFS_CONST(t, pr, decl) \
decl t* pr##_Tree2_GetNext(const t *element); \
decl t* pr##_Tree2_GetPrevious(const t *element); \
decl t* pr##_Tree2_GetBelow(const t *element); \
decl t* pr##_Tree2_GetFirstChild(const t *element); \
decl t* pr##_Tree2_GetLastChild(const t *element); \
decl t* pr##_Tree2_GetParent(const t *element);
#define GWEN_TREE2_FUNCTION_LIB_DEFS_NOCONST(t, pr, decl) \
typedef GWEN_TREE2_ELEMENT t##_TREE2_ELEMENT; \
\
decl void pr##_Tree2_Unlink(t *element); \
decl void pr##_Tree2_Replace(t *elToReplace, t *elReplacement); \
\
decl void pr##_Tree2_AddChild(t *where, t *element); \
decl void pr##_Tree2_InsertChild(t *where, t *element); \
\
decl void pr##_Tree2_ClearChildren(t *element); \
decl void pr##_Tree2_free(t *element);
#define GWEN_TREE2_FUNCTION_DEFS_CONST(t, pr) \
GWEN_TREE2_FUNCTION_LIB_DEFS_CONST(t, pr, GWEN_DUMMY_EMPTY_ARG)
#define GWEN_TREE2_FUNCTION_DEFS_NOCONST(t, pr) \
GWEN_TREE2_FUNCTION_LIB_DEFS_NOCONST(t, pr, GWEN_DUMMY_EMPTY_ARG)
#define GWEN_TREE2_FUNCTION_LIB_DEFS(t, pr, decl) \
GWEN_TREE2_FUNCTION_LIB_DEFS_CONST(t, pr, decl) \
GWEN_TREE2_FUNCTION_LIB_DEFS_NOCONST(t, pr, decl)
#define GWEN_TREE2_FUNCTION_DEFS(t, pr) \
GWEN_TREE2_FUNCTION_LIB_DEFS(t, pr, GWEN_DUMMY_EMPTY_ARG)
#define GWEN_TREE2_FUNCTIONS(t, pr) \
\
void pr##_Tree2_Unlink(t *element){ \
assert(element); \
assert(element->_tree2_element);\
GWEN_Tree2_Unlink(element->_tree2_element); \
}\
\
void pr##_Tree2_Replace(t *elToReplace, t *elReplacement) { \
assert(elToReplace); \
assert(elToReplace->_tree2_element);\
assert(elReplacement); \
assert(elReplacement->_tree2_element);\
GWEN_Tree2_Replace(elToReplace->_tree2_element, elReplacement->_tree2_element); \
} \
\
\
t* pr##_Tree2_GetNext(const t *element) { \
assert(element); \
assert(element->_tree2_element);\
return (t*)GWEN_Tree2Element_GetNext(element->_tree2_element);\
} \
\
t* pr##_Tree2_GetPrevious(const t *element) { \
assert(element); \
assert(element->_tree2_element);\
return (t*)GWEN_Tree2Element_GetPrevious(element->_tree2_element);\
} \
\
t* pr##_Tree2_GetBelow(const t *element) { \
assert(element); \
assert(element->_tree2_element);\
return (t*)GWEN_Tree2Element_GetBelow(element->_tree2_element);\
} \
\
void pr##_Tree2_AddChild(t *where, t *element) { \
assert(where); \
assert(where->_tree2_element);\
assert(element); \
assert(element->_tree2_element);\
GWEN_Tree2_AddChild(where->_tree2_element, element->_tree2_element); \
} \
\
void pr##_Tree2_InsertChild(t *where, t *element) { \
assert(where); \
assert(where->_tree2_element);\
assert(element); \
assert(element->_tree2_element);\
GWEN_Tree2_InsertChild(where->_tree2_element, element->_tree2_element); \
} \
\
void pr##_Tree2_ClearChildren(t *element) { \
t* c; \
while( (c=GWEN_Tree2Element_GetFirstChild(element->_tree2_element)) ) {\
pr##_Tree2_ClearChildren(c);\
pr##_Tree2_Unlink(c);\
pr##_free(c);\
} /* while */ \
} \
\
void pr##_Tree2_free(t *element) { \
pr##_Tree2_ClearChildren(element);\
pr##_Tree2_Unlink(element);\
pr##_free(element);\
} \
\
t* pr##_Tree2_GetFirstChild(const t *element) { \
assert(element); \
assert(element->_tree2_element);\
return (t*)GWEN_Tree2Element_GetFirstChild(element->_tree2_element);\
} \
\
t* pr##_Tree2_GetLastChild(const t *element) { \
assert(element); \
assert(element->_tree2_element);\
return (t*)GWEN_Tree2Element_GetLastChild(element->_tree2_element);\
} \
\
t* pr##_Tree2_GetParent(const t *element) { \
assert(element); \
assert(element->_tree2_element);\
return (t*)GWEN_Tree2Element_GetParent(element->_tree2_element);\
} \
\
#define GWEN_TREE2_INIT(t, element, pr) \
element->_tree2_element=GWEN_Tree2Element_new(element);
#define GWEN_TREE2_FINI(t, element, pr) \
if (element && element->_tree2_element) { \
pr##_Tree2_ClearChildren(element);\
pr##_Tree2_Unlink(element);\
GWEN_Tree2Element_free(element->_tree2_element); \
element->_tree2_element=0; \
}
/* defgroup */
#ifdef __cplusplus
}
#endif
#endif
gwenhywfarapi.h
GWENHYWFAR_API
#define GWENHYWFAR_API
Definition gwenhywfarapi.h:67
GWEN_Tree2Element_GetFirstChild
GWENHYWFAR_API void * GWEN_Tree2Element_GetFirstChild(const GWEN_TREE2_ELEMENT *el)
GWEN_Tree2Element_GetChildrenCount
GWENHYWFAR_API uint32_t GWEN_Tree2Element_GetChildrenCount(const GWEN_TREE2_ELEMENT *el)
GWEN_Tree2_Replace
GWENHYWFAR_API void GWEN_Tree2_Replace(GWEN_TREE2_ELEMENT *elToReplace, GWEN_TREE2_ELEMENT *elReplacement)
GWEN_Tree2Element_GetParent
GWENHYWFAR_API void * GWEN_Tree2Element_GetParent(const GWEN_TREE2_ELEMENT *el)
GWEN_Tree2Element_new
GWENHYWFAR_API GWEN_TREE2_ELEMENT * GWEN_Tree2Element_new(void *d)
GWEN_Tree2Element_GetNext
GWENHYWFAR_API void * GWEN_Tree2Element_GetNext(const GWEN_TREE2_ELEMENT *el)
GWEN_Tree2Element_GetPrevious
GWENHYWFAR_API void * GWEN_Tree2Element_GetPrevious(const GWEN_TREE2_ELEMENT *el)
GWEN_Tree2_AddChild
GWENHYWFAR_API void GWEN_Tree2_AddChild(GWEN_TREE2_ELEMENT *where, GWEN_TREE2_ELEMENT *el)
GWEN_Tree2_Unlink
GWENHYWFAR_API void GWEN_Tree2_Unlink(GWEN_TREE2_ELEMENT *el)
GWEN_Tree2Element_GetBelow
GWENHYWFAR_API void * GWEN_Tree2Element_GetBelow(const GWEN_TREE2_ELEMENT *el)
GWEN_Tree2Element_GetLastChild
GWENHYWFAR_API void * GWEN_Tree2Element_GetLastChild(const GWEN_TREE2_ELEMENT *el)
GWEN_Tree2_GetLastChild
GWENHYWFAR_API void * GWEN_Tree2_GetLastChild(const GWEN_TREE2_ELEMENT *el)
GWEN_Tree2_InsertChild
GWENHYWFAR_API void GWEN_Tree2_InsertChild(GWEN_TREE2_ELEMENT *where, GWEN_TREE2_ELEMENT *el)
GWEN_TREE2_ELEMENT
#define GWEN_TREE2_ELEMENT(t)
Definition tree2.h:251
GWEN_Tree2Element_free
GWENHYWFAR_API void GWEN_Tree2Element_free(GWEN_TREE2_ELEMENT *el)
GWEN_Tree2_GetFirstChild
GWENHYWFAR_API void * GWEN_Tree2_GetFirstChild(const GWEN_TREE2_ELEMENT *el)
types.h