cctools
jx_match.h
Go to the documentation of this file.
1/*
2Copyright (C) 2022 The University of Notre Dame
3This software is distributed under the GNU General Public License.
4See the file COPYING for details.
5*/
6
88#ifndef JX_MATCH_H
89#define JX_MATCH_H
90
91#include "jx.h"
92
93#ifndef JX_ANY
94#define JX_ANY -1
95#endif
96
97/*
98 * Macro to test if we're using a GNU C compiler of a specific vintage
99 * or later, for e.g. features that appeared in a particular version
100 * of GNU C. Usage:
101 *
102 * #if __GNUC_PREREQ__(major, minor)
103 * ...cool feature...
104 * #else
105 * ...delete feature...
106 * #endif
107 */
108#ifndef __GNUC_PREREQ__
109#ifdef __GNUC__
110#define __GNUC_PREREQ__(x, y) \
111 ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \
112 (__GNUC__ > (x)))
113#else
114#define __GNUC_PREREQ__(x, y) 0
115#endif
116#endif
117
118#ifndef __wur
119#if __GNUC_PREREQ__(3, 4)
120#define __wur __attribute__((warn_unused_result))
121#else
122#define __wur
123#endif
124#endif
125
126#ifndef __sentinel
127#if __GNUC_PREREQ__(4, 0)
128#define __sentinel __attribute__((sentinel))
129#else
130#define __sentinel
131#endif
132#endif
133
140int jx_match_boolean(struct jx *j, int *v) __wur;
141
148int jx_match_integer(struct jx *j, jx_int_t *v) __wur;
149
156int jx_match_double(struct jx *j, double *v) __wur;
157
176int jx_match_string(struct jx *j, char **v) __wur;
177
188int jx_match_symbol(struct jx *j, char **v) __wur;
189
205int jx_match_array(struct jx *j, ...) __wur __sentinel;
206
207#endif
JSON Expressions (JX) library.
int jx_match_symbol(struct jx *j, char **v) __wur
Unwrap a symbol value.
int jx_match_string(struct jx *j, char **v) __wur
Unwrap a string value.
int jx_match_boolean(struct jx *j, int *v) __wur
Unwrap a boolean value.
int jx_match_array(struct jx *j,...) __wur __sentinel
Destructure an array.
int jx_match_double(struct jx *j, double *v) __wur
Unwrap a double value.
int jx_match_integer(struct jx *j, jx_int_t *v) __wur
Unwrap an integer value.
JX value representing any expression type.
Definition jx.h:117