00001 #pragma once
00002 #ifndef SEXP_MANIP_H
00003 #define SEXP_MANIP_H
00004
00005 #include <stdarg.h>
00006 #include <stdint.h>
00007 #include <stdbool.h>
00008 #include <sexp-types.h>
00009
00010
00011
00012
00013
00014 SEXP_t *SEXP_number_new (SEXP_numtype_t t, const void *n);
00015 SEXP_t *SEXP_number_newb (bool n);
00016 SEXP_t *SEXP_number_newi_8 (int8_t n);
00017 SEXP_t *SEXP_number_newu_8 (uint8_t n);
00018 SEXP_t *SEXP_number_newi_16 (int16_t n);
00019 SEXP_t *SEXP_number_newu_16 (uint16_t n);
00020 #define SEXP_number_newi SEXP_number_newi_32
00021 SEXP_t *SEXP_number_newi_32 (int32_t n);
00022 int32_t SEXP_number_geti_32 (const SEXP_t *s_exp);
00023 #define SEXP_number_newu SEXP_number_newu_32
00024 SEXP_t *SEXP_number_newu_32 (uint32_t n);
00025 uint32_t SEXP_number_getu_32 (const SEXP_t *s_exp);
00026 SEXP_t *SEXP_number_newi_64 (int64_t n);
00027 int64_t SEXP_number_geti_64 (const SEXP_t *s_exp);
00028 SEXP_t *SEXP_number_newu_64 (uint64_t n);
00029 uint64_t SEXP_number_getu_64 (const SEXP_t *s_exp);
00030 SEXP_t *SEXP_number_newf (double n);
00031 double SEXP_number_getf (const SEXP_t *s_exp);
00032
00033 int SEXP_number_get (SEXP_t *s_exp, void *dst, SEXP_numtype_t type);
00034
00035 uint16_t SEXP_number_getu_16 (const SEXP_t *s_exp);
00036
00037 void SEXP_number_free (SEXP_t *s_exp);
00038 bool SEXP_numberp (const SEXP_t *s_exp);
00039 SEXP_numtype_t SEXP_number_type (const SEXP_t *sexp);
00040
00041
00042
00043
00044
00045 SEXP_t *SEXP_string_new (const void *string, size_t strlen);
00046 SEXP_t *SEXP_string_newf (const char *format, ...);
00047 void SEXP_string_free (SEXP_t *s_exp);
00048 bool SEXP_stringp (const SEXP_t *s_exp);
00049 size_t SEXP_string_length (const SEXP_t *s_exp);
00050
00051 int SEXP_strcmp (SEXP_t *s_exp, const char *str);
00052 int SEXP_strncmp (SEXP_t *s_exp, const char *str, size_t n);
00053 char *SEXP_string_cstr (SEXP_t *s_exp);
00054 size_t SEXP_string_cstr_r (SEXP_t *s_exp, char *buf, size_t len);
00055 char *SEXP_string_cstrp (const SEXP_t *s_exp);
00056
00057 char *SEXP_string_subcstr (SEXP_t *s_exp, size_t beg, size_t len);
00058 int SEXP_string_cmp (const SEXP_t *str_a, const SEXP_t *str_b);
00059
00060
00061
00062
00063
00064 SEXP_t *SEXP_list_new (SEXP_t *memb, ...);
00065 void SEXP_list_free (SEXP_t *s_exp);
00066 bool SEXP_listp (const SEXP_t *s_exp);
00067 size_t SEXP_list_length (const SEXP_t *s_exp);
00068 SEXP_t *SEXP_list_first (const SEXP_t *list);
00069 SEXP_t *SEXP_list_rest (const SEXP_t *list);
00070 SEXP_t *SEXP_list_last (const SEXP_t *list);
00071 SEXP_t *SEXP_list_nth (const SEXP_t *list, uint32_t n);
00072 SEXP_t *SEXP_list_add (SEXP_t *list, const SEXP_t *s_exp);
00073 SEXP_t *SEXP_list_join (const SEXP_t *list_a, const SEXP_t *list_b);
00074 SEXP_t *SEXP_list_push (SEXP_t *list, SEXP_t *s_exp);
00075 SEXP_t *SEXP_list_pop (SEXP_t *list);
00076 SEXP_t *SEXP_list_replace (SEXP_t *list, uint32_t n, SEXP_t *s_exp);
00077
00078 SEXP_t *SEXP_listref_first (const SEXP_t *list);
00079 SEXP_t *SEXP_listref_rest (const SEXP_t *list);
00080 SEXP_t *SEXP_listref_last (const SEXP_t *list);
00081 SEXP_t *SEXP_listref_nth (const SEXP_t *list, uint32_t n);
00082
00083 typedef struct SEXP_it SEXP_it_t;
00084
00085 #define SEXP_IT_RECURSIVE 0x01
00086 #define SEXP_IT_HARDREF 0x02
00087
00088 SEXP_it_t *SEXP_listit_new (const SEXP_t *list, int flags);
00089 SEXP_t *SEXP_listit_next(SEXP_it_t *it);
00090 SEXP_t *SEXP_listit_prev (SEXP_it_t *it);
00091 SEXP_t *SEXP_listit_length (SEXP_it_t *it);
00092 SEXP_t *SEXP_listit_seek (SEXP_it_t *it, uint32_t n);
00093 void SEXP_listit_free (SEXP_it_t *it);
00094
00095 #if __STDC_VERSION__ >= 199901L
00096 # include <sys/cdefs.h>
00097 # define __XC(a,b) __CONCAT(a,b)
00098
00099
00100
00101 #define SEXP_list_foreach(var, list) \
00102 for (uint32_t __XC(i,__LINE__) = 0; ((var) = SEXP_list_nth (list, __XC(i,__LINE__))) != NULL; ++__XC(i,__LINE__), SEXP_free (var))
00103
00104 #define SEXP_sublist_foreach(var, list, beg, end) \
00105 for (uint32_t __XC(i,__LINE__) = (beg); ((var) = SEXP_list_nth (list, __XC(i,__LINE__))) != NULL && __XC(i,__LINE__) <= (end); ++__XC(i,__LINE__), SEXP_free (var))
00106
00107 #endif
00108
00109
00110
00111
00112
00113 SEXP_t *SEXP_new (void);
00114 SEXP_t *SEXP_ref (const SEXP_t *s_exp);
00115 SEXP_t *SEXP_softref (const SEXP_t *s_exp);
00116 void SEXP_free (SEXP_t *s_exp);
00117
00118 const char *SEXP_datatype (const SEXP_t *s_exp);
00119 int SEXP_datatype_set (SEXP_t *s_exp, const char *name);
00120 SEXP_type_t SEXP_typeof (const SEXP_t *s_exp);
00121 const char *SEXP_strtype (const SEXP_t *s_exp);
00122
00123 #if !defined(NDEBUG)
00124 # define SEXP_VALIDATE(s) __SEXP_VALIDATE(s, __FILE__, __LINE__, __PRETTY_FUNCTION__)
00125 # include <stdlib.h>
00126
00127 static void __SEXP_VALIDATE(const SEXP_t *s_exp, const char *file, uint32_t line, const char *func)
00128 {
00129 if (s_exp == NULL)
00130 abort ();
00131
00132 return;
00133 }
00134
00135 #else
00136 # define SEXP_VALIDATE(s)
00137 #endif
00138
00139 #endif