🔨 simplified SAX-DOM parser

parent 5b9d03cf
...@@ -176,7 +176,8 @@ class json_sax_dom_parser : public json_sax<BasicJsonType> ...@@ -176,7 +176,8 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
bool key(std::string&& val) override bool key(std::string&& val) override
{ {
last_key = val; // add null at given key and store the reference for later
object_element = &(ref_stack.back()->m_value.object->operator[](val));
return true; return true;
} }
...@@ -219,8 +220,8 @@ class json_sax_dom_parser : public json_sax<BasicJsonType> ...@@ -219,8 +220,8 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
BasicJsonType root; BasicJsonType root;
/// stack to model hierarchy of values /// stack to model hierarchy of values
std::vector<BasicJsonType*> ref_stack; std::vector<BasicJsonType*> ref_stack;
/// helper variable for object keys /// helper to hold the reference for the next object element
std::string last_key; BasicJsonType* object_element = nullptr;
/*! /*!
@invariant If the ref stack is empty, then the passed value will be the new @invariant If the ref stack is empty, then the passed value will be the new
...@@ -247,8 +248,9 @@ class json_sax_dom_parser : public json_sax<BasicJsonType> ...@@ -247,8 +248,9 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
} }
else else
{ {
BasicJsonType& r = ref_stack.back()->m_value.object->operator[](last_key) = BasicJsonType(std::forward<Value>(v)); assert(object_element);
return &r; *object_element = BasicJsonType(std::forward<Value>(v));
return object_element;
} }
} }
} }
......
...@@ -3310,7 +3310,8 @@ class json_sax_dom_parser : public json_sax<BasicJsonType> ...@@ -3310,7 +3310,8 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
bool key(std::string&& val) override bool key(std::string&& val) override
{ {
last_key = val; // add null at given key and store the reference for later
object_element = &(ref_stack.back()->m_value.object->operator[](val));
return true; return true;
} }
...@@ -3353,8 +3354,8 @@ class json_sax_dom_parser : public json_sax<BasicJsonType> ...@@ -3353,8 +3354,8 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
BasicJsonType root; BasicJsonType root;
/// stack to model hierarchy of values /// stack to model hierarchy of values
std::vector<BasicJsonType*> ref_stack; std::vector<BasicJsonType*> ref_stack;
/// helper variable for object keys /// helper to hold the reference for the next object element
std::string last_key; BasicJsonType* object_element = nullptr;
/*! /*!
@invariant If the ref stack is empty, then the passed value will be the new @invariant If the ref stack is empty, then the passed value will be the new
...@@ -3381,8 +3382,9 @@ class json_sax_dom_parser : public json_sax<BasicJsonType> ...@@ -3381,8 +3382,9 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
} }
else else
{ {
BasicJsonType& r = ref_stack.back()->m_value.object->operator[](last_key) = BasicJsonType(std::forward<Value>(v)); assert(object_element);
return &r; *object_element = BasicJsonType(std::forward<Value>(v));
return object_element;
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment