1 // Copyright 2019 Hans Dembinski
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #ifndef BOOST_HISTOGRAM_TEST_UTILITY_SERIALIZATION_HPP
8 #define BOOST_HISTOGRAM_TEST_UTILITY_SERIALIZATION_HPP
10 #include <boost/archive/xml_iarchive.hpp>
11 #include <boost/archive/xml_oarchive.hpp>
12 #include <boost/assert.hpp>
13 #include <boost/config.hpp>
14 #include <boost/core/nvp.hpp>
19 std::string join(const char* a, const char* b) {
20 std::string filename = a;
32 void load_xml(const std::string& filename, T& t) {
33 std::ifstream ifs(filename);
34 BOOST_ASSERT(ifs.is_open());
35 // manually skip XML comments at the beginning of the stream, because of
36 // https://github.com/boostorg/serialization/issues/169
39 ifs.getline(line, 128);
40 BOOST_ASSERT(std::strlen(line) < 127);
41 } while (!ifs.fail() && !ifs.eof() && std::strstr(line, "-->") == nullptr);
42 boost::archive::xml_iarchive ia(ifs);
43 ia >> boost::make_nvp("item", t);
47 void print_xml(const std::string& filename, const T& t) {
48 std::cout << filename << "\n";
49 boost::archive::xml_oarchive oa(std::cout);
50 oa << boost::make_nvp("item", t);
51 std::cout << std::flush;