25 typedef std::map<std::string, pvd::AnyScalar> options_t;
26 typedef std::map<std::string, options_t> config_t;
30 std::string group, field, key;
37 context() :depth(0u) {}
43 if(depth<2 || depth>3)
44 throw std::runtime_error(
"Can't assign value in this context");
52 if(field==
"+atomic") {
56 }
else if(field==
"+id") {
57 grp.
id = value.
as<std::string>();
60 conf.
warning +=
"Unknown group option ";
69 fld.
type = value.
ref<std::string>();
71 }
else if(key==
"+channel") {
74 }
else if(key==
"+id") {
75 fld.
id = value.
ref<std::string>();
77 }
else if(key==
"+trigger") {
80 }
else if(key==
"+putorder") {
84 conf.
warning +=
"Unknown group field option ";
92 #define TRY context *self = (context*)ctx; try 94 #define CATCH() catch(std::exception& e) { if(self->msg.empty()) self->msg = e.what(); return 0; } 96 int conf_null(
void * ctx)
105 int conf_boolean(
void * ctx,
int boolVal)
113 int conf_integer(
void * ctx,
integer_arg integerVal)
121 int conf_double(
void * ctx,
double doubleVal)
129 int conf_string(
void * ctx,
const unsigned char * stringVal,
133 std::string val((
const char*)stringVal, stringLen);
139 int conf_start_map(
void * ctx)
144 throw std::runtime_error(
"Group field def. can't contain Object (too deep)");
149 int conf_map_key(
void * ctx,
const unsigned char * key,
153 if(stringLen==0 && self->depth!=2)
154 throw std::runtime_error(
"empty group or key name not allowed");
156 std::string name((
const char*)key, stringLen);
159 self->group.swap(name);
160 else if(self->depth==2)
161 self->field.swap(name);
162 else if(self->depth==3)
163 self->key.swap(name);
165 throw std::logic_error(
"Too deep!!");
171 int conf_end_map(
void * ctx)
174 assert(self->key.empty());
178 else if(self->depth==2)
180 else if(self->depth==1)
183 throw std::logic_error(
"Invalid depth");
209 throw std::runtime_error(
"Failed to allocate yajl handle");
222 #ifndef EPICS_YAJL_VERSION 223 yajl_parser_config conf;
224 memset(&conf, 0,
sizeof(conf));
225 conf.allowComments = 1;
229 std::istringstream strm(txt);
233 #ifndef EPICS_YAJL_VERSION 242 throw std::runtime_error(ctxt.msg);
244 ctxt.conf.swap(result);
#define assert(exp)
Declare that a condition should be true.
void yajl_free(yajl_handle handle)
int yajl_config(yajl_handle h, yajl_option opt,...)
yajl_handle yajl_alloc(const yajl_callbacks *callbacks, yajl_alloc_funcs *afs, void *ctx)
bool yajl_parse_helper(std::istream &src, yajl_handle handle)
static void parse(const char *txt, GroupConfig &result)
detail::pick_type< int8_t, signed char, detail::pick_type< uint8_t, char, unsigned char >::type >::type boolean
struct yajl_handle_t * yajl_handle
detail::any_storage_type< typename meta::strip_const< T >::type >::type & ref()