1 /*
2 Copyright (c) 1994 - 2010, Lawrence Livermore National Security, LLC.
3 LLNL-CODE-425250.
4 All rights reserved.
5 
6 This file is part of Silo. For details, see silo.llnl.gov.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions
10 are met:
11 
12    * Redistributions of source code must retain the above copyright
13      notice, this list of conditions and the disclaimer below.
14    * Redistributions in binary form must reproduce the above copyright
15      notice, this list of conditions and the disclaimer (as noted
16      below) in the documentation and/or other materials provided with
17      the distribution.
18    * Neither the name of the LLNS/LLNL nor the names of its
19      contributors may be used to endorse or promote products derived
20      from this software without specific prior written permission.
21 
22 THIS SOFTWARE  IS PROVIDED BY  THE COPYRIGHT HOLDERS  AND CONTRIBUTORS
23 "AS  IS" AND  ANY EXPRESS  OR IMPLIED  WARRANTIES, INCLUDING,  BUT NOT
24 LIMITED TO, THE IMPLIED  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 A  PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN  NO  EVENT SHALL  LAWRENCE
26 LIVERMORE  NATIONAL SECURITY, LLC,  THE U.S.  DEPARTMENT OF  ENERGY OR
27 CONTRIBUTORS BE LIABLE FOR  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 EXEMPLARY, OR  CONSEQUENTIAL DAMAGES  (INCLUDING, BUT NOT  LIMITED TO,
29 PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS  OF USE,  DATA, OR
30 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 LIABILITY, WHETHER  IN CONTRACT, STRICT LIABILITY,  OR TORT (INCLUDING
32 NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT  OF THE USE  OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 
35 This work was produced at Lawrence Livermore National Laboratory under
36 Contract No.  DE-AC52-07NA27344 with the DOE.
37 
38 Neither the  United States Government nor  Lawrence Livermore National
39 Security, LLC nor any of  their employees, makes any warranty, express
40 or  implied,  or  assumes  any  liability or  responsibility  for  the
41 accuracy, completeness,  or usefulness of  any information, apparatus,
42 product, or  process disclosed, or  represents that its use  would not
43 infringe privately-owned rights.
44 
45 Any reference herein to  any specific commercial products, process, or
46 services by trade name,  trademark, manufacturer or otherwise does not
47 necessarily  constitute or imply  its endorsement,  recommendation, or
48 favoring  by  the  United  States  Government  or  Lawrence  Livermore
49 National Security,  LLC. The views  and opinions of  authors expressed
50 herein do not necessarily state  or reflect those of the United States
51 Government or Lawrence Livermore National Security, LLC, and shall not
52 be used for advertising or product endorsement purposes.
53 */
54 #ifndef SILO_JSON_H
55 #define SILO_JSON_H
56 
57 #include <json/json.h>
58 
59 #include <silo_exports.h>
60 
61 #define JSON_C_TO_STRING_EXTPTR_AS_BINARY (JSON_C_TO_STRING_PRETTY<<1)
62 #define JSON_C_TO_STRING_EXTPTR_SKIP (JSON_C_TO_STRING_EXTPTR_AS_BINARY<<1)
63 
64 #define JSON_C_DIFF_ZERO_TOLS      0x00000001 /* ignore tolerances (e.g. set to zero) */
65 #define JSON_C_DIFF_INCLUSIVE_ONLY 0x00000002 /* ignore exclusive members */
66 #define JSON_C_DIFF_MIX_PRIM_TYPE  0x00000004 /* allow diffs of mixed primitive type */
67 #define JSON_C_DIFF_TOTAL          0x00000008 /* compute a total difference including even non-differing terms. */
68 #define JSON_C_DIFF_REVERSE_LR     0x00000010 /* INTERNAL USE ONLY (left/right operands are reversed) */
69 #define JSON_C_DIFF_RADIX_BINARY   0x00000020 /* radix at which to print numerical values 2,8,10,16 */
70 #define JSON_C_DIFF_RADIX_OCTAL    0x00000040 /* radix at which to print numerical values 2,8,10,16 */
71 #define JSON_C_DIFF_RADIX_DECIMAL  0x00000080 /* radix at which to print numerical values 2,8,10,16 */
72 #define JSON_C_DIFF_RADIX_HEX      0x00000100 /* radix at which to print numerical values 2,8,10,16 */
73 
74 #ifdef __cplusplus
75 extern "C" {
76 #endif
77 
78 enum json_diff_mode { json_diff_bool, json_diff_string, json_diff_object };
79 
80 /* A 'strptr' json object is just a string representation
81  * (e.g. '0xFFFE60A42') of a void pointer */
82 SILO_API extern struct json_object * json_object_new_strptr(void *p);
83 SILO_API extern void *               json_object_get_strptr(struct json_object *o);
84 
85 /* An 'extptr' json object is an ensemble of 4 json objects,
86  * (int) datatype, (int) ndims, (array) dims, (strptr) void *,
87  * that represent an array of data externally referenced from
88  * the json object. */
89 SILO_API extern struct json_object * json_object_new_extptr(void *p, int ndims, int const *dims, int datatype);
90 SILO_API extern void                 json_object_extptr_delete(struct json_object *jso);
91 
92 /* Inspect members of an extptr object */
93 SILO_API int                         json_object_is_extptr(struct json_object *obj);
94 SILO_API extern int                  json_object_get_extptr_datatype(struct json_object *obj);
95 SILO_API extern int                  json_object_get_extptr_ndims(struct json_object *obj);
96 SILO_API extern int                  json_object_get_extptr_dims_idx(struct json_object *obj, int idx);
97 SILO_API extern void *               json_object_get_extptr_ptr(struct json_object *obj);
98 SILO_API extern int                  json_object_reconstitute_extptrs(struct json_object *obj);
99 
100 /* Methods to serialize a json object to a binary buffer. Note that the
101  * json-c library itself can serialize Silo's json objects to a string using
102  * json_object_to_json_string(). */
103 SILO_API extern int                  json_object_to_binary_buf(struct json_object *obj, int flags, void **buf, int *len);
104 SILO_API extern struct json_object * json_object_from_binary_buf(void *buf, int len);
105 
106 /* Methods to read/write serial, json object to a file */
107 SILO_API extern int                  json_object_to_binary_file(char const *filename, struct json_object *obj);
108 SILO_API extern struct json_object * json_object_from_binary_file(char const *filename);
109 
110 SILO_API extern int json_object_diff(struct json_object *objL, struct json_object json_objR);
111 
112 /* Methods to read/write json objects as Silo objects */
113 SILO_API extern int                 DBWriteJsonObject(DBfile *dbfile, struct json_object *jobj);
114 SILO_API extern struct json_object *DBGetJsonObject(DBfile *, char const *);
115 
116 #ifdef __cplusplus
117 }
118 #endif
119 
120 #endif
121