regify utility  2.0.0-0
list.h
1 /*
2  * Copyright regify
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
87 #ifndef REGIFY_UTIL_LIST_H
88 #define REGIFY_UTIL_LIST_H
89 /* Only need to export C interface if used by C++ source code */
90 #ifdef __cplusplus
91 extern "C" {
92 #endif /* __cplusplus */
93 
94 /*****************************************************************************
95 * *
96 * ------------------------ Public List Interface ------------------------- *
97 * *
98 *****************************************************************************/
103 typedef void* ruList;
104 
109 typedef void* ruListElmt;
110 
115 typedef void* ruIterator;
116 
123 RUAPI ruList ruListNew(ruType valueType);
124 
135 RUAPI ruList ruListNewBound(ruType valueType, uint32_t maxSize, bool ordered);
136 
150 RUAPI int32_t ruListBind(ruList rl, bool bound);
151 
159 
168 RUAPI int32_t ruListClear(ruList rl);
169 
179 RUAPI int32_t ruListAppendPtr(ruList rl, perm_ptr data);
180 
190 #define ruListAppend(rl, data) ruListAppendPtr(rl, (perm_ptr)(data))
191 
201 #define ruListPush(rl, data) ruListAppendPtr(rl, (perm_ptr)(data))
202 
214 RUAPI int32_t ruListInsertIdx(ruList rl, int32_t index, perm_ptr data);
215 
226 RUAPI int32_t ruListInsertBefore(ruList rl, ruListElmt rle, perm_ptr data);
227 
238 RUAPI int32_t ruListInsertAfter(ruList rl, ruListElmt rle, perm_ptr data);
239 
247 RUAPI uint32_t ruListSize(ruList rl, int32_t* code);
248 
260 RUAPI alloc_chars ruListJoin(ruList rl, trans_chars delim, int32_t* code);
261 
270 RUAPI int32_t ruListSort(ruList rl);
271 
284 RUAPI ptr ruListRemove(ruList rl, ruListElmt* rle, int32_t* code);
285 
297 RUAPI ptr ruListRemoveIdx(ruList rl, int32_t index, int32_t* code);
298 
311 RUAPI ptr ruListPop(ruList rl, int32_t *code);
312 
327 RUAPI ptr ruListTryPop(ruList rl, msec_t timeoutMs, int32_t *code);
328 
336 RUAPI ruListElmt ruListHead(ruList rl, int32_t* code);
337 
344 #define ruListIter(rl) ruListHead(rl, NULL)
345 
353 RUAPI ruListElmt ruListTail(ruList rl, int32_t* code);
354 
362 RUAPI bool ruListElmtIsHead(ruListElmt re, int32_t* code);
363 
371 RUAPI bool ruListElmtIsTail(ruListElmt re, int32_t* code);
372 
380 RUAPI ruListElmt ruListNextElmt(ruListElmt re, int32_t* code);
381 
390 RUAPI ptr ruListNextData(ruListElmt *re, int32_t* code);
391 
399 #define ruIterNext(re, type) (type) ruListNextData(&(re), NULL)
400 
413 RUAPI ptr ruListIdxData(ruList rl, int32_t index, int32_t* code);
414 
427 #define ruListIdx(rl, index, type, code) (type)ruListIdxData(rl, index, code)
428 
442 RUAPI int32_t ruListRemoveDataTo(ruList rl, ruListElmt* rle, ptr* dest);
443 
457 #define ruListRemoveTo(rl, rle, dest) ruListRemoveDataTo(rl, &(rle), (ptr*)&(dest))
458 
471 RUAPI int32_t ruListRemoveIdxDataTo(ruList rl, int32_t index, ptr* dest);
472 
485 #define ruListRemoveIdxTo(rl, index, dest) ruListRemoveIdxDataTo(rl, index, (ptr*)&(dest))
486 
500 RUAPI int32_t ruListPopDataTo(ruList rl, ptr* dest);
501 
515 #define ruListPopTo(rl, dest) ruListPopDataTo(rl, (ptr*)&(dest))
516 
532 RUAPI int32_t ruListTryPopDataTo(ruList rl, msec_t timeoutMs, ptr* dest);
533 
549 #define ruListTryPopTo(rl, timeoutMs, dest) ruListTryPopDataTo(rl, timeoutMs, (ptr*)&(dest))
550 
563 RUAPI int32_t ruListNextDataTo(ruListElmt *re, ptr* dest);
564 
577 #define ruIterTo(re, dest) ruListNextDataTo(&(re), (ptr*)&(dest))
578 
592 RUAPI int32_t ruListIdxDataTo(ruList rl, int32_t index, ptr* dest);
593 
607 #define ruListIdxTo(rl, index, dest) ruListIdxDataTo(rl, index, (ptr*)&(dest))
608 
609 #ifdef __cplusplus
610 }
611 #endif /* __cplusplus */
612 #endif //REGIFY_UTIL_LIST_H
RUAPI int32_t ruListInsertIdx(ruList rl, int32_t index, perm_ptr data)
Inserts given object at indexed position in list in given list element.
RUAPI alloc_chars ruListJoin(ruList rl, trans_chars delim, int32_t *code)
Joins a list of char* item with given delim.
RUAPI bool ruListElmtIsHead(ruListElmt re, int32_t *code)
Indicates whether given element is the first in the given list.
RUAPI bool ruListElmtIsTail(ruListElmt re, int32_t *code)
Indicates whether given element is the last in the given list.
RUAPI int32_t ruListSort(ruList rl)
Sorts the given list using the associated types comparator function.
RUAPI int32_t ruListInsertBefore(ruList rl, ruListElmt rle, perm_ptr data)
Inserts given object before given list element.
RUAPI ruListElmt ruListHead(ruList rl, int32_t *code)
Returns the first element in the given list.
RUAPI ruListElmt ruListNextElmt(ruListElmt re, int32_t *code)
Return the next element following the given element from list.
RUAPI int32_t ruListBind(ruList rl, bool bound)
Allows ignoring or obeying the ruListNewBound maxSize of a ruList.
void * ruIterator
Opaque pointer to list iterator object. See List Collection.
Definition: list.h:115
void * ruListElmt
Opaque pointer to list element object. See List Collection.
Definition: list.h:109
RUAPI ruList ruListFree(ruList rl)
Frees the given list object.
RUAPI ruList ruListNew(ruType valueType)
Creates a new list object. To be freed with ruListFree.
RUAPI ruListElmt ruListTail(ruList rl, int32_t *code)
Returns the last element in the given list.
void * ruList
Opaque pointer to list object. See List Collection.
Definition: list.h:103
RUAPI int32_t ruListClear(ruList rl)
Clears the given list.
RUAPI ruList ruListNewBound(ruType valueType, uint32_t maxSize, bool ordered)
Creates a new bound list object. To be freed with ruListFree.
RUAPI int32_t ruListInsertAfter(ruList rl, ruListElmt rle, perm_ptr data)
Inserts given object after given list element.
RUAPI uint32_t ruListSize(ruList rl, int32_t *code)
Returns the number of elements in the list.
RUAPI int32_t ruListAppendPtr(ruList rl, perm_ptr data)
Appends the given object to the list.
RUAPI ptr ruListRemove(ruList rl, ruListElmt *rle, int32_t *code)
Remove and return the current list element from list.
RUAPI ptr ruListTryPop(ruList rl, msec_t timeoutMs, int32_t *code)
Tries to return first element of the list.
RUAPI ptr ruListIdxData(ruList rl, int32_t index, int32_t *code)
Returns the data payload of the element at given 0 based index.
RUAPI ptr ruListNextData(ruListElmt *re, int32_t *code)
Returns the data payload of the next list element.
RUAPI ptr ruListPop(ruList rl, int32_t *code)
Return first element of the list.
RUAPI ptr ruListRemoveIdx(ruList rl, int32_t index, int32_t *code)
Remove and return the list element at index position from list.
RUAPI int32_t ruListRemoveDataTo(ruList rl, ruListElmt *rle, ptr *dest)
Remove and return the current list element from list.
RUAPI int32_t ruListPopDataTo(ruList rl, ptr *dest)
Return first element of the list.
RUAPI int32_t ruListIdxDataTo(ruList rl, int32_t index, ptr *dest)
Returns the data payload of the element at given 0 based index.
RUAPI int32_t ruListRemoveIdxDataTo(ruList rl, int32_t index, ptr *dest)
Remove and return the list element at index position from list.
RUAPI int32_t ruListNextDataTo(ruListElmt *re, ptr *dest)
Returns the data payload of the next list element.
RUAPI int32_t ruListTryPopDataTo(ruList rl, msec_t timeoutMs, ptr *dest)
Tries to return first element of the list.
const void * perm_ptr
A permanent pointer.
Definition: regify-util.h:277
const char * trans_chars
A transient NULL terminated string pointer.
Definition: regify-util.h:186
char * alloc_chars
An allocated NULL terminated string pointer.
Definition: regify-util.h:199
void * ptr
A generic pointer.
Definition: regify-util.h:304
int64_t msec_t
A signed type for expressing milli seconds.
Definition: regify-util.h:318
void * ruType
An opaque type representing a type specification.
Definition: regify-util.h:344