CsonList链表增加节点删除操作

This commit is contained in:
Letter 2020-04-20 15:22:25 +08:00
parent d9cd0c8d3c
commit 0f8ffa381d
2 changed files with 46 additions and 1 deletions

View File

@ -686,6 +686,41 @@ CsonList* csonListAdd(CsonList *list, void *obj)
}
/**
* @brief CSON链表删除节点
*
* @param list
* @param obj
* @param freeMem
* @return CsonList
*/
CsonList *csonListDelete(CsonList *list, void *obj, char freeMem)
{
CSON_ASSERT(list, return NULL);
CsonList head = {0};
head.next = list;
CsonList *p = &head;
CsonList *tmp;
while (p->next)
{
if (p->next->obj && p->next->obj == obj)
{
tmp = p->next;
p->next = p->next->next ? p->next->next : NULL;
if (freeMem)
{
cson.free(tmp->obj);
cson.free(tmp);
}
break;
}
p = p->next;
}
return head.next;
}
/**
* @brief CSON新字符串
*

View File

@ -228,7 +228,7 @@ extern CsonModel csonBasicListModel[]; /**< 基础类型链表数据模型 */
*/
#define CSON_ASSERT(expr, action) \
if (!(expr)) { \
printf(#expr " assert failed at file: %s, line: %d", __FILE__, __LINE__); \
printf(#expr " assert failed at file: %s, line: %d\r\n", __FILE__, __LINE__); \
action; \
}
@ -368,6 +368,16 @@ void csonFreeJson(const char *jsonStr);
*/
CsonList* csonListAdd(CsonList *list, void *obj);
/**
* @brief CSON链表删除节点
*
* @param list
* @param obj
* @param freeMem
* @return CsonList
*/
CsonList *csonListDelete(CsonList *list, void *obj, char freeMem);
/**
* @brief CSON新字符串
*