gwenhywfar
4.7.0beta
|
Typesafe Macros | |
#define | GWEN_LIST_ELEMENT(t) GWEN_LIST1_ELEMENT *_list1_element; |
#define | GWEN_LIST_FUNCTION_LIB_DEFS_CONST(t, pr, decl) |
#define | GWEN_LIST_FUNCTION_LIB_DEFS_NOCONST(t, pr, decl) |
#define | GWEN_LIST_FUNCTION_DEFS_CONST(t, pr) GWEN_LIST_FUNCTION_LIB_DEFS_CONST(t, pr, GWEN_DUMMY_EMPTY_ARG) |
#define | GWEN_LIST_FUNCTION_DEFS_NOCONST(t, pr) GWEN_LIST_FUNCTION_LIB_DEFS_NOCONST(t, pr, GWEN_DUMMY_EMPTY_ARG) |
#define | GWEN_LIST_FUNCTION_LIB_DEFS(t, pr, decl) |
#define | GWEN_LIST_FUNCTION_DEFS(t, pr) GWEN_LIST_FUNCTION_LIB_DEFS(t, pr, GWEN_DUMMY_EMPTY_ARG) |
#define | GWEN_LIST_FUNCTIONS(t, pr) |
#define | GWEN_LIST_INIT(t, element) element->_list1_element=GWEN_List1Element_new(element); |
#define | GWEN_LIST_FINI(t, element) |
The macros of this group facilitates typesafe use of lists.
Let's assume you have a structure type called MYSTRUCT and you want to manage lists of them. Let's further assume that you want the functions dealing with that struct have prefixes like MyStruct (as in MyStruct_new)
The header file would look like this:
This defines all necessary data and function prototypes needed for list management.
The code file would look quite similar to the following:
Please note the three macros used in the code file:
Note: When writing these macro code lines, the original ISO C89 standard for the C language does not allow terminating the macro statement with a semicolon ';'. Any recent compiler will probably silently ignore such an extra ';', but you should be aware that this can cause problems once one of your users tries to compile this with a different compiler. Therefore these code lines should end directly with the closing parentheses.
The list management code assumes that there is a function called (in this example) MyStruct_free() (or generally: TYPEPREFIX_free). This is used when destroying a list of MYSTRUCT elements. In this case all elements still enlisted are destroyed upon destruction of the list.
#define GWEN_LIST_ELEMENT | ( | t) | GWEN_LIST1_ELEMENT *_list1_element; |
#define GWEN_LIST_FINI | ( | t, | |
element | |||
) |
Use this in your code file (*.c) inside the fini code for the struct you want to use in lists (in GWEN these are the functions which end with "_free".
Definition at line 459 of file list1.h.
Referenced by GWEN_Crypt_Key_free(), GWEN_Crypt_Token_Context_free(), GWEN_Crypt_Token_free(), GWEN_DateTmplChar_free(), GWEN_DB_Node_free(), GWEN_DBIO_free(), GWEN_Dialog_free(), GWEN_Gui_CProgress_free(), GWEN_IdTable_free(), GWEN_InheritData_free(), GWEN_MultiCache_Entry_free(), GWEN_MultiCache_Type_free(), GWEN_Plugin_free(), GWEN_PluginDescription_free(), GWEN_PluginManager_free(), GWEN_SarFileHeader_free(), GWEN_SigHead_free(), GWEN_SigTail_free(), GWEN_SslCertDescr_free(), GWEN_SyncIo_free(), GWEN_Tag16_free(), GWEN_TimeTmplChar_free(), GWEN_TLV_free(), GWEN_Url_free(), GWEN_XMLNode_free(), GWEN_XMLNode_NameSpace_free(), GWEN_XsdNode_free(), HtmlFont_free(), and HtmlImage_free().
#define GWEN_LIST_FUNCTION_DEFS | ( | t, | |
pr | |||
) | GWEN_LIST_FUNCTION_LIB_DEFS(t, pr, GWEN_DUMMY_EMPTY_ARG) |
This macro should be used in applications, not in libraries. In libraries please use the macro GWEN_LIST_FUNCTION_LIB_DEFS.
#define GWEN_LIST_FUNCTION_DEFS_CONST | ( | t, | |
pr | |||
) | GWEN_LIST_FUNCTION_LIB_DEFS_CONST(t, pr, GWEN_DUMMY_EMPTY_ARG) |
#define GWEN_LIST_FUNCTION_DEFS_NOCONST | ( | t, | |
pr | |||
) | GWEN_LIST_FUNCTION_LIB_DEFS_NOCONST(t, pr, GWEN_DUMMY_EMPTY_ARG) |
#define GWEN_LIST_FUNCTION_LIB_DEFS | ( | t, | |
pr, | |||
decl | |||
) |
Use this in public header files to define some prototypes for list functions. Let's assume the type of your list elements is "MYTYPE" and you want to use the prefix "MyType_" for the list functions. The following function prototypes will then be created:
#define GWEN_LIST_FUNCTION_LIB_DEFS_CONST | ( | t, | |
pr, | |||
decl | |||
) |
Use this macro in your public header files to export only list functions which do not modify a list. This allows your code to return lists which can not be modified by callers. It also prevents callers from creating their own lists (this is sometimes needed).
#define GWEN_LIST_FUNCTION_LIB_DEFS_NOCONST | ( | t, | |
pr, | |||
decl | |||
) |
#define GWEN_LIST_FUNCTIONS | ( | t, | |
pr | |||
) |
Use this inside your code files (*.c). Actually implements the functions for which the prototypes have been defined via GWEN_LIST_FUNCTION_DEFS.
#define GWEN_LIST_INIT | ( | t, | |
element | |||
) | element->_list1_element=GWEN_List1Element_new(element); |
Use this in your code file (*.c) inside the init code for the struct you want to use in lists (in GWEN these are the functions which end with "_new".
Definition at line 450 of file list1.h.
Referenced by GWEN_Crypt_Key_new(), GWEN_Crypt_Token_Context_new(), GWEN_Crypt_Token_KeyInfo_new(), GWEN_Crypt_Token_new(), GWEN_DateTmplChar_new(), GWEN_DB_Node_new(), GWEN_DBIO_new(), GWEN_Dialog_new(), GWEN_Gui_CProgress_new(), GWEN_IdTable_new(), GWEN_InheritData_new(), GWEN_MDigest_new(), GWEN_MultiCache_Entry_new(), GWEN_MultiCache_Type_new(), GWEN_Plugin_new(), GWEN_PluginDescription_dup(), GWEN_PluginDescription_new(), GWEN_PluginManager_new(), GWEN_SarFileHeader_new(), GWEN_SigHead_new(), GWEN_SigTail_new(), GWEN_SslCertDescr_new(), GWEN_SyncIo_new(), GWEN_Tag16_new(), GWEN_TimeTmplChar_new(), GWEN_TLV_new(), GWEN_Url_new(), GWEN_XMLNode_NameSpace_new(), GWEN_XMLNode_new(), GWEN_XsdNode_new(), HtmlFont_new(), and HtmlImage_new().
typedef struct GWEN_LIST1 GWEN_LIST1 |
typedef struct GWEN_LIST1_ELEMENT GWEN_LIST1_ELEMENT |
typedef int GWENHYWFAR_CB(* GWEN_LIST1_SORT_FN)(const void *a, const void *b, int ascending) |
GWENHYWFAR_API int GWEN_List1_Add | ( | GWEN_LIST1 * | l, |
GWEN_LIST1_ELEMENT * | el | ||
) |
Adds (appends) a list element at the end of the list. (This operation is also called "append" or "push_back" elsewhere.)
Definition at line 65 of file list1.c.
References DBG_ERROR, and GWEN_LOGDOMAIN.
Referenced by GWEN_List1_AddList(), and GWEN_List1_Sort().
GWENHYWFAR_API int GWEN_List1_AddList | ( | GWEN_LIST1 * | dest, |
GWEN_LIST1 * | l | ||
) |
Adds (appends) the second list to the end of the first list. (This operation is also called "append" or "concatenate" elsewhere.)
Definition at line 91 of file list1.c.
References GWEN_List1_Add(), and GWEN_List1_Del().
GWENHYWFAR_API int GWEN_List1_Del | ( | GWEN_LIST1_ELEMENT * | el) |
Deletes (removes) a list element from the list it used to belong to. The list element is not free'd or anything, it is only removed from the list it used to belong to. (This operation is also called "remove" or "unlink" elsewhere.)
Definition at line 133 of file list1.c.
References DBG_ERROR, and GWEN_LOGDOMAIN.
Referenced by GWEN_List1_AddList(), and GWEN_List1Element_free().
GWENHYWFAR_API void GWEN_List1_free | ( | GWEN_LIST1 * | l) |
Free (delete) an existing list. The list elements are untouched by this function; they need to be freed beforehand.
Definition at line 50 of file list1.c.
References GWEN_FREE_OBJECT.
GWENHYWFAR_API int GWEN_List1_GetCount | ( | const GWEN_LIST1 * | l) |
GWENHYWFAR_API void* GWEN_List1_GetFirst | ( | const GWEN_LIST1 * | l) |
GWENHYWFAR_API void* GWEN_List1_GetLast | ( | const GWEN_LIST1 * | l) |
GWENHYWFAR_API int GWEN_List1_Insert | ( | GWEN_LIST1 * | l, |
GWEN_LIST1_ELEMENT * | el | ||
) |
Inserts (prepends) a list element at the beginning of the list. (This operation is also called "prepend" or "push_front" elsewhere.)
Definition at line 107 of file list1.c.
References DBG_ERROR, and GWEN_LOGDOMAIN.
GWENHYWFAR_API GWEN_LIST1* GWEN_List1_new | ( | void | ) |
Allocate (create) a new empty list.
Definition at line 41 of file list1.c.
References GWEN_List1__defaultSortFn(), and GWEN_NEW_OBJECT.
GWENHYWFAR_API GWEN_LIST1_SORT_FN GWEN_List1_SetSortFn | ( | GWEN_LIST1 * | l, |
GWEN_LIST1_SORT_FN | fn | ||
) |
GWENHYWFAR_API void GWEN_List1_Sort | ( | GWEN_LIST1 * | l, |
int | ascending | ||
) |
Definition at line 402 of file list1.c.
References GWEN_List1__compar(), GWEN_List1_Add(), GWEN_List1_SortCtx_free(), GWEN_List1_SortCtx_new(), GWEN_List1_SortElem_free(), GWEN_List1_SortElem_new(), and NULL.
GWENHYWFAR_API void GWEN_List1Element_free | ( | GWEN_LIST1_ELEMENT * | el) |
Free (delete) a list element structure.
Definition at line 199 of file list1.c.
References GWEN_FREE_OBJECT, and GWEN_List1_Del().
GWENHYWFAR_API void* GWEN_List1Element_GetData | ( | const GWEN_LIST1_ELEMENT * | el) |
GWENHYWFAR_API void* GWEN_List1Element_GetNext | ( | const GWEN_LIST1_ELEMENT * | el) |
GWENHYWFAR_API void* GWEN_List1Element_GetPrevious | ( | const GWEN_LIST1_ELEMENT * | el) |
GWENHYWFAR_API GWEN_LIST1_ELEMENT* GWEN_List1Element_new | ( | void * | d) |
Allocate (create) a new list element structure.
Definition at line 188 of file list1.c.
References GWEN_NEW_OBJECT.