PVData C++  8.0.2
json.h
1 /*
2  * Copyright information and license terms for this software can be
3  * found in the file LICENSE that is included with the distribution
4  */
5 #ifndef PV_JSON_H
6 #define PV_JSON_H
7 
8 #include <istream>
9 #include <ostream>
10 #include <string>
11 #include <map>
12 
13 #include <pv/pvdVersion.h>
14 #include <pv/pvData.h>
15 
16 #ifdef epicsExportSharedSymbols
17 # define pvjson_epicsExportSharedSymbols
18 # undef epicsExportSharedSymbols
19 #endif
20 
21 #include <yajl_parse.h>
22 
23 #ifdef pvjson_epicsExportSharedSymbols
24 # define epicsExportSharedSymbols
25 # include "shareLib.h"
26 #endif
27 
28 #include <shareLib.h>
29 
30 namespace epics{namespace pvData{
31 
32 class BitSet;
33 
34 /** @defgroup pvjson JSON print/parse
35  *
36  * Printing PVField as JSON and parsing JSON into PVField.
37  *
38  * @{
39  */
40 
41 //! Options used during printing
42 struct epicsShareClass JSONPrintOptions
43 {
44  bool multiLine; //!< include new lines
45  bool ignoreUnprintable;//!< ignore union/union array when encountered
46  unsigned indent; //!< Initial indentation (# of spaces)
48 };
49 
50 /** Print PVStructure as JSON
51  *
52  * 'mask' selects those fields which will be printed.
53  * @version Overload added after 7.0.0
54  */
56 void printJSON(std::ostream& strm,
57  const PVStructure& val,
58  const BitSet& mask,
60 
61 /** Print PVField as JSON
62  * @version Overload added after 7.0.0
63  */
65 void printJSON(std::ostream& strm,
66  const PVField& val,
68 
69 // To be deprecated in favor of previous form
71 void printJSON(std::ostream& strm,
74 {
75  printJSON(strm, *val, opts);
76 }
77 
78 /** Parse JSON text into a PVStructure
79  *
80  * Restrictions:
81  *
82  * - Top level must be {} dict/object
83  * - field values must be number, string, array, or dict/object
84  * - array values must be number or string
85  */
88 
89 /** Parse JSON and store into the provided PVStructure.
90  *
91  * Restrictions:
92  *
93  * - array of union not supported
94  * - Only scalar value assigned to union
95  *
96  * @param strm Read JSON text from stream
97  * @param dest Store in fields of this structure
98  * @param assigned Which fields of _dest_ were assigned. (Optional)
99  * @throws std::runtime_error on failure. dest and assigned may be modified.
100  * @version Overload added after 7.0.0
101  */
103 void parseJSON(std::istream& strm,
104  PVField& dest,
105  BitSet *assigned=0);
106 
107 // To be deprecated in favor of previous form
109 void parseJSON(std::istream& strm,
110  const PVField::shared_pointer& dest,
111  BitSet *assigned=0)
112 {
113  parseJSON(strm, *dest, assigned);
114 }
115 
116 
117 /** Wrapper around yajl_parse()
118  *
119  * Parse entire input stream.
120  * Errors if extranious non-whitespace found after the point were parsing completes.
121  *
122  * @param src The stream from which input charactors are read
123  * @param handle A parser handle previously allocated with yajl_alloc(). Not free'd on success or failure.
124  *
125  * @returns true if parsing completes successfully. false if parsing cancelled by callback. throws other errors
126  *
127  * @note The form of this call depends on EPICS_YAJL_VERSION
128  */
132 
133 namespace yajl {
134 // undef implies API version 0
135 #ifndef EPICS_YAJL_VERSION
136 typedef long integer_arg;
137 typedef unsigned size_arg;
138 #else
139 typedef long long integer_arg;
140 typedef size_t size_arg;
141 #endif
142 } // namespace epics::pvData::yajl
143 
144 /** @} */
145 
146 }} // namespace epics::pvData
147 
148 #endif // PV_JSON_H
#define FORCE_INLINE
Definition: templateMeta.h:20
Options used during printing.
Definition: json.h:42
epicsShareFunc bool yajl_parse_helper(std::istream &src, yajl_handle handle)