8 #define epicsExportSharedSymbols 39 context() :depth(0u), state(Undefined), cur(&root) {}
42 #define TRY context *self = (context*)ctx; try 44 #define CATCH() catch(std::exception& e) { self->msg = e.what(); return 0; } 46 int jtree_null(
void * ctx)
49 self->msg =
"NULL value not permitted";
54 int jtree_boolean(
void * ctx,
int boolVal)
57 if(self->depth==0)
throw std::runtime_error(
"Bare value not supported");
62 self->state = context::Undefined;
66 if(self->arr.size()>0 &&
self->arr.original_type()!=
pvd::pvBoolean)
67 throw std::runtime_error(
"Mixed type array not supported");
70 self->arr = pvd::static_shared_vector_cast<
void>(arr);
74 throw std::logic_error(
"boolean in bad state");
80 int jtree_integer(
void * ctx,
integer_arg integerVal)
83 if(self->depth==0)
throw std::runtime_error(
"Bare value not supported");
86 self->cur = &
self->cur->add<
pvd::pvLong>(
self->key, integerVal);
88 self->state = context::Undefined;
92 if(self->arr.size()>0 &&
self->arr.original_type()!=
pvd::pvLong)
93 throw std::runtime_error(
"Mixed type array not supported");
96 self->arr = pvd::static_shared_vector_cast<
void>(arr);
100 throw std::logic_error(
"int64 in bad state");
106 int jtree_double(
void * ctx,
double doubleVal)
109 if(self->depth==0)
throw std::runtime_error(
"Bare value not supported");
110 switch(self->state) {
112 self->cur = &
self->cur->add<
pvd::pvDouble>(
self->key, doubleVal);
114 self->state = context::Undefined;
118 if(self->arr.size()>0 &&
self->arr.original_type()!=
pvd::pvDouble)
119 throw std::runtime_error(
"Mixed type array not supported");
122 self->arr = pvd::static_shared_vector_cast<
void>(arr);
126 throw std::logic_error(
"double in bad state");
132 int jtree_string(
void * ctx,
const unsigned char * stringVal,
136 if(self->depth==0)
throw std::runtime_error(
"Bare value not supported");
137 std::string sval((
const char*)stringVal, stringLen);
138 switch(self->state) {
142 self->state = context::Undefined;
146 if(self->arr.size()>0 &&
self->arr.original_type()!=
pvd::pvString)
147 throw std::runtime_error(
"Mixed type array not supported");
150 self->arr = pvd::static_shared_vector_cast<
void>(arr);
154 throw std::logic_error(
"double in bad state");
160 int jtree_start_map(
void * ctx)
164 if(self->key.empty())
165 throw std::logic_error(
"anonymous dict not top level?");
166 self->cur = &
self->cur->addNested(self->key);
174 int jtree_map_key(
void * ctx,
const unsigned char * key,
178 if(!self->key.empty())
179 throw std::logic_error(
"double key?");
181 throw std::runtime_error(
"empty key not allowed");
182 self->key = std::string((
const char*)key, stringLen);
183 self->state = context::Key;
188 int jtree_end_map(
void * ctx)
192 self->cur = &
self->cur->endNested();
193 else if(self->depth==0)
194 throw std::logic_error(
"Unbalenced dict");
200 int jtree_start_array(
void * ctx)
203 if(self->depth==0)
throw std::runtime_error(
"Bare array not supported");
204 if(self->state!=context::Key)
205 throw std::logic_error(
"bare array not supported");
206 self->state = context::Array;
210 int jtree_end_array(
void * ctx)
213 if(self->state!=context::Array)
214 throw std::logic_error(
"Bad array parse");
215 self->cur = &
self->cur->add(self->key, pvd::freeze(self->arr));
217 self->state = context::Undefined;
242 throw std::runtime_error(
"Failed to allocate yajl handle");
252 namespace epics{
namespace pvData{
254 epics::pvData::PVStructure::shared_pointer
257 #ifndef EPICS_YAJL_VERSION 258 yajl_parser_config conf;
259 memset(&conf, 0,
sizeof(conf));
260 conf.allowComments = 1;
266 #ifndef EPICS_YAJL_VERSION 275 throw std::runtime_error(ctxt.msg);
277 return ctxt.cur->buildPVStructure();
void yajl_free(yajl_handle handle)
A holder for a contiguous piece of memory.
TODO only here because of the Lockable.
int yajl_config(yajl_handle h, yajl_option opt,...)
void push_back(param_type v)
epics::pvData::PVStructure::shared_pointer parseJSON(std::istream &strm)
yajl_handle yajl_alloc(const yajl_callbacks *callbacks, yajl_alloc_funcs *afs, void *ctx)
bool yajl_parse_helper(std::istream &src, yajl_handle handle)
struct yajl_handle_t * yajl_handle