-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvanced_mixed.cpp
More file actions
34 lines (27 loc) · 1000 Bytes
/
Copy pathadvanced_mixed.cpp
File metadata and controls
34 lines (27 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import std;
import serial_xml;
// A complex example combining multiple features:
// attributes, named tags, iteration, nesting, and escaping.
struct Address {
std::string street;
[[= serial_xml::name{"city_name"}]] std::string city;
int zip_code;
};
struct Employee {
[[ = serial_xml::name{"emp_id"}, = serial_xml::attribute ]] int id;
std::string name;
Address address;
[[= serial_xml::iter{"skill", "skills"}]] std::vector<std::string> skills;
};
struct Department {
[[ = serial_xml::name{"dept_name"}, = serial_xml::attribute ]] std::string name;
[[= serial_xml::name{"team"}]] std::vector<Employee> employees;
};
int main() {
std::vector<Employee> team = {
Employee{1, "Alice", Address{"123 Main St", "Boston", 2128}, {"C++", "Python"}},
Employee{2, "Bob", Address{"456 Oak Ave", "Cambridge", 2140}, {"Rust", "Go"}}};
Department dept{"Engineering", team};
std::print("Combined complex example:\n");
std::print(" {}\n\n", serial_xml::to_xml(dept));
}