Debian Codegraph @

include/mps/private/list.h

raw
1 /*
2 * This file is part of MPSolve 3.2.2
3 *
4 * Copyright (C) 2001-2020, Dipartimento di Matematica "L. Tonelli", Pisa.
5 * License: http://www.gnu.org/licenses/gpl.html GPL version 3 or higher
6 *
7 * Authors:
8 * Leonardo Robol <[email protected]>
9 */
10
11 /**
12 * @file
13 * @brief Custom implementation of list inside MPSolve.
14 *
15 * This implementation may be a custom one or simply a wrapper around something more
16 * tested and proved to be working. Its main role is to abstract this choice to the internals
17 * of MPSolve.
18 */
19
20 #ifndef MPS_LIST_H_
21 #define MPS_LIST_H_
22
23 MPS_BEGIN_DECLS
24
25 struct mps_list_element {
26 /**
27 * @brief The value pointed by this list element. Note that holding this pointer
28 * in the first field of the struct allows to painlessly cast a mps_list_element
29 * to the pointer inside it.
30 */
31 void * value;
32
33 /**
34 * @brief The next element in the list.
35 *
36 * This value should be NULL if this is the last element of the list
37 * or the element is detached.
38 */
39 struct mps_list_element * next;
40
41 /**
42 * @brief The previous element in the list.
43 *
44 * This value should be NULL if this is the first element of the list
45 * or the element is detached.
46 */
47 struct mps_list_element * previous;
48 };
49
50 struct mps_list {
51 /**
52 * @brief A pointer to the first element of the list.
53 */
54 mps_list_element * first;
55
56 /**
57 * @brief A pointer to the last element of the list.
58 */
59 mps_list_element * last;
60
61 /**
62 * @brief The number of element of the list.
63 */
64 int size;
65 };
66
67 mps_list_element * mps_list_element_new (void * value);
68 void mps_list_element_free (mps_list_element * el);
69 mps_list_element * mps_list_element_next (mps_list_element * el);
70 mps_list_element * mps_list_element_previous (mps_list_element * el);
71 void * mps_list_element_value (mps_list_element * el);
72
73 mps_list * mps_list_new (void);
74 void mps_list_free (mps_list * list);
75 int mps_list_size (mps_list * list);
76 void mps_list_append (mps_list * list, mps_list_element * el);
77 mps_list_element * mps_list_first (mps_list * list);
78 mps_list_element * mps_list_last (mps_list * list);
79
80 /**
81 * @brief Shortcut for iterating over lists. Note that this structure is
82 * C99 only, since it would not compile under a strict C89 compiler.
83 */
84 #define MPS_LIST_FOREACH(type, local_var, list) \
85 for (type *__mps_local_iterator = (type*)mps_list_first (list), \
86 *local_var = (type*)mps_list_element_value ((mps_list_element*)__mps_local_iterator); \
87 __mps_local_iterator != NULL; \
88 __mps_local_iterator = (type*)mps_list_element_next ((mps_list_element*)__mps_local_iterator), \
89 local_var = (type*)mps_list_element_value ((mps_list_element*)__mps_local_iterator))
90
91 MPS_END_DECLS
92
93 #endif /* MPS_LIST_H_ */
94