00001
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #pragma once
00036 #ifndef SEXP_MANIP_H
00037 #define SEXP_MANIP_H
00038
00039 #include <stdarg.h>
00040 #include <stddef.h>
00041 #include <stdint.h>
00042 #include <stdbool.h>
00043 #include <sexp-types.h>
00044
00045
00046
00047
00048
00054 SEXP_t *SEXP_number_new (SEXP_numtype_t t, const void *n) __attribute__ ((nonnull (2)));
00055
00060 SEXP_t *SEXP_number_newb (bool n);
00061
00066 SEXP_t *SEXP_number_newi_8 (int8_t n);
00067
00072 SEXP_t *SEXP_number_newu_8 (uint8_t n);
00073
00078 uint8_t SEXP_number_getu_8 (const SEXP_t *s_exp);
00079
00084 SEXP_t *SEXP_number_newi_16 (int16_t n);
00085
00090 SEXP_t *SEXP_number_newu_16 (uint16_t n);
00091
00096 #define SEXP_number_newi SEXP_number_newi_32
00097
00102 SEXP_t *SEXP_number_newi_32 (int32_t n);
00103
00108 #define SEXP_number_geti SEXP_number_geti_32
00109
00114 int32_t SEXP_number_geti_32 (const SEXP_t *s_exp);
00115
00120 bool SEXP_number_getb (const SEXP_t *s_exp);
00121
00126 #define SEXP_number_newu SEXP_number_newu_32
00127
00132 SEXP_t *SEXP_number_newu_32 (uint32_t n);
00133
00138 #define SEXP_number_getu SEXP_number_getu_32
00139
00144 uint32_t SEXP_number_getu_32 (const SEXP_t *s_exp);
00145
00150 SEXP_t *SEXP_number_newi_64 (int64_t n);
00151
00156 int64_t SEXP_number_geti_64 (const SEXP_t *s_exp);
00157
00162 SEXP_t *SEXP_number_newu_64 (uint64_t n);
00163
00168 uint64_t SEXP_number_getu_64 (const SEXP_t *s_exp);
00169
00174 SEXP_t *SEXP_number_newf (double n);
00175
00180 double SEXP_number_getf (const SEXP_t *s_exp);
00181
00188 int SEXP_number_get (const SEXP_t *s_exp, void *dst, SEXP_numtype_t type);
00189
00194 uint16_t SEXP_number_getu_16 (const SEXP_t *s_exp);
00195
00200 void SEXP_number_free (SEXP_t *s_exp);
00201
00206 bool SEXP_numberp (const SEXP_t *s_exp);
00207
00212 SEXP_numtype_t SEXP_number_type (const SEXP_t *sexp);
00213
00214
00215
00216
00217
00223 SEXP_t *SEXP_string_new (const void *string, size_t strlen) __attribute__ ((nonnull (1)));
00224
00230 SEXP_t *SEXP_string_newf (const char *format, ...) __attribute__ ((format (printf, 1, 2), nonnull (1)));
00231
00236 void SEXP_string_free (SEXP_t *s_exp);
00237
00242 bool SEXP_stringp (const SEXP_t *s_exp);
00243
00248 size_t SEXP_string_length (const SEXP_t *s_exp);
00249
00255 int SEXP_strcmp (const SEXP_t *s_exp, const char *str) __attribute__ ((nonnull (2)));
00256
00263 int SEXP_strncmp (const SEXP_t *s_exp, const char *str, size_t n) __attribute__ ((nonnull (2)));
00264
00270 int SEXP_string_nth (const SEXP_t *s_exp, size_t n);
00271
00275 char *SEXP_string_cstr (const SEXP_t *s_exp);
00276
00284 size_t SEXP_string_cstr_r (const SEXP_t *s_exp, char *buf, size_t len) __attribute__ ((nonnull (2)));
00285
00289 char *SEXP_string_cstrp (const SEXP_t *s_exp);
00290
00297 char *SEXP_string_subcstr (const SEXP_t *s_exp, size_t beg, size_t len);
00298
00304 int SEXP_string_cmp (const SEXP_t *str_a, const SEXP_t *str_b);
00305
00306
00307
00308
00309
00316 SEXP_t *SEXP_list_new (SEXP_t *memb, ...);
00317
00322 void SEXP_list_free (SEXP_t *s_exp);
00323
00328 bool SEXP_listp (const SEXP_t *s_exp);
00329
00334 size_t SEXP_list_length (const SEXP_t *s_exp);
00335
00341 SEXP_t *SEXP_list_first (const SEXP_t *list);
00342
00348 SEXP_t *SEXP_list_rest (const SEXP_t *list);
00349
00355 SEXP_t *SEXP_list_last (const SEXP_t *list);
00356
00363 SEXP_t *SEXP_list_nth (const SEXP_t *list, uint32_t n);
00364
00371 SEXP_t *SEXP_list_add (SEXP_t *list, const SEXP_t *s_exp);
00372
00379 SEXP_t *SEXP_list_join (const SEXP_t *list_a, const SEXP_t *list_b);
00380
00387 SEXP_t *SEXP_list_push (SEXP_t *list, const SEXP_t *s_exp);
00388
00394 SEXP_t *SEXP_list_pop (SEXP_t *list);
00395
00404 SEXP_t *SEXP_list_replace (SEXP_t *list, uint32_t n, const SEXP_t *s_exp);
00405
00411 SEXP_t *SEXP_listref_first (SEXP_t *list);
00412
00418 SEXP_t *SEXP_listref_rest (SEXP_t *list);
00419
00425 SEXP_t *SEXP_listref_last (SEXP_t *list);
00426
00433 SEXP_t *SEXP_listref_nth (SEXP_t *list, uint32_t n);
00434
00435 typedef struct SEXP_it SEXP_it_t;
00436
00437 #define SEXP_IT_RECURSIVE 0x01
00438 #define SEXP_IT_HARDREF 0x02
00439
00440 SEXP_it_t *SEXP_listit_new (const SEXP_t *list, int flags);
00441 SEXP_t *SEXP_listit_next(SEXP_it_t *it);
00442 SEXP_t *SEXP_listit_prev (SEXP_it_t *it);
00443 SEXP_t *SEXP_listit_length (SEXP_it_t *it);
00444 SEXP_t *SEXP_listit_seek (SEXP_it_t *it, uint32_t n);
00445 void SEXP_listit_free (SEXP_it_t *it);
00446
00447 #if __STDC_VERSION__ >= 199901L
00448 # include <sys/cdefs.h>
00449 # define __XC(a,b) __CONCAT(a,b)
00450
00451
00457 #define SEXP_list_foreach(var, list) \
00458 for (uint32_t __XC(i,__LINE__) = 1; ((var) = SEXP_list_nth (list, __XC(i,__LINE__))) != NULL; ++__XC(i,__LINE__), SEXP_free (var))
00459
00467 #define SEXP_sublist_foreach(var, list, beg, end) \
00468 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))
00469
00470 #endif
00471
00472
00473
00474
00475
00476 SEXP_t *SEXP_new (void);
00477
00482 SEXP_t *SEXP_ref (const SEXP_t *s_exp);
00483
00488 SEXP_t *SEXP_softref (SEXP_t *s_exp);
00489 #if defined(NDEBUG)
00490
00495 void SEXP_free (SEXP_t *s_exp);
00496
00503 void SEXP_vfree (SEXP_t *s_exp, ...);
00504 #else
00505 # define SEXP_free(ptr) __SEXP_free (ptr, __FILE__, __LINE__, __PRETTY_FUNCTION__)
00506 void __SEXP_free (SEXP_t *s_exp, const char *file, uint32_t line, const char *func);
00507 # define SEXP_vfree(...) __SEXP_vfree (__FILE__, __LINE__, __PRETTY_FUNCTION__, __VA_ARGS__)
00508 void __SEXP_vfree (const char *file, uint32_t line, const char *func, SEXP_t *s_exp, ...);
00509 #endif
00510
00515 const char *SEXP_datatype (const SEXP_t *s_exp);
00516
00521 int SEXP_datatype_set (SEXP_t *s_exp, const char *name) __attribute__ ((nonnull (2)));
00522
00529 int SEXP_datatype_set_nth (SEXP_t *list, uint32_t n, const char *name) __attribute__ ((nonnull (3)));
00530
00535 SEXP_type_t SEXP_typeof (const SEXP_t *s_exp);
00536
00541 const char *SEXP_strtype (const SEXP_t *s_exp);
00542
00543 SEXP_t *SEXP_build (const char *s_str, ...);
00544
00545 size_t SEXP_sizeof (const SEXP_t *s_exp);
00546
00547 #if !defined(NDEBUG)
00548 # define SEXP_VALIDATE(s) __SEXP_VALIDATE(s, __FILE__, __LINE__, __PRETTY_FUNCTION__)
00549 # include <stdlib.h>
00550
00551 void __SEXP_VALIDATE(const SEXP_t *s_exp, const char *file, uint32_t line, const char *func);
00552
00553 #else
00554 # define SEXP_VALIDATE(s)
00555 #endif
00556
00557 #endif