kdlpp: C++20 bindings for ckdl

kdlpp is a simple C++20 wrapper around libkdl that interprets the raw parser events and build up a KDL documemnt object model using C++ the classes kdl::Document, kdl::Node, kdl::Value, and kdl::Number.

kdlpp is built together with libkdl by default, assuming you have a sufficiently recent C++ compiler. It makes use of u8string and u8string_view, which were introduced in C++20, for correct UTF-8 support.

The KDL C++20 API

A Brief Tour

Reading

auto txt = u8"node1 \"arg1\" 0xff_ff 0b100 {\n"
           u8"  child-node (f64)0.123\n"
           u8"}\n"
           u8"node2 1 2; (#the-end)node3 null";
kdl::Document doc = kdl::parse(txt);
kdl::Node const& n1 = doc.nodes()[0];
ASSERT(n1.name() == u8"node1");
ASSERT(!n1.type_annotation().has_value());
ASSERT(n1.args().size() == 3 && n1.args()[2] == 4);
ASSERT(n1.properties().empty());
kdl::Node const& child1 = n1.children()[0];
ASSERT(child1.args()[0].as<double>() - 0.123 < 1e-7);
ASSERT(doc.nodes()[1].args().size() == 2);
ASSERT(doc.nodes()[2].type_annotation() == u8"#the-end");
ASSERT(doc.nodes()[2].args()[0].type() == kdl::Type::Null);

Writing

auto doc = kdl::Document{
    kdl::Node{u8"node1", {u8"argument 1", 2, {}},
                         {{u8"node1-prop", 0xffff}},
                         {
                            kdl::Node{u8"child1"},
                            kdl::Node{u8"child2-type", u8"child2",
                                {}, {{u8"child2-prop", true}}, {}}
                         }},
    kdl::Node{u8"node2", {u8"arg1", u8"arg2"},
                         {{u8"some-property", u8"foo"}},
                         {
                            kdl::Node{u8"child3"}
                         }}
};
std::u8string expected =
    u8"node1 \"argument 1\" 2 null node1-prop=65535 {\n"
    u8"    child1\n"
    u8"    (child2-type)child2 child2-prop=true\n"
    u8"}\n"
    u8"node2 \"arg1\" \"arg2\" some-property=\"foo\" {\n"
    u8"    child3\n"
    u8"}\n";

ASSERT(doc.to_string() == expected);

API

#include <kdlpp.h>

For the actual API, please consult the header file, kdlpp.h, directly.