23 #include <lal/LALStdlib.h>
24 #include <lal/LALStdio.h>
25 #include <lal/LALValue.h>
53 size_t size =
sizeof(LALValue) + value->size;
57 return memcpy(copy, value, size);
118 memcpy(value->data, data, size);
149 size_t size = strlen(
string) + 1;
156 #define DEFINE_CREATE_FUNC(TYPE, TCODE) \
157 LALValue *XLALCreate ## TYPE ## Value(TYPE value) \
159 LALValue *v = XLALCreateValue(&value, sizeof(value), TCODE); \
161 XLAL_ERROR_NULL(XLAL_EFUNC); \
178 #undef DEFINE_CREATE_FUNC
198 if (value->size != size || value->type != type)
200 return memcpy(data, value->data, size);
205 if (value1->size == value2->size && value1->type == value2->type)
206 return memcmp(value1->data, value2->data, value1->size) == 0;
219 return memcpy(blob, value->data, value->size);
229 if (value->size == 0 || ((
const char *)(value->data))[value->size - 1] !=
'\0')
231 return (
const char *)(value->data);
234 #define DEFINE_GET_FUNC(TYPE, TCODE, FAILVAL) \
235 TYPE XLALValueGet ## TYPE (const LALValue *value) \
237 XLAL_CHECK_VAL(FAILVAL, value->type == TCODE, XLAL_ETYPE); \
238 return *(const TYPE *)(value->data); \
254 #undef DEFINE_GET_FUNC
263 switch (value->type) {
265 if (value->size == 1)
266 result = *(
const CHAR *)value;
278 if (i > max_as_double || -i > max_as_double)
282 if (value->size == 1)
295 if (u > umax_as_double)
317 switch (value->type) {
319 if (value->size == 1)
325 if (value->size !=
sizeof(
INT2))
330 if (value->size !=
sizeof(
INT4))
335 if (value->size !=
sizeof(
INT8))
340 if (value->size ==
sizeof(
UCHAR))
344 for (
size_t i = 0; i < value->size; ++i)
350 if (value->size !=
sizeof(
UINT2))
355 if (value->size !=
sizeof(
UINT4))
360 if (value->size !=
sizeof(
UINT8))
365 if (value->size !=
sizeof(
REAL4))
370 if (value->size !=
sizeof(
REAL8))
376 if (value->size !=
sizeof(
COMPLEX8))
398 dprintf(fd,
"%s", s);
char * XLALStringAppendFmt(char *s, const char *fmt,...)
Append the formatted string 'fmt' to the string 's', which is reallocated with XLALRealloc() to the r...
LALValue * XLALValueRealloc(LALValue *value, size_t size)
REAL8 XLALValueGetAsREAL8(const LALValue *value)
char * XLALValueAsStringAppend(char *s, const LALValue *value)
LALValue * XLALValueDuplicate(const LALValue *value)
int XLALValueEqual(const LALValue *value1, const LALValue *value2)
#define DEFINE_GET_FUNC(TYPE, TCODE, FAILVAL)
void * XLALValueGetBLOB(const LALValue *value)
void XLALDestroyValue(LALValue *value)
LALValue * XLALCreateValue(const void *data, size_t size, LALTYPECODE type)
void XLALValuePrint(const LALValue *value, int fd)
LALValue * XLALValueCopy(LALValue *copy, const LALValue *orig)
LALValue * XLALCreateStringValue(const char *string)
#define DEFINE_CREATE_FUNC(TYPE, TCODE)
size_t XLALValueGetSize(const LALValue *value)
const void * XLALValueGetDataPtr(const LALValue *value)
const char * XLALValueGetString(const LALValue *value)
LALValue * XLALCreateBLOBValue(const void *blob, size_t size)
void * XLALValueGetData(void *data, size_t size, LALTYPECODE type, const LALValue *value)
LALValue * XLALValueAlloc(size_t size)
LALTYPECODE XLALValueGetType(const LALValue *value)
LALValue * XLALValueSet(LALValue *value, const void *data, size_t size, LALTYPECODE type)
REAL8 XLALValueGetREAL8(const LALValue *value)
REAL4 XLALValueGetREAL4(const LALValue *value)
INT2 XLALValueGetINT2(const LALValue *value)
INT8 XLALValueGetINT8(const LALValue *value)
UCHAR XLALValueGetUCHAR(const LALValue *value)
COMPLEX8 XLALValueGetCOMPLEX8(const LALValue *value)
COMPLEX16 XLALValueGetCOMPLEX16(const LALValue *value)
UINT8 XLALValueGetUINT8(const LALValue *value)
INT4 XLALValueGetINT4(const LALValue *value)
UINT4 XLALValueGetUINT4(const LALValue *value)
UINT2 XLALValueGetUINT2(const LALValue *value)
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)
#define LAL_INT8_C(c)
Macro for use in defining v as an INT8 constant.
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)
#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_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.
#define XLAL_PRINT_WARNING(...)
Macro that will print a warning message with a standard format.
#define XLAL_CHECK_NULL(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns a pointe...
@ XLAL_ENOMEM
Memory allocation error.
@ XLAL_EFAULT
Invalid pointer.
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
@ XLAL_ETYPE
Wrong or unknown type.
@ XLAL_FAILURE
Failure return value (not an error number)