/* slist.h * * Copyright 2026 Francois Techene * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * Except as contained in this notice, the name(s) of the above copyright * holders shall not be used in advertising or otherwise to promote the sale, * use or other dealings in this Software without prior written * authorization. */ #ifndef __SLIST_H__ #define __SLIST_H__ typedef struct _SListItem { void* data; struct _SListItem* next; } SListItem; typedef struct _SList { void* (*first)(struct _SList* self); void* (*last)(struct _SList* self); void* (*next)(struct _SList* self, SListItem* item); SListItem* head; int count; } SList; // SListItem //////////////// // SListItem* NewSListItem(); void DeleteSListItem(SListItem* item); // SList //////////////////// // SList* NewSList(); void DeleteSList(SList* self); void* SListFirst(SList* self); void* SListLast(SList* self); void* SListNext(SList* self, SListItem* item); void SListAppend(SList* self, void* data); void SListInsertAt(SList* self, void* data, int index); void SListInsertAfter(SList* self, void* data, void* value); void SListRemoveAt(SList* self, int index); void SListRemoveLast(SList* self); void SListRemoveValue(SList* self, void* data); void SListEmpty(SList* self); #define SL_FOREACH(item, list) \ for ((item) = (list)->first(list); \ (item) != (list)->last(list); \ (item) = (list)->next(list, item)) #endif