af93cbdf |
/*
* circular list maintenance macros
*
* Copyright (C) 2005 iptelorg GmbH
*
|
02ca141b |
* This file is part of Kamailio, a free SIP server.
|
af93cbdf |
*
|
02ca141b |
* Kamailio is free software; you can redistribute it and/or modify
|
af93cbdf |
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
|
02ca141b |
* Kamailio is distributed in the hope that it will be useful,
|
af93cbdf |
* 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 this program; if not, write to the Free Software
|
9e1ff448 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
af93cbdf |
*/
|
5a03489e |
/*!
* \file
|
02ca141b |
* \brief Kamailio core :: circular list maintenance macros
|
5a03489e |
*
|
02ca141b |
* \author andrei
|
5a03489e |
* \ingroup core
* Module: \ref core
*/
|
af93cbdf |
#ifndef _clist_h
#define _clist_h
|
3ca1a53f |
/*! \brief circular list */
|
af93cbdf |
#define clist_init(c, next, prev) \
do{ \
|
5b2134e3 |
(c)->next=(void*)(c); \
(c)->prev=(void*)(c); \
|
af93cbdf |
} while(0)
|
5a03489e |
/*! \brief adds an entire sublist { s,e } (including s & e )
|
af93cbdf |
* after head
|
5a03489e |
*
* \note WARNING: clist_insert_sublist(head, n, n->prev) won't work,
|
dcb59e67 |
* same for clist_insert_sublist(head, n->next, n)
* (macro!), use e=n->prev; clist_insert_sublist(head, n, e, ...)
* instead!
|
af93cbdf |
*/
#define clist_insert_sublist(head, s, e, next, prev) \
do{ \
|
5b2134e3 |
(s)->prev=(void*)(head); \
|
af93cbdf |
(e)->next=(head)->next; \
(e)->next->prev=(e); \
(head)->next=s; \
}while(0)
|
5a03489e |
/*! \brief appends an entire sublist { s,e } (including s & e )
|
af93cbdf |
* at the end of the list
|
5a03489e |
*
|
dcb59e67 |
* WARNING: clist_append_sublist(head, n, n->prev, ...) won't work,
* (macro!), use e=n->prev; clist_append_sublist(head, n, e, ...)
* instead!
|
af93cbdf |
*/
#define clist_append_sublist(head, s, e, next, prev) \
do{ \
(s)->prev=(head)->prev; \
(e)->next=(void*)(head); \
(s)->prev->next=(s); \
(head)->prev=(e); \
}while(0)
|
dcb59e67 |
|
5a03489e |
/*! \brief remove sublist { s,e } (including s & e )
|
af93cbdf |
* always, if start is the beginning of the list use
|
dcb59e67 |
* clist_rm_sublist(head->next, e, next, prev )
* WARNING: clist_rm_sublist(n, n->prev, ...) won't work,
* (macro!), use e=n->prev; clist_rm_sublist(n, e, ...)
* instead! */
|
af93cbdf |
#define clist_rm_sublist(s, e, next, prev) \
do{\
|
5b2134e3 |
(s)->prev->next=(e)->next; \
|
ad6916e6 |
(e)->next->prev=(s)->prev; \
(s)->prev=NULL; \
(e)->next=NULL; \
|
af93cbdf |
}while(0)
|
5a03489e |
/*! \brief insert after (head) */
|
af93cbdf |
#define clist_insert(head, c, next, prev) \
clist_insert_sublist(head, c, c, next, prev)
|
5a03489e |
/*! \brief append at the end of the list (head->prev) */
|
af93cbdf |
#define clist_append(head, c, next, prev) \
clist_append_sublist(head, c, c, next, prev)
|
5a03489e |
/*! \brief remove and element */
|
af93cbdf |
#define clist_rm(c, next, prev) \
clist_rm_sublist(c, c, next, prev)
|
5a03489e |
/*! \brief iterate on a clist */
|
af93cbdf |
#define clist_foreach(head, v, dir) \
for((v)=(head)->dir; (v)!=(void*)(head); (v)=(v)->dir)
|
5a03489e |
/*! \brief iterate on a clist, safe version (requires an extra bak. var)
|
af93cbdf |
* (it allows removing of the current element) */
#define clist_foreach_safe(head, v, bak, dir) \
for((v)=(head)->dir, (bak)=(v)->dir; (v)!=(void*)(head); \
(v)=(bak), (bak)=(v)->dir)
#endif
|