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
00314 bool SEXP_string_getb (const SEXP_t *s_exp);
00315
00316
00317
00318
00319
00326 SEXP_t *SEXP_list_new (SEXP_t *memb, ...);
00327
00332 void SEXP_list_free (SEXP_t *s_exp);
00333
00338 bool SEXP_listp (const SEXP_t *s_exp);
00339
00344 size_t SEXP_list_length (const SEXP_t *s_exp);
00345
00351 SEXP_t *SEXP_list_first (const SEXP_t *list);
00352
00358 SEXP_t *SEXP_list_rest (const SEXP_t *list);
00359
00365 SEXP_t *SEXP_list_last (const SEXP_t *list);
00366
00373 SEXP_t *SEXP_list_nth (const SEXP_t *list, uint32_t n);
00374
00381 SEXP_t *SEXP_list_add (SEXP_t *list, const SEXP_t *s_exp);
00382
00389 SEXP_t *SEXP_list_join (const SEXP_t *list_a, const SEXP_t *list_b);
00390
00397 SEXP_t *SEXP_list_push (SEXP_t *list, const SEXP_t *s_exp);
00398
00404 SEXP_t *SEXP_list_pop (SEXP_t *list);
00405
00414 SEXP_t *SEXP_list_replace (SEXP_t *list, uint32_t n, const SEXP_t *s_exp);
00415
00421 SEXP_t *SEXP_listref_first (SEXP_t *list);
00422
00428 SEXP_t *SEXP_listref_rest (SEXP_t *list);
00429
00435 SEXP_t *SEXP_listref_last (SEXP_t *list);
00436
00443 SEXP_t *SEXP_listref_nth (SEXP_t *list, uint32_t n);
00444
00445 typedef struct SEXP_it SEXP_it_t;
00446
00447 #define SEXP_IT_RECURSIVE 0x01
00448 #define SEXP_IT_HARDREF 0x02
00449
00450 SEXP_it_t *SEXP_listit_new (const SEXP_t *list, int flags);
00451 SEXP_t *SEXP_listit_next(SEXP_it_t *it);
00452 SEXP_t *SEXP_listit_prev (SEXP_it_t *it);
00453 SEXP_t *SEXP_listit_length (SEXP_it_t *it);
00454 SEXP_t *SEXP_listit_seek (SEXP_it_t *it, uint32_t n);
00455 void SEXP_listit_free (SEXP_it_t *it);
00456
00457 #if __STDC_VERSION__ >= 199901L
00458 # include <common/util.h>
00459
00460
00466 #define SEXP_list_foreach(var, list) \
00467 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))
00468
00476 #define SEXP_sublist_foreach(var, list, beg, end) \
00477 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))
00478
00479 #define SEXP_LIST_END (UINT32_MAX - 1)
00480
00481 #endif
00482
00483
00484
00485
00486 SEXP_t *SEXP_new (void);
00487
00492 SEXP_t *SEXP_ref (const SEXP_t *s_exp);
00493
00494 SEXP_t *SEXP_unref (SEXP_t *s_exp_o);
00495
00500 SEXP_t *SEXP_softref (SEXP_t *s_exp);
00501
00506 bool SEXP_softrefp(const SEXP_t *s_exp);
00507
00512 uint32_t SEXP_refs (const SEXP_t *ref);
00513
00514 bool SEXP_eq (const SEXP_t *a, const SEXP_t *b);
00515
00516 #if defined(NDEBUG)
00517
00521 void SEXP_free (SEXP_t *s_exp);
00522
00529 void SEXP_vfree (SEXP_t *s_exp, ...);
00530 #else
00531 # define SEXP_free(ptr) __SEXP_free (ptr, __FILE__, __LINE__, __PRETTY_FUNCTION__)
00532 void __SEXP_free (SEXP_t *s_exp, const char *file, uint32_t line, const char *func);
00533 # define SEXP_vfree(...) __SEXP_vfree (__FILE__, __LINE__, __PRETTY_FUNCTION__, __VA_ARGS__)
00534 void __SEXP_vfree (const char *file, uint32_t line, const char *func, SEXP_t *s_exp, ...);
00535 #endif
00536
00541 const char *SEXP_datatype (const SEXP_t *s_exp);
00542
00547 int SEXP_datatype_set (SEXP_t *s_exp, const char *name) __attribute__ ((nonnull (2)));
00548
00555 int SEXP_datatype_set_nth (SEXP_t *list, uint32_t n, const char *name) __attribute__ ((nonnull (3)));
00556
00561 SEXP_type_t SEXP_typeof (const SEXP_t *s_exp);
00562
00567 const char *SEXP_strtype (const SEXP_t *s_exp);
00568
00569 SEXP_t *SEXP_build (const char *s_str, ...);
00570
00571 size_t SEXP_sizeof (const SEXP_t *s_exp);
00572
00573 #if !defined(NDEBUG)
00574 # define SEXP_VALIDATE(s) __SEXP_VALIDATE(s, __FILE__, __LINE__, __PRETTY_FUNCTION__)
00575 # include <stdlib.h>
00576
00577 void __SEXP_VALIDATE(const SEXP_t *s_exp, const char *file, uint32_t line, const char *func);
00578
00579 #else
00580 # define SEXP_VALIDATE(s)
00581 #endif
00582
00583 #ifdef __cplusplus
00584 }
00585 #endif
00586
00587 #endif
00588