Advertisement
Guest User

list.h

a guest
Oct 4th, 2010
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.45 KB | None | 0 0
  1. /*
  2.  *******************************************************************************
  3.  * list.h
  4.  * Creation date: 07.03.2007
  5.  * Author:        Firoball
  6.  *
  7.  *******************************************************************************
  8.  * $Date: 2010-08-05 00:23:10 +0200 (Do, 05 Aug 2010) $
  9.  * $Revision: 4 $
  10.  * $Author: Firo $
  11.  *
  12.  *******************************************************************************
  13.  * Description
  14.  *
  15.  * Definition script for List management
  16.  *
  17.  * Comments
  18.  *
  19.  * for short descriptions see comments in this file
  20.  *
  21.  *******************************************************************************
  22.  */
  23.  
  24. #ifndef LIST_H
  25. #define LIST_H
  26. /*! \file
  27.  *  Include file for expendable lists.
  28.  */
  29.  
  30. /* ----- DEFINITIONS ----- */
  31.  
  32.  
  33. #define LIST_ACTIVE /*!< This define can be evaluated to check if this module is included and active */
  34.  
  35.  
  36. /*! \name Configuration Data
  37.  *  The values of these parameters can be overwritten by defining them before including this file.
  38.  * \{ */
  39. #ifndef LIST_ARRAY_STEPS
  40. #define LIST_ARRAY_STEPS 20 /*!< Choosing higher values results in less copying but requires more memory from beginning */
  41. #endif
  42. /* \} */
  43.  
  44.  
  45. /* ----- STRUCTURES ----- */
  46.  
  47.  
  48. /*! Definition of a list.
  49.  *  A list is used to store a set of pointers to user defined objects.
  50.  *  The size of the list is adapted automatically at runtime. The size of new memory
  51.  *  allocated when the list has reached its current limit, can be modified by redefining
  52.  *  LIST_ARRAY_STEPS.
  53.  *  Use the LIST_create function for creation of a new list.
  54.  */
  55. typedef struct
  56. {
  57.     int iCount;     /*!< Number of objects stored in list */
  58.     int iRange;     /*!< Number of memory extensions done (multiplied with LIST_ARRAY_STEPS) */
  59.     void** ppList;  /*!< Pointer to pointer array for custom objects */
  60.  
  61. }LIST;
  62.  
  63.  
  64. /* ----- EXTERNAL FUNCTIONS ----- */
  65.  
  66.  
  67. /*! creates new list.
  68.  *  \return pointer to newly created LIST
  69.  */
  70. LIST* LIST_create();
  71.  
  72. /*! Removes a list from memory.
  73.  *  Caution: Contained items are not affected and remain in memory!
  74.  *  \param  psHost  Pointer to host LIST
  75.  */
  76. void LIST_remove(LIST* psHost);
  77.  
  78. /*! Removes a list from memory.
  79.  *  Contained items are deleted  - use with care!!
  80.  *   DO NOT USE with stored engine objects!!
  81.  *   Take care when storing structs containing pointers to allocated memory!!
  82.  *  \param  psHost  Pointer to host LIST
  83.  */
  84. void LIST_removeAll(LIST* psHost);
  85.  
  86. /*! Remove item from LIST by index.
  87.  *  Memory occupied by item is NOT freed!
  88.  *  Indices of follow-up items are NOT affected
  89.  *  \param  psHost  Pointer to host LIST
  90.  *  \param  iIndex List index for stored item
  91.  */
  92. void LIST_removeItem(LIST* psHost, int iIndex);
  93.  
  94. /*! Append new item to LIST
  95.  *  \param  psHost    Pointer to host LIST
  96.  *  \param  psNewItem Pointer to item to be added (casted to void*)
  97.  */
  98. void LIST_append(LIST* psHost, void* psNewItem);
  99.  
  100. /*! Get item from list by index.
  101.  *  \param  psHost  Pointer to host LIST
  102.  *  \param  iIndex List index for stored item
  103.  *  \return Pointer to item or NULL
  104.  */
  105. void* LIST_getItem(LIST* psHost, int iIndex);
  106.  
  107. /*! Get amount of stored items.
  108.  *  \param  psHost Pointer to host LIST
  109.  *  \return Amount of stored items
  110.  */
  111. int LIST_items(LIST* psHost);
  112.  
  113.  
  114. /* ----- INTERNAL FUNCTIONS - DO NOT USE ----- */
  115.  
  116.  
  117. /*! \internal - Do not use! */
  118. void LIST__extend(LIST* psHost);
  119. /*! \internal - Do not use! */
  120. void LIST__init(LIST* psHost);
  121.  
  122. #include "list.c"
  123.  
  124. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement