mirror of https://github.com/tstack/lnav.git
[yajlpp] fix config save
This commit is contained in:
parent
a9e9613214
commit
de6ec92f2f
|
@ -106,9 +106,7 @@ public:
|
|||
this->msg = (const char *) yajl_msg.in();
|
||||
}
|
||||
|
||||
~yajlpp_error() override {
|
||||
|
||||
}
|
||||
~yajlpp_error() override = default;
|
||||
|
||||
const char *what() const noexcept override {
|
||||
return this->msg.c_str();
|
||||
|
@ -135,10 +133,6 @@ struct json_path_handler_base {
|
|||
json_path_handler_base(const char *path)
|
||||
: jph_path(path),
|
||||
jph_regex(path, PCRE_ANCHORED),
|
||||
jph_gen_callback(nullptr),
|
||||
jph_field_getter(nullptr),
|
||||
jph_obj_provider(nullptr),
|
||||
jph_path_provider(nullptr),
|
||||
jph_synopsis(""),
|
||||
jph_description(""),
|
||||
jph_children(nullptr),
|
||||
|
@ -174,12 +168,11 @@ struct json_path_handler_base {
|
|||
const char * jph_path;
|
||||
pcrepp jph_regex;
|
||||
yajl_callbacks jph_callbacks;
|
||||
yajl_gen_status (*jph_gen_callback)(yajlpp_gen_context &, const json_path_handler_base &, yajl_gen);
|
||||
void (*jph_validator)(yajlpp_parse_context &ypc,
|
||||
const json_path_handler_base &jph);
|
||||
void *(*jph_field_getter)(void *root, nonstd::optional<std::string> name);
|
||||
void *(*jph_obj_provider)(const yajlpp_provider_context &pe, void *root);
|
||||
void (*jph_path_provider)(void *root, std::vector<std::string> &paths_out);
|
||||
std::function<yajl_gen_status (yajlpp_gen_context &, const json_path_handler_base &, yajl_gen)> jph_gen_callback;
|
||||
std::function<void (yajlpp_parse_context &ypc, const json_path_handler_base &jph)> jph_validator;
|
||||
std::function<void *(void *root, nonstd::optional<std::string> name)> jph_field_getter;
|
||||
std::function<void *(const yajlpp_provider_context &pe, void *root)> jph_obj_provider;
|
||||
std::function<void (void *root, std::vector<std::string> &paths_out)> jph_path_provider;
|
||||
const char * jph_synopsis;
|
||||
const char * jph_description;
|
||||
json_path_handler_base *jph_children;
|
||||
|
|
|
@ -326,21 +326,23 @@ struct json_path_handler : public json_path_handler_base {
|
|||
return gen(obj->*FIELD);
|
||||
};
|
||||
|
||||
template<typename T, typename R, R T::*FIELD>
|
||||
static yajl_gen_status map_field_gen(yajlpp_gen_context &ygc,
|
||||
const json_path_handler_base &jph,
|
||||
yajl_gen handle)
|
||||
{
|
||||
const auto def_obj = (std::map<std::string, std::string> *) (
|
||||
ygc.ygc_default_stack.empty() ? nullptr
|
||||
: ygc.ygc_default_stack.top());
|
||||
auto obj = (std::map<std::string, std::string> *) ygc.ygc_obj_stack.top();
|
||||
const auto def_container = (T *) (ygc.ygc_default_stack.empty() ?
|
||||
nullptr : ygc.ygc_default_stack.top());
|
||||
auto container = (T *) ygc.ygc_obj_stack.top();
|
||||
auto &obj = container->*FIELD;
|
||||
yajl_gen_status rc;
|
||||
|
||||
for (auto &pair : *obj) {
|
||||
if (def_obj != nullptr) {
|
||||
auto iter = def_obj->find(pair.first);
|
||||
for (const auto &pair : obj) {
|
||||
if (def_container != nullptr) {
|
||||
auto &def_obj = def_container->*FIELD;
|
||||
auto iter = def_obj.find(pair.first);
|
||||
|
||||
if (iter != def_obj->end() && iter->second == pair.second) {
|
||||
if (iter != def_obj.end() && iter->second == pair.second) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -371,7 +373,7 @@ struct json_path_handler : public json_path_handler_base {
|
|||
template<typename T, typename STR_T, std::map<std::string, std::string> T::*STR>
|
||||
json_path_handler &for_field() {
|
||||
this->add_cb(string_field_cb<T, STR_T, STR>);
|
||||
this->jph_gen_callback = map_field_gen;
|
||||
this->jph_gen_callback = map_field_gen<T, STR_T, STR>;
|
||||
this->jph_validator = string_field_validator<T, STR_T, STR>;
|
||||
|
||||
return *this;
|
||||
|
|
Loading…
Reference in New Issue