2016-03-27 18:37:15 +02:00
|
|
|
/*
|
|
|
|
This file is part of actube.
|
|
|
|
|
|
|
|
actube is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
libcapwap is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2016-02-28 13:41:45 +01:00
|
|
|
#ifndef __MLIST_H
|
|
|
|
#define __MLIST_H
|
|
|
|
|
2016-03-27 18:37:15 +02:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief Mlist Mini list
|
|
|
|
*/
|
|
|
|
|
2018-03-11 10:34:20 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
2016-03-27 18:37:15 +02:00
|
|
|
/**
|
2018-03-25 11:14:37 +02:00
|
|
|
* @addtogroup ALGOS
|
2016-03-27 18:37:15 +02:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2018-03-25 11:14:37 +02:00
|
|
|
/**
|
|
|
|
* @defgroup MLIST Mlist
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-27 18:37:15 +02:00
|
|
|
/**
|
|
|
|
* Element of an mlist.
|
|
|
|
* It's a simple connected list, just with pone connection to the
|
|
|
|
* next element.
|
|
|
|
*/
|
2018-03-11 10:34:20 +01:00
|
|
|
struct mlistelem {
|
|
|
|
struct mlistelem *next;
|
|
|
|
struct mlistelem *prev;
|
2016-02-28 13:41:45 +01:00
|
|
|
};
|
2018-03-11 10:34:20 +01:00
|
|
|
typedef struct mlistelem mlistelem_t;
|
2016-02-28 13:41:45 +01:00
|
|
|
|
|
|
|
struct mlist {
|
2018-03-11 10:34:20 +01:00
|
|
|
/* void *data;*/
|
2018-02-24 23:58:31 +01:00
|
|
|
int (*cmp) (const void *d1, const void *d2);
|
2018-03-11 10:34:20 +01:00
|
|
|
void (*del) (void *data);
|
|
|
|
struct mlistelem *first;
|
|
|
|
struct mlistelem *last;
|
2018-03-09 15:38:21 +01:00
|
|
|
int count;
|
2018-03-11 10:34:20 +01:00
|
|
|
size_t data_size;
|
2016-02-28 13:41:45 +01:00
|
|
|
};
|
2018-02-24 23:58:31 +01:00
|
|
|
typedef struct mlist * mlist_t;
|
2016-02-28 13:41:45 +01:00
|
|
|
|
2018-03-11 10:34:20 +01:00
|
|
|
#define mlistelem_dataptr(elem) ((void*)(((uint8_t*)(elem))+sizeof(struct mlistelem)))
|
2016-02-28 13:41:45 +01:00
|
|
|
|
2016-03-27 18:37:15 +02:00
|
|
|
/**
|
|
|
|
* defgroup MLIST_FUNCTIONS
|
|
|
|
* @{
|
|
|
|
*/
|
2018-03-11 10:34:20 +01:00
|
|
|
mlist_t mlist_create(int (*cmp) (const void *v1, const void *v2), void (*del)(void *), size_t data_size);
|
|
|
|
|
|
|
|
struct mlistelem *mlist_append(mlist_t l, void *data);
|
2018-04-07 19:28:00 +02:00
|
|
|
struct mlistelem * mlist_delete(mlist_t list, void *data);
|
|
|
|
|
2018-03-12 18:01:40 +01:00
|
|
|
struct mlistelem * mlist_get(mlist_t list, const void *data);
|
2018-03-12 11:22:06 +01:00
|
|
|
void mlist_destroy(mlist_t l);
|
2018-03-12 18:01:40 +01:00
|
|
|
struct mlistelem *mlist_replace(mlist_t l, void *data);
|
|
|
|
|
2018-03-11 10:34:20 +01:00
|
|
|
|
|
|
|
extern struct mlistelem *mlist_find(mlist_t l, struct mlistelem *start, void *data);
|
2018-03-12 18:01:40 +01:00
|
|
|
|
2016-02-28 13:41:45 +01:00
|
|
|
|
2018-03-12 11:22:06 +01:00
|
|
|
|
|
|
|
|
2018-02-24 23:58:31 +01:00
|
|
|
#define mlist_add mlist_append
|
2016-03-27 18:37:15 +02:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2018-03-11 10:34:20 +01:00
|
|
|
#define mlist_foreach(elem,list)\
|
|
|
|
for (elem=list->first; elem; elem=elem->next)
|
2018-03-12 11:22:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
#define mlistelem_get_ptr(elem) (*((void**)(mlistelem_dataptr(elem))))
|
|
|
|
#define mlistelem_get_str(elem) mlistelem_get_ptr(elem)
|
|
|
|
#define mlist_create_conststr() mlist_create(NULL,NULL,sizeof(const char*))
|
2018-03-31 08:37:18 +02:00
|
|
|
|
|
|
|
|
2018-03-12 11:22:06 +01:00
|
|
|
mlistelem_t * mlist_append_ptr (mlist_t list, void * ptr);
|
|
|
|
|
2018-03-31 08:37:18 +02:00
|
|
|
/*#define mlist_append_ptr(list,ptr) mlist_append(list,&(ptr))*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-27 18:37:15 +02:00
|
|
|
/**
|
2018-03-25 11:14:37 +02:00
|
|
|
* @} MLIST
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @} ALGOS
|
2016-03-27 18:37:15 +02:00
|
|
|
*/
|
2016-02-28 13:41:45 +01:00
|
|
|
|
|
|
|
#endif
|