FreeWRL / FreeX3D 4.3.0
cson_amalgamation_core.h
1/* auto-generated! Do not edit! */
2/* begin file include/wh/cson/cson.h */
3#if !defined(WANDERINGHORSE_NET_CSON_H_INCLUDED)
4#define WANDERINGHORSE_NET_CSON_H_INCLUDED 1
5
6/*#include <stdint.h> C99: fixed-size int types. */
7#include <stdio.h> /* FILE decl */
8
36#if defined(__cplusplus)
37extern "C" {
38#endif
39
40#if defined(_WIN32) || defined(_WIN64)
41# define CSON_ENABLE_UNIX 0
42#else
43# define CSON_ENABLE_UNIX 1
44#endif
45
46
52#ifdef _WIN32
53typedef __int64 cson_int_t;
54#define CSON_INT_T_SFMT "I64d"
55#define CSON_INT_T_PFMT "I64d"
56#elif (__STDC_VERSION__ >= 199901L) || (HAVE_LONG_LONG == 1)
57typedef long long cson_int_t;
58#define CSON_INT_T_SFMT "lld"
59#define CSON_INT_T_PFMT "lld"
60#else
61typedef long cson_int_t;
62#define CSON_INT_T_SFMT "ld"
63#define CSON_INT_T_PFMT "ld"
64#endif
65
89#if defined(HAVE_LONG_DOUBLE)
90 typedef long double cson_double_t;
91# ifndef CSON_DOUBLE_T_SFMT
92# define CSON_DOUBLE_T_SFMT "Lf"
93# endif
94# ifndef CSON_DOUBLE_T_PFMT
95# define CSON_DOUBLE_T_PFMT "Lf"
96# endif
97#else
98 typedef double cson_double_t;
99# ifndef CSON_DOUBLE_T_SFMT
100# define CSON_DOUBLE_T_SFMT "f"
101# endif
102# ifndef CSON_DOUBLE_T_PFMT
103# define CSON_DOUBLE_T_PFMT "f"
104# endif
105#endif
106
124#if !defined(CSON_VOID_PTR_IS_BIG)
125
126/* Largely taken from http://predef.sourceforge.net/prearch.html
127
128See also: http://poshlib.hookatooka.com/poshlib/trac.cgi/browser/posh.h
129*/
130# if defined(_WIN64) || defined(__LP64__)/*gcc*/ \
131 || defined(_M_X64) || defined(__amd64__) || defined(__amd64) \
132 || defined(__x86_64__) || defined(__x86_64) \
133 || defined(__ia64__) || defined(__ia64) || defined(_IA64) || defined(__IA64__) \
134 || defined(_M_IA64) \
135 || defined(__sparc_v9__) || defined(__sparcv9) || defined(_ADDR64) \
136 || defined(__64BIT__)
137# define CSON_VOID_PTR_IS_BIG 1
138# else
139# define CSON_VOID_PTR_IS_BIG 0
140# endif
141#endif
142
170enum cson_type_id {
176 CSON_TYPE_UNDEF = 0,
180 CSON_TYPE_NULL = 1,
184 CSON_TYPE_BOOL = 2,
189 CSON_TYPE_INTEGER = 3,
194 CSON_TYPE_DOUBLE = 4,
198 CSON_TYPE_STRING = 5,
200 CSON_TYPE_ARRAY = 6,
202 CSON_TYPE_OBJECT = 7
203};
207typedef enum cson_type_id cson_type_id;
208
209
213typedef struct cson_value cson_value;
214
324static const struct cson_rc_
325{
327 const int OK;
329 const int ArgError;
331 const int RangeError;
333 const int TypeError;
335 const int IOError;
337 const int AllocError;
339 const int NYIError;
341 const int InternalError;
346 const int UnsupportedError;
350 const int NotFoundError;
356 const int UnknownError;
360 const int Parse_INVALID_CHAR;
365 const int Parse_INVALID_KEYWORD;
369 const int Parse_INVALID_ESCAPE_SEQUENCE;
374 const int Parse_INVALID_UNICODE_SEQUENCE;
378 const int Parse_INVALID_NUMBER;
383 const int Parse_NESTING_DEPTH_REACHED;
387 const int Parse_UNBALANCED_COLLECTION;
391 const int Parse_EXPECTED_KEY;
396 const int Parse_EXPECTED_COLON;
397} cson_rc = {
3980/*OK*/,
3991/*ArgError*/,
4002/*RangeError*/,
4013/*TypeError*/,
4024/*IOError*/,
4035/*AllocError*/,
4046/*NYIError*/,
4057/*InternalError*/,
4068/*UnsupportedError*/,
4079/*NotFoundError*/,
40810/*UnknownError*/,
40911/*Parse_INVALID_CHAR*/,
41012/*Parse_INVALID_KEYWORD*/,
41113/*Parse_INVALID_ESCAPE_SEQUENCE*/,
41214/*Parse_INVALID_UNICODE_SEQUENCE*/,
41315/*Parse_INVALID_NUMBER*/,
41416/*Parse_NESTING_DEPTH_REACHED*/,
41517/*Parse_UNBALANCED_COLLECTION*/,
41618/*Parse_EXPECTED_KEY*/,
41719/*Parse_EXPECTED_COLON*/
418};
419
427char const * cson_rc_string(int rc);
428
434{
438 unsigned short maxDepth;
445};
446typedef struct cson_parse_opt cson_parse_opt;
447
451#define cson_parse_opt_empty_m { 25/*maxDepth*/, 0/*allowComments*/}
452
453
459{
463 unsigned int line;
467 unsigned int col;
468
472 unsigned int length;
473
478
483 unsigned int totalKeyCount;
484
489 unsigned int totalValueCount;
490};
491typedef struct cson_parse_info cson_parse_info;
492
496#define cson_parse_info_empty_m {1/*line*/,\
497 0/*col*/, \
498 0/*length*/, \
499 0/*errorCode*/, \
500 0/*totalKeyCount*/, \
501 0/*totalValueCount*/ \
502 }
506extern const cson_parse_info cson_parse_info_empty;
507
511extern const cson_parse_opt cson_parse_opt_empty;
512
518{
529 unsigned char indentation;
530
536 unsigned short maxDepth;
537
543
549
556
573};
574typedef struct cson_output_opt cson_output_opt;
575
579#define cson_output_opt_empty_m { 0/*indentation*/,\
580 25/*maxDepth*/, \
581 0/*addNewline*/, \
582 0/*addSpaceAfterColon*/, \
583 0/*indentSingleMemberValues*/, \
584 0/*escapeForwardSlashes*/ \
585 }
586
590extern const cson_output_opt cson_output_opt_empty;
591
616typedef int (*cson_data_source_f)( void * state, void * dest, unsigned int * n );
617
639typedef int (*cson_data_dest_f)( void * state, void const * src, unsigned int n );
640
730int cson_parse( cson_value ** tgt, cson_data_source_f src, void * srcState,
731 cson_parse_opt const * opt, cson_parse_info * info );
736int cson_data_source_FILE( void * state, void * dest, unsigned int * n );
737
743int cson_parse_FILE( cson_value ** tgt, FILE * src,
744 cson_parse_opt const * opt, cson_parse_info * info );
745
753int cson_parse_filename( cson_value ** tgt, char const * src,
754 cson_parse_opt const * opt, cson_parse_info * info );
755
766int cson_parse_string( cson_value ** tgt, char const * src, unsigned int len,
767 cson_parse_opt const * opt, cson_parse_info * info );
768
769
770
797int cson_output( cson_value const * src, cson_data_dest_f dest, void * destState, cson_output_opt const * opt );
798
799
804int cson_data_dest_FILE( void * state, void const * src, unsigned int n );
805
814int cson_output_FILE( cson_value const * src, FILE * dest, cson_output_opt const * opt );
821int cson_output_filename( cson_value const * src, char const * dest, cson_output_opt const * fmt );
822
826cson_type_id cson_value_type_id( cson_value const * v );
827
828
830char cson_value_is_undef( cson_value const * v );
832char cson_value_is_null( cson_value const * v );
834char cson_value_is_bool( cson_value const * v );
836char cson_value_is_integer( cson_value const * v );
838char cson_value_is_double( cson_value const * v );
840char cson_value_is_number( cson_value const * v );
842char cson_value_is_string( cson_value const * v );
844char cson_value_is_array( cson_value const * v );
846char cson_value_is_object( cson_value const * v );
847
874typedef struct cson_object cson_object;
875
902typedef struct cson_array cson_array;
903
919typedef struct cson_string cson_string;
920
938int cson_value_fetch_bool( cson_value const * val, char * v );
939
956int cson_value_fetch_integer( cson_value const * val, cson_int_t * v );
957
963int cson_value_fetch_double( cson_value const * val, cson_double_t * v );
964
988int cson_value_fetch_string( cson_value const * val, cson_string ** str );
989
1014int cson_value_fetch_object( cson_value const * val, cson_object ** obj );
1015
1021int cson_value_fetch_array( cson_value const * val, cson_array ** tgt );
1022
1027char cson_value_get_bool( cson_value const * val );
1028
1033cson_int_t cson_value_get_integer( cson_value const * val );
1034
1039cson_double_t cson_value_get_double( cson_value const * val );
1040
1045cson_string * cson_value_get_string( cson_value const * val );
1046
1058char const * cson_string_cstr( cson_string const * str );
1059
1068char const * cson_value_get_cstr( cson_value const * val );
1069
1073int cson_string_cmp( cson_string const * lhs, cson_string const * rhs );
1074
1098int cson_string_cmp_cstr_n( cson_string const * lhs, char const * rhs, unsigned int rhsLen );
1099
1103int cson_string_cmp_cstr( cson_string const * lhs, char const * rhs );
1104
1114unsigned int cson_string_length_bytes( cson_string const * str );
1115
1123unsigned int cson_string_length_utf8( cson_string const * str );
1124
1130char * cson_value_get_string_copy( cson_value const * val );
1131
1136cson_object * cson_value_get_object( cson_value const * val );
1137
1142cson_array * cson_value_get_array( cson_value const * val );
1143
1147cson_array const * cson_value_get_array_c( cson_value const * val );
1148
1162int cson_array_value_fetch( cson_array const * ar, unsigned int pos, cson_value ** v );
1163
1169cson_value * cson_array_get( cson_array const * ar, unsigned int pos );
1170
1183int cson_array_reserve( cson_array * ar, unsigned int size );
1184
1189int cson_array_length_fetch( cson_array const * ar, unsigned int * v );
1190
1195unsigned int cson_array_length_get( cson_array const * ar );
1196
1230int cson_array_set( cson_array * ar, unsigned int ndx, cson_value * v );
1231
1256int cson_array_append( cson_array * ar, cson_value * v );
1257
1258
1273cson_value * cson_value_new_bool( char v );
1274
1275
1279cson_value * cson_new_bool(char v);
1280
1288cson_value * cson_value_null();
1289
1293cson_value * cson_value_true();
1294
1298cson_value * cson_value_false();
1299
1303cson_value * cson_value_new_integer( cson_int_t v );
1304
1308cson_value * cson_new_int(cson_int_t v);
1309
1313cson_value * cson_value_new_double( cson_double_t v );
1314
1318cson_value * cson_new_double(cson_double_t v);
1319
1333cson_value * cson_value_new_string( char const * str, unsigned int n );
1334
1347cson_value * cson_value_new_object();
1348
1362cson_object * cson_new_object();
1363
1368cson_array * cson_new_array();
1369
1374cson_string * cson_new_string(char const * val, unsigned int len);
1375
1379void cson_free_object(cson_object *x);
1380
1384void cson_free_array(cson_array *x);
1385
1389void cson_free_string(cson_string *x);
1390
1391
1404cson_value * cson_value_new_array();
1405
1425void cson_value_free(cson_value * v);
1426
1430void cson_free_value(cson_value * v);
1431
1432
1481int cson_object_set( cson_object * obj, char const * key, cson_value * v );
1482
1495int cson_object_set_s( cson_object * obj, cson_string * key, cson_value * v );
1496
1512int cson_object_unset( cson_object * obj, char const * key );
1513
1527cson_value * cson_object_get( cson_object const * obj, char const * key );
1528
1533cson_value * cson_object_get_s( cson_object const * obj, cson_string const *key );
1534
1552cson_value * cson_object_take( cson_object * obj, char const * key );
1553
1622int cson_object_fetch_sub( cson_object const * obj, cson_value ** tgt, char const * path, char separator );
1623
1634int cson_object_fetch_sub2( cson_object const * obj, cson_value ** tgt, char const * path );
1635
1640cson_value * cson_object_get_sub( cson_object const * obj, char const * path, char sep );
1641
1646cson_value * cson_object_get_sub2( cson_object const * obj, char const * path );
1647
1652enum CSON_MERGE_FLAGS {
1653 CSON_MERGE_DEFAULT = 0,
1654 CSON_MERGE_REPLACE = 0x01,
1655 CSON_MERGE_NO_RECURSE = 0x02
1656};
1657
1687int cson_object_merge( cson_object * dest, cson_object const * src, int flags );
1688
1689
1700{
1701
1705 cson_object const * obj;
1709 unsigned int pos;
1710};
1712
1716#define cson_object_iterator_empty_m {NULL/*obj*/,0/*pos*/}
1717
1721extern const cson_object_iterator cson_object_iterator_empty;
1722
1733int cson_object_iter_init( cson_object const * obj, cson_object_iterator * iter );
1734
1743typedef struct cson_kvp cson_kvp;
1744
1776cson_kvp * cson_object_iter_next( cson_object_iterator * iter );
1777
1778
1785cson_string * cson_kvp_key( cson_kvp const * kvp );
1786
1793cson_value * cson_kvp_value( cson_kvp const * kvp );
1794
1798typedef unsigned int cson_size_t;
1799
1827{
1832 cson_size_t capacity;
1841 cson_size_t used;
1842
1850 cson_size_t timesExpanded;
1851
1868 unsigned char * mem;
1869};
1871typedef struct cson_buffer cson_buffer;
1872
1874#define cson_buffer_empty_m {0/*capacity*/,0/*used*/,0/*timesExpanded*/,NULL/*mem*/}
1876extern const cson_buffer cson_buffer_empty;
1877
1923int cson_output_buffer( cson_value const * v, cson_buffer * buf,
1924 cson_output_opt const * opt );
1925
1939int cson_parse_buffer( cson_value ** tgt, cson_buffer const * buf,
1940 cson_parse_opt const * opt, cson_parse_info * err );
1941
1942
1965int cson_buffer_reserve( cson_buffer * buf, cson_size_t n );
1966
1972cson_size_t cson_buffer_fill( cson_buffer * buf, char c );
1973
2045int cson_buffer_fill_from( cson_buffer * dest, cson_data_source_f src, void * state );
2046
2047
2145int cson_value_add_reference( cson_value * v );
2146
2147#if 0
2159int cson_value_refcount_set( cson_value * v, unsigned short rc );
2160#endif
2161
2207cson_value * cson_value_clone( cson_value const * orig );
2208
2220cson_value * cson_string_value(cson_string const * s);
2225cson_value * cson_object_value(cson_object const * s);
2226
2231cson_value * cson_array_value(cson_array const * s);
2232
2233
2264unsigned int cson_value_msize(cson_value const * v);
2265
2316int cson_parse_argv_flags( int argc, char const * const * argv,
2317 cson_object ** tgt, unsigned int * count );
2318
2319
2320/* LICENSE
2321
2322This software's source code, including accompanying documentation and
2323demonstration applications, are licensed under the following
2324conditions...
2325
2326Certain files are imported from external projects and have their own
2327licensing terms. Namely, the JSON_parser.* files. See their files for
2328their official licenses, but the summary is "do what you want [with
2329them] but leave the license text and copyright in place."
2330
2331The author (Stephan G. Beal [http://wanderinghorse.net/home/stephan/])
2332explicitly disclaims copyright in all jurisdictions which recognize
2333such a disclaimer. In such jurisdictions, this software is released
2334into the Public Domain.
2335
2336In jurisdictions which do not recognize Public Domain property
2337(e.g. Germany as of 2011), this software is Copyright (c) 2011 by
2338Stephan G. Beal, and is released under the terms of the MIT License
2339(see below).
2340
2341In jurisdictions which recognize Public Domain property, the user of
2342this software may choose to accept it either as 1) Public Domain, 2)
2343under the conditions of the MIT License (see below), or 3) under the
2344terms of dual Public Domain/MIT License conditions described here, as
2345they choose.
2346
2347The MIT License is about as close to Public Domain as a license can
2348get, and is described in clear, concise terms at:
2349
2350 http://en.wikipedia.org/wiki/MIT_License
2351
2352The full text of the MIT License follows:
2353
2354--
2355Copyright (c) 2011 Stephan G. Beal (http://wanderinghorse.net/home/stephan/)
2356
2357Permission is hereby granted, free of charge, to any person
2358obtaining a copy of this software and associated documentation
2359files (the "Software"), to deal in the Software without
2360restriction, including without limitation the rights to use,
2361copy, modify, merge, publish, distribute, sublicense, and/or sell
2362copies of the Software, and to permit persons to whom the
2363Software is furnished to do so, subject to the following
2364conditions:
2365
2366The above copyright notice and this permission notice shall be
2367included in all copies or substantial portions of the Software.
2368
2369THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2370EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
2371OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2372NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
2373HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
2374WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2375FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2376OTHER DEALINGS IN THE SOFTWARE.
2377
2378--END OF MIT LICENSE--
2379
2380For purposes of the above license, the term "Software" includes
2381documentation and demonstration source code which accompanies
2382this software. ("Accompanies" = is contained in the Software's
2383primary public source code repository.)
2384
2385*/
2386
2387#if defined(__cplusplus)
2388} /*extern "C"*/
2389#endif
2390
2391#endif /* WANDERINGHORSE_NET_CSON_H_INCLUDED */
2392/* end file include/wh/cson/cson.h */
cson_array is an opaque handle to an Array value.
A generic buffer class.
unsigned char * mem
The memory allocated for and owned by this buffer.
cson_size_t used
The number of bytes "used" by this object.
cson_size_t timesExpanded
This is a debugging/metric-counting value intended to help certain malloc()-conscious clients tweak t...
cson_size_t capacity
The number of bytes allocated for this object.
A key/value pair collection.
An iterator type for traversing object properties.
cson_object is an opaque handle to an Object value.
Client-configurable options for the cson_output() family of functions.
unsigned short maxDepth
Maximum object/array depth to traverse.
char addSpaceAfterColon
If true, a space will be added after the colon operator in objects' key/value pairs.
char addNewline
If true, a newline will be added to generated output, else not.
char indentSingleMemberValues
If set to 1 then objects/arrays containing only a single value will not indent an extra level for tha...
char escapeForwardSlashes
The JSON format allows, but does not require, JSON generators to backslash-escape forward slashes.
unsigned char indentation
Specifies how to indent (or not) output.
A class for holding JSON parser information.
unsigned int length
Length, in bytes.
unsigned int totalValueCount
The total number of object/array values successfully processed by the parser, including the root node...
unsigned int col
0-based column number.
int errorCode
Error code of the parse run (0 for no error).
unsigned int line
1-based line number.
unsigned int totalKeyCount
The total number of object keys successfully processed by the parser.
Client-configurable options for the cson_parse() family of functions.
char allowComments
Whether or not to allow C-style comments.
unsigned short maxDepth
Maximum object/array depth to traverse.
Strings are allocated as an instances of this class with N+1 trailing bytes, where N is the length of...
The core value type of this API.
Definition Viewer.h:139