diff --git a/bm/bm_parse.cpp b/bm/bm_parse.cpp index 51be1d304..c97c708fc 100644 --- a/bm/bm_parse.cpp +++ b/bm/bm_parse.cpp @@ -27,7 +27,7 @@ int main(int argc, char** argv) ryml::id_type estimate_capacity(ryml::csubstr src) { - return (3 * ryml::Parser::estimate_tree_capacity(src)) >> 1; + return (3 * ryml::estimate_tree_capacity(src)) >> 1; } diff --git a/changelog/current.md b/changelog/current.md index 632052ee7..ba80c6acc 100644 --- a/changelog/current.md +++ b/changelog/current.md @@ -19,6 +19,10 @@ Most of the changes are from the giant Parser refactor described below. Before g NodeRef::depth_asc() const; NodeRef::depth_desc() const; ``` +- [#PR432](https://github.com/biojppm/rapidyaml/pull/432) - Added a function to estimate the required tree capacity, based on yaml markup: + ```cpp + size_t estimate_tree_capacity(csubstr); // estimate number of nodes resulting from yaml + ``` ------ diff --git a/samples/quickstart.cpp b/samples/quickstart.cpp index 59de52064..71c382226 100644 --- a/samples/quickstart.cpp +++ b/samples/quickstart.cpp @@ -357,8 +357,8 @@ john: doe)"; // The lower level index API is based on the indices of nodes, // where the node's id is the node's position in the tree's data // array. This API is very efficient, but somewhat difficult to use: - size_t root_id = tree.root_id(); - size_t bar_id = tree.find_child(root_id, "bar"); // need to get the index right + ryml::id_type root_id = tree.root_id(); + ryml::id_type bar_id = tree.find_child(root_id, "bar"); // need to get the index right CHECK(tree.is_map(root_id)); // all of the index methods are in the tree CHECK(tree.is_seq(bar_id)); // ... and receive the subject index @@ -426,14 +426,14 @@ john: doe)"; // IMPORTANT. The ryml tree uses an index-based linked list for // storing children, so the complexity of - // `Tree::operator[csubstr]` and `Tree::operator[size_t]` is O(n), + // `Tree::operator[csubstr]` and `Tree::operator[id_type]` is O(n), // linear on the number of root children. If you use // `Tree::operator[]` with a large tree where the root has many // children, you will see a performance hit. // // To avoid this hit, you can create your own accelerator // structure. For example, before doing a lookup, do a single - // traverse at the root level to fill an `map` + // traverse at the root level to fill an `map` // mapping key names to node indices; with a node index, a lookup // (via `Tree::get()`) is O(1), so this way you can get O(log n) // lookup from a key. (But please do not use `std::map` if you @@ -479,20 +479,20 @@ john: doe)"; ryml::csubstr expected_keys[] = {"foo", "bar", "john"}; // iterate children using the high-level node API: { - size_t count = 0; + ryml::id_type count = 0; for(ryml::ConstNodeRef const& child : root.children()) CHECK(child.key() == expected_keys[count++]); } // iterate siblings using the high-level node API: { - size_t count = 0; + ryml::id_type count = 0; for(ryml::ConstNodeRef const& child : root["foo"].siblings()) CHECK(child.key() == expected_keys[count++]); } // iterate children using the lower-level tree index API: { - size_t count = 0; - for(size_t child_id = tree.first_child(root_id); child_id != ryml::NONE; child_id = tree.next_sibling(child_id)) + ryml::id_type count = 0; + for(ryml::id_type child_id = tree.first_child(root_id); child_id != ryml::NONE; child_id = tree.next_sibling(child_id)) CHECK(tree.key(child_id) == expected_keys[count++]); } // iterate siblings using the lower-level tree index API: @@ -500,8 +500,8 @@ john: doe)"; // preamble, which calls tree.first_sibling(bar_id) instead of // tree.first_child(root_id)) { - size_t count = 0; - for(size_t child_id = tree.first_sibling(bar_id); child_id != ryml::NONE; child_id = tree.next_sibling(child_id)) + ryml::id_type count = 0; + for(ryml::id_type child_id = tree.first_sibling(bar_id); child_id != ryml::NONE; child_id = tree.next_sibling(child_id)) CHECK(tree.key(child_id) == expected_keys[count++]); } } @@ -3629,7 +3629,7 @@ void write(ryml::NodeRef *n, my_type const& val) template bool read(ryml::ConstNodeRef const& n, my_seq_type *seq) { - seq->seq_member.resize(n.num_children()); // num_children() is O(N) + seq->seq_member.resize(static_cast(n.num_children())); // num_children() is O(N) size_t pos = 0; for(auto const ch : n.children()) ch >> seq->seq_member[pos++]; @@ -3813,7 +3813,7 @@ void sample_float_precision() CHECK(output.size() == reference.size()); for(size_t i = 0; i < reference.size(); ++i) { - CHECK(get_num_digits(tree[i].val()) == num_digits_original); + CHECK(get_num_digits(tree[(ryml::id_type)i].val()) == num_digits_original); CHECK(fabs(output[i] - reference[i]) < precision_safe); } } @@ -4577,12 +4577,12 @@ d: 3 CHECK(tree.docref(1).id() == stream.child(1).id()); CHECK(tree.docref(2).id() == stream.child(2).id()); // equivalent: using the lower level index API - const size_t stream_id = tree.root_id(); + const ryml::id_type stream_id = tree.root_id(); CHECK(tree.is_root(stream_id)); CHECK(tree.is_stream(stream_id)); CHECK(!tree.is_doc(stream_id)); CHECK(tree.num_children(stream_id) == 3); - for(size_t doc_id = tree.first_child(stream_id); doc_id != ryml::NONE; doc_id = tree.next_sibling(stream_id)) + for(ryml::id_type doc_id = tree.first_child(stream_id); doc_id != ryml::NONE; doc_id = tree.next_sibling(stream_id)) CHECK(tree.is_doc(doc_id)); CHECK(tree.doc(0) == tree.child(stream_id, 0)); CHECK(tree.doc(1) == tree.child(stream_id, 1)); @@ -4594,7 +4594,7 @@ d: 3 CHECK(stream[0]["a"].val() == "0"); CHECK(stream[0]["b"].val() == "1"); // equivalent: using the index API - const size_t doc0_id = tree.first_child(stream_id); + const ryml::id_type doc0_id = tree.first_child(stream_id); CHECK(tree.is_doc(doc0_id)); CHECK(tree.is_map(doc0_id)); CHECK(tree.val(tree.find_child(doc0_id, "a")) == "0"); @@ -4606,7 +4606,7 @@ d: 3 CHECK(stream[1]["c"].val() == "2"); CHECK(stream[1]["d"].val() == "3"); // equivalent: using the index API - const size_t doc1_id = tree.next_sibling(doc0_id); + const ryml::id_type doc1_id = tree.next_sibling(doc0_id); CHECK(tree.is_doc(doc1_id)); CHECK(tree.is_map(doc1_id)); CHECK(tree.val(tree.find_child(doc1_id, "c")) == "2"); @@ -4620,7 +4620,7 @@ d: 3 CHECK(stream[2][2].val() == "6"); CHECK(stream[2][3].val() == "7"); // equivalent: using the index API - const size_t doc2_id = tree.next_sibling(doc1_id); + const ryml::id_type doc2_id = tree.next_sibling(doc1_id); CHECK(tree.is_doc(doc2_id)); CHECK(tree.is_seq(doc2_id)); CHECK(tree.val(tree.child(doc2_id, 0)) == "4"); @@ -4644,18 +4644,18 @@ d: 3 }; // using the node API { - size_t count = 0; + ryml::id_type count = 0; const ryml::ConstNodeRef stream = tree.rootref(); - CHECK(stream.num_children() == C4_COUNTOF(expected_json)); + CHECK(stream.num_children() == (ryml::id_type)C4_COUNTOF(expected_json)); for(ryml::ConstNodeRef doc : stream.children()) CHECK(ryml::emitrs_json(doc) == expected_json[count++]); } // equivalent: using the index API { - size_t count = 0; - const size_t stream_id = tree.root_id(); - CHECK(tree.num_children(stream_id) == C4_COUNTOF(expected_json)); - for(size_t doc_id = tree.first_child(stream_id); doc_id != ryml::NONE; doc_id = tree.next_sibling(doc_id)) + ryml::id_type count = 0; + const ryml::id_type stream_id = tree.root_id(); + CHECK(tree.num_children(stream_id) == (ryml::id_type)C4_COUNTOF(expected_json)); + for(ryml::id_type doc_id = tree.first_child(stream_id); doc_id != ryml::NONE; doc_id = tree.next_sibling(doc_id)) CHECK(ryml::emitrs_json(tree, doc_id) == expected_json[count++]); } } diff --git a/src/c4/yml/emit.def.hpp b/src/c4/yml/emit.def.hpp index efbaa3519..5ea901f89 100644 --- a/src/c4/yml/emit.def.hpp +++ b/src/c4/yml/emit.def.hpp @@ -81,7 +81,7 @@ void Emitter::_emit_yaml(id_type id) break; ++end; } - const size_t parent = m_tree->parent(next_node); + const id_type parent = m_tree->parent(next_node); for( ; tagds.b != end; ++tagds.b) { if(next_node != m_tree->first_child(parent)) @@ -199,7 +199,7 @@ void Emitter::_write_doc(id_type id) } else // docval { - RYML_ASSERT(m_tree->has_val(id)); + _RYML_CB_ASSERT(m_tree->callbacks(), m_tree->has_val(id)); // some plain scalars such as '...' and '---' must not // appear at 0-indentation const csubstr val = m_tree->val(id); @@ -245,9 +245,9 @@ void Emitter::_do_visit_flow_sl(id_type node, id_type depth, id_type ile { const bool prev_flow = m_flow; m_flow = true; - RYML_ASSERT(!m_tree->is_stream(node)); - RYML_ASSERT(m_tree->is_container(node) || m_tree->is_doc(node)); - RYML_ASSERT(m_tree->is_root(node) || (m_tree->parent_is_map(node) || m_tree->parent_is_seq(node))); + _RYML_CB_ASSERT(m_tree->callbacks(), !m_tree->is_stream(node)); + _RYML_CB_ASSERT(m_tree->callbacks(), m_tree->is_container(node) || m_tree->is_doc(node)); + _RYML_CB_ASSERT(m_tree->callbacks(), m_tree->is_root(node) || (m_tree->parent_is_map(node) || m_tree->parent_is_seq(node))); if(C4_UNLIKELY(depth > m_opts.max_depth())) _RYML_CB_ERR(m_tree->callbacks(), "max depth exceeded"); @@ -273,7 +273,7 @@ void Emitter::_do_visit_flow_sl(id_type node, id_type depth, id_type ile } else if(m_tree->is_container(node)) { - RYML_ASSERT(m_tree->is_map(node) || m_tree->is_seq(node)); + _RYML_CB_ASSERT(m_tree->callbacks(), m_tree->is_map(node) || m_tree->is_seq(node)); bool spc = false; // write a space @@ -451,9 +451,9 @@ void Emitter::_do_visit_block_container(id_type node, id_type depth, id_ template void Emitter::_do_visit_block(id_type node, id_type depth, id_type ilevel, id_type do_indent) { - RYML_ASSERT(!m_tree->is_stream(node)); - RYML_ASSERT(m_tree->is_container(node) || m_tree->is_doc(node)); - RYML_ASSERT(m_tree->is_root(node) || (m_tree->parent_is_map(node) || m_tree->parent_is_seq(node))); + _RYML_CB_ASSERT(m_tree->callbacks(), !m_tree->is_stream(node)); + _RYML_CB_ASSERT(m_tree->callbacks(), m_tree->is_container(node) || m_tree->is_doc(node)); + _RYML_CB_ASSERT(m_tree->callbacks(), m_tree->is_root(node) || (m_tree->parent_is_map(node) || m_tree->parent_is_seq(node))); if(C4_UNLIKELY(depth > m_opts.max_depth())) _RYML_CB_ERR(m_tree->callbacks(), "max depth exceeded"); if(m_tree->is_doc(node)) @@ -464,7 +464,7 @@ void Emitter::_do_visit_block(id_type node, id_type depth, id_type ileve } else if(m_tree->is_container(node)) { - RYML_ASSERT(m_tree->is_map(node) || m_tree->is_seq(node)); + _RYML_CB_ASSERT(m_tree->callbacks(), m_tree->is_map(node) || m_tree->is_seq(node)); bool spc = false; // write a space bool nl = false; // write a newline if(m_tree->has_key(node)) @@ -672,9 +672,9 @@ size_t Emitter::_write_escaped_newlines(csubstr s, size_t i) this->Writer::_do_write('\n'); // write the newline again ++i; // increase the outer loop counter! } while(i < s.len && s.str[i] == '\n'); - RYML_ASSERT(i > 0); + _RYML_CB_ASSERT(m_tree->callbacks(), i > 0); --i; - RYML_ASSERT(s.str[i] == '\n'); + _RYML_CB_ASSERT(m_tree->callbacks(), s.str[i] == '\n'); return i; } @@ -690,10 +690,10 @@ template size_t Emitter::_write_indented_block(csubstr s, size_t i, id_type ilevel) { //_c4dbgpf("indblock@i={} rem=[{}]~~~\n{}~~~", i, s.sub(i).len, s.sub(i)); - RYML_ASSERT(i > 0); - RYML_ASSERT(s.str[i-1] == '\n'); - RYML_ASSERT(i < s.len); - RYML_ASSERT(s.str[i] == ' ' || s.str[i] == '\t' || s.str[i] == '\n'); + _RYML_CB_ASSERT(m_tree->callbacks(), i > 0); + _RYML_CB_ASSERT(m_tree->callbacks(), s.str[i-1] == '\n'); + _RYML_CB_ASSERT(m_tree->callbacks(), i < s.len); + _RYML_CB_ASSERT(m_tree->callbacks(), s.str[i] == ' ' || s.str[i] == '\t' || s.str[i] == '\n'); again: size_t pos = s.find("\n ", i); if(pos == npos) @@ -725,7 +725,7 @@ size_t Emitter::_write_indented_block(csubstr s, size_t i, id_type ileve template void Emitter::_write_scalar_literal(csubstr s, id_type ilevel, bool explicit_key) { - RYML_ASSERT(s.find("\r") == csubstr::npos); + _RYML_CB_ASSERT(m_tree->callbacks(), s.find("\r") == csubstr::npos); if(explicit_key) this->Writer::_do_write("? "); csubstr trimmed = s.trimr('\n'); @@ -773,7 +773,7 @@ void Emitter::_write_scalar_folded(csubstr s, id_type ilevel, bool expli { if(explicit_key) this->Writer::_do_write("? "); - RYML_ASSERT(s.find("\r") == csubstr::npos); + _RYML_CB_ASSERT(m_tree->callbacks(), s.find("\r") == csubstr::npos); csubstr trimmed = s.trimr('\n'); const size_t numnewlines_at_end = s.len - trimmed.len; const bool is_newline_only = (trimmed.len == 0 && (s.len > 0)); diff --git a/src/c4/yml/event_handler_tree.hpp b/src/c4/yml/event_handler_tree.hpp index f9bf597f7..b46238f4d 100644 --- a/src/c4/yml/event_handler_tree.hpp +++ b/src/c4/yml/event_handler_tree.hpp @@ -346,13 +346,13 @@ struct EventHandlerTree : public EventHandlerStacknode_id, scalar.len, scalar, reinterpret_cast(scalar.str)); m_curr->tr_data->m_key.scalar = scalar; _enable_(KEY|KEY_PLAIN); } - C4_ALWAYS_INLINE void set_val_scalar_plain(csubstr scalar) + C4_ALWAYS_INLINE void set_val_scalar_plain(csubstr scalar) noexcept { _c4dbgpf("node[{}]: set val scalar plain: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast(scalar.str)); m_curr->tr_data->m_val.scalar = scalar; @@ -360,13 +360,13 @@ struct EventHandlerTree : public EventHandlerStacknode_id, scalar.len, scalar, reinterpret_cast(scalar.str)); m_curr->tr_data->m_key.scalar = scalar; _enable_(KEY|KEY_DQUO); } - C4_ALWAYS_INLINE void set_val_scalar_dquoted(csubstr scalar) + C4_ALWAYS_INLINE void set_val_scalar_dquoted(csubstr scalar) noexcept { _c4dbgpf("node[{}]: set val scalar dquot: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast(scalar.str)); m_curr->tr_data->m_val.scalar = scalar; @@ -374,13 +374,13 @@ struct EventHandlerTree : public EventHandlerStacknode_id, scalar.len, scalar, reinterpret_cast(scalar.str)); m_curr->tr_data->m_key.scalar = scalar; _enable_(KEY|KEY_SQUO); } - C4_ALWAYS_INLINE void set_val_scalar_squoted(csubstr scalar) + C4_ALWAYS_INLINE void set_val_scalar_squoted(csubstr scalar) noexcept { _c4dbgpf("node[{}]: set val scalar squot: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast(scalar.str)); m_curr->tr_data->m_val.scalar = scalar; @@ -388,13 +388,13 @@ struct EventHandlerTree : public EventHandlerStacknode_id, scalar.len, scalar, reinterpret_cast(scalar.str)); m_curr->tr_data->m_key.scalar = scalar; _enable_(KEY|KEY_LITERAL); } - C4_ALWAYS_INLINE void set_val_scalar_literal(csubstr scalar) + C4_ALWAYS_INLINE void set_val_scalar_literal(csubstr scalar) noexcept { _c4dbgpf("node[{}]: set val scalar literal: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast(scalar.str)); m_curr->tr_data->m_val.scalar = scalar; @@ -402,13 +402,13 @@ struct EventHandlerTree : public EventHandlerStacknode_id, scalar.len, scalar, reinterpret_cast(scalar.str)); m_curr->tr_data->m_key.scalar = scalar; _enable_(KEY|KEY_FOLDED); } - C4_ALWAYS_INLINE void set_val_scalar_folded(csubstr scalar) + C4_ALWAYS_INLINE void set_val_scalar_folded(csubstr scalar) noexcept { _c4dbgpf("node[{}]: set val scalar folded: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast(scalar.str)); m_curr->tr_data->m_val.scalar = scalar; @@ -416,11 +416,11 @@ struct EventHandlerTree : public EventHandlerStacknode_id, anchor.len, anchor); - RYML_ASSERT(!anchor.begins_with('&')); + _RYML_CB_ASSERT(m_stack.m_callbacks, !anchor.begins_with('&')); _enable_(KEYANCH); m_curr->tr_data->m_key.anchor = anchor; } - void set_val_anchor(csubstr anchor) + void set_val_anchor(csubstr anchor) RYML_NOEXCEPT { _c4dbgpf("node[{}]: set val anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor); - RYML_ASSERT(!anchor.begins_with('&')); + _RYML_CB_ASSERT(m_stack.m_callbacks, !anchor.begins_with('&')); _enable_(VALANCH); m_curr->tr_data->m_val.anchor = anchor; } - void set_key_ref(csubstr ref) + void set_key_ref(csubstr ref) RYML_NOEXCEPT { _c4dbgpf("node[{}]: set key ref: [{}]~~~{}~~~", m_curr->node_id, ref.len, ref); - RYML_ASSERT(ref.begins_with('*')); + _RYML_CB_ASSERT(m_stack.m_callbacks, ref.begins_with('*')); _enable_(KEY|KEYREF); m_curr->tr_data->m_key.anchor = ref.sub(1); m_curr->tr_data->m_key.scalar = ref; } - void set_val_ref(csubstr ref) + void set_val_ref(csubstr ref) RYML_NOEXCEPT { _c4dbgpf("node[{}]: set val ref: [{}]~~~{}~~~", m_curr->node_id, ref.len, ref); - RYML_ASSERT(ref.begins_with('*')); + _RYML_CB_ASSERT(m_stack.m_callbacks, ref.begins_with('*')); _enable_(VAL|VALREF); m_curr->tr_data->m_val.anchor = ref.sub(1); m_curr->tr_data->m_val.scalar = ref; @@ -471,13 +471,13 @@ struct EventHandlerTree : public EventHandlerStacknode_id, tag.len, tag); _enable_(KEYTAG); m_curr->tr_data->m_key.tag = tag; } - void set_val_tag(csubstr tag) + void set_val_tag(csubstr tag) noexcept { _c4dbgpf("node[{}]: set val tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag); _enable_(VALTAG); diff --git a/src/c4/yml/node.hpp b/src/c4/yml/node.hpp index 510e0bfca..8ff63943b 100644 --- a/src/c4/yml/node.hpp +++ b/src/c4/yml/node.hpp @@ -187,6 +187,8 @@ struct RoNodeMethods RYML_ASSERT(tree_ != nullptr); \ _RYML_CB_ASSERT(tree_->m_callbacks, id_ != NONE); \ _RYML_CB_ASSERT(tree_->m_callbacks, (((Impl const* C4_RESTRICT)this)->readable())) + // a SFINAE beautifier to enable a function only if the + // implementation is mutable #define _C4_IF_MUTABLE(ty) typename std::enable_if::value, ty>::type /** @endcond */ @@ -201,27 +203,27 @@ struct RoNodeMethods template C4_ALWAYS_INLINE auto get() RYML_NOEXCEPT -> _C4_IF_MUTABLE(NodeData*) { return ((Impl const*)this)->readable() ? tree__->get(id__) : nullptr; } - C4_ALWAYS_INLINE NodeType type() const RYML_NOEXCEPT { _C4RR(); return tree_->type(id_); } - C4_ALWAYS_INLINE const char* type_str() const RYML_NOEXCEPT { _C4RR(); return tree_->type_str(id_); } + C4_ALWAYS_INLINE NodeType type() const RYML_NOEXCEPT { _C4RR(); return tree_->type(id_); } /**< Forward to @ref Tree::type_str(). Node must be readable. */ + C4_ALWAYS_INLINE const char* type_str() const RYML_NOEXCEPT { _C4RR(); return tree_->type_str(id_); } /**< Forward to @ref Tree::type_str(). Node must be readable. */ - C4_ALWAYS_INLINE csubstr key() const RYML_NOEXCEPT { _C4RR(); return tree_->key(id_); } - C4_ALWAYS_INLINE csubstr key_tag() const RYML_NOEXCEPT { _C4RR(); return tree_->key_tag(id_); } - C4_ALWAYS_INLINE csubstr key_ref() const RYML_NOEXCEPT { _C4RR(); return tree_->key_ref(id_); } - C4_ALWAYS_INLINE csubstr key_anchor() const RYML_NOEXCEPT { _C4RR(); return tree_->key_anchor(id_); } + C4_ALWAYS_INLINE csubstr key() const RYML_NOEXCEPT { _C4RR(); return tree_->key(id_); } /**< Forward to @ref Tree::key(). Node must be readable. */ + C4_ALWAYS_INLINE csubstr key_tag() const RYML_NOEXCEPT { _C4RR(); return tree_->key_tag(id_); } /**< Forward to @ref Tree::key_tag(). Node must be readable. */ + C4_ALWAYS_INLINE csubstr key_ref() const RYML_NOEXCEPT { _C4RR(); return tree_->key_ref(id_); } /**< Forward to @ref Tree::key_ref(). Node must be readable. */ + C4_ALWAYS_INLINE csubstr key_anchor() const RYML_NOEXCEPT { _C4RR(); return tree_->key_anchor(id_); } /**< Forward to @ref Tree::key_anchor(). Node must be readable. */ - C4_ALWAYS_INLINE csubstr val() const RYML_NOEXCEPT { _C4RR(); return tree_->val(id_); } - C4_ALWAYS_INLINE csubstr val_tag() const RYML_NOEXCEPT { _C4RR(); return tree_->val_tag(id_); } - C4_ALWAYS_INLINE csubstr val_ref() const RYML_NOEXCEPT { _C4RR(); return tree_->val_ref(id_); } - C4_ALWAYS_INLINE csubstr val_anchor() const RYML_NOEXCEPT { _C4RR(); return tree_->val_anchor(id_); } + C4_ALWAYS_INLINE csubstr val() const RYML_NOEXCEPT { _C4RR(); return tree_->val(id_); } /**< Forward to @ref Tree::val(). Node must be readable. */ + C4_ALWAYS_INLINE csubstr val_tag() const RYML_NOEXCEPT { _C4RR(); return tree_->val_tag(id_); } /**< Forward to @ref Tree::val_tag(). Node must be readable. */ + C4_ALWAYS_INLINE csubstr val_ref() const RYML_NOEXCEPT { _C4RR(); return tree_->val_ref(id_); } /**< Forward to @ref Tree::val_ref(). Node must be readable. */ + C4_ALWAYS_INLINE csubstr val_anchor() const RYML_NOEXCEPT { _C4RR(); return tree_->val_anchor(id_); } /**< Forward to @ref Tree::val_anchor(). Node must be readable. */ - C4_ALWAYS_INLINE NodeScalar const& keysc() const RYML_NOEXCEPT { _C4RR(); return tree_->keysc(id_); } - C4_ALWAYS_INLINE NodeScalar const& valsc() const RYML_NOEXCEPT { _C4RR(); return tree_->valsc(id_); } + C4_ALWAYS_INLINE NodeScalar const& keysc() const RYML_NOEXCEPT { _C4RR(); return tree_->keysc(id_); } /**< Forward to @ref Tree::keysc(). Node must be readable. */ + C4_ALWAYS_INLINE NodeScalar const& valsc() const RYML_NOEXCEPT { _C4RR(); return tree_->valsc(id_); } /**< Forward to @ref Tree::valsc(). Node must be readable. */ - C4_ALWAYS_INLINE bool key_is_null() const RYML_NOEXCEPT { _C4RR(); return tree_->key_is_null(id_); } - C4_ALWAYS_INLINE bool val_is_null() const RYML_NOEXCEPT { _C4RR(); return tree_->val_is_null(id_); } + C4_ALWAYS_INLINE bool key_is_null() const RYML_NOEXCEPT { _C4RR(); return tree_->key_is_null(id_); } /**< Forward to @ref Tree::key_is_null(). Node must be readable. */ + C4_ALWAYS_INLINE bool val_is_null() const RYML_NOEXCEPT { _C4RR(); return tree_->val_is_null(id_); } /**< Forward to @ref Tree::val_is_null(). Node must be readable. */ - C4_ALWAYS_INLINE C4_PURE bool is_key_unfiltered() const noexcept { _C4RR(); return tree_->is_key_unfiltered(id_); } - C4_ALWAYS_INLINE C4_PURE bool is_val_unfiltered() const noexcept { _C4RR(); return tree_->is_val_unfiltered(id_); } + C4_ALWAYS_INLINE bool is_key_unfiltered() const noexcept { _C4RR(); return tree_->is_key_unfiltered(id_); } /**< Forward to @ref Tree::is_key_unfiltered(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_val_unfiltered() const noexcept { _C4RR(); return tree_->is_val_unfiltered(id_); } /**< Forward to @ref Tree::is_val_unfiltered(). Node must be readable. */ /** @} */ @@ -230,26 +232,26 @@ struct RoNodeMethods /** @name node type predicates */ /** @{ */ - C4_ALWAYS_INLINE bool empty() const RYML_NOEXCEPT { _C4RR(); return tree_->empty(id_); } /**< Forward to Tree::empty(). Node must be readable. */ - C4_ALWAYS_INLINE bool is_stream() const RYML_NOEXCEPT { _C4RR(); return tree_->is_stream(id_); } /**< Forward to Tree::is_stream(). Node must be readable. */ - C4_ALWAYS_INLINE bool is_doc() const RYML_NOEXCEPT { _C4RR(); return tree_->is_doc(id_); } /**< Forward to Tree::is_doc(). Node must be readable. */ - C4_ALWAYS_INLINE bool is_container() const RYML_NOEXCEPT { _C4RR(); return tree_->is_container(id_); } /**< Forward to Tree::is_container(). Node must be readable. */ - C4_ALWAYS_INLINE bool is_map() const RYML_NOEXCEPT { _C4RR(); return tree_->is_map(id_); } /**< Forward to Tree::is_map(). Node must be readable. */ - C4_ALWAYS_INLINE bool is_seq() const RYML_NOEXCEPT { _C4RR(); return tree_->is_seq(id_); } /**< Forward to Tree::is_seq(). Node must be readable. */ - C4_ALWAYS_INLINE bool has_val() const RYML_NOEXCEPT { _C4RR(); return tree_->has_val(id_); } /**< Forward to Tree::has_val(). Node must be readable. */ - C4_ALWAYS_INLINE bool has_key() const RYML_NOEXCEPT { _C4RR(); return tree_->has_key(id_); } /**< Forward to Tree::has_key(). Node must be readable. */ - C4_ALWAYS_INLINE bool is_val() const RYML_NOEXCEPT { _C4RR(); return tree_->is_val(id_); } /**< Forward to Tree::is_val(). Node must be readable. */ - C4_ALWAYS_INLINE bool is_keyval() const RYML_NOEXCEPT { _C4RR(); return tree_->is_keyval(id_); } /**< Forward to Tree::is_keyval(). Node must be readable. */ - C4_ALWAYS_INLINE bool has_key_tag() const RYML_NOEXCEPT { _C4RR(); return tree_->has_key_tag(id_); } /**< Forward to Tree::has_key_tag(). Node must be readable. */ - C4_ALWAYS_INLINE bool has_val_tag() const RYML_NOEXCEPT { _C4RR(); return tree_->has_val_tag(id_); } /**< Forward to Tree::has_val_tag(). Node must be readable. */ - C4_ALWAYS_INLINE bool has_key_anchor() const RYML_NOEXCEPT { _C4RR(); return tree_->has_key_anchor(id_); } /**< Forward to Tree::has_key_anchor(). Node must be readable. */ - C4_ALWAYS_INLINE bool has_val_anchor() const RYML_NOEXCEPT { _C4RR(); return tree_->has_val_anchor(id_); } /**< Forward to Tree::has_val_anchor(). Node must be readable. */ - C4_ALWAYS_INLINE bool has_anchor() const RYML_NOEXCEPT { _C4RR(); return tree_->has_anchor(id_); } /**< Forward to Tree::has_anchor(). Node must be readable. */ - C4_ALWAYS_INLINE bool is_key_ref() const RYML_NOEXCEPT { _C4RR(); return tree_->is_key_ref(id_); } /**< Forward to Tree::is_key_ref(). Node must be readable. */ - C4_ALWAYS_INLINE bool is_val_ref() const RYML_NOEXCEPT { _C4RR(); return tree_->is_val_ref(id_); } /**< Forward to Tree::is_val_ref(). Node must be readable. */ - C4_ALWAYS_INLINE bool is_ref() const RYML_NOEXCEPT { _C4RR(); return tree_->is_ref(id_); } /**< Forward to Tree::is_ref(). Node must be readable. */ - C4_ALWAYS_INLINE bool parent_is_seq() const RYML_NOEXCEPT { _C4RR(); return tree_->parent_is_seq(id_); } /**< Forward to Tree::parent_is_seq(). Node must be readable. */ - C4_ALWAYS_INLINE bool parent_is_map() const RYML_NOEXCEPT { _C4RR(); return tree_->parent_is_map(id_); } /**< Forward to Tree::parent_is_map(). Node must be readable. */ + C4_ALWAYS_INLINE bool empty() const RYML_NOEXCEPT { _C4RR(); return tree_->empty(id_); } /**< Forward to @ref Tree::empty(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_stream() const RYML_NOEXCEPT { _C4RR(); return tree_->is_stream(id_); } /**< Forward to @ref Tree::is_stream(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_doc() const RYML_NOEXCEPT { _C4RR(); return tree_->is_doc(id_); } /**< Forward to @ref Tree::is_doc(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_container() const RYML_NOEXCEPT { _C4RR(); return tree_->is_container(id_); } /**< Forward to @ref Tree::is_container(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_map() const RYML_NOEXCEPT { _C4RR(); return tree_->is_map(id_); } /**< Forward to @ref Tree::is_map(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_seq() const RYML_NOEXCEPT { _C4RR(); return tree_->is_seq(id_); } /**< Forward to @ref Tree::is_seq(). Node must be readable. */ + C4_ALWAYS_INLINE bool has_val() const RYML_NOEXCEPT { _C4RR(); return tree_->has_val(id_); } /**< Forward to @ref Tree::has_val(). Node must be readable. */ + C4_ALWAYS_INLINE bool has_key() const RYML_NOEXCEPT { _C4RR(); return tree_->has_key(id_); } /**< Forward to @ref Tree::has_key(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_val() const RYML_NOEXCEPT { _C4RR(); return tree_->is_val(id_); } /**< Forward to @ref Tree::is_val(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_keyval() const RYML_NOEXCEPT { _C4RR(); return tree_->is_keyval(id_); } /**< Forward to @ref Tree::is_keyval(). Node must be readable. */ + C4_ALWAYS_INLINE bool has_key_tag() const RYML_NOEXCEPT { _C4RR(); return tree_->has_key_tag(id_); } /**< Forward to @ref Tree::has_key_tag(). Node must be readable. */ + C4_ALWAYS_INLINE bool has_val_tag() const RYML_NOEXCEPT { _C4RR(); return tree_->has_val_tag(id_); } /**< Forward to @ref Tree::has_val_tag(). Node must be readable. */ + C4_ALWAYS_INLINE bool has_key_anchor() const RYML_NOEXCEPT { _C4RR(); return tree_->has_key_anchor(id_); } /**< Forward to @ref Tree::has_key_anchor(). Node must be readable. */ + C4_ALWAYS_INLINE bool has_val_anchor() const RYML_NOEXCEPT { _C4RR(); return tree_->has_val_anchor(id_); } /**< Forward to @ref Tree::has_val_anchor(). Node must be readable. */ + C4_ALWAYS_INLINE bool has_anchor() const RYML_NOEXCEPT { _C4RR(); return tree_->has_anchor(id_); } /**< Forward to @ref Tree::has_anchor(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_key_ref() const RYML_NOEXCEPT { _C4RR(); return tree_->is_key_ref(id_); } /**< Forward to @ref Tree::is_key_ref(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_val_ref() const RYML_NOEXCEPT { _C4RR(); return tree_->is_val_ref(id_); } /**< Forward to @ref Tree::is_val_ref(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_ref() const RYML_NOEXCEPT { _C4RR(); return tree_->is_ref(id_); } /**< Forward to @ref Tree::is_ref(). Node must be readable. */ + C4_ALWAYS_INLINE bool parent_is_seq() const RYML_NOEXCEPT { _C4RR(); return tree_->parent_is_seq(id_); } /**< Forward to @ref Tree::parent_is_seq(). Node must be readable. */ + C4_ALWAYS_INLINE bool parent_is_map() const RYML_NOEXCEPT { _C4RR(); return tree_->parent_is_map(id_); } /**< Forward to @ref Tree::parent_is_map(). Node must be readable. */ RYML_DEPRECATED("use has_key_anchor()") bool is_key_anchor() const noexcept { _C4RR(); return tree_->has_key_anchor(id_); } RYML_DEPRECATED("use has_val_anchor()") bool is_val_hanchor() const noexcept { _C4RR(); return tree_->has_val_anchor(id_); } @@ -263,31 +265,33 @@ struct RoNodeMethods /** @name node container+scalar style predicates */ /** @{ */ - C4_ALWAYS_INLINE C4_PURE bool type_has_any(NodeType_e bits) const { _C4RR(); return tree_->type_has_any(id_, bits); } - C4_ALWAYS_INLINE C4_PURE bool type_has_all(NodeType_e bits) const { _C4RR(); return tree_->type_has_all(id_, bits); } - C4_ALWAYS_INLINE C4_PURE bool type_has_none(NodeType_e bits) const { _C4RR(); return tree_->type_has_none(id_, bits); } - - C4_ALWAYS_INLINE C4_PURE bool is_container_styled() const { _C4RR(); return tree_->is_container_styled(id_); } - C4_ALWAYS_INLINE C4_PURE bool is_block() const { _C4RR(); return tree_->is_block(id_); } - C4_ALWAYS_INLINE C4_PURE bool is_flow_sl() const { _C4RR(); return tree_->is_flow_sl(id_); } - C4_ALWAYS_INLINE C4_PURE bool is_flow_ml() const { _C4RR(); return tree_->is_flow_ml(id_); } - C4_ALWAYS_INLINE C4_PURE bool is_flow() const { _C4RR(); return tree_->is_flow(id_); } - - C4_ALWAYS_INLINE C4_PURE bool is_key_styled() const { _C4RR(); return tree_->is_key_styled(id_); } - C4_ALWAYS_INLINE C4_PURE bool is_val_styled() const { _C4RR(); return tree_->is_val_styled(id_); } - C4_ALWAYS_INLINE C4_PURE bool is_key_literal() const { _C4RR(); return tree_->is_key_literal(id_); } - C4_ALWAYS_INLINE C4_PURE bool is_val_literal() const { _C4RR(); return tree_->is_val_literal(id_); } - C4_ALWAYS_INLINE C4_PURE bool is_key_folded() const { _C4RR(); return tree_->is_key_folded(id_); } - C4_ALWAYS_INLINE C4_PURE bool is_val_folded() const { _C4RR(); return tree_->is_val_folded(id_); } - C4_ALWAYS_INLINE C4_PURE bool is_key_squo() const { _C4RR(); return tree_->is_key_squo(id_); } - C4_ALWAYS_INLINE C4_PURE bool is_val_squo() const { _C4RR(); return tree_->is_val_squo(id_); } - C4_ALWAYS_INLINE C4_PURE bool is_key_dquo() const { _C4RR(); return tree_->is_key_dquo(id_); } - C4_ALWAYS_INLINE C4_PURE bool is_val_dquo() const { _C4RR(); return tree_->is_val_dquo(id_); } - C4_ALWAYS_INLINE C4_PURE bool is_key_plain() const { _C4RR(); return tree_->is_key_plain(id_); } - C4_ALWAYS_INLINE C4_PURE bool is_val_plain() const { _C4RR(); return tree_->is_val_plain(id_); } - C4_ALWAYS_INLINE C4_PURE bool is_key_quoted() const { _C4RR(); return tree_->is_key_quoted(id_); } /**< Forward to Tree::is_key_quoted(). Node must be readable. */ - C4_ALWAYS_INLINE C4_PURE bool is_val_quoted() const { _C4RR(); return tree_->is_val_quoted(id_); } /**< Forward to Tree::is_val_quoted(). Node must be readable. */ - C4_ALWAYS_INLINE C4_PURE bool is_quoted() const { _C4RR(); return tree_->is_quoted(id_); } /**< Forward to Tree::is_quoted(). Node must be readable. */ + // documentation to the right --> + + C4_ALWAYS_INLINE bool type_has_any(NodeType_e bits) const RYML_NOEXCEPT { _C4RR(); return tree_->type_has_any(id_, bits); } /**< Forward to @ref Tree::type_has_any(). Node must be readable. */ + C4_ALWAYS_INLINE bool type_has_all(NodeType_e bits) const RYML_NOEXCEPT { _C4RR(); return tree_->type_has_all(id_, bits); } /**< Forward to @ref Tree::type_has_all(). Node must be readable. */ + C4_ALWAYS_INLINE bool type_has_none(NodeType_e bits) const RYML_NOEXCEPT { _C4RR(); return tree_->type_has_none(id_, bits); } /**< Forward to @ref Tree::type_has_none(). Node must be readable. */ + + C4_ALWAYS_INLINE bool is_container_styled() const RYML_NOEXCEPT { _C4RR(); return tree_->is_container_styled(id_); } /**< Forward to @ref Tree::is_container_styled(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_block() const RYML_NOEXCEPT { _C4RR(); return tree_->is_block(id_); } /**< Forward to @ref Tree::is_block(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_flow_sl() const RYML_NOEXCEPT { _C4RR(); return tree_->is_flow_sl(id_); } /**< Forward to @ref Tree::is_flow_sl(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_flow_ml() const RYML_NOEXCEPT { _C4RR(); return tree_->is_flow_ml(id_); } /**< Forward to @ref Tree::is_flow_ml(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_flow() const RYML_NOEXCEPT { _C4RR(); return tree_->is_flow(id_); } /**< Forward to @ref Tree::is_flow(). Node must be readable. */ + + C4_ALWAYS_INLINE bool is_key_styled() const RYML_NOEXCEPT { _C4RR(); return tree_->is_key_styled(id_); } /**< Forward to @ref Tree::is_key_styled(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_val_styled() const RYML_NOEXCEPT { _C4RR(); return tree_->is_val_styled(id_); } /**< Forward to @ref Tree::is_val_styled(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_key_literal() const RYML_NOEXCEPT { _C4RR(); return tree_->is_key_literal(id_); } /**< Forward to @ref Tree::is_key_literal(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_val_literal() const RYML_NOEXCEPT { _C4RR(); return tree_->is_val_literal(id_); } /**< Forward to @ref Tree::is_val_literal(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_key_folded() const RYML_NOEXCEPT { _C4RR(); return tree_->is_key_folded(id_); } /**< Forward to @ref Tree::is_key_folded(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_val_folded() const RYML_NOEXCEPT { _C4RR(); return tree_->is_val_folded(id_); } /**< Forward to @ref Tree::is_val_folded(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_key_squo() const RYML_NOEXCEPT { _C4RR(); return tree_->is_key_squo(id_); } /**< Forward to @ref Tree::is_key_squo(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_val_squo() const RYML_NOEXCEPT { _C4RR(); return tree_->is_val_squo(id_); } /**< Forward to @ref Tree::is_val_squo(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_key_dquo() const RYML_NOEXCEPT { _C4RR(); return tree_->is_key_dquo(id_); } /**< Forward to @ref Tree::is_key_dquo(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_val_dquo() const RYML_NOEXCEPT { _C4RR(); return tree_->is_val_dquo(id_); } /**< Forward to @ref Tree::is_val_dquo(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_key_plain() const RYML_NOEXCEPT { _C4RR(); return tree_->is_key_plain(id_); } /**< Forward to @ref Tree::is_key_plain(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_val_plain() const RYML_NOEXCEPT { _C4RR(); return tree_->is_val_plain(id_); } /**< Forward to @ref Tree::is_val_plain(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_key_quoted() const RYML_NOEXCEPT { _C4RR(); return tree_->is_key_quoted(id_); } /**< Forward to @ref Tree::is_key_quoted(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_val_quoted() const RYML_NOEXCEPT { _C4RR(); return tree_->is_val_quoted(id_); } /**< Forward to @ref Tree::is_val_quoted(). Node must be readable. */ + C4_ALWAYS_INLINE bool is_quoted() const RYML_NOEXCEPT { _C4RR(); return tree_->is_quoted(id_); } /**< Forward to @ref Tree::is_quoted(). Node must be readable. */ /** @} */ @@ -296,19 +300,20 @@ struct RoNodeMethods /** @name hierarchy predicates */ /** @{ */ - C4_ALWAYS_INLINE bool is_root() const RYML_NOEXCEPT { _C4RR(); return tree_->is_root(id_); } /**< Forward to Tree::is_root(). Node must be readable. */ - C4_ALWAYS_INLINE bool has_parent() const RYML_NOEXCEPT { _C4RR(); return tree_->has_parent(id_); } /**< Forward to Tree::has_parent() Node must be readable. */ + // documentation to the right --> - C4_ALWAYS_INLINE bool has_child(ConstImpl const& n) const RYML_NOEXCEPT { _C4RR(); return n.readable() ? tree_->has_child(id_, n.m_id) : false; } /**< Node must be readable. */ - C4_ALWAYS_INLINE bool has_child(id_type node) const RYML_NOEXCEPT { _C4RR(); return tree_->has_child(id_, node); } /**< Node must be readable. */ - C4_ALWAYS_INLINE bool has_child(csubstr name) const RYML_NOEXCEPT { _C4RR(); return tree_->has_child(id_, name); } /**< Node must be readable. */ - C4_ALWAYS_INLINE bool has_children() const RYML_NOEXCEPT { _C4RR(); return tree_->has_children(id_); } /**< Node must be readable. */ + C4_ALWAYS_INLINE bool is_root() const RYML_NOEXCEPT { _C4RR(); return tree_->is_root(id_); } /**< Forward to @ref Tree::is_root(). Node must be readable. */ + C4_ALWAYS_INLINE bool has_parent() const RYML_NOEXCEPT { _C4RR(); return tree_->has_parent(id_); } /**< Forward to @ref Tree::has_parent() Node must be readable. */ - C4_ALWAYS_INLINE bool has_sibling(ConstImpl const& n) const RYML_NOEXCEPT { _C4RR(); return n.readable() ? tree_->has_sibling(id_, n.m_id) : false; } /**< Node must be readable. */ - C4_ALWAYS_INLINE bool has_sibling(id_type node) const RYML_NOEXCEPT { _C4RR(); return tree_->has_sibling(id_, node); } /**< Node must be readable. */ - C4_ALWAYS_INLINE bool has_sibling(csubstr name) const RYML_NOEXCEPT { _C4RR(); return tree_->has_sibling(id_, name); } /**< Node must be readable. */ - /** does not count with this */ - C4_ALWAYS_INLINE bool has_other_siblings() const RYML_NOEXCEPT { _C4RR(); return tree_->has_other_siblings(id_); } + C4_ALWAYS_INLINE bool has_child(ConstImpl const& n) const RYML_NOEXCEPT { _C4RR(); return n.readable() ? tree_->has_child(id_, n.m_id) : false; } /**< Forward to @ref Tree::has_child(). Node must be readable. */ + C4_ALWAYS_INLINE bool has_child(id_type node) const RYML_NOEXCEPT { _C4RR(); return tree_->has_child(id_, node); } /**< Forward to @ref Tree::has_child(). Node must be readable. */ + C4_ALWAYS_INLINE bool has_child(csubstr name) const RYML_NOEXCEPT { _C4RR(); return tree_->has_child(id_, name); } /**< Forward to @ref Tree::has_child(). Node must be readable. */ + C4_ALWAYS_INLINE bool has_children() const RYML_NOEXCEPT { _C4RR(); return tree_->has_children(id_); } /**< Forward to @ref Tree::has_child(). Node must be readable. */ + + C4_ALWAYS_INLINE bool has_sibling(ConstImpl const& n) const RYML_NOEXCEPT { _C4RR(); return n.readable() ? tree_->has_sibling(id_, n.m_id) : false; } /**< Forward to @ref Tree::has_sibling(). Node must be readable. */ + C4_ALWAYS_INLINE bool has_sibling(id_type node) const RYML_NOEXCEPT { _C4RR(); return tree_->has_sibling(id_, node); } /**< Forward to @ref Tree::has_sibling(). Node must be readable. */ + C4_ALWAYS_INLINE bool has_sibling(csubstr name) const RYML_NOEXCEPT { _C4RR(); return tree_->has_sibling(id_, name); } /**< Forward to @ref Tree::has_sibling(). Node must be readable. */ + C4_ALWAYS_INLINE bool has_other_siblings() const RYML_NOEXCEPT { _C4RR(); return tree_->has_other_siblings(id_); } /**< Forward to @ref Tree::has_sibling(). Node must be readable. */ RYML_DEPRECATED("use has_other_siblings()") bool has_siblings() const RYML_NOEXCEPT { _C4RR(); return tree_->has_siblings(id_); } @@ -319,69 +324,62 @@ struct RoNodeMethods /** @name hierarchy getters */ /** @{ */ + // documentation to the right --> + template - C4_ALWAYS_INLINE auto doc(id_type i) RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { RYML_ASSERT(tree_); return {tree__, tree__->doc(i)}; } /**< Forward to Tree::doc(). Node must be readable. */ + C4_ALWAYS_INLINE auto doc(id_type i) RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { RYML_ASSERT(tree_); return {tree__, tree__->doc(i)}; } /**< Forward to @ref Tree::doc(). Node must be readable. */ /** succeeds even when the node may have invalid or seed id */ - C4_ALWAYS_INLINE ConstImpl doc(id_type i) const RYML_NOEXCEPT { RYML_ASSERT(tree_); return {tree_, tree_->doc(i)}; } /**< Forward to Tree::doc(). Node must be readable. */ + C4_ALWAYS_INLINE ConstImpl doc(id_type i) const RYML_NOEXCEPT { RYML_ASSERT(tree_); return {tree_, tree_->doc(i)}; } /**< Forward to @ref Tree::doc(). Node must be readable. */ template - C4_ALWAYS_INLINE auto parent() RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->parent(id__)}; } /**< Forward to Tree::parent(). Node must be readable. */ - C4_ALWAYS_INLINE ConstImpl parent() const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->parent(id_)}; } /**< Forward to Tree::parent(). Node must be readable. */ + C4_ALWAYS_INLINE auto parent() RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->parent(id__)}; } /**< Forward to @ref Tree::parent(). Node must be readable. */ + C4_ALWAYS_INLINE ConstImpl parent() const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->parent(id_)}; } /**< Forward to @ref Tree::parent(). Node must be readable. */ template - C4_ALWAYS_INLINE auto first_child() RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->first_child(id__)}; } /**< Forward to Tree::first_child(). Node must be readable. */ - C4_ALWAYS_INLINE ConstImpl first_child() const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->first_child(id_)}; } /**< Forward to Tree::first_child(). Node must be readable. */ + C4_ALWAYS_INLINE auto first_child() RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->first_child(id__)}; } /**< Forward to @ref Tree::first_child(). Node must be readable. */ + C4_ALWAYS_INLINE ConstImpl first_child() const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->first_child(id_)}; } /**< Forward to @ref Tree::first_child(). Node must be readable. */ template - C4_ALWAYS_INLINE auto last_child() RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->last_child(id__)}; } /**< Forward to Tree::last_child(). Node must be readable. */ - C4_ALWAYS_INLINE ConstImpl last_child () const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->last_child (id_)}; } /**< Forward to Tree::last_child(). Node must be readable. */ + C4_ALWAYS_INLINE auto last_child() RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->last_child(id__)}; } /**< Forward to @ref Tree::last_child(). Node must be readable. */ + C4_ALWAYS_INLINE ConstImpl last_child () const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->last_child (id_)}; } /**< Forward to @ref Tree::last_child(). Node must be readable. */ template - C4_ALWAYS_INLINE auto child(id_type pos) RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->child(id__, pos)}; } /**< Forward to Tree::child(). Node must be readable. */ - C4_ALWAYS_INLINE ConstImpl child(id_type pos) const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->child(id_, pos)}; } /**< Forward to Tree::child(). Node must be readable. */ + C4_ALWAYS_INLINE auto child(id_type pos) RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->child(id__, pos)}; } /**< Forward to @ref Tree::child(). Node must be readable. */ + C4_ALWAYS_INLINE ConstImpl child(id_type pos) const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->child(id_, pos)}; } /**< Forward to @ref Tree::child(). Node must be readable. */ template - C4_ALWAYS_INLINE auto find_child(csubstr name) RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->find_child(id__, name)}; } /**< Forward to Tree::first_child(). Node must be readable. */ - C4_ALWAYS_INLINE ConstImpl find_child(csubstr name) const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->find_child(id_, name)}; } /**< Forward to Tree::first_child(). Node must be readable. */ + C4_ALWAYS_INLINE auto find_child(csubstr name) RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->find_child(id__, name)}; } /**< Forward to @ref Tree::first_child(). Node must be readable. */ + C4_ALWAYS_INLINE ConstImpl find_child(csubstr name) const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->find_child(id_, name)}; } /**< Forward to @ref Tree::first_child(). Node must be readable. */ template - C4_ALWAYS_INLINE auto prev_sibling() RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->prev_sibling(id__)}; } /**< Forward to Tree::prev_sibling(). Node must be readable. */ - C4_ALWAYS_INLINE ConstImpl prev_sibling() const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->prev_sibling(id_)}; } /**< Forward to Tree::prev_sibling(). Node must be readable. */ + C4_ALWAYS_INLINE auto prev_sibling() RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->prev_sibling(id__)}; } /**< Forward to @ref Tree::prev_sibling(). Node must be readable. */ + C4_ALWAYS_INLINE ConstImpl prev_sibling() const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->prev_sibling(id_)}; } /**< Forward to @ref Tree::prev_sibling(). Node must be readable. */ template - C4_ALWAYS_INLINE auto next_sibling() RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->next_sibling(id__)}; } /**< Forward to Tree::next_sibling(). Node must be readable. */ - C4_ALWAYS_INLINE ConstImpl next_sibling() const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->next_sibling(id_)}; } /**< Forward to Tree::next_sibling(). Node must be readable. */ + C4_ALWAYS_INLINE auto next_sibling() RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->next_sibling(id__)}; } /**< Forward to @ref Tree::next_sibling(). Node must be readable. */ + C4_ALWAYS_INLINE ConstImpl next_sibling() const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->next_sibling(id_)}; } /**< Forward to @ref Tree::next_sibling(). Node must be readable. */ template - C4_ALWAYS_INLINE auto first_sibling() RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->first_sibling(id__)}; } /**< Forward to Tree::first_sibling(). Node must be readable. */ - C4_ALWAYS_INLINE ConstImpl first_sibling() const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->first_sibling(id_)}; } /**< Forward to Tree::first_sibling(). Node must be readable. */ + C4_ALWAYS_INLINE auto first_sibling() RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->first_sibling(id__)}; } /**< Forward to @ref Tree::first_sibling(). Node must be readable. */ + C4_ALWAYS_INLINE ConstImpl first_sibling() const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->first_sibling(id_)}; } /**< Forward to @ref Tree::first_sibling(). Node must be readable. */ template - C4_ALWAYS_INLINE auto last_sibling() RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->last_sibling(id__)}; } /**< Forward to Tree::last_sibling(). Node must be readable. */ - C4_ALWAYS_INLINE ConstImpl last_sibling () const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->last_sibling(id_)}; } /**< Forward to Tree::last_sibling(). Node must be readable. */ + C4_ALWAYS_INLINE auto last_sibling() RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->last_sibling(id__)}; } /**< Forward to @ref Tree::last_sibling(). Node must be readable. */ + C4_ALWAYS_INLINE ConstImpl last_sibling () const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->last_sibling(id_)}; } /**< Forward to @ref Tree::last_sibling(). Node must be readable. */ template - C4_ALWAYS_INLINE auto sibling(id_type pos) RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->sibling(id__, pos)}; } /**< Forward to Tree::sibling(). Node must be readable. */ - C4_ALWAYS_INLINE ConstImpl sibling(id_type pos) const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->sibling(id_, pos)}; } /**< Forward to Tree::sibling(). Node must be readable. */ + C4_ALWAYS_INLINE auto sibling(id_type pos) RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->sibling(id__, pos)}; } /**< Forward to @ref Tree::sibling(). Node must be readable. */ + C4_ALWAYS_INLINE ConstImpl sibling(id_type pos) const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->sibling(id_, pos)}; } /**< Forward to @ref Tree::sibling(). Node must be readable. */ template - C4_ALWAYS_INLINE auto find_sibling(csubstr name) RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->find_sibling(id__, name)}; } /**< Forward to Tree::find_sibling(). Node must be readable. */ - C4_ALWAYS_INLINE ConstImpl find_sibling(csubstr name) const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->find_sibling(id_, name)}; } /**< Forward to Tree::find_sibling(). Node must be readable. */ - - /** O(num_children). Forward to Tree::num_children(). */ - C4_ALWAYS_INLINE id_type num_children() const RYML_NOEXCEPT { _C4RR(); return tree_->num_children(id_); } - - /** O(num_children). Forward to Tree::num_siblings(). */ - C4_ALWAYS_INLINE id_type num_siblings() const RYML_NOEXCEPT { _C4RR(); return tree_->num_siblings(id_); } + C4_ALWAYS_INLINE auto find_sibling(csubstr name) RYML_NOEXCEPT -> _C4_IF_MUTABLE(Impl) { _C4RR(); return {tree__, tree__->find_sibling(id__, name)}; } /**< Forward to @ref Tree::find_sibling(). Node must be readable. */ + C4_ALWAYS_INLINE ConstImpl find_sibling(csubstr name) const RYML_NOEXCEPT { _C4RR(); return {tree_, tree_->find_sibling(id_, name)}; } /**< Forward to @ref Tree::find_sibling(). Node must be readable. */ - /** O(num_siblings). Forward to Tree::num_other_siblings(). */ - C4_ALWAYS_INLINE id_type num_other_siblings() const RYML_NOEXCEPT { _C4RR(); return tree_->num_other_siblings(id_); } - - /** O(num_children). Forward to Tree::child_pos(). */ - C4_ALWAYS_INLINE id_type child_pos(ConstImpl const& n) const RYML_NOEXCEPT { _C4RR(); _RYML_CB_ASSERT(tree_->m_callbacks, n.readable()); return tree_->child_pos(id_, n.m_id); } - - /** O(num_siblings). Forward to Tree::sibling_pos(). */ - C4_ALWAYS_INLINE id_type sibling_pos(ConstImpl const& n) const RYML_NOEXCEPT { _C4RR(); _RYML_CB_ASSERT(tree_->callbacks(), n.readable()); return tree_->child_pos(tree_->parent(id_), n.m_id); } + C4_ALWAYS_INLINE id_type num_children() const RYML_NOEXCEPT { _C4RR(); return tree_->num_children(id_); } /**< O(num_children). Forward to @ref Tree::num_children(). */ + C4_ALWAYS_INLINE id_type num_siblings() const RYML_NOEXCEPT { _C4RR(); return tree_->num_siblings(id_); } /**< O(num_children). Forward to @ref Tree::num_siblings(). */ + C4_ALWAYS_INLINE id_type num_other_siblings() const RYML_NOEXCEPT { _C4RR(); return tree_->num_other_siblings(id_); } /**< O(num_siblings). Forward to @ref Tree::num_other_siblings(). */ + C4_ALWAYS_INLINE id_type child_pos(ConstImpl const& n) const RYML_NOEXCEPT { _C4RR(); _RYML_CB_ASSERT(tree_->m_callbacks, n.readable()); return tree_->child_pos(id_, n.m_id); } /**< O(num_children). Forward to @ref Tree::child_pos(). */ + C4_ALWAYS_INLINE id_type sibling_pos(ConstImpl const& n) const RYML_NOEXCEPT { _C4RR(); _RYML_CB_ASSERT(tree_->callbacks(), n.readable()); return tree_->child_pos(tree_->parent(id_), n.m_id); } /**< O(num_siblings). Forward to @ref Tree::sibling_pos(). */ C4_ALWAYS_INLINE id_type depth_asc() const RYML_NOEXCEPT { _C4RR(); return tree_->depth_asc(id_); } /** O(log(num_nodes)). Forward to Tree::depth_asc(). Node must be readable. */ C4_ALWAYS_INLINE id_type depth_desc() const RYML_NOEXCEPT { _C4RR(); return tree_->depth_desc(id_); } /** O(num_nodes). Forward to Tree::depth_desc(). Node must be readable. */ @@ -617,6 +615,7 @@ struct RoNodeMethods /** @name deserialization */ /** @{ */ + /** deserialize the node's val to the given variable */ template ConstImpl const& operator>> (T &v) const { @@ -626,7 +625,8 @@ struct RoNodeMethods return *((ConstImpl const*)this); } - /** deserialize the node's key to the given variable */ + /** deserialize the node's key to the given variable; use @ref key() + * to disambiguate; for example: `node >> ryml::key(var)` */ template ConstImpl const& operator>> (Key v) const { @@ -636,14 +636,14 @@ struct RoNodeMethods return *((ConstImpl const*)this); } - /** deserialize the node's key as base64 */ + /** deserialize the node's key as base64. lightweight wrapper over @ref deserialize_key() */ ConstImpl const& operator>> (Key w) const { deserialize_key(w.wrapper); return *((ConstImpl const*)this); } - /** deserialize the node's val as base64 */ + /** deserialize the node's val as base64. lightweight wrapper over @ref deserialize_val() */ ConstImpl const& operator>> (fmt::base64_wrapper w) const { deserialize_val(w); @@ -667,6 +667,8 @@ struct RoNodeMethods return from_chars(val(), &v); }; + /** look for a child by name, if it exists assign to var. return + * true if the child existed. */ template bool get_if(csubstr name, T *var) const { @@ -678,6 +680,9 @@ struct RoNodeMethods return true; } + /** look for a child by name, if it exists assign to var, + * otherwise default to fallback. return true if the child + * existed. */ template bool get_if(csubstr name, T *var, T const& fallback) const { @@ -717,14 +722,20 @@ struct RoNodeMethods using children_view = detail::children_view_; using const_children_view = detail::children_view_; + /** get an iterator to the first child */ template C4_ALWAYS_INLINE auto begin() RYML_NOEXCEPT -> _C4_IF_MUTABLE(iterator) { _C4RR(); return iterator(tree__, tree__->first_child(id__)); } + /** get an iterator to the first child */ C4_ALWAYS_INLINE const_iterator begin() const RYML_NOEXCEPT { _C4RR(); return const_iterator(tree_, tree_->first_child(id_)); } + /** get an iterator to the first child */ C4_ALWAYS_INLINE const_iterator cbegin() const RYML_NOEXCEPT { _C4RR(); return const_iterator(tree_, tree_->first_child(id_)); } + /** get an iterator to after the last child */ template C4_ALWAYS_INLINE auto end() RYML_NOEXCEPT -> _C4_IF_MUTABLE(iterator) { _C4RR(); return iterator(tree__, NONE); } + /** get an iterator to after the last child */ C4_ALWAYS_INLINE const_iterator end() const RYML_NOEXCEPT { _C4RR(); return const_iterator(tree_, NONE); } + /** get an iterator to after the last child */ C4_ALWAYS_INLINE const_iterator cend() const RYML_NOEXCEPT { _C4RR(); return const_iterator(tree_, tree_->first_child(id_)); } /** get an iterable view over children */ @@ -838,17 +849,17 @@ class RYML_EXPORT ConstNodeRef : public detail::RoNodeMethodsroot_id()) {} - ConstNodeRef(Tree const *t, id_type id) : m_tree(t), m_id(id) {} - ConstNodeRef(std::nullptr_t) : m_tree(nullptr), m_id(NONE) {} + ConstNodeRef() noexcept : m_tree(nullptr), m_id(NONE) {} + ConstNodeRef(Tree const &t) noexcept : m_tree(&t), m_id(t .root_id()) {} + ConstNodeRef(Tree const *t) noexcept : m_tree(t ), m_id(t->root_id()) {} + ConstNodeRef(Tree const *t, id_type id) noexcept : m_tree(t), m_id(id) {} + ConstNodeRef(std::nullptr_t) noexcept : m_tree(nullptr), m_id(NONE) {} - ConstNodeRef(ConstNodeRef const&) = default; - ConstNodeRef(ConstNodeRef &&) = default; + ConstNodeRef(ConstNodeRef const&) noexcept = default; + ConstNodeRef(ConstNodeRef &&) noexcept = default; - ConstNodeRef(NodeRef const&); - ConstNodeRef(NodeRef &&); + ConstNodeRef(NodeRef const&) noexcept; + ConstNodeRef(NodeRef &&) noexcept; /** @} */ @@ -857,13 +868,13 @@ class RYML_EXPORT ConstNodeRef : public detail::RoNodeMethods /** @name construction */ /** @{ */ - NodeRef() : m_tree(nullptr), m_id(NONE), m_seed() { _clear_seed(); } - NodeRef(Tree &t) : m_tree(&t), m_id(t .root_id()), m_seed() { _clear_seed(); } - NodeRef(Tree *t) : m_tree(t ), m_id(t->root_id()), m_seed() { _clear_seed(); } - NodeRef(Tree *t, id_type id) : m_tree(t), m_id(id), m_seed() { _clear_seed(); } - NodeRef(Tree *t, id_type id, id_type seed_pos) : m_tree(t), m_id(id), m_seed() { m_seed.str = nullptr; m_seed.len = (size_t)seed_pos; } - NodeRef(Tree *t, id_type id, csubstr seed_key) : m_tree(t), m_id(id), m_seed(seed_key) {} - NodeRef(std::nullptr_t) : m_tree(nullptr), m_id(NONE), m_seed() {} + NodeRef() noexcept : m_tree(nullptr), m_id(NONE), m_seed() { _clear_seed(); } + NodeRef(Tree &t) noexcept : m_tree(&t), m_id(t .root_id()), m_seed() { _clear_seed(); } + NodeRef(Tree *t) noexcept : m_tree(t ), m_id(t->root_id()), m_seed() { _clear_seed(); } + NodeRef(Tree *t, id_type id) noexcept : m_tree(t), m_id(id), m_seed() { _clear_seed(); } + NodeRef(Tree *t, id_type id, id_type seed_pos) noexcept : m_tree(t), m_id(id), m_seed() { m_seed.str = nullptr; m_seed.len = (size_t)seed_pos; } + NodeRef(Tree *t, id_type id, csubstr seed_key) noexcept : m_tree(t), m_id(id), m_seed(seed_key) {} + NodeRef(std::nullptr_t) noexcept : m_tree(nullptr), m_id(NONE), m_seed() {} - inline void _clear_seed() { /*do the following manually or an assert is triggered: */ m_seed.str = nullptr; m_seed.len = NONE; } + inline void _clear_seed() noexcept { /*do the following manually or an assert is triggered: */ m_seed.str = nullptr; m_seed.len = npos; } /** @} */ @@ -1016,11 +1027,11 @@ class RYML_EXPORT NodeRef : public detail::RoNodeMethods /** @name assignment */ /** @{ */ - NodeRef(NodeRef const&) = default; - NodeRef(NodeRef &&) = default; + NodeRef(NodeRef const&) noexcept = default; + NodeRef(NodeRef &&) noexcept = default; - NodeRef& operator= (NodeRef const&) = default; - NodeRef& operator= (NodeRef &&) = default; + NodeRef& operator= (NodeRef const&) noexcept = default; + NodeRef& operator= (NodeRef &&) noexcept = default; /** @} */ @@ -1029,12 +1040,12 @@ class RYML_EXPORT NodeRef : public detail::RoNodeMethods /** @name state_queries * @{ */ - /** true if the object is not referring to any existing or seed node @see the doc for the NodeRef */ - inline bool invalid() const { return m_tree == nullptr || m_id == NONE; } - /** true if the object is not invalid and in seed state. @see the doc for the NodeRef */ - inline bool is_seed() const { return (m_tree != NULL && m_id != NONE) && (m_seed.str != nullptr || m_seed.len != (size_t)NONE); } - /** true if the object is not invalid and not in seed state. @see the doc for the NodeRef */ - inline bool readable() const { return (m_tree != NULL && m_id != NONE) && (m_seed.str == nullptr && m_seed.len == (size_t)NONE); } + /** true if the object is not referring to any existing or seed node. @see the doc for @ref NodeRef */ + inline bool invalid() const noexcept { return m_tree == nullptr || m_id == NONE; } + /** true if the object is not invalid and in seed state. @see the doc for @ref NodeRef */ + inline bool is_seed() const noexcept { return (m_tree != NULL && m_id != NONE) && (m_seed.str != nullptr || m_seed.len != (size_t)NONE); } + /** true if the object is not invalid and not in seed state. @see the doc for @ref NodeRef */ + inline bool readable() const noexcept { return (m_tree != NULL && m_id != NONE) && (m_seed.str == nullptr && m_seed.len == (size_t)NONE); } RYML_DEPRECATED("use one of readable(), is_seed() or !invalid()") inline bool valid() const { return m_tree != nullptr && m_id != NONE; } @@ -1081,10 +1092,10 @@ class RYML_EXPORT NodeRef : public detail::RoNodeMethods /** @name node_property_getters * @{ */ - C4_ALWAYS_INLINE C4_PURE Tree * tree() noexcept { return m_tree; } - C4_ALWAYS_INLINE C4_PURE Tree const* tree() const noexcept { return m_tree; } + C4_ALWAYS_INLINE Tree * tree() noexcept { return m_tree; } + C4_ALWAYS_INLINE Tree const* tree() const noexcept { return m_tree; } - C4_ALWAYS_INLINE C4_PURE id_type id() const noexcept { return m_id; } + C4_ALWAYS_INLINE id_type id() const noexcept { return m_id; } /** @} */ @@ -1550,27 +1561,27 @@ class RYML_EXPORT NodeRef : public detail::RoNodeMethods //----------------------------------------------------------------------------- -inline ConstNodeRef::ConstNodeRef(NodeRef const& that) +inline ConstNodeRef::ConstNodeRef(NodeRef const& that) noexcept : m_tree(that.m_tree) , m_id(!that.is_seed() ? that.id() : (id_type)NONE) { } -inline ConstNodeRef::ConstNodeRef(NodeRef && that) +inline ConstNodeRef::ConstNodeRef(NodeRef && that) noexcept : m_tree(that.m_tree) , m_id(!that.is_seed() ? that.id() : (id_type)NONE) { } -inline ConstNodeRef& ConstNodeRef::operator= (NodeRef const& that) +inline ConstNodeRef& ConstNodeRef::operator= (NodeRef const& that) noexcept { m_tree = (that.m_tree); m_id = (!that.is_seed() ? that.id() : (id_type)NONE); return *this; } -inline ConstNodeRef& ConstNodeRef::operator= (NodeRef && that) +inline ConstNodeRef& ConstNodeRef::operator= (NodeRef && that) noexcept { m_tree = (that.m_tree); m_id = (!that.is_seed() ? that.id() : (id_type)NONE); diff --git a/src/c4/yml/parse.cpp b/src/c4/yml/parse.cpp index a2c43f482..144a6c4ad 100644 --- a/src/c4/yml/parse.cpp +++ b/src/c4/yml/parse.cpp @@ -147,5 +147,18 @@ RYML_EXPORT C4_NO_INLINE size_t _find_last_newline_and_larger_indentation(csubst return npos; } +//----------------------------------------------------------------------------- + +RYML_EXPORT id_type estimate_tree_capacity(csubstr src) +{ + id_type num_nodes = 1; // root + for(size_t i = 0; i < src.len; ++i) + { + const char c = src.str[i]; + num_nodes += (c == '\n') || (c == ',') || (c == '[') || (c == '{'); + } + return num_nodes; +} + } // namespace yml } // namespace c4 diff --git a/src/c4/yml/parse.hpp b/src/c4/yml/parse.hpp index 005bf54f2..240709be2 100644 --- a/src/c4/yml/parse.hpp +++ b/src/c4/yml/parse.hpp @@ -12,6 +12,8 @@ class Tree; class NodeRef; template class ParseEngine; struct EventHandlerTree; +RYML_EXPORT id_type estimate_tree_capacity(csubstr src); + /** @addtogroup doc_parse * @{ */ diff --git a/src/c4/yml/parse_engine.def.hpp b/src/c4/yml/parse_engine.def.hpp index c5d912c44..4faf68fce 100644 --- a/src/c4/yml/parse_engine.def.hpp +++ b/src/c4/yml/parse_engine.def.hpp @@ -7953,22 +7953,6 @@ void ParseEngine::parse_in_place_ev(csubstr filename, substr src) m_evt_handler->finish_parse(); } - -//----------------------------------------------------------------------------- - -template -id_type ParseEngine::estimate_tree_capacity(csubstr src) -{ - id_type num_nodes = 1; // root - for(size_t i = 0; i < src.len; ++i) - { - const char c = src.str[i]; - num_nodes += (c == '\n') || (c == ',') || (c == '[') || (c == '{'); - } - return num_nodes; -} - - } // namespace yml } // namespace c4 diff --git a/src/c4/yml/parse_engine.hpp b/src/c4/yml/parse_engine.hpp index 5cca11987..06f660ab9 100644 --- a/src/c4/yml/parse_engine.hpp +++ b/src/c4/yml/parse_engine.hpp @@ -384,21 +384,6 @@ class ParseEngine /** parse JSON in place, emitting events to the current handler */ void parse_json_in_place_ev(csubstr filename, substr src); - /** Quickly inspect the source to estimate the number of nodes the - * resulting tree is likely have. If a tree is empty before - * parsing, considerable time will be spent growing it, so calling - * this to reserve the tree size prior to parsing is likely to - * result in a time gain. We encourage using this method before - * parsing, but as always measure its impact in performance to - * obtain a good trade-off. - * - * @note since this method is meant for optimizing performance, it - * is approximate. The result may be actually smaller than the - * resulting number of nodes, notably if the YAML uses implicit - * maps as flow seq members as in `[these: are, individual: - * maps]`. */ - static id_type estimate_tree_capacity(csubstr src); - /** @} */ public: @@ -756,6 +741,22 @@ class ParseEngine RYML_EXPORT C4_NO_INLINE size_t _find_last_newline_and_larger_indentation(csubstr s, size_t indentation) noexcept; /** @endcond */ + +/** Quickly inspect the source to estimate the number of nodes the + * resulting tree is likely have. If a tree is empty before + * parsing, considerable time will be spent growing it, so calling + * this to reserve the tree size prior to parsing is likely to + * result in a time gain. We encourage using this method before + * parsing, but as always measure its impact in performance to + * obtain a good trade-off. + * + * @note since this method is meant for optimizing performance, it + * is approximate. The result may be actually smaller than the + * resulting number of nodes, notably if the YAML uses implicit + * maps as flow seq members as in `[these: are, individual: + * maps]`. */ +RYML_EXPORT id_type estimate_tree_capacity(csubstr src); + /** @} */ } // namespace yml diff --git a/src/c4/yml/parser_state.hpp b/src/c4/yml/parser_state.hpp index 2c9ec6783..b1bcfdd69 100644 --- a/src/c4/yml/parser_state.hpp +++ b/src/c4/yml/parser_state.hpp @@ -160,7 +160,7 @@ struct ParserState void reset_after_push() { node_id = NONE; - indref = NONE; + indref = npos; more_indented = false; ++level; has_children = false; diff --git a/src/c4/yml/std/vector.hpp b/src/c4/yml/std/vector.hpp index 9927fef73..44dedf02a 100644 --- a/src/c4/yml/std/vector.hpp +++ b/src/c4/yml/std/vector.hpp @@ -24,7 +24,9 @@ void write(c4::yml::NodeRef *n, std::vector const& vec) template bool read(c4::yml::ConstNodeRef const& n, std::vector *vec) { - vec->resize(n.num_children()); + C4_SUPPRESS_WARNING_GCC_WITH_PUSH("-Wuseless-cast") + vec->resize(static_cast(n.num_children())); + C4_SUPPRESS_WARNING_GCC_POP size_t pos = 0; for(ConstNodeRef const child : n) child >> (*vec)[pos++]; @@ -36,7 +38,9 @@ bool read(c4::yml::ConstNodeRef const& n, std::vector *vec) template bool read(c4::yml::ConstNodeRef const& n, std::vector *vec) { - vec->resize(n.num_children()); + C4_SUPPRESS_WARNING_GCC_WITH_PUSH("-Wuseless-cast") + vec->resize(static_cast(n.num_children())); + C4_SUPPRESS_WARNING_GCC_POP size_t pos = 0; bool tmp = {}; for(ConstNodeRef const child : n) diff --git a/src/c4/yml/tree.cpp b/src/c4/yml/tree.cpp index ce4a8162b..a5fe9c6ff 100644 --- a/src/c4/yml/tree.cpp +++ b/src/c4/yml/tree.cpp @@ -119,12 +119,12 @@ Tree& Tree::operator= (Tree const& that) return *this; } -Tree::Tree(Tree && that) : Tree(that.m_callbacks) +Tree::Tree(Tree && that) noexcept : Tree(that.m_callbacks) { _move(that); } -Tree& Tree::operator= (Tree && that) +Tree& Tree::operator= (Tree && that) RYML_NOEXCEPT { _free(); m_callbacks = that.m_callbacks; @@ -195,7 +195,7 @@ void Tree::_copy(Tree const& that) m_tag_directives[i] = that.m_tag_directives[i]; } -void Tree::_move(Tree & that) +void Tree::_move(Tree & that) noexcept { _RYML_CB_ASSERT(m_callbacks, m_buf == nullptr); _RYML_CB_ASSERT(m_callbacks, m_arena.str == nullptr); diff --git a/src/c4/yml/tree.hpp b/src/c4/yml/tree.hpp index 38e8e8fc5..0dbcb3de8 100644 --- a/src/c4/yml/tree.hpp +++ b/src/c4/yml/tree.hpp @@ -249,10 +249,10 @@ class RYML_EXPORT Tree ~Tree(); Tree(Tree const& that); - Tree(Tree && that); + Tree(Tree && that) noexcept; Tree& operator= (Tree const& that); - Tree& operator= (Tree && that); + Tree& operator= (Tree && that) RYML_NOEXCEPT; /** @} */ @@ -1019,6 +1019,7 @@ class RYML_EXPORT Tree substr _request_span(size_t sz) { + _RYML_CB_ASSERT(m_callbacks, m_arena_pos + sz <= m_arena.len); substr s; s = m_arena.sub(m_arena_pos, sz); m_arena_pos += sz; @@ -1029,7 +1030,7 @@ class RYML_EXPORT Tree { _RYML_CB_ASSERT(m_callbacks, m_arena.is_super(s)); _RYML_CB_ASSERT(m_callbacks, m_arena.sub(0, m_arena_pos).is_super(s)); - auto pos = (s.str - m_arena.str); + auto pos = (s.str - m_arena.str); // this is larger than 0 based on the assertions above substr r(next_arena.str + pos, s.len); _RYML_CB_ASSERT(m_callbacks, r.str - next_arena.str == pos); _RYML_CB_ASSERT(m_callbacks, next_arena.sub(0, m_arena_pos).is_super(r)); @@ -1105,7 +1106,7 @@ class RYML_EXPORT Tree void _clear(); void _free(); void _copy(Tree const& that); - void _move(Tree & that); + void _move(Tree & that) noexcept; void _relocate(substr next_arena); diff --git a/test/test_callbacks.cpp b/test/test_callbacks.cpp index caeea1e81..9bce233b2 100644 --- a/test/test_callbacks.cpp +++ b/test/test_callbacks.cpp @@ -11,7 +11,7 @@ namespace c4 { namespace yml { static_assert(std::is_same::type, size_t>::value, "invalid type"); -static_assert(std::is_same::type, size_t>::value, "invalid type"); +static_assert(std::is_same::type, id_type>::value, "invalid type"); static_assert(size_t(c4::yml::npos) == ((size_t)-1), "invalid value"); // some debuggers show the wrong value... static_assert(size_t(c4::yml::NONE) == ((size_t)-1), "invalid value"); // some debuggers show the wrong value... diff --git a/test/test_github_issues.cpp b/test/test_github_issues.cpp index 4101a3481..6d44f0e3d 100644 --- a/test/test_github_issues.cpp +++ b/test/test_github_issues.cpp @@ -42,8 +42,8 @@ TEST(github, 277) #endif ConstNodeRef root = tree.crootref(); ASSERT_TRUE(root["B"].is_map()); - size_t num_childs = root["B"].num_children(); - size_t child = 0; + id_type num_childs = root["B"].num_children(); + id_type child = 0; ASSERT_EQ(num_childs, 3); for (const auto node : root["B"].children()) { @@ -54,7 +54,7 @@ TEST(github, 277) // test whether the tree is corrupted test_invariants(tree); child = num_childs; - for (size_t n = tree.last_child(root["B"].id()); n != NONE; n = tree.prev_sibling(n)) + for (id_type n = tree.last_child(root["B"].id()); n != NONE; n = tree.prev_sibling(n)) { ASSERT_NE(child, 0); EXPECT_EQ(tree.key(n), csubstr(keys[child - 1], 1)); diff --git a/test/test_lib/test_case.cpp b/test/test_lib/test_case.cpp index ef591937d..b5e8323ec 100644 --- a/test/test_lib/test_case.cpp +++ b/test/test_lib/test_case.cpp @@ -487,7 +487,7 @@ void test_invariants(ConstNodeRef const& n) EXPECT_EQ(n.parent().num_children() > 1, n.has_other_siblings()); EXPECT_TRUE(n.parent().has_child(n)); EXPECT_EQ(n.parent().num_children(), n.num_siblings()); - EXPECT_EQ(n.parent().num_children(), n.num_other_siblings()+1u); + EXPECT_EQ(n.parent().num_children(), n.num_other_siblings()+id_type(1)); // doc parent must be a seq and a stream if(n.is_doc()) { diff --git a/test/test_number.cpp b/test/test_number.cpp index 57654f0ea..9cf42a04c 100644 --- a/test/test_number.cpp +++ b/test/test_number.cpp @@ -56,7 +56,7 @@ void test_ints() ASSERT_EQ(parsed["bin"].num_children(), values.size()); ASSERT_EQ(parsed["oct"].num_children(), values.size()); ASSERT_EQ(parsed["versions"].num_children(), 4u); - size_t pos = 0; + id_type pos = 0; for(I val : values) { I out = notval(val); @@ -86,7 +86,7 @@ void test_ints() ASSERT_EQ(parsed["bin"].num_children(), values.size()); ASSERT_EQ(parsed["oct"].num_children(), values.size()); ASSERT_EQ(parsed["versions"].num_children(), 4u); - size_t pos = 0; + id_type pos = 0; for(I val : values) { I out = notval(val); diff --git a/test/test_parser.cpp b/test/test_parser.cpp index 1baba8f01..c1f6969f9 100644 --- a/test/test_parser.cpp +++ b/test/test_parser.cpp @@ -381,19 +381,17 @@ TEST(Parser, filename_and_buffer_are_stored) TEST(Parser, estimate_tree_capacity) { - Parser::handler_type evt_handler = {}; - Parser parser(&evt_handler); - EXPECT_EQ(2, parser.estimate_tree_capacity(R"([])")); - EXPECT_EQ(2, parser.estimate_tree_capacity(R"([a])")); - EXPECT_EQ(3, parser.estimate_tree_capacity(R"([a, b])")); - EXPECT_EQ(4, parser.estimate_tree_capacity(R"([a, b, c])")); - EXPECT_EQ(5, parser.estimate_tree_capacity(R"([a, b, c, d])")); - EXPECT_EQ(2, parser.estimate_tree_capacity(R"({})")); - EXPECT_EQ(2, parser.estimate_tree_capacity(R"({a: 0})")); - EXPECT_EQ(3, parser.estimate_tree_capacity(R"({a: 0, b: 1})")); - EXPECT_EQ(4, parser.estimate_tree_capacity(R"({a: 0, b: 1, c: 2})")); - EXPECT_EQ(5, parser.estimate_tree_capacity(R"({a: 0, b: 1, c: 2, d: 3})")); - EXPECT_EQ(9, parser.estimate_tree_capacity(R"(- {a: 0, b: 1, c: 2, d: 3} + EXPECT_EQ(2, estimate_tree_capacity(R"([])")); + EXPECT_EQ(2, estimate_tree_capacity(R"([a])")); + EXPECT_EQ(3, estimate_tree_capacity(R"([a, b])")); + EXPECT_EQ(4, estimate_tree_capacity(R"([a, b, c])")); + EXPECT_EQ(5, estimate_tree_capacity(R"([a, b, c, d])")); + EXPECT_EQ(2, estimate_tree_capacity(R"({})")); + EXPECT_EQ(2, estimate_tree_capacity(R"({a: 0})")); + EXPECT_EQ(3, estimate_tree_capacity(R"({a: 0, b: 1})")); + EXPECT_EQ(4, estimate_tree_capacity(R"({a: 0, b: 1, c: 2})")); + EXPECT_EQ(5, estimate_tree_capacity(R"({a: 0, b: 1, c: 2, d: 3})")); + EXPECT_EQ(9, estimate_tree_capacity(R"(- {a: 0, b: 1, c: 2, d: 3} - a - b - c @@ -444,8 +442,8 @@ TEST(parse_in_place, overloads) EXPECT_EQ(tree["c"].val(), "d"); EXPECT_EQ(tree["e"].is_map(), true); EXPECT_EQ(tree["e"].has_children(), false); - size_t e = tree.find_child(tree.root_id(), "e"); - ASSERT_NE(e, (size_t)NONE); + id_type e = tree.find_child(tree.root_id(), "e"); + ASSERT_NE(e, (id_type)NONE); parse_in_place(src1_, &tree, e); EXPECT_EQ(tree["c"].val(), "d"); EXPECT_EQ(tree["e"].has_children(), true); @@ -456,8 +454,8 @@ TEST(parse_in_place, overloads) EXPECT_EQ(tree["c"].val(), "d"); EXPECT_EQ(tree["e"].is_map(), true); EXPECT_EQ(tree["e"].has_children(), false); - size_t e = tree.find_child(tree.root_id(), "e"); - ASSERT_NE(e, (size_t)NONE); + id_type e = tree.find_child(tree.root_id(), "e"); + ASSERT_NE(e, (id_type)NONE); parse_in_place("src1", src1_, &tree, e); EXPECT_EQ(tree["c"].val(), "d"); EXPECT_EQ(tree["e"].has_children(), true); @@ -493,27 +491,27 @@ TEST(parse_in_arena, overloads) Tree tree = parse_in_arena(src1); EXPECT_EQ(tree["a"].val(), "b"); EXPECT_FALSE(tree.arena().empty()); - EXPECT_NE(tree.arena().find(src1), (size_t)npos); + EXPECT_NE(tree.arena().find(src1), npos); } { Tree tree = parse_in_arena("src1", src1); EXPECT_EQ(tree["a"].val(), "b"); EXPECT_FALSE(tree.arena().empty()); - EXPECT_NE(tree.arena().find(src1), (size_t)npos); + EXPECT_NE(tree.arena().find(src1), npos); } { Tree tree; parse_in_arena(src1, &tree); EXPECT_EQ(tree["a"].val(), "b"); EXPECT_FALSE(tree.arena().empty()); - EXPECT_NE(tree.arena().find(src1), (size_t)npos); + EXPECT_NE(tree.arena().find(src1), npos); } { Tree tree; parse_in_arena("src1", src1, &tree); EXPECT_EQ(tree["a"].val(), "b"); EXPECT_FALSE(tree.arena().empty()); - EXPECT_NE(tree.arena().find(src1), (size_t)npos); + EXPECT_NE(tree.arena().find(src1), npos); } { Tree tree = parse_in_arena(src2); @@ -521,16 +519,16 @@ TEST(parse_in_arena, overloads) EXPECT_EQ(tree["e"].is_map(), true); EXPECT_EQ(tree["e"].has_children(), false); EXPECT_FALSE(tree.arena().empty()); - EXPECT_NE(tree.arena().find(src2), (size_t)npos); - size_t e = tree.find_child(tree.root_id(), "e"); - ASSERT_NE(e, (size_t)NONE); + EXPECT_NE(tree.arena().find(src2), npos); + id_type e = tree.find_child(tree.root_id(), "e"); + ASSERT_NE(e, (id_type)NONE); parse_in_arena(src1, &tree, e); EXPECT_EQ(tree["c"].val(), "d"); EXPECT_EQ(tree["e"].has_children(), true); EXPECT_EQ(tree["e"]["a"].val(), "b"); EXPECT_FALSE(tree.arena().empty()); - EXPECT_NE(tree.arena().find(src1), (size_t)npos); - EXPECT_NE(tree.arena().find(src2), (size_t)npos); + EXPECT_NE(tree.arena().find(src1), npos); + EXPECT_NE(tree.arena().find(src2), npos); } { Tree tree = parse_in_arena("src2", src2); @@ -538,16 +536,16 @@ TEST(parse_in_arena, overloads) EXPECT_EQ(tree["e"].is_map(), true); EXPECT_EQ(tree["e"].has_children(), false); EXPECT_FALSE(tree.arena().empty()); - EXPECT_NE(tree.arena().find(src2), (size_t)npos); - size_t e = tree.find_child(tree.root_id(), "e"); - ASSERT_NE(e, (size_t)NONE); + EXPECT_NE(tree.arena().find(src2), npos); + id_type e = tree.find_child(tree.root_id(), "e"); + ASSERT_NE(e, (id_type)NONE); parse_in_arena("src1", src1, &tree, e); EXPECT_EQ(tree["c"].val(), "d"); EXPECT_EQ(tree["e"].has_children(), true); EXPECT_EQ(tree["e"]["a"].val(), "b"); EXPECT_FALSE(tree.arena().empty()); - EXPECT_NE(tree.arena().find(src1), (size_t)npos); - EXPECT_NE(tree.arena().find(src2), (size_t)npos); + EXPECT_NE(tree.arena().find(src1), npos); + EXPECT_NE(tree.arena().find(src2), npos); } { Tree tree = parse_in_arena(src2); @@ -555,14 +553,14 @@ TEST(parse_in_arena, overloads) EXPECT_EQ(tree["e"].is_map(), true); EXPECT_EQ(tree["e"].has_children(), false); EXPECT_FALSE(tree.arena().empty()); - EXPECT_NE(tree.arena().find(src2), (size_t)npos); + EXPECT_NE(tree.arena().find(src2), npos); parse_in_arena(src1, tree["e"]); EXPECT_EQ(tree["c"].val(), "d"); EXPECT_EQ(tree["e"].has_children(), true); EXPECT_EQ(tree["e"]["a"].val(), "b"); EXPECT_FALSE(tree.arena().empty()); - EXPECT_NE(tree.arena().find(src1), (size_t)npos); - EXPECT_NE(tree.arena().find(src2), (size_t)npos); + EXPECT_NE(tree.arena().find(src1), npos); + EXPECT_NE(tree.arena().find(src2), npos); } { Tree tree = parse_in_arena("src2", src2); @@ -570,14 +568,14 @@ TEST(parse_in_arena, overloads) EXPECT_EQ(tree["e"].is_map(), true); EXPECT_EQ(tree["e"].has_children(), false); EXPECT_FALSE(tree.arena().empty()); - EXPECT_NE(tree.arena().find(src2), (size_t)npos); + EXPECT_NE(tree.arena().find(src2), npos); parse_in_arena("src1", src1, tree["e"]); EXPECT_EQ(tree["c"].val(), "d"); EXPECT_EQ(tree["e"].has_children(), true); EXPECT_EQ(tree["e"]["a"].val(), "b"); EXPECT_FALSE(tree.arena().empty()); - EXPECT_NE(tree.arena().find(src1), (size_t)npos); - EXPECT_NE(tree.arena().find(src2), (size_t)npos); + EXPECT_NE(tree.arena().find(src1), npos); + EXPECT_NE(tree.arena().find(src2), npos); } } @@ -1984,7 +1982,7 @@ TEST_F(ParseToMapFlowTest, map_flow__to__map_flow__root) { NodeRef dst = dst_map_flow.rootref(); parse_in_arena(to_csubstr(map_flow), dst); - const Tree expected = parse_in_arena("map: flow\nyes: it is\n"); + const Tree expected = parse_in_arena("{map: flow, yes: it is}"); _c4dbg_tree("expected", expected); _c4dbg_tree("actual", dst_map_flow); test_compare(dst_map_flow, expected); @@ -1994,7 +1992,7 @@ TEST_F(ParseToMapFlowTest, map_flow__to__map_flow__new_child) { NodeRef dst = dst_map_flow.rootref().append_child({KEY, "dst"}); parse_in_arena(to_csubstr(map_flow), dst); - const Tree expected = parse_in_arena("dst:\n map: flow\n yes: it is\n"); + const Tree expected = parse_in_arena("{dst: {map: flow, yes: it is}}"); _c4dbg_tree("expected", expected); _c4dbg_tree("actual", dst_map_flow); test_compare(dst_map_flow, expected); diff --git a/test/test_seq.cpp b/test/test_seq.cpp index 3436c6bde..3dfd48690 100644 --- a/test/test_seq.cpp +++ b/test/test_seq.cpp @@ -93,7 +93,7 @@ TEST(simple_seq, deeply_nested_to_cover_parse_stack_resizes) [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[0, 1, 2, 3, 4, 5, 6, 7]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] )"; Tree t = parse_in_arena(yaml); - size_t id = t.root_id(); + id_type id = t.root_id(); while(t.has_children(id)) id = t.first_child(id); ASSERT_TRUE(t.cref(id).has_parent()); diff --git a/test/test_serialize.cpp b/test/test_serialize.cpp index a76d5f191..5cb3b9361 100644 --- a/test/test_serialize.cpp +++ b/test/test_serialize.cpp @@ -495,23 +495,23 @@ TEST(serialize, create_anchor_ref_trip) )"; Tree tree; - const size_t root_id = tree.root_id(); + const id_type root_id = tree.root_id(); tree.to_map(root_id); - const size_t anchor_list_id = tree.append_child(root_id); + const id_type anchor_list_id = tree.append_child(root_id); tree.to_seq(anchor_list_id, "anchor_objects"); - const size_t anchor_map0 = tree.append_child(anchor_list_id); + const id_type anchor_map0 = tree.append_child(anchor_list_id); tree.to_map(anchor_map0); tree.set_val_anchor(anchor_map0, "id001"); - const size_t anchor_elem0 = tree.append_child(anchor_map0); + const id_type anchor_elem0 = tree.append_child(anchor_map0); tree.to_keyval(anchor_elem0, "name", "a_name"); - const size_t ref_list_id = tree.append_child(root_id); + const id_type ref_list_id = tree.append_child(root_id); tree.to_seq(ref_list_id, "reference_list"); - const size_t elem0_id = tree.append_child(ref_list_id); + const id_type elem0_id = tree.append_child(ref_list_id); tree.set_val_ref(elem0_id, "id001"); EXPECT_EQ(emitrs_yaml(tree), expected_yaml); diff --git a/test/test_stack.cpp b/test/test_stack.cpp index f7e0b9444..ce87b4df6 100644 --- a/test/test_stack.cpp +++ b/test/test_stack.cpp @@ -13,25 +13,26 @@ namespace c4 { namespace yml { C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH("-Wold-style-cast") +C4_SUPPRESS_WARNING_GCC("-Wuseless-cast") namespace detail { -template +template using istack = stack; using ip = int const*; -template +template void to_large(istack *s) { - size_t sz = 3u * N; + id_type sz = 3u * N; s->reserve(sz); EXPECT_NE(s->m_stack, s->m_buf); } -template +template void fill_to_large(istack *s) { - size_t sz = 3u * N; + id_type sz = 3u * N; s->reserve(sz); for(int i = 0, e = (int)sz; i < e; ++i) s->push(i); @@ -43,18 +44,18 @@ void fill_to_large(istack *s) //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -template +template void test_stack_small_vs_large() { istack s; - for(size_t i = 0; i < N; ++i) + for(id_type i = 0; i < N; ++i) { s.push(static_cast(i)); EXPECT_EQ(s.size(), i+1); } EXPECT_EQ(s.size(), N); EXPECT_EQ(s.m_stack, s.m_buf); - for(size_t i = 0; i < N; ++i) + for(id_type i = 0; i < N; ++i) { EXPECT_EQ(s.top(N-1-i), static_cast(i)); } @@ -63,7 +64,7 @@ void test_stack_small_vs_large() EXPECT_EQ(s.top(), static_cast(N)); EXPECT_EQ(s.pop(), static_cast(N)); EXPECT_NE(s.m_stack, s.m_buf); - for(size_t i = 0; i < N; ++i) + for(id_type i = 0; i < N; ++i) { EXPECT_EQ(s.top(N-1-i), static_cast(i)); } @@ -82,13 +83,13 @@ TEST(stack, small_vs_large) //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -template +template void test_copy_ctor() { istack src; // small - for(size_t i = 0; i < N; ++i) + for(id_type i = 0; i < N; ++i) { src.push((int)i); } @@ -103,7 +104,7 @@ void test_copy_ctor() } // large - for(size_t i = 0; i < 2*N; ++i) + for(id_type i = 0; i < 2*N; ++i) { src.push((int)i); // large } @@ -131,34 +132,34 @@ TEST(stack, copy_ctor) //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -template +template void test_move_ctor() { istack src; // small - for(size_t i = 0; i < N; ++i) + for(id_type i = 0; i < N; ++i) { src.push((int)i); } EXPECT_EQ(src.m_stack, src.m_buf); ip b = src.begin(); - size_t sz = src.size(); + id_type sz = src.size(); { istack dst(std::move(src)); EXPECT_EQ(dst.size(), sz); EXPECT_EQ(dst.m_stack, dst.m_buf); EXPECT_NE(dst.m_stack, b); - EXPECT_EQ(src.size(), size_t(0)); + EXPECT_EQ(src.size(), id_type(0)); EXPECT_EQ((ip)src.begin(), src.m_buf); EXPECT_NE((ip)dst.begin(), b); } - EXPECT_EQ(src.size(), size_t(0)); + EXPECT_EQ(src.size(), id_type(0)); EXPECT_EQ(src.capacity(), N); EXPECT_EQ(src.m_stack, src.m_buf); // redo - for(size_t i = 0; i < N; ++i) + for(id_type i = 0; i < N; ++i) { src.push((int)i); } @@ -166,7 +167,7 @@ void test_move_ctor() EXPECT_EQ(src.capacity(), N); EXPECT_EQ(src.m_stack, src.m_buf); // large - for(size_t i = 0; i < 2*N; ++i) + for(id_type i = 0; i < 2*N; ++i) { src.push((int)i); // large } @@ -180,7 +181,7 @@ void test_move_ctor() EXPECT_NE(dst.m_stack, dst.m_buf); EXPECT_EQ(dst.m_stack, b); EXPECT_EQ(src.capacity(), N); - EXPECT_EQ(src.size(), size_t(0)); + EXPECT_EQ(src.size(), id_type(0)); EXPECT_EQ((ip)src.begin(), src.m_buf); EXPECT_EQ((ip)dst.begin(), b); } @@ -198,19 +199,19 @@ TEST(stack, move_ctor) //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -template +template void test_copy_assign() { istack dst; istack srcs; // small istack srcl; // large - for(size_t i = 0; i < N; ++i) + for(id_type i = 0; i < N; ++i) { srcs.push((int)i); // small srcl.push((int)i); // large } - for(size_t i = 0; i < 2*N; ++i) + for(id_type i = 0; i < 2*N; ++i) { srcl.push((int)i); // large } @@ -257,17 +258,17 @@ TEST(stack, copy_assign) //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -template +template void test_move_assign() { istack srcs, srcl, dst; - for(size_t i = 0; i < N; ++i) + for(id_type i = 0; i < N; ++i) { srcs.push((int)i); // small srcl.push((int)i); // large } - for(size_t i = 0; i < 2*N; ++i) + for(id_type i = 0; i < 2*N; ++i) { srcl.push((int)i); // large } @@ -275,7 +276,7 @@ void test_move_assign() EXPECT_NE(srcl.m_stack, srcl.m_buf); ip bs = srcs.begin()/*, bl = srcl.begin()*/; - size_t szs = srcs.size(), szl = srcl.size(); + id_type szs = srcs.size(), szl = srcl.size(); for(int i = 0; i < 10; ++i) { @@ -287,7 +288,7 @@ void test_move_assign() dst = std::move(srcs); EXPECT_TRUE(srcs.empty()); EXPECT_FALSE(dst.empty()); - EXPECT_EQ(srcs.size(), size_t(0)); + EXPECT_EQ(srcs.size(), id_type(0)); EXPECT_EQ(srcs.capacity(), N); EXPECT_EQ(dst.size(), szs); EXPECT_EQ(dst.m_stack, dst.m_buf); @@ -309,7 +310,7 @@ void test_move_assign() dst = std::move(srcl); EXPECT_TRUE(srcl.empty()); EXPECT_FALSE(dst.empty()); - EXPECT_EQ(srcl.size(), size_t(0)); + EXPECT_EQ(srcl.size(), id_type(0)); EXPECT_EQ(srcl.capacity(), N); EXPECT_EQ(dst.size(), szl); EXPECT_NE(dst.m_stack, dst.m_buf); @@ -332,7 +333,7 @@ TEST(stack, move_assign) //----------------------------------------------------------------------------- -template +template void test_callbacks_default_ctor() { CallbacksTester td; @@ -349,7 +350,7 @@ TEST(stack, callbacks_default_ctor) test_callbacks_default_ctor<128>(); } -template +template void test_callbacks_ctor() { CallbacksTester td; @@ -370,7 +371,7 @@ TEST(stack, callbacks_ctor) //----------------------------------------------------------------------------- // copy ctor -template +template void test_callbacks_copy_ctor_small() { CallbacksTester ts("src"); @@ -397,7 +398,7 @@ void test_callbacks_copy_ctor_small() } } -template +template void test_callbacks_copy_ctor_large_unfilled() { CallbacksTester ts("src"); @@ -422,7 +423,7 @@ void test_callbacks_copy_ctor_large_unfilled() } } -template +template void test_callbacks_copy_ctor_large_filled() { CallbacksTester ts("src"); @@ -475,7 +476,7 @@ TEST(stack, callbacks_copy_ctor_large_filled) //----------------------------------------------------------------------------- // copy ctor -template +template void test_callbacks_move_ctor_small() { CallbacksTester ts; @@ -493,7 +494,7 @@ void test_callbacks_move_ctor_small() EXPECT_EQ(ts.num_allocs, nbefore); } -template +template void test_callbacks_move_ctor_large_unfilled() { CallbacksTester ts; @@ -512,7 +513,7 @@ void test_callbacks_move_ctor_large_unfilled() EXPECT_EQ(ts.num_allocs, nbefore); } -template +template void test_callbacks_move_ctor_large_filled() { CallbacksTester ts; @@ -559,7 +560,7 @@ TEST(stack, callbacks_move_ctor_large_filled) //----------------------------------------------------------------------------- // copy assign -template +template void test_callbacks_copy_assign_to_empty() { CallbacksTester ts("src"); @@ -590,7 +591,7 @@ TEST(stack, callbacks_copy_assign_to_empty) test_callbacks_copy_assign_to_empty<128>(); } -template +template void test_callbacks_copy_assign_to_nonempty() { CallbacksTester ts("src"); @@ -681,7 +682,7 @@ TEST(stack, callbacks_move_assign_to_empty) test_callbacks_move_assign_to_empty<128>(); } -template +template void test_callbacks_move_assign_to_nonempty() { CallbacksTester ts("src"); @@ -732,7 +733,7 @@ TEST(stack, callbacks_move_assign_to_nonempty) //----------------------------------------------------------------------------- -template +template void test_reserve() { { @@ -777,7 +778,7 @@ TEST(stack, reserve_capacity) } -template +template void grow_to_large__push() { istack s; @@ -792,7 +793,7 @@ void grow_to_large__push() } for(int i = 0; i < NumTimes * ni; ++i) { - EXPECT_EQ(s.bottom((size_t)i), i); + EXPECT_EQ(s.bottom((id_type)i), i); } } @@ -803,7 +804,7 @@ TEST(stack, push_to_large_twice) grow_to_large__push<32, 8>(); } -template +template void grow_to_large__push_top() { istack s; @@ -821,7 +822,7 @@ void grow_to_large__push_top() } for(int i = 0; i < NumTimes * ni; ++i) { - EXPECT_EQ(s.bottom((size_t)i), i); + EXPECT_EQ(s.bottom((id_type)i), i); } } diff --git a/test/test_suite/test_suite_events.cpp b/test/test_suite/test_suite_events.cpp index 82ab5dcf6..d4b33f338 100644 --- a/test/test_suite/test_suite_events.cpp +++ b/test/test_suite/test_suite_events.cpp @@ -103,7 +103,7 @@ struct Scalar OptionalScalar tag = {}; NodeType flags = {}; inline operator bool() const { if(anchor || tag) { RYML_ASSERT(scalar); } return scalar.was_set; } - void add_key_props(Tree *tree, size_t node) const + void add_key_props(Tree *tree, id_type node) const { if(ref) { @@ -132,7 +132,7 @@ struct Scalar tree->_add_flags(node, flags & KEY_STYLE); } } - void add_val_props(Tree *tree, size_t node) const + void add_val_props(Tree *tree, id_type node) const { if(ref) { @@ -303,7 +303,7 @@ bool compare_events(csubstr ref_evts, csubstr emt_evts, bool ignore_container_st void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_) { - struct ParseLevel { size_t tree_node; }; + struct ParseLevel { id_type tree_node; }; detail::stack m_stack = {}; Tree &C4_RESTRICT tree = *tree_; size_t linenum = 0; (void)linenum; @@ -367,7 +367,7 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_) ASSERT_FALSE(key); ASSERT_TRUE(curr); _nfo_logf("seq[{}]: adding child", top.tree_node); - size_t node = tree.append_child(top.tree_node); + id_type node = tree.append_child(top.tree_node); NodeType as_doc = tree.is_stream(top.tree_node) ? DOC : NOTYPE; _nfo_logf("seq[{}]: child={} val='{}' as_doc=", top.tree_node, node, curr.scalar.maybe_get(), as_doc.type_str()); tree.to_val(node, curr.filtered_scalar(&tree), as_doc); @@ -385,7 +385,7 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_) else { _nfo_logf("map[{}]: adding child", top.tree_node); - size_t node = tree.append_child(top.tree_node); + id_type node = tree.append_child(top.tree_node); NodeType as_doc = tree.is_stream(top.tree_node) ? DOC : NOTYPE; _nfo_logf("map[{}]: child={} key='{}' val='{}' as_doc={}", top.tree_node, node, key.scalar.maybe_get(), curr.scalar.maybe_get(), as_doc.type_str()); tree.to_keyval(node, key.filtered_scalar(&tree), curr.filtered_scalar(&tree), as_doc); @@ -411,7 +411,7 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_) { _nfo_logf("node[{}] is seq: set {} as val ref", top.tree_node, alias); ASSERT_FALSE(key); - size_t node = tree.append_child(top.tree_node); + id_type node = tree.append_child(top.tree_node); tree.to_val(node, alias); tree.set_val_ref(node, alias); } @@ -420,7 +420,7 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_) if(key) { _nfo_logf("node[{}] is map and key '{}' is pending: set {} as val ref", top.tree_node, key.scalar.maybe_get(), alias); - size_t node = tree.append_child(top.tree_node); + id_type node = tree.append_child(top.tree_node); tree.to_keyval(node, key.filtered_scalar(&tree), alias); key.add_key_props(&tree, node); tree.set_val_ref(node, alias); @@ -459,7 +459,7 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_) _nfo_log("seq is block"); } parse_anchor_and_tag(more_tokens, &anchor, &tag); - size_t node = tree.root_id(); + id_type node = tree.root_id(); if(m_stack.empty()) { _nfo_log("stack was empty, set root to SEQ"); @@ -469,9 +469,9 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_) } else { - size_t parent = m_stack.top().tree_node; + id_type parent = m_stack.top().tree_node; _nfo_logf("stack was not empty. parent={}", parent); - ASSERT_NE(parent, (size_t)NONE); + ASSERT_NE(parent, (id_type)NONE); if(tree.is_doc(parent) && !(tree.is_seq(parent) || tree.is_map(parent))) { _nfo_logf("set node to parent={}, add DOC", parent); @@ -534,7 +534,7 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_) _nfo_log("map is block"); } parse_anchor_and_tag(more_tokens, &anchor, &tag); - size_t node = tree.root_id(); + id_type node = tree.root_id(); if(m_stack.empty()) { _nfo_log("stack was empty, set root to MAP"); @@ -544,9 +544,9 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_) } else { - size_t parent = m_stack.top().tree_node; + id_type parent = m_stack.top().tree_node; _nfo_logf("stack was not empty. parent={}", parent); - ASSERT_NE(parent, (size_t)NONE); + ASSERT_NE(parent, (id_type)NONE); if(tree.is_doc(parent) && !(tree.is_seq(parent) || tree.is_map(parent))) { _nfo_logf("set node to parent={}, add DOC", parent); @@ -592,7 +592,7 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_) else if(line.begins_with("-SEQ")) { _nfo_logf("popping SEQ, empty={}", m_stack.empty()); - size_t node; + id_type node; if(m_stack.empty()) node = tree.root_id(); else @@ -602,7 +602,7 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_) else if(line.begins_with("-MAP")) { _nfo_logf("popping MAP, empty={}", m_stack.empty()); - size_t node; + id_type node; if(m_stack.empty()) node = tree.root_id(); else @@ -613,7 +613,7 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_) { csubstr rem = line.stripl("+DOC").triml(' '); _nfo_logf("pushing DOC: {}", rem); - size_t node = tree.root_id(); + id_type node = tree.root_id(); auto is_sep = rem.first_of_any("---\n", "--- ", "---\r") || rem.ends_with("---"); ASSERT_EQ(key, false); // for the key to exist, the parent must exist and be a map if(m_stack.empty()) @@ -660,9 +660,9 @@ void parse_events_to_tree(csubstr src, Tree *C4_RESTRICT tree_) } else { - size_t parent = m_stack.top().tree_node; + id_type parent = m_stack.top().tree_node; _nfo_logf("add DOC to parent={}", parent); - ASSERT_NE(parent, (size_t)NONE); + ASSERT_NE(parent, (id_type)NONE); node = tree.append_child(parent); _nfo_logf("child DOC={}", node); tree.to_doc(node); diff --git a/test/test_suite/test_suite_events_emitter.cpp b/test/test_suite/test_suite_events_emitter.cpp index 16f5c2e1f..f52ee6007 100644 --- a/test/test_suite/test_suite_events_emitter.cpp +++ b/test/test_suite/test_suite_events_emitter.cpp @@ -15,12 +15,12 @@ struct EventsEmitter std::string tagbuf; Tree const* C4_RESTRICT m_tree; EventsEmitter(Tree const& tree, substr buf_) : buf(buf_), pos(), m_tree(&tree) {} - void emit_tag(csubstr tag, size_t node); + void emit_tag(csubstr tag, id_type node); void emit_scalar(csubstr val, char openchar); - void emit_key_anchor_tag(size_t node); - void emit_val_anchor_tag(size_t node); - void emit_events(size_t node); - void emit_doc(size_t node); + void emit_key_anchor_tag(id_type node); + void emit_val_anchor_tag(id_type node); + void emit_events(id_type node); + void emit_doc(id_type node); void emit_events(); template C4_ALWAYS_INLINE void pr(const char (&s)[N]) @@ -81,11 +81,11 @@ inline char _ev_scalar_code_val(NodeType t) { return _ev_scalar_code(t & VAL_STYLE); } -inline char _ev_scalar_code_key(Tree const* p, size_t node) +inline char _ev_scalar_code_key(Tree const* p, id_type node) { return _ev_scalar_code(p->_p(node)->m_type & KEY_STYLE); } -inline char _ev_scalar_code_val(Tree const* p, size_t node) +inline char _ev_scalar_code_val(Tree const* p, id_type node) { return _ev_scalar_code(p->_p(node)->m_type & VAL_STYLE); } @@ -152,7 +152,7 @@ void EventsEmitter::emit_scalar(csubstr val, char openchar) pr(val.sub(prev)); // print remaining portion } -void EventsEmitter::emit_tag(csubstr tag, size_t node) +void EventsEmitter::emit_tag(csubstr tag, id_type node) { size_t tagsize = m_tree->resolve_tag(to_substr(tagbuf), tag, node); if(tagsize) @@ -185,7 +185,7 @@ void EventsEmitter::emit_tag(csubstr tag, size_t node) } } -void EventsEmitter::emit_key_anchor_tag(size_t node) +void EventsEmitter::emit_key_anchor_tag(id_type node) { if(m_tree->has_key_anchor(node)) { @@ -199,7 +199,7 @@ void EventsEmitter::emit_key_anchor_tag(size_t node) } } -void EventsEmitter::emit_val_anchor_tag(size_t node) +void EventsEmitter::emit_val_anchor_tag(id_type node) { if(m_tree->has_val_anchor(node)) { @@ -213,7 +213,7 @@ void EventsEmitter::emit_val_anchor_tag(size_t node) } } -void EventsEmitter::emit_events(size_t node) +void EventsEmitter::emit_events(id_type node) { if(m_tree->has_key(node)) { @@ -264,7 +264,7 @@ void EventsEmitter::emit_events(size_t node) pr((m_tree->type(node) & CONTAINER_STYLE_FLOW) ? csubstr("+MAP {}") : csubstr("+MAP")); emit_val_anchor_tag(node); pr('\n'); - for(size_t child = m_tree->first_child(node); child != NONE; child = m_tree->next_sibling(child)) + for(id_type child = m_tree->first_child(node); child != NONE; child = m_tree->next_sibling(child)) emit_events(child); pr("-MAP\n"); } @@ -273,13 +273,13 @@ void EventsEmitter::emit_events(size_t node) pr((m_tree->type(node) & CONTAINER_STYLE_FLOW) ? csubstr("+SEQ []") : csubstr("+SEQ")); emit_val_anchor_tag(node); pr('\n'); - for(size_t child = m_tree->first_child(node); child != NONE; child = m_tree->next_sibling(child)) + for(id_type child = m_tree->first_child(node); child != NONE; child = m_tree->next_sibling(child)) emit_events(child); pr("-SEQ\n"); } } -void EventsEmitter::emit_doc(size_t node) +void EventsEmitter::emit_doc(id_type node) { if(m_tree->type(node) == NOTYPE) return; @@ -308,9 +308,9 @@ void EventsEmitter::emit_events() pr("+STR\n"); if(!m_tree->empty()) { - size_t root = m_tree->root_id(); + id_type root = m_tree->root_id(); if(m_tree->is_stream(root)) - for(size_t node = m_tree->first_child(root); node != NONE; node = m_tree->next_sibling(node)) + for(id_type node = m_tree->first_child(root); node != NONE; node = m_tree->next_sibling(node)) emit_doc(node); else emit_doc(root); diff --git a/test/test_tag_property.cpp b/test/test_tag_property.cpp index e81015809..27469d6fa 100644 --- a/test/test_tag_property.cpp +++ b/test/test_tag_property.cpp @@ -812,14 +812,14 @@ TEST(tags, parsing) TEST(tags, setting) { Tree t; - size_t rid = t.root_id(); + id_type rid = t.root_id(); t.to_map(rid); t.set_val_tag(rid, "!valtag"); EXPECT_EQ(t.val_tag(rid), "!valtag"); // a keymap { - size_t child = t.append_child(rid); + id_type child = t.append_child(rid); t.to_seq(child, "key2"); t.set_key_tag(child, "!keytag"); t.set_val_tag(child, "!valtag2"); @@ -832,7 +832,7 @@ TEST(tags, setting) // a keyseq { - size_t child = t.append_child(rid); + id_type child = t.append_child(rid); t.to_seq(child, "key2"); t.set_key_tag(child, "!keytag"); t.set_val_tag(child, "!valtag2"); @@ -845,7 +845,7 @@ TEST(tags, setting) // a keyval { - size_t child = t.append_child(rid); + id_type child = t.append_child(rid); t.to_keyval(child, "key", "val"); t.set_key_tag(child, "!keytag"); t.set_val_tag(child, "!valtag"); @@ -859,9 +859,9 @@ TEST(tags, setting) // a val { - size_t seqid = t[1].id(); + id_type seqid = t[1].id(); ASSERT_TRUE(t.is_seq(seqid)); - size_t child = t.append_child(seqid); + id_type child = t.append_child(seqid); t.to_val(child, "val"); t.set_val_tag(child, "!valtag"); EXPECT_FALSE(t.has_key(child)); @@ -874,17 +874,17 @@ TEST(tags, setting) TEST(tags, errors) { Tree t = parse_in_arena("{key: val, keymap: {}, keyseq: [val]}"); - size_t keyval = t["keyval"].id(); - size_t keymap = t["keymap"].id(); - size_t keyseq = t["keyseq"].id(); - size_t val = t["keyseq"][0].id(); - size_t empty_keyval = t.append_child(keymap); - size_t empty_val = t.append_child(keyseq); - - ASSERT_NE(keyval, (size_t)npos); - ASSERT_NE(keymap, (size_t)npos); - ASSERT_NE(keyseq, (size_t)npos); - ASSERT_NE(val, (size_t)npos); + id_type keyval = t["keyval"].id(); + id_type keymap = t["keymap"].id(); + id_type keyseq = t["keyseq"].id(); + id_type val = t["keyseq"][0].id(); + id_type empty_keyval = t.append_child(keymap); + id_type empty_val = t.append_child(keyseq); + + ASSERT_NE(keyval, (id_type)npos); + ASSERT_NE(keymap, (id_type)npos); + ASSERT_NE(keyseq, (id_type)npos); + ASSERT_NE(val, (id_type)npos); // cannot get key tag in a node that does not have a key tag EXPECT_FALSE(t.has_key_tag(empty_keyval)); @@ -955,14 +955,14 @@ key: val keymap: {} keyseq: [val] )"); - size_t keyval = t["keyval"].id(); - size_t keymap = t["keymap"].id(); - size_t keyseq = t["keyseq"].id(); - size_t val = t["keyseq"][0].id(); - ASSERT_NE(keyval, (size_t)npos); - ASSERT_NE(keymap, (size_t)npos); - ASSERT_NE(keyseq, (size_t)npos); - ASSERT_NE(val, (size_t)npos); + id_type keyval = t["keyval"].id(); + id_type keymap = t["keymap"].id(); + id_type keyseq = t["keyseq"].id(); + id_type val = t["keyseq"][0].id(); + ASSERT_NE(keyval, (id_type)npos); + ASSERT_NE(keymap, (id_type)npos); + ASSERT_NE(keyseq, (id_type)npos); + ASSERT_NE(val, (id_type)npos); // without leading mark t.set_key_tag(keyseq, "keytag"); diff --git a/test/test_tree.cpp b/test/test_tree.cpp index a6e9cfad5..5e75cf3c5 100644 --- a/test/test_tree.cpp +++ b/test/test_tree.cpp @@ -1363,9 +1363,9 @@ TEST(Tree, is_stream) Tree t = parse_in_arena(R"(--- foo: bar ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t keyval_id = t.first_child(doc_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type keyval_id = t.first_child(doc_id); ConstNodeRef stream = t.ref(stream_id); ConstNodeRef doc = t.ref(doc_id); ConstNodeRef keyval = t.ref(keyval_id); @@ -1403,10 +1403,10 @@ foo: bar --- a scalar ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t keyval_id = t.first_child(doc_id); - const size_t docval_id = t.last_child(stream_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type keyval_id = t.first_child(doc_id); + const id_type docval_id = t.last_child(stream_id); ConstNodeRef stream = t.ref(stream_id); ConstNodeRef doc = t.ref(doc_id); ConstNodeRef keyval = t.ref(keyval_id); @@ -1489,13 +1489,13 @@ seq: [foo, bar] --- a scalar ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t keyval_id = t.first_child(map_id); - const size_t seq_id = t.last_child(doc_id); - const size_t val_id = t.first_child(seq_id); - const size_t docval_id = t.last_child(stream_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type keyval_id = t.first_child(map_id); + const id_type seq_id = t.last_child(doc_id); + const id_type val_id = t.first_child(seq_id); + const id_type docval_id = t.last_child(stream_id); ConstNodeRef stream = t.ref(stream_id); ConstNodeRef doc = t.ref(doc_id); ConstNodeRef map = t.ref(map_id); @@ -1578,13 +1578,13 @@ seq: [foo, bar] --- a scalar ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t keyval_id = t.first_child(map_id); - const size_t seq_id = t.last_child(doc_id); - const size_t val_id = t.first_child(seq_id); - const size_t docval_id = t.last_child(stream_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type keyval_id = t.first_child(map_id); + const id_type seq_id = t.last_child(doc_id); + const id_type val_id = t.first_child(seq_id); + const id_type docval_id = t.last_child(stream_id); ConstNodeRef stream = t.ref(stream_id); ConstNodeRef doc = t.ref(doc_id); ConstNodeRef map = t.ref(map_id); @@ -1667,13 +1667,13 @@ seq: [foo, bar] --- a scalar ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t keyval_id = t.first_child(map_id); - const size_t seq_id = t.last_child(doc_id); - const size_t val_id = t.first_child(seq_id); - const size_t docval_id = t.last_child(stream_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type keyval_id = t.first_child(map_id); + const id_type seq_id = t.last_child(doc_id); + const id_type val_id = t.first_child(seq_id); + const id_type docval_id = t.last_child(stream_id); ConstNodeRef stream = t.ref(stream_id); ConstNodeRef doc = t.ref(doc_id); ConstNodeRef map = t.ref(map_id); @@ -1756,13 +1756,13 @@ seq: [foo, bar] --- a scalar ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t keyval_id = t.first_child(map_id); - const size_t seq_id = t.last_child(doc_id); - const size_t val_id = t.first_child(seq_id); - const size_t docval_id = t.last_child(stream_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type keyval_id = t.first_child(map_id); + const id_type seq_id = t.last_child(doc_id); + const id_type val_id = t.first_child(seq_id); + const id_type docval_id = t.last_child(stream_id); ConstNodeRef stream = t.ref(stream_id); ConstNodeRef doc = t.ref(doc_id); ConstNodeRef map = t.ref(map_id); @@ -1845,13 +1845,13 @@ seq: [foo, bar] --- a scalar ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t keyval_id = t.first_child(map_id); - const size_t seq_id = t.last_child(doc_id); - const size_t val_id = t.first_child(seq_id); - const size_t docval_id = t.last_child(stream_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type keyval_id = t.first_child(map_id); + const id_type seq_id = t.last_child(doc_id); + const id_type val_id = t.first_child(seq_id); + const id_type docval_id = t.last_child(stream_id); ConstNodeRef stream = t.ref(stream_id); ConstNodeRef doc = t.ref(doc_id); ConstNodeRef map = t.ref(map_id); @@ -1933,13 +1933,13 @@ seq: [foo, bar] --- a scalar ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t keyval_id = t.first_child(map_id); - const size_t seq_id = t.last_child(doc_id); - const size_t val_id = t.first_child(seq_id); - const size_t docval_id = t.last_child(stream_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type keyval_id = t.first_child(map_id); + const id_type seq_id = t.last_child(doc_id); + const id_type val_id = t.first_child(seq_id); + const id_type docval_id = t.last_child(stream_id); ConstNodeRef stream = t.ref(stream_id); ConstNodeRef doc = t.ref(doc_id); ConstNodeRef map = t.ref(map_id); @@ -2022,13 +2022,13 @@ seq: [foo, bar] --- a scalar ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t keyval_id = t.first_child(map_id); - const size_t seq_id = t.last_child(doc_id); - const size_t val_id = t.first_child(seq_id); - const size_t docval_id = t.last_child(stream_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type keyval_id = t.first_child(map_id); + const id_type seq_id = t.last_child(doc_id); + const id_type val_id = t.first_child(seq_id); + const id_type docval_id = t.last_child(stream_id); ConstNodeRef stream = t.ref(stream_id); ConstNodeRef doc = t.ref(doc_id); ConstNodeRef map = t.ref(map_id); @@ -2107,15 +2107,15 @@ TEST(Tree, has_key_tag) --- a scalar ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t keyval_id = t.first_child(map_id); - const size_t keyvalnotag_id = t.last_child(map_id); - const size_t seq_id = t.last_child(doc_id); - const size_t val_id = t.first_child(seq_id); - const size_t valnotag_id = t.last_child(seq_id); - const size_t docval_id = t.last_child(stream_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type keyval_id = t.first_child(map_id); + const id_type keyvalnotag_id = t.last_child(map_id); + const id_type seq_id = t.last_child(doc_id); + const id_type val_id = t.first_child(seq_id); + const id_type valnotag_id = t.last_child(seq_id); + const id_type docval_id = t.last_child(stream_id); ConstNodeRef stream = t.ref(stream_id); ConstNodeRef doc = t.ref(doc_id); ConstNodeRef map = t.ref(map_id); @@ -2210,15 +2210,15 @@ seq: !seqtag [!footag foo, bar] --- a scalar ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t keyval_id = t.first_child(map_id); - const size_t keyvalnotag_id = t.last_child(map_id); - const size_t seq_id = t.last_child(doc_id); - const size_t val_id = t.first_child(seq_id); - const size_t valnotag_id = t.last_child(seq_id); - const size_t docval_id = t.last_child(stream_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type keyval_id = t.first_child(map_id); + const id_type keyvalnotag_id = t.last_child(map_id); + const id_type seq_id = t.last_child(doc_id); + const id_type val_id = t.first_child(seq_id); + const id_type valnotag_id = t.last_child(seq_id); + const id_type docval_id = t.last_child(stream_id); ConstNodeRef stream = t.ref(stream_id); ConstNodeRef doc = t.ref(doc_id); ConstNodeRef map = t.ref(map_id); @@ -2311,14 +2311,14 @@ TEST(Tree, has_key_anchor) &mapanchor map: {&keyvalanchor foo: bar, anchor: none} &seqanchor seq: [&valanchor foo, bar] ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t keyval_id = t.first_child(map_id); - const size_t keyvalnoanchor_id = t.last_child(map_id); - const size_t seq_id = t.last_child(doc_id); - const size_t val_id = t.first_child(seq_id); - const size_t valnoanchor_id = t.last_child(seq_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type keyval_id = t.first_child(map_id); + const id_type keyvalnoanchor_id = t.last_child(map_id); + const id_type seq_id = t.last_child(doc_id); + const id_type val_id = t.first_child(seq_id); + const id_type valnoanchor_id = t.last_child(seq_id); ConstNodeRef stream = t.ref(stream_id); ConstNodeRef doc = t.ref(doc_id); ConstNodeRef map = t.ref(map_id); @@ -2404,14 +2404,14 @@ map: &mapanchor {foo: &keyvalanchor bar, anchor: none} seq: &seqanchor [&valanchor foo, bar] ...)"); _c4dbg_tree(t); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t keyval_id = t.first_child(map_id); - const size_t keyvalnoanchor_id = t.last_child(map_id); - const size_t seq_id = t.last_child(doc_id); - const size_t val_id = t.first_child(seq_id); - const size_t valnoanchor_id = t.last_child(seq_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type keyval_id = t.first_child(map_id); + const id_type keyvalnoanchor_id = t.last_child(map_id); + const id_type seq_id = t.last_child(doc_id); + const id_type val_id = t.first_child(seq_id); + const id_type valnoanchor_id = t.last_child(seq_id); ConstNodeRef stream = t.cref(stream_id); ConstNodeRef doc = t.cref(doc_id); ConstNodeRef map = t.cref(map_id); @@ -2502,14 +2502,14 @@ map: &mapanchor {foo: &keyvalanchor bar, anchor: none} &seqanchor seq: [&valanchor foo, bar] ...)"); _c4dbg_tree(t); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t keyval_id = t.first_child(map_id); - const size_t keyvalnoanchor_id = t.last_child(map_id); - const size_t seq_id = t.last_child(doc_id); - const size_t val_id = t.first_child(seq_id); - const size_t valnoanchor_id = t.last_child(seq_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type keyval_id = t.first_child(map_id); + const id_type keyvalnoanchor_id = t.last_child(map_id); + const id_type seq_id = t.last_child(doc_id); + const id_type val_id = t.first_child(seq_id); + const id_type valnoanchor_id = t.last_child(seq_id); ConstNodeRef stream = t.ref(stream_id); ConstNodeRef doc = t.ref(doc_id); ConstNodeRef map = t.ref(map_id); @@ -2591,12 +2591,12 @@ TEST(Tree, is_key_ref) *mapref : {foo: bar, notag: none} *seqref : [foo, bar] ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t keyval_id = t.first_child(map_id); - const size_t seq_id = t.last_child(doc_id); - const size_t val_id = t.first_child(seq_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type keyval_id = t.first_child(map_id); + const id_type seq_id = t.last_child(doc_id); + const id_type val_id = t.first_child(seq_id); ConstNodeRef stream = t.cref(stream_id); ConstNodeRef doc = t.cref(doc_id); ConstNodeRef map = t.cref(map_id); @@ -2665,12 +2665,12 @@ TEST(Tree, is_val_ref) map: {foo: *keyvalref, notag: none} seq: [*valref, bar] ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t keyval_id = t.first_child(map_id); - const size_t seq_id = t.last_child(doc_id); - const size_t val_id = t.first_child(seq_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type keyval_id = t.first_child(map_id); + const id_type seq_id = t.last_child(doc_id); + const id_type val_id = t.first_child(seq_id); ConstNodeRef stream = t.ref(stream_id); ConstNodeRef doc = t.ref(doc_id); ConstNodeRef map = t.ref(map_id); @@ -2743,12 +2743,12 @@ TEST(Tree, is_ref) map: {foo: *keyvalref, notag: none} seq: [*valref, bar] ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t keyval_id = t.first_child(map_id); - const size_t seq_id = t.last_child(doc_id); - const size_t val_id = t.first_child(seq_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type keyval_id = t.first_child(map_id); + const id_type seq_id = t.last_child(doc_id); + const id_type val_id = t.first_child(seq_id); ConstNodeRef stream = t.ref(stream_id); ConstNodeRef doc = t.ref(doc_id); ConstNodeRef map = t.ref(map_id); @@ -2817,9 +2817,9 @@ TEST(Tree, is_key_quoted) "quoted": foo notquoted: bar ...)"); - const size_t map_id = t.first_child(t.root_id()); - const size_t quoted_id = t.first_child(map_id); - const size_t notquoted_id = t.last_child(map_id); + const id_type map_id = t.first_child(t.root_id()); + const id_type quoted_id = t.first_child(map_id); + const id_type notquoted_id = t.last_child(map_id); ConstNodeRef map = t.ref(map_id); ConstNodeRef quoted = t.ref(quoted_id); ConstNodeRef notquoted = t.ref(notquoted_id); @@ -2864,9 +2864,9 @@ TEST(Tree, is_val_quoted) "quoted": "foo" notquoted: bar ...)"); - const size_t map_id = t.first_child(t.root_id()); - const size_t quoted_id = t.first_child(map_id); - const size_t notquoted_id = t.last_child(map_id); + const id_type map_id = t.first_child(t.root_id()); + const id_type quoted_id = t.first_child(map_id); + const id_type notquoted_id = t.last_child(map_id); ConstNodeRef map = t.ref(map_id); ConstNodeRef quoted = t.ref(quoted_id); ConstNodeRef notquoted = t.ref(notquoted_id); @@ -2921,14 +2921,14 @@ quoted5: 'foo' 'quoted6': 'foo' notquoted: bar ...)"); - const size_t map_id = t.first_child(t.root_id()); - const size_t quoted1_id = t.find_child(map_id, "quoted1"); - const size_t quoted2_id = t.find_child(map_id, "quoted2"); - const size_t quoted3_id = t.find_child(map_id, "quoted3"); - const size_t quoted4_id = t.find_child(map_id, "quoted4"); - const size_t quoted5_id = t.find_child(map_id, "quoted5"); - const size_t quoted6_id = t.find_child(map_id, "quoted6"); - const size_t notquoted_id = t.last_child(map_id); + const id_type map_id = t.first_child(t.root_id()); + const id_type quoted1_id = t.find_child(map_id, "quoted1"); + const id_type quoted2_id = t.find_child(map_id, "quoted2"); + const id_type quoted3_id = t.find_child(map_id, "quoted3"); + const id_type quoted4_id = t.find_child(map_id, "quoted4"); + const id_type quoted5_id = t.find_child(map_id, "quoted5"); + const id_type quoted6_id = t.find_child(map_id, "quoted6"); + const id_type notquoted_id = t.last_child(map_id); ConstNodeRef map = t.ref(map_id); ConstNodeRef quoted1 = t.ref(quoted1_id); ConstNodeRef quoted2 = t.ref(quoted2_id); @@ -3007,12 +3007,12 @@ TEST(Tree, parent_is_seq) map: {foo: *keyvalref, notag: none} seq: &seq [*valref, bar] ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t keyval_id = t.first_child(map_id); - const size_t seq_id = t.last_child(doc_id); - const size_t val_id = t.first_child(seq_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type keyval_id = t.first_child(map_id); + const id_type seq_id = t.last_child(doc_id); + const id_type val_id = t.first_child(seq_id); ConstNodeRef doc = t.ref(doc_id); ConstNodeRef map = t.ref(map_id); ConstNodeRef keyval = t.ref(keyval_id); @@ -3065,12 +3065,12 @@ TEST(Tree, parent_is_map) map: {foo: *keyvalref, notag: none} seq: &seq [*valref, bar] ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t keyval_id = t.first_child(map_id); - const size_t seq_id = t.last_child(doc_id); - const size_t val_id = t.first_child(seq_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type keyval_id = t.first_child(map_id); + const id_type seq_id = t.last_child(doc_id); + const id_type val_id = t.first_child(seq_id); ConstNodeRef doc = t.ref(doc_id); ConstNodeRef map = t.ref(map_id); ConstNodeRef keyval = t.ref(keyval_id); @@ -3124,12 +3124,12 @@ TEST(Tree, has_parent) map: {foo: *keyvalref, notag: none} seq: &seq [*valref, bar] ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t keyval_id = t.first_child(map_id); - const size_t seq_id = t.last_child(doc_id); - const size_t val_id = t.first_child(seq_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type keyval_id = t.first_child(map_id); + const id_type seq_id = t.last_child(doc_id); + const id_type val_id = t.first_child(seq_id); ConstNodeRef stream = t.ref(stream_id); ConstNodeRef doc = t.ref(doc_id); ConstNodeRef map = t.ref(map_id); @@ -3189,12 +3189,12 @@ TEST(Tree, num_children) map: {foo: *keyvalref, notag: none} seq: &seq [*valref, bar] ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t keyval_id = t.first_child(map_id); - const size_t seq_id = t.last_child(doc_id); - const size_t val_id = t.first_child(seq_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type keyval_id = t.first_child(map_id); + const id_type seq_id = t.last_child(doc_id); + const id_type val_id = t.first_child(seq_id); ConstNodeRef stream = t.ref(stream_id); ConstNodeRef doc = t.ref(doc_id); ConstNodeRef map = t.ref(map_id); @@ -3238,12 +3238,12 @@ TEST(Tree, child) map: {foo: *keyvalref, notag: none} seq: &seq [*valref, bar] ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t keyval_id = t.first_child(map_id); - const size_t seq_id = t.last_child(doc_id); - const size_t val_id = t.first_child(seq_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type keyval_id = t.first_child(map_id); + const id_type seq_id = t.last_child(doc_id); + const id_type val_id = t.first_child(seq_id); ConstNodeRef stream = t.ref(stream_id); ConstNodeRef doc = t.ref(doc_id); ConstNodeRef map = t.ref(map_id); @@ -3259,9 +3259,9 @@ seq: &seq [*valref, bar] EXPECT_EQ(t.child(stream_id, 0), doc_id); EXPECT_EQ(t.child(doc_id, 0), map_id); EXPECT_EQ(t.child(map_id, 0), keyval_id); - EXPECT_EQ(t.child(keyval_id, 0), (size_t)NONE); + EXPECT_EQ(t.child(keyval_id, 0), (id_type)NONE); EXPECT_EQ(t.child(seq_id, 0), val_id); - EXPECT_EQ(t.child(val_id, 0), (size_t)NONE); + EXPECT_EQ(t.child(val_id, 0), (id_type)NONE); EXPECT_EQ(stream.child(0).id(), t.child(stream_id, 0)); EXPECT_EQ(doc.child(0).id(), t.child(doc_id, 0)); EXPECT_EQ(map.child(0).id(), t.child(map_id, 0)); @@ -3287,20 +3287,20 @@ TEST(Tree, find_child_by_name) map: {foo: *keyvalref, notag: none} seq: &seq [*valref, bar] ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t keyval_id = t.first_child(map_id); - const size_t seq_id = t.last_child(doc_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type keyval_id = t.first_child(map_id); + const id_type seq_id = t.last_child(doc_id); ConstNodeRef doc = t.cref(doc_id); ConstNodeRef map = t.cref(map_id); NodeRef mdoc = t.ref(doc_id); NodeRef mmap = t.ref(map_id); EXPECT_EQ(t.find_child(doc_id, "map"), map_id); EXPECT_EQ(t.find_child(doc_id, "seq"), seq_id); - EXPECT_EQ(t.find_child(doc_id, "..."), (size_t)NONE); + EXPECT_EQ(t.find_child(doc_id, "..."), (id_type)NONE); EXPECT_EQ(t.find_child(map_id, "foo"), keyval_id); - EXPECT_EQ(t.find_child(map_id, "bar"), (size_t)NONE); + EXPECT_EQ(t.find_child(map_id, "bar"), (id_type)NONE); EXPECT_EQ(doc.find_child("map").id(), t.find_child(doc_id, "map")); EXPECT_EQ(doc.find_child("seq").id(), t.find_child(doc_id, "seq")); EXPECT_EQ(doc.find_child("...").id(), t.find_child(doc_id, "...")); @@ -3324,10 +3324,10 @@ TEST(Tree, find_sibling_by_name) map: {foo: *keyvalref, notag: none} seq: &seq [*valref, bar] ...)"); - const size_t stream_id = t.root_id(); - const size_t doc_id = t.first_child(stream_id); - const size_t map_id = t.first_child(doc_id); - const size_t seq_id = t.last_child(doc_id); + const id_type stream_id = t.root_id(); + const id_type doc_id = t.first_child(stream_id); + const id_type map_id = t.first_child(doc_id); + const id_type seq_id = t.last_child(doc_id); ConstNodeRef map = t.cref(map_id); ConstNodeRef seq = t.cref(seq_id); NodeRef mmap = t.ref(map_id); @@ -3335,10 +3335,10 @@ seq: &seq [*valref, bar] // EXPECT_EQ(t.find_sibling(map_id, "map"), map_id); EXPECT_EQ(t.find_sibling(map_id, "seq"), seq_id); - EXPECT_EQ(t.find_sibling(map_id, "..."), (size_t)NONE); + EXPECT_EQ(t.find_sibling(map_id, "..."), (id_type)NONE); EXPECT_EQ(t.find_sibling(seq_id, "map"), map_id); EXPECT_EQ(t.find_sibling(seq_id, "seq"), seq_id); - EXPECT_EQ(t.find_sibling(seq_id, "..."), (size_t)NONE); + EXPECT_EQ(t.find_sibling(seq_id, "..."), (id_type)NONE); // EXPECT_TRUE(t.has_sibling(map_id, "map")); EXPECT_TRUE(t.has_sibling(map_id, "seq")); @@ -3607,31 +3607,31 @@ TEST(Tree, lookup_path) auto lp = t.lookup_path("x"); EXPECT_FALSE(lp); - EXPECT_EQ(lp.target, (size_t)NONE); - EXPECT_EQ(lp.closest, (size_t)NONE); + EXPECT_EQ(lp.target, (id_type)NONE); + EXPECT_EQ(lp.closest, (id_type)NONE); EXPECT_EQ(lp.resolved(), ""); EXPECT_EQ(lp.unresolved(), "x"); lp = t.lookup_path("a.x"); EXPECT_FALSE(lp); - EXPECT_EQ(lp.target, (size_t)NONE); + EXPECT_EQ(lp.target, (id_type)NONE); EXPECT_EQ(lp.closest, 1); EXPECT_EQ(lp.resolved(), "a"); EXPECT_EQ(lp.unresolved(), "x"); lp = t.lookup_path("a.b.x"); EXPECT_FALSE(lp); - EXPECT_EQ(lp.target, (size_t)NONE); + EXPECT_EQ(lp.target, (id_type)NONE); EXPECT_EQ(lp.closest, 2); EXPECT_EQ(lp.resolved(), "a.b"); EXPECT_EQ(lp.unresolved(), "x"); lp = t.lookup_path("a.c.x"); EXPECT_FALSE(lp); - EXPECT_EQ(lp.target, (size_t)NONE); + EXPECT_EQ(lp.target, (id_type)NONE); EXPECT_EQ(lp.closest, 3); EXPECT_EQ(lp.resolved(), "a.c"); EXPECT_EQ(lp.unresolved(), "x"); - size_t sz = t.size(); - EXPECT_EQ(t.lookup_path("x").target, (size_t)NONE); + id_type sz = t.size(); + EXPECT_EQ(t.lookup_path("x").target, (id_type)NONE); EXPECT_EQ(t.lookup_path_or_modify("x", "x"), sz); EXPECT_EQ(t.lookup_path("x").target, sz); EXPECT_EQ(t.val(sz), "x"); @@ -3641,7 +3641,7 @@ TEST(Tree, lookup_path) EXPECT_EQ(t.val(sz), "z"); sz = t.size(); - EXPECT_EQ(t.lookup_path("a.x").target, (size_t)NONE); + EXPECT_EQ(t.lookup_path("a.x").target, (id_type)NONE); EXPECT_EQ(t.lookup_path_or_modify("x", "a.x"), sz); EXPECT_EQ(t.lookup_path("a.x").target, sz); EXPECT_EQ(t.val(sz), "x"); @@ -3651,7 +3651,7 @@ TEST(Tree, lookup_path) EXPECT_EQ(t.val(sz), "z"); sz = t.size(); - EXPECT_EQ(t.lookup_path("a.c.x").target, (size_t)NONE); + EXPECT_EQ(t.lookup_path("a.c.x").target, (id_type)NONE); EXPECT_EQ(t.lookup_path_or_modify("x", "a.c.x"), sz); EXPECT_EQ(t.lookup_path("a.c.x").target, sz); EXPECT_EQ(t.val(sz), "x"); @@ -3679,11 +3679,11 @@ TEST(Tree, lookup_path_or_modify) t.rootref() |= MAP; csubstr bigpath = "newmap.newseq[0].newmap.newseq[0].first"; auto result = t.lookup_path(bigpath); - EXPECT_EQ(result.target, (size_t)NONE); - EXPECT_EQ(result.closest, (size_t)NONE); + EXPECT_EQ(result.target, (id_type)NONE); + EXPECT_EQ(result.closest, (id_type)NONE); EXPECT_EQ(result.resolved(), ""); EXPECT_EQ(result.unresolved(), bigpath); - size_t sz = t.lookup_path_or_modify("x", bigpath); + id_type sz = t.lookup_path_or_modify("x", bigpath); EXPECT_EQ(t.lookup_path(bigpath).target, sz); EXPECT_EQ(t.val(sz), "x"); EXPECT_EQ(t["newmap"]["newseq"].num_children(), 1u); @@ -3693,7 +3693,7 @@ TEST(Tree, lookup_path_or_modify) EXPECT_EQ(t["newmap"]["newseq"][0]["newmap"]["newseq"].num_children(), 1u); EXPECT_EQ(t["newmap"]["newseq"][0]["newmap"]["newseq"][0].is_map(), true); EXPECT_EQ(t["newmap"]["newseq"][0]["newmap"]["newseq"][0]["first"].val(), "x"); - size_t sz2 = t.lookup_path_or_modify("y", bigpath); + id_type sz2 = t.lookup_path_or_modify("y", bigpath); EXPECT_EQ(t["newmap"]["newseq"][0]["newmap"]["newseq"][0]["first"].val(), "y"); EXPECT_EQ(sz2, sz); EXPECT_EQ(t.lookup_path(bigpath).target, sz); @@ -4057,7 +4057,7 @@ doc3 --- doc4 )"); - size_t ir = t.root_id(); + id_type ir = t.root_id(); ASSERT_EQ(t.num_children(ir), 5u); ASSERT_TRUE(t.is_stream(ir)); EXPECT_EQ(t.child(ir, 0), t.doc(0)); @@ -4124,9 +4124,9 @@ TEST(Tree, add_tag_directives) TagDirective{csubstr("!e!"), csubstr("!ey-"), 0u}, }; Tree t; - auto check_up_to = [&](size_t num) + auto check_up_to = [&](id_type num) { - size_t pos = 0; + id_type pos = 0; EXPECT_EQ(t.num_tag_directives(), num); for(TagDirective const& d : t.tag_directives()) { diff --git a/tools/parse_emit.cpp b/tools/parse_emit.cpp index cd8dac4c1..dda9729f9 100644 --- a/tools/parse_emit.cpp +++ b/tools/parse_emit.cpp @@ -15,6 +15,8 @@ using namespace c4; C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH("-Wold-style-cast") +C4_SUPPRESS_WARNING_GCC("-Wuseless-cast") + //----------------------------------------------------------------------------- @@ -89,13 +91,13 @@ int main(int argc, const char *argv[]) } { TS(tree_reserve); - size_t nlines; + yml::id_type cap; { - TS(count_lines); - nlines = to_csubstr(contents).count('\n'); + TS(estimate_capacity); + cap = yml::estimate_tree_capacity(to_csubstr(contents)); } - fprintf(stderr, "reserving #lines=%zu\n", nlines); - tree.reserve(nlines); + fprintf(stderr, "reserving capacity=%zu\n", (size_t)cap); + tree.reserve(cap); } { TS(parse_yml); diff --git a/tools/yaml_events.cpp b/tools/yaml_events.cpp index efa247fc2..edbfae927 100644 --- a/tools/yaml_events.cpp +++ b/tools/yaml_events.cpp @@ -107,7 +107,7 @@ int main(int argc, const char *argv[]) std::string emit_events_from_tree(csubstr filename, substr filecontents) { Tree tree(create_custom_callbacks()); - tree.reserve(filecontents.count('\n')); + tree.reserve(estimate_tree_capacity(filecontents)); parse_in_place(filename, filecontents, &tree); return emit_events_from_tree(tree); }