C Tool Box 0.1.0
Loading...
Searching...
No Matches
ctb_DListIterator.h
Go to the documentation of this file.
1/**
2 * @file
3 */
4#ifndef CTB_DLISTITERATOR_H
5#define CTB_DLISTITERATOR_H
6
7/**
8 * @brief Doubly linked list iterator type
9 */
11
12#include "ctb_DNode.h"
13#include <stdbool.h>
14
15/**
16 * @brief Typedef for predicate function used to find a node in the doubly linked list
17 *
18 * @param node Pointer to the node
19 * @return True if the node satisfies the predicate, false otherwise
20 */
21typedef bool (*ctb_DListIterator_FindPredicate_t)(ctb_DNode_t * const node);
22
23/**
24 * @brief Typedef for operation function to be applied to each node in the doubly linked list
25 *
26 * @param node Pointer to the node
27 */
29
30#include "ctb_DList.h"
31
32/**
33 * @brief Doubly linked list iterator data structure
34 */
36 ctb_DList_t * list; /**< Pointer to the doubly linked list */
37 ctb_DNode_t * current; /**< Pointer to the current node */
38};
39
40/**
41 * @brief Initializes a doubly linked list iterator
42 *
43 * @param self Pointer to a doubly linked list iterator
44 * @param list Pointer to the doubly linked list
45 * @return Pointer to the initialized doubly linked list iterator
46 */
48 ctb_DListIterator_t * const self, ctb_DList_t * const list
49);
50
51/**
52 * @brief Resets the iterator to the first node
53 *
54 * @param self Pointer to a doubly linked list iterator
55 * @return Pointer to the doubly linked list iterator reset to the first node
56 */
58 ctb_DListIterator_t * const self
59);
60
61/**
62 * @brief Resets the iterator to the last node
63 *
64 * @param self Pointer to a doubly linked list iterator
65 * @return Pointer to the doubly linked list iterator reset to the last node
66 */
68 ctb_DListIterator_t * const self
69);
70
71/**
72 * @brief Checks if there is a node after the current node
73 *
74 * @param self Pointer to a doubly linked list iterator
75 * @return True if there is a node after the current node, false otherwise
76 */
78
79/**
80 * @brief Checks if there is a node before the current node
81 *
82 * @param self Pointer to a doubly linked list iterator
83 * @return True if there is a node before the current node, false otherwise
84 */
86
87/**
88 * @brief Returns the next node
89 *
90 * @param self Pointer to a doubly linked list iterator
91 * @return Pointer to the next node, or NULL if there is no next node
92 */
94
95/**
96 * @brief Returns the previous node
97 *
98 * @param self Pointer to a doubly linked list iterator
99 * @return Pointer to the previous node, or NULL if there is no previous node
100 */
102
103/**
104 * @brief Applies an operation to each node in the doubly linked list
105 *
106 * @param self Pointer to a doubly linked list iterator
107 * @param operation Operation to apply to each node
108 */
110 ctb_DListIterator_t * const self,
112);
113
114/**
115 * @brief Finds a node in the doubly linked list that satisfies a predicate
116 *
117 * @param self Pointer to a doubly linked list iterator
118 * @param predicate Predicate function
119 * @return Pointer to the found node, or NULL if no node satisfies the predicate
120 */
122 ctb_DListIterator_t * const self,
124);
125
126#endif // CTB_DLISTITERATOR_H
ctb_DListIterator_t * ctb_DListIterator_resetToLast(ctb_DListIterator_t *const self)
Resets the iterator to the last node.
Definition ctb_DListIterator.c:21
bool ctb_DListIterator_hasNext(ctb_DListIterator_t *const self)
Checks if there is a node after the current node.
Definition ctb_DListIterator.c:29
void ctb_DListIterator_forEach(ctb_DListIterator_t *const self, ctb_DListIterator_ForEachOperation_t const operation)
Applies an operation to each node in the doubly linked list.
Definition ctb_DListIterator.c:61
void(* ctb_DListIterator_ForEachOperation_t)(ctb_DNode_t *const node)
Typedef for operation function to be applied to each node in the doubly linked list.
Definition ctb_DListIterator.h:28
ctb_DListIterator_t * ctb_DListIterator_resetToFirst(ctb_DListIterator_t *const self)
Resets the iterator to the first node.
Definition ctb_DListIterator.c:13
ctb_DNode_t * ctb_DListIterator_find(ctb_DListIterator_t *const self, ctb_DListIterator_FindPredicate_t const predicate)
Finds a node in the doubly linked list that satisfies a predicate.
Definition ctb_DListIterator.c:72
ctb_DNode_t * ctb_DListIterator_previous(ctb_DListIterator_t *const self)
Returns the previous node.
Definition ctb_DListIterator.c:51
bool(* ctb_DListIterator_FindPredicate_t)(ctb_DNode_t *const node)
Typedef for predicate function used to find a node in the doubly linked list.
Definition ctb_DListIterator.h:21
ctb_DNode_t * ctb_DListIterator_next(ctb_DListIterator_t *const self)
Returns the next node.
Definition ctb_DListIterator.c:41
bool ctb_DListIterator_hasPrevious(ctb_DListIterator_t *const self)
Checks if there is a node before the current node.
Definition ctb_DListIterator.c:35
ctb_DListIterator_t * ctb_DListIterator_init(ctb_DListIterator_t *const self, ctb_DList_t *const list)
Initializes a doubly linked list iterator.
Definition ctb_DListIterator.c:4
Doubly linked list iterator data structure.
Definition ctb_DListIterator.h:35
ctb_DList_t * list
Definition ctb_DListIterator.h:36
ctb_DNode_t * current
Definition ctb_DListIterator.h:37
Doubly linked list data structure.
Definition ctb_DList.h:20
Doubly linked node data structure.
Definition ctb_DNode.h:15