An easy-to-use data serialization format
int
,double
,string
,bool
,Array
,Reference
- Indentation is not required
- The
;
after the statement is not required
<xxxx>
- Duplicate names are not allowed
- Node:
id: end
- Value:
id = xxx
{}
.
id = a::b::c::id
- just
#include "libczh/czh.hpp"
! - Requires C++ 20
czh::InputMode::file
->str
is a pathczh::InputMode::string
->str
is astd::string
where czh is stored
Czh("example: a = 1; end;", czh::InputMode::string);
- Returns a Node named str
- Similar to
Node::operator[str]
, but it provides a better error message.
- When the Array value's type in czh is not unique, T must be czh::value::Array
auto arr = node["czh"]["any_array"].get<czh::value::Array>();
- When the values under Node are of the same type, use
value_map()
to get astd::map
consisting of all ids and values.
- Returns
std::map<std::string, T>
auto value_map = example["example"]["arrays"].value_map<vector<int>>();
example:
arrays:
a = {1,2,3}
b = {1,2,3}
end
end
node["czh"]["int_array"] = Range(1, 10); // custom container
node["czh"]["int_array"] = std::ranges::views::iota(1,10); // std::ranges
node["czh"]["int_array"] = {1, 2, 3}; // brace-enclosed initializer list
node["czh"]["any_array"] = {false, 1, "2", 3.0};// czh::value::Array
- Add a new Value named
key
whose value isvalue
before the Node namedbefore
. -before
defaults to be empty, which will add at the end. - Returns a reference to the added Node.
example["add"].add("add", "123", "abc");
- Add a new Node named
name
before the Node namedbefore
. - Returns a reference to the added Node.
example.add_node("new", "before");
example["example"].remove();
example["example"].clear();
example["a"].rename("b");
- libczh originally support three writers
Writer | Format |
---|---|
BasicWriter | No Format |
PrettyWriter | Format |
ColorWriter | Format + Highlight(ANSI Escape Code) |
- accept a
Writer
writer::BasicWriter<std::ostream> w{ std::cout };
node.accept(w);
- equal to
BasicWriter
- All we need is to write a class satisfied the following concept.
template<typename T>
concept Writer =
requires(T w)
{
{ w.node_begin(std::string()) };
{ w.node_end() };
{ w.value_begin(std::string()) };
{ w.value(value::Value{}) };
{ w.value_ref_path_set_global() };
{ w.value_ref_path(std::string()) };
{ w.value_ref_id(std::string()) };
{ w.value_array_begin() };
{ w.value_array_value(value::Array::value_type{}) };
{ w.value_array_end(value::Array::value_type{}) };
{ w.value_array_end() };
};
- If you have any questions or suggestions, please submit an issue or email me.
- Email: cao2013zh at 163 dot com
- Any contributions are welcomed, just send a PR.
- libczh is licensed under the Apache-2.0 license