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 #ifdef __cplusplus
00046 extern "C" {
00047 #endif
00048
00049
00050
00051
00052
00058 SEXP_t *SEXP_number_new (SEXP_numtype_t t, const void *n) __attribute__ ((nonnull (2)));
00059
00064 SEXP_t *SEXP_number_newb (bool n);
00065
00070 SEXP_t *SEXP_number_newi_8 (int8_t n);
00071
00076 SEXP_t *SEXP_number_newu_8 (uint8_t n);
00077
00082 uint8_t SEXP_number_getu_8 (const SEXP_t *s_exp);
00083
00088 SEXP_t *SEXP_number_newi_16 (int16_t n);
00089
00094 SEXP_t *SEXP_number_newu_16 (uint16_t n);
00095
00100 #define SEXP_number_newi SEXP_number_newi_32
00101
00106 SEXP_t *SEXP_number_newi_32 (int32_t n);
00107
00112 #define SEXP_number_geti SEXP_number_geti_32
00113
00118 int32_t SEXP_number_geti_32 (const SEXP_t *s_exp);
00119
00124 bool SEXP_number_getb (const SEXP_t *s_exp);
00125
00130 #define SEXP_number_newu SEXP_number_newu_32
00131
00136 SEXP_t *SEXP_number_newu_32 (uint32_t n);
00137
00142 #define SEXP_number_getu SEXP_number_getu_32
00143
00148 uint32_t SEXP_number_getu_32 (const SEXP_t *s_exp);
00149
00154 SEXP_t *SEXP_number_newi_64 (int64_t n);
00155
00160 int64_t SEXP_number_geti_64 (const SEXP_t *s_exp);
00161
00166 SEXP_t *SEXP_number_newu_64 (uint64_t n);
00167
00172 uint64_t SEXP_number_getu_64 (const SEXP_t *s_exp);
00173
00178 SEXP_t *SEXP_number_newf (double n);
00179
00184 double SEXP_number_getf (const SEXP_t *s_exp);
00185
00192 int SEXP_number_get (const SEXP_t *s_exp, void *dst, SEXP_numtype_t type);
00193
00198 uint16_t SEXP_number_getu_16 (const SEXP_t *s_exp);
00199
00204 void SEXP_number_free (SEXP_t *s_exp);
00205
00210 bool SEXP_numberp (const SEXP_t *s_exp);
00211
00216 SEXP_numtype_t SEXP_number_type (const SEXP_t *sexp);
00217
00218
00219
00220
00221
00227 SEXP_t *SEXP_string_new (const void *string, size_t strlen) __attribute__ ((nonnull (1)));
00228
00234 SEXP_t *SEXP_string_newf (const char *format, ...) __attribute__ ((format (printf, 1, 2), nonnull (1)));
00235
00240 void SEXP_string_free (SEXP_t *s_exp);
00241
00246 bool SEXP_stringp (const SEXP_t *s_exp);
00247
00252 size_t SEXP_string_length (const SEXP_t *s_exp);
00253
00259 int SEXP_strcmp (const SEXP_t *s_exp, const char *str) __attribute__ ((nonnull (2)));
00260
00267 int SEXP_strncmp (const SEXP_t *s_exp, const char *str, size_t n) __attribute__ ((nonnull (2)));
00268
00274 int SEXP_string_nth (const SEXP_t *s_exp, size_t n);
00275
00279 char *SEXP_string_cstr (const SEXP_t *s_exp);
00280
00288 size_t SEXP_string_cstr_r (const SEXP_t *s_exp, char *buf, size_t len) __attribute__ ((nonnull (2)));
00289
00293 char *SEXP_string_cstrp (const SEXP_t *s_exp);
00294
00301 char *SEXP_string_subcstr (const SEXP_t *s_exp, size_t beg, size_t len);
00302
00308 int SEXP_string_cmp (const SEXP_t *str_a, const SEXP_t *str_b);
00309
00310
00311
00312
00313
00320 SEXP_t *SEXP_list_new (SEXP_t *memb, ...);
00321
00326 void SEXP_list_free (SEXP_t *s_exp);
00327
00332 bool SEXP_listp (const SEXP_t *s_exp);
00333
00338 size_t SEXP_list_length (const SEXP_t *s_exp);
00339
00345 SEXP_t *SEXP_list_first (const SEXP_t *list);
00346
00352 SEXP_t *SEXP_list_rest (const SEXP_t *list);
00353
00359 SEXP_t *SEXP_list_last (const SEXP_t *list);
00360
00367 SEXP_t *SEXP_list_nth (const SEXP_t *list, uint32_t n);
00368
00375 SEXP_t *SEXP_list_add (SEXP_t *list, const SEXP_t *s_exp);
00376
00383 SEXP_t *SEXP_list_join (const SEXP_t *list_a, const SEXP_t *list_b);
00384
00391 SEXP_t *SEXP_list_push (SEXP_t *list, const SEXP_t *s_exp);
00392
00398 SEXP_t *SEXP_list_pop (SEXP_t *list);
00399
00408 SEXP_t *SEXP_list_replace (SEXP_t *list, uint32_t n, const SEXP_t *s_exp);
00409
00415 SEXP_t *SEXP_listref_first (SEXP_t *list);
00416
00422 SEXP_t *SEXP_listref_rest (SEXP_t *list);
00423
00429 SEXP_t *SEXP_listref_last (SEXP_t *list);
00430
00437 SEXP_t *SEXP_listref_nth (SEXP_t *list, uint32_t n);
00438
00439 typedef struct SEXP_it SEXP_it_t;
00440
00441 #define SEXP_IT_RECURSIVE 0x01
00442 #define SEXP_IT_HARDREF 0x02
00443
00444 SEXP_it_t *SEXP_listit_new (const SEXP_t *list, int flags);
00445 SEXP_t *SEXP_listit_next(SEXP_it_t *it);
00446 SEXP_t *SEXP_listit_prev (SEXP_it_t *it);
00447 SEXP_t *SEXP_listit_length (SEXP_it_t *it);
00448 SEXP_t *SEXP_listit_seek (SEXP_it_t *it, uint32_t n);
00449 void SEXP_listit_free (SEXP_it_t *it);
00450
00451 #if __STDC_VERSION__ >= 199901L
00452 # include <common/util.h>
00453
00454
00460 #define SEXP_list_foreach(var, list) \
00461 for (uint32_t OSCAP_CONCAT(i,__LINE__) = 1; ((var) = SEXP_list_nth (list, OSCAP_CONCAT(i,__LINE__))) != NULL; ++OSCAP_CONCAT(i,__LINE__), SEXP_free (var))
00462
00470 #define SEXP_sublist_foreach(var, list, beg, end) \
00471 for (uint32_t OSCAP_CONCAT(i,__LINE__) = (beg); OSCAP_CONCAT(i,__LINE__) <= ((size_t)(end)) && ((var) = SEXP_list_nth (list, OSCAP_CONCAT(i,__LINE__))) != NULL; ++OSCAP_CONCAT(i,__LINE__), SEXP_free (var))
00472
00473 #endif
00474
00475
00476
00477
00478 SEXP_t *SEXP_new (void);
00479
00484 SEXP_t *SEXP_ref (const SEXP_t *s_exp);
00485
00486 SEXP_t *SEXP_unref (SEXP_t *s_exp_o);
00487
00492 SEXP_t *SEXP_softref (SEXP_t *s_exp);
00493
00498 uint32_t SEXP_refs (const SEXP_t *ref);
00499
00500 bool SEXP_eq (const SEXP_t *a, const SEXP_t *b);
00501
00502 #if defined(NDEBUG)
00503
00507 void SEXP_free (SEXP_t *s_exp);
00508
00515 void SEXP_vfree (SEXP_t *s_exp, ...);
00516 #else
00517 # define SEXP_free(ptr) __SEXP_free (ptr, __FILE__, __LINE__, __PRETTY_FUNCTION__)
00518 void __SEXP_free (SEXP_t *s_exp, const char *file, uint32_t line, const char *func);
00519 # define SEXP_vfree(...) __SEXP_vfree (__FILE__, __LINE__, __PRETTY_FUNCTION__, __VA_ARGS__)
00520 void __SEXP_vfree (const char *file, uint32_t line, const char *func, SEXP_t *s_exp, ...);
00521 #endif
00522
00527 const char *SEXP_datatype (const SEXP_t *s_exp);
00528
00533 int SEXP_datatype_set (SEXP_t *s_exp, const char *name) __attribute__ ((nonnull (2)));
00534
00541 int SEXP_datatype_set_nth (SEXP_t *list, uint32_t n, const char *name) __attribute__ ((nonnull (3)));
00542
00547 SEXP_type_t SEXP_typeof (const SEXP_t *s_exp);
00548
00553 const char *SEXP_strtype (const SEXP_t *s_exp);
00554
00555 SEXP_t *SEXP_build (const char *s_str, ...);
00556
00557 size_t SEXP_sizeof (const SEXP_t *s_exp);
00558
00559 #if !defined(NDEBUG)
00560 # define SEXP_VALIDATE(s) __SEXP_VALIDATE(s, __FILE__, __LINE__, __PRETTY_FUNCTION__)
00561 # include <stdlib.h>
00562
00563 void __SEXP_VALIDATE(const SEXP_t *s_exp, const char *file, uint32_t line, const char *func);
00564
00565 #else
00566 # define SEXP_VALIDATE(s)
00567 #endif
00568
00569 #ifdef __cplusplus
00570 }
00571 #endif
00572
00573 #endif
00574