PageRenderTime 1298ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/list/list.h

https://github.com/vcosta/derclou
C++ Header | 86 lines | 49 code | 14 blank | 23 comment | 0 complexity | fe38692710ac8e4dabb10d33c2941931 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. /*
  2. ** Der Clou!
  3. **
  4. ** $VER: list/list.h 0.2 (10.11.2000)
  5. **
  6. ** Reproduced by Oliver Gantert <lucyg@t-online.de>
  7. */
  8. /****************************************************************************
  9. Portions copyright (c) 2005 Vasco Alexandre da Silva Costa
  10. Please read the license terms contained in the LICENSE and
  11. publiclicensecontract.doc files which should be contained with this
  12. distribution.
  13. ****************************************************************************/
  14. #ifndef MODULE_LIST
  15. #define MODULE_LIST
  16. #include <stdlib.h>
  17. #include "theclou.h"
  18. /**************
  19. * Structures *
  20. **************/
  21. typedef struct Node {
  22. struct Node *Succ;
  23. struct Node *Pred;
  24. char *Name;
  25. size_t Size;
  26. } NODE;
  27. typedef struct List {
  28. NODE Head;
  29. NODE Tail;
  30. } LIST;
  31. /**********
  32. * Macros *
  33. **********/
  34. #define NODE_SUCC(node) (((NODE *)(node))->Succ)
  35. #define NODE_PRED(node) (((NODE *)(node))->Pred)
  36. #define NODE_NAME(node) (((NODE *)(node))->Name)
  37. #define NODE_SIZE(node) (((NODE *)(node))->Size)
  38. #define INNER_HEAD(list) (&(list)->Head)
  39. #define INNER_TAIL(list) (&(list)->Tail)
  40. #define LIST_HEAD(list) (NODE_SUCC(INNER_HEAD((list))))
  41. #define LIST_TAIL(list) (NODE_PRED(INNER_TAIL((list))))
  42. #define LIST_EMPTY(list) (!NODE_SUCC(LIST_HEAD((list))))
  43. /**************
  44. * Prototypes *
  45. **************/
  46. LIST *CreateList(void);
  47. void RemoveList(LIST *list);
  48. void FreeList(LIST *list);
  49. void *AddNode(LIST *list, void *node, void *predNode);
  50. void *AddTailNode(LIST *list, void *node);
  51. void *AddHeadNode(LIST *list, void *node);
  52. void *RemNode(void *node);
  53. void *RemHeadNode(LIST *list);
  54. void *RemTailNode(LIST *list);
  55. void *CreateNode(LIST *list, size_t size, const char *name);
  56. void RemoveNode(LIST *list, const char *name);
  57. void FreeNode(void *node);
  58. void *GetNode(LIST *list, const char *name);
  59. void *GetNthNode(LIST *list, U32 nth);
  60. U32 GetNrOfNodes(LIST *list);
  61. U32 GetNodeNrByAddr(LIST *list, void *node);
  62. U32 GetNodeNr(LIST *list, const char *name);
  63. void foreach(LIST *list, void (*processNode) (void *));
  64. void Link(LIST *list, void *node, void *predNode);
  65. void *UnLinkByAddr(LIST *list, void *node, NODE **predNode);
  66. void *UnLink(LIST *list, const char *name, NODE **predNode);
  67. void ReplaceNodeByAddr(LIST *list, void *node, NODE *newNode);
  68. void ReplaceNode(LIST *list, const char *name, NODE *newNode);
  69. U32 ReadList(LIST *list, size_t size, char *fileName);
  70. void WriteList(LIST *list, char *fileName);
  71. #endif /* MODULE_LIST */