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