22 #include <lal/LALStdio.h>
23 #include <lal/LALStdlib.h>
24 #include <lal/LALList.h>
45 item->value.size = size;
56 item->value.size = size;
62 if (
XLALValueSet(&item->value, data, size, type) == NULL)
76 size_t size =
sizeof(LALListItem) + item->value.size;
80 return memcpy(copy, item, size);
121 #define DEFINE_GET_FUNC(TYPE, FAILVAL) \
122 TYPE XLALListItemGet ## TYPE ## Value(const LALListItem *item) \
124 const LALValue *value = XLALListItemGetValue(item); \
126 XLAL_ERROR_VAL(FAILVAL, XLAL_EFUNC); \
127 return XLALValueGet ## TYPE (value); \
143 #undef DEFINE_GET_FUNC
158 LALListItem *item = list->head;
177 const LALListItem *item = list->head;
178 LALListItem *head = NULL;
179 LALListItem *prev = NULL;
182 LALListItem *copy = NULL;
194 newlist->head = head;
201 LALListItem *item = list->head;
202 LALListItem *tsil = NULL;
214 static LALListItem *
XLALListSortMerge(LALListItem *
a, LALListItem *b,
int (*
cmp)(
const LALValue *,
const LALValue *,
void *),
void *thunk)
216 LALListItem *result = NULL;
222 if (
cmp(&
a->value, &b->value, thunk) <= 0) {
233 int XLALListSort(LALList *list,
int (*
cmp)(
const LALValue *,
const LALValue *,
void *),
void *thunk)
240 if (list->head == NULL || list->head->next == NULL)
246 while (fast != NULL) {
255 head.head = list->head;
256 tail.head = slow->next;
272 const LALListItem *item = list->head;
284 LALListItem *item = list->head;
286 func(&item->value, thunk);
295 LALListItem *item = NULL;
296 if (list != NULL && list->head != NULL) {
298 list->head = item->next;
305 LALListItem *item = NULL;
306 if (list != NULL && list->head != NULL) {
308 while (item->next != NULL)
314 LALListItem *
XLALListFind(LALList *list,
int (*func)(
const LALValue *,
void *),
void *thunk)
316 LALListItem *item = NULL;
320 if (func(&item->value, thunk))
330 const LALValue *target = (
const LALValue *)thunk;
336 void *thunk = (
void *)(uintptr_t)
value;
344 LALListItem *item = list->head;
345 LALListItem *prev = NULL;
347 if (func(&item->value, thunk)) {
348 LALListItem *orig = item;
377 LALListItem *item = list->head;
378 LALListItem *prev = NULL;
380 if (func(&item->value, thunk)) {
381 LALListItem *orig = item;
407 void *thunk = (
void *)(uintptr_t)
value;
413 void *thunk = (
void *)(uintptr_t)
value;
417 int XLALListRemove(LALList *list,
int (*func)(
const LALValue *,
void *),
void *thunk)
420 LALListItem *item = list->head;
421 LALListItem *prev = NULL;
423 if (func(&item->value, thunk)) {
425 list->head = item->next;
427 prev->next = item->next;
442 LALListItem *item = list->head;
443 LALListItem *prev = NULL;
445 if (func(&item->value, thunk)) {
465 void *thunk = (
void *)(uintptr_t)
value;
471 void *thunk = (
void *)(uintptr_t)
value;
477 iter->next = list == NULL ? NULL : list->head;
482 if (iter->next == NULL)
504 item->next = list->head;
524 size_t size = strlen(
string) + 1;
528 #define DEFINE_ADD_FUNC(TYPE, TCODE) \
529 int XLALListAdd ## TYPE ## Value (LALList *list, TYPE value) \
530 { return XLALListAdd(list, &value, sizeof(value), TCODE); } \
545 #undef DEFINE_ADD_FUNC
575 dprintf(fd,
"%s",
s);
void XLALListPrint(LALList *list, int fd)
int XLALListAddValue(LALList *list, const LALValue *value)
#define DEFINE_GET_FUNC(TYPE, FAILVAL)
LALListItem * XLALListItemRealloc(LALListItem *item, size_t size)
LALList * XLALListDuplicate(const LALList *list)
int XLALListReverse(LALList *list)
static LALListItem * XLALListSortMerge(LALListItem *a, LALListItem *b, int(*cmp)(const LALValue *, const LALValue *, void *), void *thunk)
LALListItem * XLALListLast(LALList *list)
size_t XLALListSize(const LALList *list)
static int XLALListFindValueFunc(const LALValue *value, void *thunk)
void XLALListIterInit(LALListIter *iter, LALList *list)
const char * XLALListItemGetStringValue(const LALListItem *item)
REAL8 XLALListItemGetValueAsREAL8(const LALListItem *item)
void * XLALListItemGetValueData(void *data, size_t size, LALTYPECODE type, const LALListItem *item)
#define DEFINE_ADD_FUNC(TYPE, TCODE)
int XLALListRemoveValue(LALList *list, const LALValue *value)
void * XLALListItemGetBLOBValue(const LALListItem *item)
LALListItem * XLALListFind(LALList *list, int(*func)(const LALValue *, void *), void *thunk)
int XLALListReplaceValue(LALList *list, const LALValue *value, const LALValue *replace)
int XLALListReplaceValueAll(LALList *list, const LALValue *value, const LALValue *replace)
int XLALListSort(LALList *list, int(*cmp)(const LALValue *, const LALValue *, void *), void *thunk)
int XLALListAddStringValue(LALList *list, const char *string)
void XLALListForeach(LALList *list, void(*func)(LALValue *, void *), void *thunk)
int XLALListRemoveValueAll(LALList *list, const LALValue *value)
int XLALListAddBLOBValue(LALList *list, const void *blob, size_t size)
static void XLALListAsStringAppendValueFunc(LALValue *value, void *thunk)
LALTYPECODE XLALListItemGetValueType(const LALListItem *item)
int XLALListReplaceAll(LALList *list, int(*func)(const LALValue *, void *), void *thunk, const LALValue *replace)
int XLALListAdd(LALList *list, const void *data, size_t size, LALTYPECODE type)
LALListItem * XLALListItemSet(LALListItem *item, const void *data, size_t size, LALTYPECODE type)
const LALValue * XLALListItemGetValue(const LALListItem *item)
int XLALListRemoveAll(LALList *list, int(*func)(const LALValue *, void *), void *thunk)
void XLALDestroyList(LALList *list)
int XLALListRemove(LALList *list, int(*func)(const LALValue *, void *), void *thunk)
LALListItem * XLALListItemDuplicate(const LALListItem *item)
LALListItem * XLALListPop(LALList *list)
LALListItem * XLALListIterNext(LALListIter *iter)
LALList * XLALCreateList(void)
LALListItem * XLALListItemSetValue(LALListItem *item, const LALValue *value)
int XLALListReplace(LALList *list, int(*func)(const LALValue *, void *), void *thunk, const LALValue *replace)
char * XLALListAsStringAppend(char *s, LALList *list)
LALListItem * XLALListFindValue(LALList *list, const LALValue *value)
LALListItem * XLALListItemAlloc(size_t size)
static int replace(int c, void *param)
REAL8 XLALValueGetAsREAL8(const LALValue *value)
char * XLALValueAsStringAppend(char *s, const LALValue *value)
int XLALValueEqual(const LALValue *value1, const LALValue *value2)
void * XLALValueGetBLOB(const LALValue *value)
LALValue * XLALValueCopy(LALValue *copy, const LALValue *orig)
size_t XLALValueGetSize(const LALValue *value)
const void * XLALValueGetDataPtr(const LALValue *value)
const char * XLALValueGetString(const LALValue *value)
void * XLALValueGetData(void *data, size_t size, LALTYPECODE type, const LALValue *value)
LALTYPECODE XLALValueGetType(const LALValue *value)
LALValue * XLALValueSet(LALValue *value, const void *data, size_t size, LALTYPECODE type)
static int cmp(REAL4Sequence *a, REAL4Sequence *b)
LALTYPECODE
Type codes: use these type codes to identify a LAL atomic data type, see Headers LAL(Atomic)Datatypes...
unsigned char UCHAR
One-byte unsigned integer, see Headers LAL(Atomic)Datatypes.h for more details.
uint64_t UINT8
Eight-byte unsigned integer; on some platforms this is equivalent to unsigned long int instead.
double complex COMPLEX16
Double-precision floating-point complex number (16 bytes total)
double REAL8
Double precision real floating-point number (8 bytes).
int16_t INT2
Two-byte signed integer.
int64_t INT8
Eight-byte signed integer; on some platforms this is equivalent to long int instead.
uint16_t UINT2
Two-byte unsigned integer.
char CHAR
One-byte signed integer, see Headers LAL(Atomic)Datatypes.h for more details.
uint32_t UINT4
Four-byte unsigned integer.
float complex COMPLEX8
Single-precision floating-point complex number (8 bytes total)
int32_t INT4
Four-byte signed integer.
float REAL4
Single precision real floating-point number (4 bytes).
@ LAL_C_TYPE_CODE
COMPLEX8 type code (27)
@ LAL_CHAR_TYPE_CODE
CHAR type code (0)
@ LAL_U2_TYPE_CODE
UINT2 type code (33)
@ LAL_Z_TYPE_CODE
COMPLEX16 type code (28)
@ LAL_S_TYPE_CODE
REAL4 type code (18)
@ LAL_I2_TYPE_CODE
INT2 type code (1)
@ LAL_I8_TYPE_CODE
INT8 type code (3)
@ LAL_D_TYPE_CODE
REAL8 type code (19)
@ LAL_I4_TYPE_CODE
INT4 type code (2)
@ LAL_UCHAR_TYPE_CODE
UCHAR type code (32)
@ LAL_U8_TYPE_CODE
UINT8 type code (35)
@ LAL_U4_TYPE_CODE
UINT4 type code (34)
#define XLALRealloc(p, n)
char * XLALStringAppend(char *s, const char *append)
Like strcat but dynamically reallocates string with LALRealloc.
#define XLAL_ERROR_VOID(...)
Macro to invoke a failure from a XLAL routine returning void.
#define XLAL_ERROR_REAL8(...)
Macro to invoke a failure from a XLAL routine returning a REAL8.
#define XLAL_ERROR_NULL(...)
Macro to invoke a failure from a XLAL routine returning a pointer.
#define XLAL_ERROR(...)
Macro to invoke a failure from a XLAL routine returning an integer.
#define XLAL_CHECK(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns an integ...
#define XLAL_CHECK_VOID(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns void.
#define XLAL_REAL4_FAIL_NAN
Floating-point value of the XLAL REAL4 failure NaN.
#define XLAL_REAL8_FAIL_NAN
Floating-point value of the XLAL REAL8 failure NaN.
@ XLAL_ENOMEM
Memory allocation error.
@ XLAL_EFAULT
Invalid pointer.
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
@ XLAL_FAILURE
Failure return value (not an error number)
struct tagLALListItem * head
struct tagLALListItem * next