Skip to content

Expose pugi::xml_node interop and custom node constructor in rfl::xml - #66

Closed
clockblocker wants to merge 2 commits into
mainfrom
xml-pugixml
Closed

clockblocker wants to merge 2 commits into
mainfrom
xml-pugixml

Conversation

@clockblocker

Copy link
Copy Markdown
Owner

Summary

Exposes the underlying pugixml DOM directly in rfl::xml so codebases using pugixml can combine XPath / DOM navigation on complex outer documents with zero-boilerplate reflect-cpp serialization on clean subtrees — with zero new dependencies.

Changes

  • include/rfl/xml/read.hpp:
    • Add rfl::xml::read<T, Ps...>(const pugi::xml_node&) and rfl::xml::read<T, Ps...>(const pugi::xml_document&).
    • Cleanly return rfl::Error on empty nodes / element-less documents, and skip declarations/comments when reading from a node_document.
  • include/rfl/xml/write.hpp:
    • Add rfl::xml::write<_root, Ps...>(obj, pugi::xml_node _parent) and runtime root-name rfl::xml::write<Ps...>(obj, pugi::xml_node _parent, const std::string& _root_name) to splice reflected structs into existing pugixml trees without clobbering siblings/comments (returns the newly appended pugi::xml_node, zero ABI change to Writer).
    • Fix the std::string write(obj, _indent) overload ignoring _indent.
  • include/rfl/xml/Reader.hpp:
    • Implement has_custom_constructor and use_custom_constructor via T::from_xml_node(const pugi::xml_node&) (returning T or rfl::Result<T>), allowing individual messy fields (mixed content, namespaces, XPath) to drop down to pugixml inside an otherwise reflected struct.
    • Fix missing ++i in get_field_from_array.
  • tests/xml/test_pugixml_interop.cpp:
    • End-to-end tests for XPath subtree reads, parse_full document reads, empty-node errors, splicing into existing nodes/documents, from_xml_node custom fields (including mixed content, errors, attribute rejection, move-only types), get_field_from_array / tuple round-trips, and custom indentation.

Verification

  • Built with Ninja (-Wall -Werror) and ran ctest: 58/58 XML tests pass.

…ment overload, guard empty root name, add docs
@clockblocker

Copy link
Copy Markdown
Owner Author

Branch is preserved on fork and showcase/all-lanes (d0f1fca1) as a reference artifact and parked in #117 (Moonshots & Possible Scope Creep).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant