DEFINE_LIST_OF.pod 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. =pod
  2. =head1 NAME
  3. DEFINE_LIST_OF, OSSL_LIST_MEMBER, OSSL_LIST,
  4. ossl_list_TYPE_init, ossl_list_TYPE_init_elem,
  5. ossl_list_TYPE_is_empty, ossl_list_TYPE_num,
  6. ossl_list_TYPE_head, ossl_list_TYPE_tail,
  7. ossl_list_TYPE_next, ossl_list_TYPE_prev,
  8. ossl_list_TYPE_remove, ossl_list_TYPE_insert_head, ossl_list_TYPE_insert_tail,
  9. ossl_list_TYPE_insert_before, ossl_list_TYPE_after
  10. - doubly linked list
  11. =head1 SYNOPSIS
  12. =for openssl generic
  13. #include "internal/list.h"
  14. OSSL_LIST(name);
  15. OSSL_LIST_MEMBER(NAME, TYPE);
  16. DEFINE_LIST_OF(NAME, TYPE);
  17. void ossl_list_TYPE_init(OSSL_LIST(name) *list);
  18. void ossl_list_TYPE_init_elem(type *elem);
  19. int ossl_list_TYPE_is_empty(const OSSL_LIST(name) *list);
  20. size_t ossl_list_TYPE_num(const OSSL_LIST(name) *list);
  21. type *ossl_list_TYPE_head(const OSSL_LIST(name) *list);
  22. type *ossl_list_TYPE_tail(const OSSL_LIST(name) *list);
  23. type *ossl_list_TYPE_next(const type *elem);
  24. type *ossl_list_TYPE_prev(const type *elem);
  25. void ossl_list_TYPE_remove(OSSL_LIST(name) *list, type *elem);
  26. void ossl_list_TYPE_insert_head(OSSL_LIST(name) *list, type *elem);
  27. void ossl_list_TYPE_insert_tail(OSSL_LIST(name) *list, type *elem);
  28. void ossl_list_TYPE_insert_before(OSSL_LIST(name) *list, type *existing,
  29. type *elem);
  30. void ossl_list_TYPE_insert_after(OSSL_LIST(name) *list, type *existing, type *elem);
  31. =head1 DESCRIPTION
  32. Create type safe linked list. These macros define typesafe inline
  33. functions that implement the various list operations. In the description
  34. here, B<I<TYPE>> is used as a placeholder for any datatype. Lists are intended to
  35. be incorporated into other structures and rather than being a standalone data
  36. structure.
  37. The OSSL_LIST() macro returns the name for a list of the specified
  38. B<I<TYPE>>. This is a structure which should be treated as opaque.
  39. DEFINE_LIST_OF() creates a set of functions for a list of B<I<TYPE>>
  40. elements with the name B<I<TYPE>>. The type is represented
  41. by B<OSSL_LIST>(B<I<TYPE>>) and each function name begins with
  42. B<ossl_list_I<TYPE>_>. The list's linkages are stored in the
  43. B<OSSL_LIST_MEMBER>(B<I<TYPE>>, B<I<TYPE>>) field.
  44. B<ossl_list_I<TYPE>_init>() initialises the memory pointed to by I<list>
  45. to zero which creates an empty list.
  46. B<ossl_list_I<TYPE>_init_elem>() initialises the list related memory pointed
  47. to by I<elem> to zero which allows it to be used in lists.
  48. B<ossl_list_I<TYPE>_is_empty>() returns nonzero if I<list> has no elements and
  49. zero otherwise.
  50. B<ossl_list_I<TYPE>_num>() returns the number of elements in I<list>.
  51. B<ossl_list_I<TYPE>_head>() returns the first element in the I<list>
  52. or NULL if there are no elements.
  53. B<ossl_list_I<TYPE>_tail>() returns the last element in the I<list>
  54. or NULL if there are no elements.
  55. B<ossl_list_I<TYPE>_remove>() removes the specified element I<elem> from
  56. the I<list>. It is illegal to remove an element that isn't in the list.
  57. B<ossl_list_I<TYPE>_insert_head>() inserts the element I<elem>, which
  58. must not be in the list, into the first position in the I<list>.
  59. B<ossl_list_I<TYPE>_insert_tail>() inserts the element I<elem>, which
  60. must not be in the list, into the last position in the I<list>.
  61. B<ossl_list_I<TYPE>_insert_before>() inserts the element I<elem>,
  62. which must not be in the list, into the I<list> immediately before the
  63. I<existing> element.
  64. B<ossl_list_I<TYPE>_insert_after>() inserts the element I<elem>,
  65. which must not be in the list, into the I<list> immediately after the
  66. I<existing> element.
  67. =head1 RETURN VALUES
  68. B<ossl_list_I<TYPE>_is_empty>() returns nonzero if the list is empty and zero
  69. otherwise.
  70. B<ossl_list_I<TYPE>_num>() returns the number of elements in the
  71. list.
  72. B<ossl_list_I<TYPE>_head>(), B<ossl_list_I<TYPE>_tail>(),
  73. B<ossl_list_I<TYPE>_next>() and B<ossl_list_I<TYPE>_prev>() return
  74. the specified element in the list.
  75. =head1 EXAMPLES
  76. typedef struct item_st ITEM;
  77. struct item_st {
  78. ...
  79. OSSL_LIST_MEMBER(new_items, ITEM);
  80. ...
  81. };
  82. DEFINE_LIST_OF(new_items, ITEM);
  83. OSSL_LIST(new_items) new;
  84. ITEM *p;
  85. for (p = ossl_list_new_items_head(&st->new); p != NULL;
  86. p = ossl_list_new_items_next(p))
  87. /* do something */
  88. =head1 HISTORY
  89. The functions described here were all added in OpenSSL 3.2.
  90. =head1 COPYRIGHT
  91. Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
  92. Licensed under the Apache License 2.0 (the "License"). You may not use
  93. this file except in compliance with the License. You can obtain a copy
  94. in the file LICENSE in the source distribution or at
  95. L<https://www.openssl.org/source/license.html>.
  96. =cut