10 #ifndef DtXmlFileIo_H_
11 #define DtXmlFileIo_H_
15 #include <boost/archive/xml_iarchive.hpp>
16 #include <boost/archive/xml_oarchive.hpp>
21 #include <boost/iostreams/device/mapped_file.hpp>
22 #include <boost/iostreams/stream.hpp>
39 static bool write(
const std::string& filePath,
const T& t,
const std::string& tagName =
"Record")
44 std::string tmpPath = filePath +
".tmp";
48 std::ofstream ofs(tmpPath.c_str());
55 boost::archive::xml_oarchive oa(ofs);
56 oa << boost::serialization::make_nvp(tagName.c_str(), t);
61 std::remove(filePath.c_str());
62 if(std::rename(tmpPath.c_str(), filePath.c_str()) != 0)
64 std::remove(tmpPath.c_str());
70 std::remove(tmpPath.c_str());
81 static bool read(
const std::string& filePath, T& t,
const std::string& tagName =
"Record")
86 std::ifstream ifs(filePath.c_str());
93 boost::archive::xml_iarchive ia(ifs);
95 ia >> boost::serialization::make_nvp(tagName.c_str(), t);
97 catch (boost::archive::archive_exception& ex)
99 std::cerr <<
"Archive Exception during deserializing:" << filePath << std::endl;
100 std::cerr << ex.what() << std::endl;
Contains DLL export macros.
static bool read(const std::string &filePath, T &t, const std::string &tagName="Record")
Definition: DtXmlFileIo.h:81
A DtXmlFileIo has the static functions for reading and writing to an XML archive. ...
Definition: DtXmlFileIo.h:30
#define DT_DLL_MAKARCHIVES
Definition: makArchives.h:31
static bool write(const std::string &filePath, const T &t, const std::string &tagName="Record")
Definition: DtXmlFileIo.h:39