DVBCore  1.0
Open source DVB engine
midware/stb/inc/stbllist.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002  * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
00003  * Copyright © 2004 Ocean Blue Software Ltd
00004  *
00005  * This file is part of a DTVKit Software Component
00006  * You are permitted to copy, modify or distribute this file subject to the terms
00007  * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org
00008  * 
00009  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
00010  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
00011  * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
00012  * 
00013  * If you or your organisation is not a member of DTVKit then you have access
00014  * to this source code outside of the terms of the licence agreement
00015  * and you are expected to delete this and any associated files immediately.
00016  * Further information on DTVKit, membership and terms can be found at www.dtvkit.org
00017  *******************************************************************************/
00024 #ifndef _STBLLIST_H
00025 
00026 #define _STBLLIST_H
00027 
00028 //---Constant and macro definitions for public use-----------------------------
00029 
00030 #define CREATE_LINK_LIST_HEADER(list) static LINK_LIST_HEADER list = {NULL, &list, &list}
00031 
00032 //---Enumerations for public use-----------------------------------------------
00033 
00034 //---Global type defs for public use-------------------------------------------
00035 
00036 typedef struct
00037 {
00038    void *next;
00039    void *prev;
00040 } LINK_LIST_PTR_BLK;
00041 
00042 
00043 typedef struct
00044 {
00045    void *null_next;  // this MUST be in the same position as the next field in LINK_LIST_PTR_BLK. It
00046                      // is used to identify the header from an real block
00047    void *first;
00048    void *last;
00049 } LINK_LIST_HEADER;
00050 
00051 //---Global Function prototypes for public use---------------------------------
00052 // Initialise the header variables of the linked list
00053 // Note: Header space defined (NOT static) but not initlaised.
00054 void STB_LLInitialiseHeader(LINK_LIST_HEADER *hdr);
00055 
00056 void STB_LLAddBlockToEnd(LINK_LIST_HEADER *hdr, LINK_LIST_PTR_BLK *new_blk);
00057 void STB_LLAddBlockToStart(LINK_LIST_HEADER *hdr, LINK_LIST_PTR_BLK *new_blk);
00058 void STB_LLAddBlockBefore(LINK_LIST_PTR_BLK *blk, LINK_LIST_PTR_BLK *new_blk);
00059 void STB_LLAddBlockAfter(LINK_LIST_PTR_BLK *blk, LINK_LIST_PTR_BLK *new_blk);
00060 
00061 void STB_LLRemoveBlock(LINK_LIST_PTR_BLK *blk);
00062 
00063 LINK_LIST_PTR_BLK* STB_LLGetNextBlock(LINK_LIST_PTR_BLK *blk);
00064 LINK_LIST_PTR_BLK* STB_LLGetPrevBlock(LINK_LIST_PTR_BLK *blk);
00065 LINK_LIST_PTR_BLK* STB_LLGetFirstBlock(LINK_LIST_HEADER *hdr);
00066 LINK_LIST_PTR_BLK* STB_LLGetLastBlock(LINK_LIST_HEADER *hdr);
00067 LINK_LIST_PTR_BLK* STB_LLGetBlock(LINK_LIST_HEADER *hdr, U16BIT num);
00068 U16BIT STB_LLGetNumBlocks(LINK_LIST_HEADER *hdr);
00069 
00070 BOOLEAN STB_LLCheckBlockInList(LINK_LIST_HEADER *hdr, LINK_LIST_PTR_BLK *blk);
00071 
00072 //-------------------------------------------------------------------------------------------------
00073 // Function Name: STB_LLSort
00074 // Description:   Sorts the blocks of a link list object in ascending or descending order
00075 //                ----------------------------------------------------------------------
00076 //                NOTE: The order in which the blocks will be sorted is determined solely
00077 //                      by the callback compare function
00078 //                NOTE: callback function must Not alter contents of linked list
00079 //                NOTE: STB_LLSort is NOT re-entrant -- ie. It cannot be called recursively
00080 //                ----------------------------------------------------------------------
00081 // Parameters:    ll_hdr   - pointer to the HEADER of the linked list to be sorted
00082 //                cmp_func - pointer to the compare function
00083 //                           ------------------------------------------------
00084 //                           S16BIT (*cmp_func)(LINK_LIST_PTR_BLK** blk_1, LINK_LIST_PTR_BLK** blk_2)
00085 //                           ------------------------------------------------
00086 //                           The callback function must take two LINK_LIST_PTR_BLK pointer to pointer params
00087 //                           and must return an S16BIT value of:-
00088 //                              equal to  0 -- if both compare blocks are identical
00089 //                              less than 0 -- if block_1 has a lower ordinal position than block_2
00090 //                           greater than 0 -- if block_1 has a higher ordinal position than block_2
00091 //                           ----------------------------------------------------------------------
00092 //                           NOTE: It is the order of the ordinal positions that determines whether
00093 //                                 the linked list is sorted in ascending of descending order
00094 //                           ----------------------------------------------------------------------
00095 // Returns:       TRUE  if successful, FALSE if failed
00096 BOOLEAN STB_LLSort(LINK_LIST_HEADER * ll_hdr, S16BIT (*cmp_func)(LINK_LIST_PTR_BLK **, LINK_LIST_PTR_BLK **));
00097 
00098 
00099 LINK_LIST_PTR_BLK **STB_LLSortedArray( LINK_LIST_HEADER * ll_hdr,
00100                                        S16BIT (*cmp_func)(LINK_LIST_PTR_BLK **, LINK_LIST_PTR_BLK **),
00101                                        U32BIT * num_ptr );
00102 
00103 #endif //  _STBLLIST_H
00104 
00105 //*****************************************************************************
00106 // End of file
00107 //*****************************************************************************
 All Data Structures Files Functions Typedefs Defines