Boost::ptree parser can't read the container from the xml file



I need to make a simple input-output of the XML file. I'm using the boost::ptree.



struct structure
{
std::string str;
int ival;
std::list<bool> bval;

void save(const std::string& filename) {
ptree pt;
pt.put("main.str", str);
pt.put("main.ival", ival);

for (const auto& x : bval)
pt.put("main.bval.b", x);

write_xml(filename, pt);
}

void load(const std::string& filename) {
ptree pt;

read_xml(filename, pt);

str = pt.get("main.str", str);
ival = pt.get("main.ival", ival);

for(auto& v : pt.get_child("main.bval"))
bval.insert(v.second.data());
}
};

int main()
{
structure b, s;
s.str = "abc";
s.ival = 14;
s.bval = { 1, 0, 0, 1, 0, 1, 0, 0, 0, 1 };

try
{
s.save("zxx.xml");

b.load("zxx.xml");
}
catch (std::exception& exc)
{
std::cout << exc.what() << std::endl;
}
return 0;
}


The input doesn't work correctly because only one element of the "bval" write in the file. Also, I don't know how to make the output of this container (bval). Please help!


No comments:

Post a Comment