Skip to content

OnDemand logic

Daniel Lemire edited this page Apr 5, 2021 · 3 revisions

object

When searching for a key, if the key is found then we are left pointing at the colon, and we are one depth below the object itself.

If the key is not found then we are left pointing at the either the start of the object or else a comma. We are at the depth of the object itself.

depth

The depth is set in the following functions:

  1. reenter_child
  2. abandon (sets the depth to 0)

The child() method in value_iterator will return a value_iterator which is set at depth() + 1. In turn, the child() method is called by

  1. operator*() in the array iterator (thus ensuring that values accessed from the array are at depth() + 1 compared to the array).
  2. by find_field_unordered and find_field in the object class. Note that the operator[] in object calls find_field_unordered.
  3. by field.start

The depth is incremented in these instances:

  1. when encountering a colon in field_value().
  2. in started_array() when it is not an empty array. Note that started_object does not similarly increment the depth.
  3. in has_next_element() when encountering a comma. Note that a comma in an object does not change the depth (see has_next_field()).

The depth is decremented in these instances:

  1. When an object is closed by } (in started_object(), in has_next_field()).
  2. When an array is closed by ] (in started_array(), in has_next_element()).
  3. In advance_start(), in advance_root_scalar(), in advance_non_root_scalar().

Skip child will, as a first step, decrement the depth when encountering },] or an atom (anything that does not start with [,{,:, or the comma), and then scan the structural elements, incrementing on [,{ and decrementing on },].