dpl_list.h
上传用户:hualang
上传日期:2022-04-11
资源大小:104k
文件大小:20k
开发平台:

C/C++

  1. /************************** Filename: dp_list.h ******************************/
  2. /* ========================================================================= */
  3. /*                                                                           */
  4. /* 0000  000   000  00000 0  000  0   0 0 0000                               */
  5. /* 0   0 0  0 0   0 0     0 0   0 0   0 0 0   0                              */
  6. /* 0   0 0  0 0   0 0     0 0     0   0 0 0   0      Einsteinstra遝 6        */
  7. /* 0000  000  0   0 000   0 0     00000 0 0000       91074 Herzogenaurach    */
  8. /* 0     00   0   0 0     0 0     0   0 0 0                                  */
  9. /* 0     0 0  0   0 0     0 0   0 0   0 0 0          Tel: ++49-9132-744-200  */
  10. /* 0     0  0  000  0     0  000  0   0 0 0    GmbH  Fax: ++49-9132-744-204  */
  11. /*                                                                           */
  12. /* ========================================================================= */
  13. /*                                                                           */
  14. /* Description: macros for double pointered list                             */
  15. /*                                                                           */
  16. /* ------------------------------------------------------------------------- */
  17. /*                                                                           */
  18. /* Technical support:       P. Fredehorst                                    */
  19. /*                          Tel. : ++49-9132/744-214                         */
  20. /*                          Fax. :              -204                         */
  21. /*                          eMail: pfredehorst@profichip.com                 */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24. /*****************************************************************************/
  25. /* contents:
  26.     dpl_init_list__                  (list_ptr)
  27.     dpl_list_empty__                 (list_ptr)
  28.     dpl_list_not_empty__             (list_ptr)
  29.     dpl_put_blk_to_list_start__      (list_ptr, blk_ptr)
  30.     dpl_put_blk_to_list_end__        (list_ptr, blk_ptr)
  31.     dpl_put_blk_queue_to_list_end__  (list_ptr, blk_start_ptr, blk_end_ptr)
  32.     dpl_get_blk_from_list__          (list_ptr, adr_blk_ptr)
  33.     dpl_remove_blk_from_list__       (list_ptr)
  34.     dpl_get_remove_blk_from_list__   (list_ptr, adr_blk_ptr)
  35.     dpl_remove_blk__                 (blk_ptr)
  36. */
  37. /*****************************************************************************/
  38. /* reinclude protection */
  39. #ifndef DPLLIST_H
  40. #define DPLLIST_H
  41. /*****************************************************************************/
  42. /*  CHECK PARAMETER                                                          */
  43. /*****************************************************************************/
  44. #define DPL_PTR_ATTR PTR_ATTR
  45. #define DPL_HOST_PTR_COMPARE_TYPE   void *
  46. #ifdef  DPL_PTR_ATTR
  47. /*****************************************************************************/
  48. /*  ANCHOR                                                                   */
  49. /*****************************************************************************/
  50. typedef struct dpl_list_cb
  51. {
  52.     struct dpl_list_cb DPL_PTR_ATTR *next_blk_ptr;
  53.     struct dpl_list_cb DPL_PTR_ATTR *prev_blk_ptr;
  54. }   DPL_STRUC_LIST_CB;
  55. #define DPL_STRUC_LIST_CB_PTR            DPL_STRUC_LIST_CB DPL_PTR_ATTR *
  56. /*****************************************************************************/
  57. /*  CASTS                                                                    */
  58. /*****************************************************************************/
  59. #define DPL_LIST_CB_PTR                                                       
  60.         DPL_STRUC_LIST_CB DPL_PTR_ATTR *
  61. #define DPL_LIST_CB_PTR_PTR                                                   
  62.         DPL_STRUC_LIST_CB DPL_PTR_ATTR * DPL_PTR_ATTR *
  63. /*****************************************************************************/
  64. /*  LIST HANDLING                                                            */
  65. /*****************************************************************************/
  66. /*****************************************************************************/
  67. /*                                                                           */
  68. /*                           double pointered list                           */
  69. /*                                                                           */
  70. /*         +-------------------------------------------------------+         */
  71. /*         |                                                       |         */
  72. /*         |   list-anchor                                         |         */
  73. /*         |    +------+     +------+     +------+     +------+    |         */
  74. /*         +--> | next | --> | next | --> | next | ... | next | ---+         */
  75. /*         +--- | prev | <-- | prev | <-- | prev | ... | prev | <--+         */
  76. /*         |    +------+     | ...  |     | ...  |     | ...  |    |         */
  77. /*         |                 +------+     +------+     +------+    |         */
  78. /*         |                                                       |         */
  79. /*         +-------------------------------------------------------+         */
  80. /*                                                                           */
  81. /*****************************************************************************/
  82. /*****************************************************************************/
  83. /*  D e s c r i p t i o n :                                                  */
  84. /*                                                                           */
  85. /*  initialize desired double pointered list.                                */
  86. /*                                                                           */
  87. /*****************************************************************************/
  88. #define dpl_init_list__(list_ptr)                                             
  89. {                                                                             
  90.   /* list.next = list.prev = list */                                          
  91.   ((DPL_LIST_CB_PTR) (list_ptr)) -> next_blk_ptr                              
  92.   = ((DPL_LIST_CB_PTR) (list_ptr)) -> prev_blk_ptr                            
  93.   = (DPL_LIST_CB_PTR) (list_ptr);                                             
  94. }                                                                             
  95. /*****************************************************************************/
  96. /*  D e s c r i p t i o n :                                                  */
  97. /*                                                                           */
  98. /*  check if desired double pointered list is empty.                         */
  99. /*                                                                           */
  100. /*****************************************************************************/
  101. #define dpl_list_empty__(list_ptr)                                            
  102. (                                                                             
  103.   /* list.next == list */                                                     
  104.   ((DPL_HOST_PTR_COMPARE_TYPE)                                                
  105.   (((DPL_LIST_CB_PTR) (list_ptr)) -> next_blk_ptr))                           
  106.   ==                                                                          
  107.   ((DPL_HOST_PTR_COMPARE_TYPE)                                                
  108.   (list_ptr))                                                                 
  109. )
  110. /*****************************************************************************/
  111. /*  D e s c r i p t i o n :                                                  */
  112. /*                                                                           */
  113. /*  check if desired double pointered list is not empty.                     */
  114. /*                                                                           */
  115. /*****************************************************************************/
  116. #define dpl_list_not_empty__(list_ptr)                                        
  117. (                                                                             
  118.   /* list.next != list */                                                     
  119.   ((DPL_HOST_PTR_COMPARE_TYPE)                                                
  120.   (((DPL_LIST_CB_PTR) (list_ptr)) -> next_blk_ptr))                           
  121.   !=                                                                          
  122.   ((DPL_HOST_PTR_COMPARE_TYPE)                                                
  123.   (list_ptr))                                                                 
  124. )
  125. /*****************************************************************************/
  126. /*  D e s c r i p t i o n :                                                  */
  127. /*                                                                           */
  128. /*  put block to start of double pointered list.                             */
  129. /*                                                                           */
  130. /*****************************************************************************/
  131. #define dpl_put_blk_to_list_start__(list_ptr, blk_ptr)                        
  132. {                                                                             
  133.   /* list.next -> prev = blk */                                               
  134.   ((DPL_LIST_CB_PTR) (list_ptr)) -> next_blk_ptr -> prev_blk_ptr              
  135.   = (DPL_LIST_CB_PTR) (blk_ptr);                                              
  136.                                                                               
  137.   /* blk.next = list.next */                                                  
  138.   ((DPL_LIST_CB_PTR) (blk_ptr)) -> next_blk_ptr                               
  139.   = ((DPL_LIST_CB_PTR) (list_ptr)) -> next_blk_ptr;                           
  140.                                                                               
  141.   /* list.next = blk */                                                       
  142.   ((DPL_LIST_CB_PTR) (list_ptr)) -> next_blk_ptr                              
  143.   = (DPL_LIST_CB_PTR) (blk_ptr);                                              
  144.                                                                               
  145.   /* blk.prev = list */                                                       
  146.   ((DPL_LIST_CB_PTR) (blk_ptr)) -> prev_blk_ptr                               
  147.   = (DPL_LIST_CB_PTR) (list_ptr);                                             
  148. }                                                                             
  149. /*****************************************************************************/
  150. /*  D e s c r i p t i o n :                                                  */
  151. /*                                                                           */
  152. /*  put block to end of double pointered list.                               */
  153. /*                                                                           */
  154. /*****************************************************************************/
  155. #define dpl_put_blk_to_list_end__(list_ptr, blk_ptr)                          
  156. {                                                                             
  157.   /* blk.next = list */                                                       
  158.   ((DPL_LIST_CB_PTR) (blk_ptr)) -> next_blk_ptr                               
  159.   = (DPL_LIST_CB_PTR) (list_ptr);                                             
  160.                                                                               
  161.   /* list.prev -> next = blk */                                               
  162.   ((DPL_LIST_CB_PTR) (list_ptr)) -> prev_blk_ptr -> next_blk_ptr              
  163.   = (DPL_LIST_CB_PTR) (blk_ptr);                                              
  164.                                                                               
  165.   /* blk.prev = list.prev */                                                  
  166.   ((DPL_LIST_CB_PTR) (blk_ptr)) -> prev_blk_ptr                               
  167.   = ((DPL_LIST_CB_PTR) (list_ptr)) -> prev_blk_ptr;                           
  168.                                                                               
  169.   /* list.prev = blk */                                                       
  170.   ((DPL_LIST_CB_PTR) (list_ptr)) -> prev_blk_ptr                              
  171.   = (DPL_LIST_CB_PTR) (blk_ptr);                                              
  172. }                                                                             
  173. /*****************************************************************************/
  174. /*  D e s c r i p t i o n :                                                  */
  175. /*                                                                           */
  176. /*  put queue of blocks to end of double pointered list.                     */
  177. /*                                                                           */
  178. /*****************************************************************************/
  179. #define dpl_put_blk_queue_to_list_end__(list_ptr, blk_start_ptr, blk_end_ptr)
  180. {                                                                             
  181.   /* list.prev -> next = first blk */                                         
  182.   ((DPL_LIST_CB_PTR) (list_ptr)) -> prev_blk_ptr -> next_blk_ptr              
  183.   = (DPL_LIST_CB_PTR) (blk_start_ptr);                                        
  184.                                                                               
  185.   /* first blk.prev = list.prev */                                            
  186.   ((DPL_LIST_CB_PTR) (blk_start_ptr)) -> prev_blk_ptr                         
  187.   = ((DPL_LIST_CB_PTR) (list_ptr)) -> prev_blk_ptr;                           
  188.                                                                               
  189.   /* list.prev = last blk */                                                  
  190.   ((DPL_LIST_CB_PTR) (list_ptr)) -> prev_blk_ptr                              
  191.   = (DPL_LIST_CB_PTR) (blk_end_ptr);                                          
  192.                                                                               
  193.   /* last blk.next = list */                                                  
  194.   ((DPL_LIST_CB_PTR) (blk_end_ptr)) -> next_blk_ptr                           
  195.   = (DPL_LIST_CB_PTR) (list_ptr);                                             
  196. }                                                                             
  197. /*****************************************************************************/
  198. /*  D e s c r i p t i o n :                                                  */
  199. /*                                                                           */
  200. /*  get block from start of desired double pointered list.                   */
  201. /*                                                                           */
  202. /*****************************************************************************/
  203. #define dpl_get_blk_from_list__(list_ptr, adr_blk_ptr)                        
  204. {                                                                             
  205.   /* blk = list.next */                                                       
  206.   *((DPL_LIST_CB_PTR_PTR) (adr_blk_ptr))                                      
  207.   = ((DPL_LIST_CB_PTR) (list_ptr)) -> next_blk_ptr;                           
  208. }                                                                             
  209. /*****************************************************************************/
  210. /*  D e s c r i p t i o n :                                                  */
  211. /*                                                                           */
  212. /*  remove block from start of desired double pointered list.                */
  213. /*                                                                           */
  214. /*****************************************************************************/
  215. #define dpl_remove_blk_from_list__(list_ptr)                                  
  216. {                                                                             
  217.   /* list.next = list.next -> next */                                         
  218.   ((DPL_LIST_CB_PTR) (list_ptr)) -> next_blk_ptr                              
  219.   = ((DPL_LIST_CB_PTR) (list_ptr)) -> next_blk_ptr -> next_blk_ptr;           
  220.                                                                               
  221.   /* list.next -> prev = list */                                              
  222.   ((DPL_LIST_CB_PTR) (list_ptr)) -> next_blk_ptr -> prev_blk_ptr              
  223.   = (DPL_LIST_CB_PTR) (list_ptr);                                             
  224. }                                                                             
  225. /*****************************************************************************/
  226. /*  D e s c r i p t i o n :                                                  */
  227. /*                                                                           */
  228. /*  get and remove block from start of desired double pointered list.        */
  229. /*                                                                           */
  230. /*****************************************************************************/
  231. #define dpl_get_remove_blk_from_list__(list_ptr, adr_blk_ptr)                 
  232. {                                                                             
  233.   dpl_get_blk_from_list__((list_ptr), (adr_blk_ptr));                         
  234.                                                                               
  235.   dpl_remove_blk_from_list__(list_ptr);                                       
  236. }                                                                             
  237. /*****************************************************************************/
  238. /*  D e s c r i p t i o n :                                                  */
  239. /*                                                                           */
  240. /*  remove block from anywhere inside a double pointered list.               */
  241. /*                                                                           */
  242. /*****************************************************************************/
  243. #define dpl_remove_blk__(blk_ptr)                                             
  244. {                                                                             
  245.   /* blk.prev -> next = blk.next */                                           
  246.   ((DPL_LIST_CB_PTR) (blk_ptr)) -> prev_blk_ptr -> next_blk_ptr               
  247.   = ((DPL_LIST_CB_PTR) (blk_ptr)) -> next_blk_ptr;                            
  248.                                                                               
  249.   /* blk.next -> prev = blk.prev */                                           
  250.   ((DPL_LIST_CB_PTR) (blk_ptr)) -> next_blk_ptr -> prev_blk_ptr               
  251.   = ((DPL_LIST_CB_PTR) (blk_ptr)) -> prev_blk_ptr;                            
  252. }                                                                             
  253. /*****************************************************************************/
  254. /* parameter check */
  255. #else
  256.     #error dplist handler: no list handling data attribute DPL_PTR_ATTR defined !
  257. #endif
  258. /*****************************************************************************/
  259. /* reinclude-protection */
  260. #else
  261.     #pragma message ("The header DPLLIST.H is included twice or more !")
  262. #endif
  263. /*****************************************************************************/
  264. /*  Copyright (C) profichip GmbH 2004. Confidential.                         */
  265. /*****************************************************************************/