00001
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #pragma once
00040 #ifndef SEXP_MANIP_H
00041 #define SEXP_MANIP_H
00042
00043 #include <stdarg.h>
00044 #include <stddef.h>
00045 #include <stdint.h>
00046 #include <stdbool.h>
00047 #include <sexp-types.h>
00048
00049 #ifdef __cplusplus
00050 extern "C" {
00051 #endif
00052
00053
00054
00055
00056
00062 SEXP_t *SEXP_number_new (SEXP_numtype_t t, const void *n) __attribute__ ((nonnull (2)));
00063
00068 SEXP_t *SEXP_number_newb (bool n);
00069
00074 SEXP_t *SEXP_number_newi_8 (int8_t n);
00075
00080 SEXP_t *SEXP_number_newu_8 (uint8_t n);
00081
00086 uint8_t SEXP_number_getu_8 (const SEXP_t *s_exp);
00087
00092 SEXP_t *SEXP_number_newi_16 (int16_t n);
00093
00098 SEXP_t *SEXP_number_newu_16 (uint16_t n);
00099
00104 #define SEXP_number_newi SEXP_number_newi_32
00105
00110 SEXP_t *SEXP_number_newi_32 (int32_t n);
00111
00116 #define SEXP_number_geti SEXP_number_geti_32
00117
00122 int32_t SEXP_number_geti_32 (const SEXP_t *s_exp);
00123
00128 bool SEXP_number_getb (const SEXP_t *s_exp);
00129
00134 #define SEXP_number_newu SEXP_number_newu_32
00135
00140 SEXP_t *SEXP_number_newu_32 (uint32_t n);
00141
00146 #define SEXP_number_getu SEXP_number_getu_32
00147
00152 uint32_t SEXP_number_getu_32 (const SEXP_t *s_exp);
00153
00158 SEXP_t *SEXP_number_newi_64 (int64_t n);
00159
00164 int64_t SEXP_number_geti_64 (const SEXP_t *s_exp);
00165
00170 SEXP_t *SEXP_number_newu_64 (uint64_t n);
00171
00176 uint64_t SEXP_number_getu_64 (const SEXP_t *s_exp);
00177
00182 SEXP_t *SEXP_number_newf (double n);
00183
00188 double SEXP_number_getf (const SEXP_t *s_exp);
00189
00196 int SEXP_number_get (const SEXP_t *s_exp, void *dst, SEXP_numtype_t type);
00197
00202 uint16_t SEXP_number_getu_16 (const SEXP_t *s_exp);
00203
00208 void SEXP_number_free (SEXP_t *s_exp);
00209
00214 bool SEXP_numberp (const SEXP_t *s_exp);
00215
00220 SEXP_numtype_t SEXP_number_type (const SEXP_t *sexp);
00221
00222
00223
00224
00225
00231 SEXP_t *SEXP_string_new (const void *string, size_t strlen) __attribute__ ((nonnull (1)));
00232
00238 SEXP_t *SEXP_string_newf (const char *format, ...) __attribute__ ((format (printf, 1, 2), nonnull (1)));
00239
00244 void SEXP_string_free (SEXP_t *s_exp);
00245
00250 bool SEXP_stringp (const SEXP_t *s_exp);
00251
00256 size_t SEXP_string_length (const SEXP_t *s_exp);
00257
00263 int SEXP_strcmp (const SEXP_t *s_exp, const char *str) __attribute__ ((nonnull (2)));
00264
00271 int SEXP_strncmp (const SEXP_t *s_exp, const char *str, size_t n) __attribute__ ((nonnull (2)));
00272
00278 int SEXP_string_nth (const SEXP_t *s_exp, size_t n);
00279
00283 char *SEXP_string_cstr (const SEXP_t *s_exp);
00284
00292 size_t SEXP_string_cstr_r (const SEXP_t *s_exp, char *buf, size_t len) __attribute__ ((nonnull (2)));
00293
00297 char *SEXP_string_cstrp (const SEXP_t *s_exp);
00298
00305 char *SEXP_string_subcstr (const SEXP_t *s_exp, size_t beg, size_t len);
00306
00312 int SEXP_string_cmp (const SEXP_t *str_a, const SEXP_t *str_b);
00313
00314
00315
00316
00317
00324 SEXP_t *SEXP_list_new (SEXP_t *memb, ...);
00325
00330 void SEXP_list_free (SEXP_t *s_exp);
00331
00336 bool SEXP_listp (const SEXP_t *s_exp);
00337
00342 size_t SEXP_list_length (const SEXP_t *s_exp);
00343
00349 SEXP_t *SEXP_list_first (const SEXP_t *list);
00350
00356 SEXP_t *SEXP_list_rest (const SEXP_t *list);
00357
00363 SEXP_t *SEXP_list_last (const SEXP_t *list);
00364
00371 SEXP_t *SEXP_list_nth (const SEXP_t *list, uint32_t n);
00372
00379 SEXP_t *SEXP_list_add (SEXP_t *list, const SEXP_t *s_exp);
00380
00387 SEXP_t *SEXP_list_join (const SEXP_t *list_a, const SEXP_t *list_b);
00388
00395 SEXP_t *SEXP_list_push (SEXP_t *list, const SEXP_t *s_exp);
00396
00402 SEXP_t *SEXP_list_pop (SEXP_t *list);
00403
00412 SEXP_t *SEXP_list_replace (SEXP_t *list, uint32_t n, const SEXP_t *s_exp);
00413
00419 SEXP_t *SEXP_listref_first (SEXP_t *list);
00420
00426 SEXP_t *SEXP_listref_rest (SEXP_t *list);
00427
00433 SEXP_t *SEXP_listref_last (SEXP_t *list);
00434
00441 SEXP_t *SEXP_listref_nth (SEXP_t *list, uint32_t n);
00442
00443 typedef struct SEXP_it SEXP_it_t;
00444
00445 #define SEXP_IT_RECURSIVE 0x01
00446 #define SEXP_IT_HARDREF 0x02
00447
00448 SEXP_it_t *SEXP_listit_new (const SEXP_t *list, int flags);
00449 SEXP_t *SEXP_listit_next(SEXP_it_t *it);
00450 SEXP_t *SEXP_listit_prev (SEXP_it_t *it);
00451 SEXP_t *SEXP_listit_length (SEXP_it_t *it);
00452 SEXP_t *SEXP_listit_seek (SEXP_it_t *it, uint32_t n);
00453 void SEXP_listit_free (SEXP_it_t *it);
00454
00455 #if __STDC_VERSION__ >= 199901L
00456 # include <sys/cdefs.h>
00457 # define __XC(a,b) __CONCAT(a,b)
00458
00459
00465 #define SEXP_list_foreach(var, list) \
00466 for (uint32_t __XC(i,__LINE__) = 1; ((var) = SEXP_list_nth (list, __XC(i,__LINE__))) != NULL; ++__XC(i,__LINE__), SEXP_free (var))
00467
00475 #define SEXP_sublist_foreach(var, list, beg, end) \
00476 for (uint32_t __XC(i,__LINE__) = (beg); __XC(i,__LINE__) <= ((size_t)(end)) && ((var) = SEXP_list_nth (list, __XC(i,__LINE__))) != NULL; ++__XC(i,__LINE__), SEXP_free (var))
00477
00478 #endif
00479
00480
00481
00482
00483
00484 SEXP_t *SEXP_new (void);
00485
00490 SEXP_t *SEXP_ref (const SEXP_t *s_exp);
00491
00492 SEXP_t *SEXP_unref (SEXP_t *s_exp_o);
00493
00498 SEXP_t *SEXP_softref (SEXP_t *s_exp);
00499 #if defined(NDEBUG)
00500
00505 void SEXP_free (SEXP_t *s_exp);
00506
00513 void SEXP_vfree (SEXP_t *s_exp, ...);
00514 #else
00515 # define SEXP_free(ptr) __SEXP_free (ptr, __FILE__, __LINE__, __PRETTY_FUNCTION__)
00516 void __SEXP_free (SEXP_t *s_exp, const char *file, uint32_t line, const char *func);
00517 # define SEXP_vfree(...) __SEXP_vfree (__FILE__, __LINE__, __PRETTY_FUNCTION__, __VA_ARGS__)
00518 void __SEXP_vfree (const char *file, uint32_t line, const char *func, SEXP_t *s_exp, ...);
00519 #endif
00520
00525 const char *SEXP_datatype (const SEXP_t *s_exp);
00526
00531 int SEXP_datatype_set (SEXP_t *s_exp, const char *name) __attribute__ ((nonnull (2)));
00532
00539 int SEXP_datatype_set_nth (SEXP_t *list, uint32_t n, const char *name) __attribute__ ((nonnull (3)));
00540
00545 SEXP_type_t SEXP_typeof (const SEXP_t *s_exp);
00546
00551 const char *SEXP_strtype (const SEXP_t *s_exp);
00552
00553 SEXP_t *SEXP_build (const char *s_str, ...);
00554
00555 size_t SEXP_sizeof (const SEXP_t *s_exp);
00556
00557 #if !defined(NDEBUG)
00558 # define SEXP_VALIDATE(s) __SEXP_VALIDATE(s, __FILE__, __LINE__, __PRETTY_FUNCTION__)
00559 # include <stdlib.h>
00560
00561 void __SEXP_VALIDATE(const SEXP_t *s_exp, const char *file, uint32_t line, const char *func);
00562
00563 #else
00564 # define SEXP_VALIDATE(s)
00565 #endif
00566
00567 #ifdef __cplusplus
00568 }
00569 #endif
00570
00571 #endif