summaryrefslogtreecommitdiffstats
path: root/src/yajlpp/yajlpp.hh
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/yajlpp/yajlpp.hh63
1 files changed, 55 insertions, 8 deletions
diff --git a/src/yajlpp/yajlpp.hh b/src/yajlpp/yajlpp.hh
index 7632329..ecf9734 100644
--- a/src/yajlpp/yajlpp.hh
+++ b/src/yajlpp/yajlpp.hh
@@ -112,6 +112,14 @@ struct factory_container : public positioned_property<std::shared_ptr<T>> {
return Err(
lnav::console::to_user_message(src, from_res.unwrapErr()));
}
+
+ std::string to_string() const
+ {
+ if (this->pp_value != nullptr) {
+ return this->pp_value->to_string();
+ }
+ return "";
+ }
};
template<typename... Args>
@@ -131,6 +139,14 @@ struct factory_container : public positioned_property<std::shared_ptr<T>> {
return Err(lnav::console::to_user_message(src, from_res.unwrapErr()));
}
+
+ std::string to_string() const
+ {
+ if (this->pp_value != nullptr) {
+ return this->pp_value->to_string();
+ }
+ return "";
+ }
};
class yajlpp_gen_context;
@@ -228,11 +244,11 @@ struct json_path_handler_base {
yajl_gen_status gen(yajlpp_gen_context& ygc, yajl_gen handle) const;
yajl_gen_status gen_schema(yajlpp_gen_context& ygc) const;
yajl_gen_status gen_schema_type(yajlpp_gen_context& ygc) const;
- void walk(
- const std::function<
- void(const json_path_handler_base&, const std::string&, void*)>& cb,
- void* root = nullptr,
- const std::string& base = "/") const;
+ void walk(const std::function<void(const json_path_handler_base&,
+ const std::string&,
+ const void*)>& cb,
+ void* root = nullptr,
+ const std::string& base = "/") const;
enum class schema_type_t : std::uint32_t {
ANY,
@@ -255,7 +271,7 @@ struct json_path_handler_base {
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)>
+ std::function<const void*(void* root, nonstd::optional<std::string> name)>
jph_field_getter;
std::function<void*(const yajlpp_provider_context& pe, void* root)>
jph_obj_provider;
@@ -283,8 +299,7 @@ struct json_path_handler_base {
std::function<int(yajlpp_parse_context*, int)> jph_bool_cb;
std::function<int(yajlpp_parse_context*, long long)> jph_integer_cb;
std::function<int(yajlpp_parse_context*, double)> jph_double_cb;
- std::function<int(
- yajlpp_parse_context*, const unsigned char* str, size_t len)>
+ std::function<int(yajlpp_parse_context*, const string_fragment& sf)>
jph_str_cb;
void validate_string(yajlpp_parse_context& ypc, string_fragment sf) const;
@@ -301,6 +316,9 @@ struct json_path_handler_base {
void report_error(yajlpp_parse_context* ypc,
const std::string& value_str,
lnav::console::user_message um) const;
+ void report_tz_error(yajlpp_parse_context* ypc,
+ const std::string& value_str,
+ const char* msg) const;
attr_line_t get_help_text(const std::string& full_path) const;
attr_line_t get_help_text(yajlpp_parse_context* ypc) const;
@@ -452,6 +470,16 @@ public:
return obj->*MEM;
}
+ void fill_in_source()
+ {
+ if (this->ypc_locations != nullptr) {
+ (*this->ypc_locations)[this->get_full_path()] = source_location{
+ this->ypc_source,
+ this->get_line_number(),
+ };
+ }
+ }
+
const intern_string_t ypc_source;
int ypc_line_number{1};
const struct json_path_container* ypc_handlers;
@@ -673,10 +701,29 @@ struct json_string {
memcpy((void*) this->js_content.in(), buf, this->js_len);
}
+ explicit json_string(auto_buffer&& buf)
+ {
+ auto buf_pair = buf.release();
+
+ this->js_content = (const unsigned char*) buf_pair.first;
+ this->js_len = buf_pair.second;
+ }
+
+ string_fragment to_string_fragment() const
+ {
+ return string_fragment::from_bytes(this->js_content, this->js_len);
+ }
+
auto_mem<const unsigned char> js_content;
size_t js_len{0};
};
void dump_schema_to(const json_path_container& jpc, const char* internals_dir);
+namespace yajlpp {
+
+auto_mem<yajl_handle_t> alloc_handle(const yajl_callbacks* cb, void* cu);
+
+} // namespace yajlpp
+
#endif